/** * Miscellaneous utilities module * * @module misc * * @example * Import misc utilities: * ```typescript * import { log, error, delay, getConfig, getCallerName } from '@vvlad1973/utils'; * ``` */ /** * Configuration object with optional redirect */ export interface Config { redirect?: string; fileName?: string; [key: string]: any; } /** * Configuration item with environment variable support */ export interface ConfigItem { env?: string; [key: string]: any; } /** * Logs a message to console * * @param message - Message to log * * @example * ```typescript * log('Application started'); * ``` */ export declare function log(message: string): void; /** * Logs an error message to console * * @param message - Error message to log * * @example * ```typescript * error('Something went wrong'); * ``` */ export declare function error(message: string): void; /** * Creates a promise that resolves after a specified delay * * @param ms - Milliseconds to delay * @returns Promise that resolves after the delay * @throws {Error} If ms is not a non-negative finite number * * @example * ```typescript * await delay(1000); // Wait 1 second * ``` */ export declare function delay(ms: number): Promise; /** * Gets the name of the calling function from the stack trace * * @param level - Stack level (optional, for automatic mode leave undefined) * @returns Name of the calling function or 'anonymous' * * @example * ```typescript * function myFunction() { * const caller = getCallerName(); * console.log(caller); // 'myFunction' * } * ``` */ export declare function getCallerName(level?: number): string; /** * Loads configuration from standard config files * * @param root - Root directory to search for config * @param scope - Array of config file paths to try * @param removeComments - Whether to remove comments from JSON * @returns Promise resolving to config object or undefined * * @example * ```typescript * const config = await getConfig('./'); * ``` */ export declare function getConfig(root?: string, scope?: string[], removeComments?: boolean): Promise; /** * Checks if a value exists in an enum object * * @template T - Enum type * @param value - Value to check * @param enumObject - Enum object to check against * @returns True if value exists in enum * * @example * ```typescript * enum Status { Active = 'active', Inactive = 'inactive' } * checkEnumValue('active', Status); // true * checkEnumValue('unknown', Status); // false * ``` */ export declare function checkEnumValue>(value: any, enumObject: T): boolean; /** * Gets a configuration item value, supporting environment variables * * @param configItem - Config item (string or object with env property) * @param defaultValue - Default value if not found * @returns Config value or default * * @example * ```typescript * getConfigItem({ env: 'DATABASE_URL' }, 'localhost'); * getConfigItem('direct-value'); * ``` */ export declare function getConfigItem(configItem: string | ConfigItem, defaultValue?: string): string; /** * Substitutes environment variables in a string * * Supports the following bash-like patterns: * - `${VAR_NAME}` - substitutes with environment variable value or empty string if not set * - `${VAR_NAME:-default}` - use default if variable is unset or empty * - `${VAR_NAME-default}` - use default if variable is unset (empty string is kept) * - `${VAR_NAME:=default}` - set and use default if variable is unset or empty * - `${VAR_NAME=default}` - set and use default if variable is unset (empty string is kept) * - `${VAR_NAME:?error}` - throw error if variable is unset or empty * - `${VAR_NAME?error}` - throw error if variable is unset (empty string is allowed) * - `${VAR_NAME:+alternate}` - use alternate if variable is set and non-empty * - `${VAR_NAME+alternate}` - use alternate if variable is set (even if empty) * * @param template - String template with environment variable placeholders * @returns String with substituted environment variables * @throws {Error} If using :? or ? operator and variable is not set * * @example * ```typescript * // Basic substitution * envSubst('User home: ${HOME}'); * // returns: "User home: /home/user" * * // Use default if unset or empty (:-) * envSubst('Database: ${DB_HOST:-localhost}'); * // returns: "Database: localhost" (if DB_HOST not set or empty) * * // Use default if unset only (-) * process.env.EMPTY = ''; * envSubst('Value: ${EMPTY-default}'); * // returns: "Value: " (empty string is kept) * * // Set and use default (:=) * envSubst('Port: ${PORT:=8080}'); * // returns: "Port: 8080" and sets process.env.PORT = '8080' * * // Use alternate if set (:+) * process.env.DEBUG = 'true'; * envSubst('Run ${DEBUG:+--verbose}'); * // returns: "Run --verbose" * * // Throw error if not set (:?) * envSubst('Required: ${REQUIRED_VAR:?Variable is required}'); * // throws Error: "REQUIRED_VAR: Variable is required" * ``` */ export declare function envSubst(template: string): string;