/** * Shared Common Patterns Utility * * Consolidates the most frequently repeated small patterns * to eliminate final DRY opportunities across the codebase. */ /** * Common logging patterns */ export declare const logging: { /** * Standardized debug logging */ debug: (message: string, ...args: any[]) => void; /** * Standardized info logging */ info: (message: string, ...args: any[]) => void; /** * Standardized warning logging */ warn: (message: string, ...args: any[]) => void; /** * Standardized error logging */ error: (message: string, error?: any) => void; /** * Standardized success logging */ success: (message: string, ...args: any[]) => void; }; /** * Common validation patterns */ export declare const validation: { /** * Check if value is defined */ isDefined: (value: T | undefined) => value is T; /** * Check if string is not empty */ nonEmpty: (value: string | null | undefined) => boolean; /** * Check if array has elements */ hasElements: (array: T[] | null | undefined) => boolean; /** * Check if object has properties */ hasProperties: (obj: object | null | undefined) => boolean; /** * Validate string length */ validLength: (str: string, min: number, max?: number) => boolean; /** * Validate number range */ inRange: (num: number, min: number, max: number) => boolean; }; /** * Common async patterns */ export declare const asyncCommon: { /** * Create resolved promise */ resolved: (value: T) => Promise; /** * Create rejected promise with error */ rejected: (message: string, code?: string) => Promise; /** * Create rejected promise with any type */ rejectedAny: (error: any) => Promise; /** * Execute with fallback */ withFallback: (primary: () => Promise, fallback: () => Promise) => Promise; /** * Wait for specified time */ wait: (ms: number) => Promise; }; /** * Common object patterns */ export declare const objects: { /** * Deep clone object */ clone: (obj: T) => T; /** * Merge objects */ merge: (...objects: T[]) => T; /** * Pick properties from object */ pick: (obj: T, keys: K[]) => Pick; /** * Omit properties from object */ omit: (obj: T, keys: K[]) => Omit; }; /** * Common array patterns */ export declare const arrays: { /** * Remove duplicates from array */ unique: (array: T[]) => T[]; /** * Group array by key */ groupBy: (array: T[], key: K) => Record; /** * Check if array contains value */ includes: (array: T[], value: T) => boolean; /** * Find first matching item */ find: (array: T[], predicate: (item: T) => boolean) => T | undefined; }; /** * Common string patterns */ export declare const strings: { /** * Capitalize first letter */ capitalize: (str: string) => string; /** * Convert to camelCase */ camelCase: (str: string) => string; /** * Convert to kebab-case */ kebabCase: (str: string) => string; /** * Truncate string with ellipsis */ truncate: (str: string, maxLength: number) => string; }; /** * Common type utilities */ export declare const types: { /** * Check if value is a string */ isString: (value: any) => value is string; /** * Check if value is a number */ isNumber: (value: any) => value is number; /** * Check if value is a boolean */ isBoolean: (value: any) => value is boolean; /** * Check if value is an object */ isObject: (value: any) => value is object; /** * Check if value is an array */ isArray: (value: any) => value is any[]; /** * Check if value is a function */ isFunction: (value: any) => value is Function; }; /** * Common conditional patterns */ export declare const conditionals: { /** * Execute function if condition is true */ ifTrue: (condition: boolean, fn: () => T, fallback: T) => T; /** * Execute function if value is defined */ ifDefined: (value: T | undefined, fn: (val: T) => R, fallback: R) => R; /** * Execute function based on string comparison */ when: (value: string, cases: Record T>, fallback: () => T) => T; }; /** * Common performance patterns */ export declare const performance: { /** * Create a performance monitor */ monitor: (name: string) => { end: () => number; }; /** * Create a simple profiler */ profile: (name: string, fn: () => Promise) => Promise<{ result: T; duration: number; }>; }; /** * Common environment patterns */ export declare const environment: { /** * Get environment variable with default */ getVar: (name: string, defaultValue?: string) => string; /** * Check if running in development */ isDev: () => boolean; /** * Check if running in production */ isProd: () => boolean; /** * Check if running in test */ isTest: () => boolean; }; export declare const common: { logging: { /** * Standardized debug logging */ debug: (message: string, ...args: any[]) => void; /** * Standardized info logging */ info: (message: string, ...args: any[]) => void; /** * Standardized warning logging */ warn: (message: string, ...args: any[]) => void; /** * Standardized error logging */ error: (message: string, error?: any) => void; /** * Standardized success logging */ success: (message: string, ...args: any[]) => void; }; validation: { /** * Check if value is defined */ isDefined: (value: T | undefined) => value is T; /** * Check if string is not empty */ nonEmpty: (value: string | null | undefined) => boolean; /** * Check if array has elements */ hasElements: (array: T[] | null | undefined) => boolean; /** * Check if object has properties */ hasProperties: (obj: object | null | undefined) => boolean; /** * Validate string length */ validLength: (str: string, min: number, max?: number) => boolean; /** * Validate number range */ inRange: (num: number, min: number, max: number) => boolean; }; asyncCommon: { /** * Create resolved promise */ resolved: (value: T) => Promise; /** * Create rejected promise with error */ rejected: (message: string, code?: string) => Promise; /** * Create rejected promise with any type */ rejectedAny: (error: any) => Promise; /** * Execute with fallback */ withFallback: (primary: () => Promise, fallback: () => Promise) => Promise; /** * Wait for specified time */ wait: (ms: number) => Promise; }; objects: { /** * Deep clone object */ clone: (obj: T) => T; /** * Merge objects */ merge: (...objects: T[]) => T; /** * Pick properties from object */ pick: (obj: T, keys: K[]) => Pick; /** * Omit properties from object */ omit: (obj: T, keys: K[]) => Omit; }; arrays: { /** * Remove duplicates from array */ unique: (array: T[]) => T[]; /** * Group array by key */ groupBy: (array: T[], key: K) => Record; /** * Check if array contains value */ includes: (array: T[], value: T) => boolean; /** * Find first matching item */ find: (array: T[], predicate: (item: T) => boolean) => T | undefined; }; strings: { /** * Capitalize first letter */ capitalize: (str: string) => string; /** * Convert to camelCase */ camelCase: (str: string) => string; /** * Convert to kebab-case */ kebabCase: (str: string) => string; /** * Truncate string with ellipsis */ truncate: (str: string, maxLength: number) => string; }; types: { /** * Check if value is a string */ isString: (value: any) => value is string; /** * Check if value is a number */ isNumber: (value: any) => value is number; /** * Check if value is a boolean */ isBoolean: (value: any) => value is boolean; /** * Check if value is an object */ isObject: (value: any) => value is object; /** * Check if value is an array */ isArray: (value: any) => value is any[]; /** * Check if value is a function */ isFunction: (value: any) => value is Function; }; conditionals: { /** * Execute function if condition is true */ ifTrue: (condition: boolean, fn: () => T, fallback: T) => T; /** * Execute function if value is defined */ ifDefined: (value: T | undefined, fn: (val: T) => R, fallback: R) => R; /** * Execute function based on string comparison */ when: (value: string, cases: Record T>, fallback: () => T) => T; }; performance: { /** * Create a performance monitor */ monitor: (name: string) => { end: () => number; }; /** * Create a simple profiler */ profile: (name: string, fn: () => Promise) => Promise<{ result: T; duration: number; }>; }; environment: { /** * Get environment variable with default */ getVar: (name: string, defaultValue?: string) => string; /** * Check if running in development */ isDev: () => boolean; /** * Check if running in production */ isProd: () => boolean; /** * Check if running in test */ isTest: () => boolean; }; }; //# sourceMappingURL=commonPatterns.d.ts.map