/** * Domma Utils Module - TypeScript Declarations * 120+ Lodash-compatible utility functions */ export type Collection = T[] | Record; export type Iteratee = (value: T, index: number | string, collection: Collection) => R; export type Predicate = (value: T, index: number | string, collection: Collection) => boolean; export type PropertyIteratee = ((value: T) => any) | keyof T; export interface DebounceOptions { leading?: boolean; trailing?: boolean; maxWait?: number; } export interface ThrottleOptions { leading?: boolean; trailing?: boolean; } export interface TruncateOptions { length?: number; omission?: string; separator?: string | RegExp; } export interface TemplateOptions { partials?: Record; helpers?: Record any>; } export interface DebouncedFunction any> { (...args: Parameters): ReturnType; cancel(): void; flush(): ReturnType; } export interface MemoizedFunction any> { (...args: Parameters): ReturnType; cache: Map>; } export interface Utils { // ============================================ // Array Utilities // ============================================ /** Creates an array of elements split into groups of the specified size */ chunk(array: T[], size?: number): T[][]; /** Creates an array with all falsy values removed */ compact(array: T[]): T[]; /** Creates a new array concatenating array with additional arrays/values */ concat(array: T[], ...values: (T | T[])[]): T[]; /** Creates an array of values not included in the other given arrays */ difference(array: T[], ...values: T[][]): T[]; /** Creates a slice of array with n elements dropped from the beginning */ drop(array: T[], n?: number): T[]; /** Creates a slice of array with n elements dropped from the end */ dropRight(array: T[], n?: number): T[]; /** Fills elements of array with value from start up to end */ fill(array: T[], value: T, start?: number, end?: number): T[]; /** Returns the index of the first element predicate returns truthy for */ findIndex(array: T[], predicate: Predicate, fromIndex?: number): number; /** Returns the index of the last element predicate returns truthy for */ findLastIndex(array: T[], predicate: Predicate, fromIndex?: number): number; /** Gets the first element of array */ first(array: T[]): T | undefined; /** Alias for first */ head(array: T[]): T | undefined; /** Flattens array a single level deep */ flatten(array: (T | T[])[]): T[]; /** Recursively flattens array */ flattenDeep(array: any[]): T[]; /** Flattens array up to depth times */ flattenDepth(array: any[], depth?: number): T[]; /** Returns an object composed from key-value pairs */ fromPairs(pairs: [string, T][]): Record; /** Gets the index at which the first occurrence of value is found */ indexOf(array: T[], value: T, fromIndex?: number): number; /** Gets all but the last element of array */ initial(array: T[]): T[]; /** Creates an array of unique values that are included in all given arrays */ intersection(...arrays: T[][]): T[]; /** Converts all elements in array into a string separated by separator */ join(array: T[], separator?: string): string; /** Gets the last element of array */ last(array: T[]): T | undefined; /** Gets the index at which the last occurrence of value is found */ lastIndexOf(array: T[], value: T, fromIndex?: number): number; /** Gets the element at index n of array (supports negative indices) */ nth(array: T[], n?: number): T | undefined; /** Removes all given values from array (mutates) */ pull(array: T[], ...values: T[]): T[]; /** Removes elements from array corresponding to indexes (mutates) */ pullAt(array: T[], ...indexes: (number | number[])[]): T[]; /** Reverses array (mutates) */ reverse(array: T[]): T[]; /** Creates a slice of array from start up to end */ slice(array: T[], start?: number, end?: number): T[]; /** Gets all but the first element of array */ tail(array: T[]): T[]; /** Creates a slice of array with n elements taken from the beginning */ take(array: T[], n?: number): T[]; /** Creates a slice of array with n elements taken from the end */ takeRight(array: T[], n?: number): T[]; /** Creates an array of unique values, in order, from all given arrays */ union(...arrays: T[][]): T[]; /** Creates a duplicate-free version of an array */ uniq(array: T[]): T[]; /** Creates a duplicate-free version using iteratee */ uniqBy(array: T[], iteratee: (value: T) => any): T[]; /** Creates an array excluding all given values */ without(array: T[], ...values: T[]): T[]; /** Creates an array of unique values that is the symmetric difference */ xor(...arrays: T[][]): T[]; /** Creates an array of grouped elements */ zip(...arrays: T[][]): T[][]; /** Creates an object composed from arrays of keys and values */ zipObject(keys: string[], values?: T[]): Record; /** Invokes the iteratee n times, returning an array of the results */ times(n: number, iteratee?: (index: number) => T): T[]; /** Creates an array of numbers from start up to, but not including, end */ range(end: number): number[]; range(start: number, end: number, step?: number): number[]; /** Generates a unique ID. If prefix is given, the ID is appended to it */ uniqueId(prefix?: string): string; // ============================================ // Collection Utilities // ============================================ /** Creates an object composed of keys generated from running each element through iteratee */ countBy(collection: Collection, iteratee: (value: T) => string | number): Record; /** Iterates over elements invoking iteratee for each element */ each(collection: Collection, iteratee: Iteratee): Collection; /** Alias for each */ forEach(collection: Collection, iteratee: Iteratee): Collection; /** Iterates over elements in reverse invoking iteratee for each element */ eachRight(collection: Collection, iteratee: Iteratee): Collection; /** Alias for eachRight */ forEachRight(collection: Collection, iteratee: Iteratee): Collection; /** Checks if predicate returns truthy for all elements of collection */ every(collection: Collection, predicate: Predicate): boolean; /** Returns an array of all elements predicate returns truthy for */ filter(collection: Collection, predicate: Predicate): T[]; /** Returns the first element predicate returns truthy for */ find(collection: Collection, predicate: Predicate): T | undefined; /** Returns the last element predicate returns truthy for */ findLast(collection: Collection, predicate: Predicate): T | undefined; /** Creates a flattened array of values by running each element through iteratee */ flatMap(collection: Collection, iteratee: Iteratee): R[]; /** Recursively flattens the mapped results */ flatMapDeep(collection: Collection, iteratee: Iteratee): R[]; /** Creates an object composed of keys generated from running each element through iteratee */ groupBy(collection: Collection, iteratee: PropertyIteratee): Record; /** Checks if value is in collection */ includes(collection: Collection | string, value: T | string, fromIndex?: number): boolean; /** Creates an object with keys generated from running each element through iteratee */ keyBy(collection: Collection, iteratee: PropertyIteratee): Record; /** Creates an array of values by running each element through iteratee */ map(collection: Collection, iteratee: Iteratee): R[]; /** Creates an array of elements sorted by the specified iteratees */ orderBy(collection: Collection, iteratees: PropertyIteratee | PropertyIteratee[], orders?: ('asc' | 'desc') | ('asc' | 'desc')[]): T[]; /** Creates an array of elements split into two groups */ partition(collection: Collection, predicate: Predicate): [T[], T[]]; /** Reduces collection to a value */ reduce(collection: Collection, iteratee: (accumulator: R, value: T, index: number | string, collection: Collection) => R, accumulator?: R): R; /** Reduces collection from right to left */ reduceRight(collection: Collection, iteratee: (accumulator: R, value: T, index: number | string, collection: Collection) => R, accumulator?: R): R; /** Returns elements predicate does not return truthy for */ reject(collection: Collection, predicate: Predicate): T[]; /** Gets a random element from collection */ sample(collection: Collection): T | undefined; /** Gets n random elements from collection */ sampleSize(collection: Collection, n?: number): T[]; /** Creates a shuffled array using Fisher-Yates shuffle */ shuffle(collection: Collection): T[]; /** Gets the size of collection */ size(collection: Collection | string | null | undefined): number; /** Checks if predicate returns truthy for any element of collection */ some(collection: Collection, predicate: Predicate): boolean; /** Creates an array of elements sorted by iteratee */ sortBy(collection: Collection, iteratee: PropertyIteratee): T[]; // ============================================ // Function Utilities // ============================================ /** Creates a function that invokes func once it's called n or more times */ after any>(n: number, func: T): T; /** Creates a function that invokes func, with up to n arguments */ ary any>(func: T, n?: number): T; /** Creates a function that invokes func while it's called less than n times */ before any>(n: number, func: T): T; /** Creates a function that invokes func with the this binding of thisArg */ bind any>(func: T, thisArg: any, ...partials: any[]): T; /** Creates a function that accepts arguments and returns a curried function */ curry any>(func: T, arity?: number): (...args: any[]) => any; /** Like curry but arguments are processed right to left */ curryRight any>(func: T, arity?: number): (...args: any[]) => any; /** Creates a debounced function that delays invoking func until after wait ms */ debounce any>(func: T, wait?: number, options?: DebounceOptions): DebouncedFunction; /** Defers invoking the func until the current call stack has cleared */ defer any>(func: T, ...args: Parameters): number; /** Invokes func after wait milliseconds */ delay any>(func: T, wait: number, ...args: Parameters): number; /** Creates a function that invokes func with arguments reversed */ flip any>(func: T): T; /** Creates a function that memoizes the result of func */ memoize any>(func: T, resolver?: (...args: Parameters) => any): MemoizedFunction; /** Creates a function that negates the result of the predicate func */ negate boolean>(predicate: T): T; /** Creates a function that is restricted to invoking func once */ once any>(func: T): T; /** Creates a function that invokes func with partials prepended */ partial any>(func: T, ...partials: any[]): (...args: any[]) => ReturnType; /** Creates a function that invokes func with partials appended */ partialRight any>(func: T, ...partials: any[]): (...args: any[]) => ReturnType; /** Creates a throttled function that only invokes func at most once per every wait ms */ throttle any>(func: T, wait?: number, options?: ThrottleOptions): DebouncedFunction; /** Creates a function that accepts up to one argument */ unary any>(func: T): (arg: Parameters[0]) => ReturnType; /** Creates a function that provides value to wrapper as its first argument */ wrap(value: T, wrapper: (value: T, ...args: any[]) => R): (...args: any[]) => R; // ============================================ // Object Utilities // ============================================ /** Assigns own enumerable properties of source objects to the destination object */ assign(object: T, ...sources: object[]): T; /** Like assign but iterates over own and inherited source properties */ assignIn(object: T, ...sources: object[]): T; /** Alias for assignIn */ extend(object: T, ...sources: object[]): T; /** Creates an array of values corresponding to paths of object */ at(object: T, ...paths: (string | string[])[]): any[]; /** Creates a shallow clone of value */ clone(value: T): T; /** Creates a deep clone of value */ cloneDeep(value: T): T; /** Assigns properties of source objects for destination properties that resolve to undefined */ defaults(object: T, ...sources: object[]): T; /** Like defaults but recursively assigns default properties */ defaultsDeep(object: T, ...sources: object[]): T; /** Creates an array of own enumerable string keyed-value pairs */ entries(object: T): [string, T[keyof T]][]; /** Alias for entries */ toPairs(object: T): [string, T[keyof T]][]; /** Returns the key of the first element predicate returns truthy for */ findKey(object: T, predicate: (value: T[keyof T], key: string, object: T) => boolean): string | undefined; /** Returns the key of the last element predicate returns truthy for */ findLastKey(object: T, predicate: (value: T[keyof T], key: string, object: T) => boolean): string | undefined; /** Iterates over own and inherited enumerable properties of an object */ forIn(object: T, iteratee: (value: T[keyof T], key: string, object: T) => void | false): T; /** Iterates over own enumerable properties of an object */ forOwn(object: T, iteratee: (value: T[keyof T], key: string, object: T) => void | false): T; /** Gets the value at path of object */ get(object: any, path: string | string[], defaultValue?: T): T; /** Checks if path is a direct property of object */ has(object: any, path: string | string[]): boolean; /** Creates an object composed of the inverted keys and values of object */ invert(object: T): Record; /** Like invert but accepts iteratee which is invoked for each element */ invertBy(object: T, iteratee?: (value: T[keyof T]) => string): Record; /** Creates an array of the own enumerable property names of object */ keys(object: T): string[]; /** Creates an array of own and inherited enumerable property names */ keysIn(object: T): string[]; /** Creates an object with the same values and keys generated by iteratee */ mapKeys(object: T, iteratee: (value: T[keyof T], key: string, object: T) => string): Record; /** Creates an object with the same keys and values generated by iteratee */ mapValues(object: T, iteratee: (value: T[keyof T], key: string, object: T) => R): Record; /** Recursively merges own and inherited enumerable properties of source objects */ merge(object: T, ...sources: object[]): T; /** Creates an object composed of the own properties that are not omitted */ omit(object: T, ...paths: (K | K[])[]): Omit; /** Creates an object composed of the properties predicate doesn't return truthy for */ omitBy(object: T, predicate: (value: T[keyof T], key: string) => boolean): Partial; /** Creates an object composed of the picked object properties */ pick(object: T, ...paths: (K | K[])[]): Pick; /** Creates an object composed of the properties predicate returns truthy for */ pickBy(object: T, predicate: (value: T[keyof T], key: string) => boolean): Partial; /** Sets the value at path of object */ set(object: T, path: string | string[], value: any): T; /** Removes the property at path of object */ unset(object: any, path: string | string[]): boolean; /** Sets the value at path of object if the resolved value is undefined */ setIfUndefined(object: T, path: string | string[], value: any): T; /** Creates an array of own enumerable string keyed property values of object */ values(object: T): T[keyof T][]; /** Creates an array of own and inherited enumerable property values */ valuesIn(object: T): any[]; // ============================================ // Lang Utilities (Type Checking) // ============================================ /** Checks if value is an Array */ isArray(value: any): value is any[]; /** Checks if value is a boolean primitive or object */ isBoolean(value: any): value is boolean; /** Checks if value is a Date object */ isDate(value: any): value is Date; /** Checks if value is an empty object, collection, map, or set */ isEmpty(value: any): boolean; /** Performs a deep comparison between two values */ isEqual(value: any, other: any): boolean; /** Checks if object contains equivalent property values */ isMatch(object: any, source: any): boolean; /** Checks if value is a finite number */ isFinite(value: any): value is number; /** Checks if value is a Function object */ isFunction(value: any): value is (...args: any[]) => any; /** Checks if value is an integer */ isInteger(value: any): value is number; /** Checks if value is NaN */ isNaN(value: any): boolean; /** Checks if value is null or undefined */ isNil(value: any): value is null | undefined; /** Checks if value is null */ isNull(value: any): value is null; /** Checks if value is a number primitive or object */ isNumber(value: any): value is number; /** Checks if value is the language type of Object */ isObject(value: any): value is object; /** Checks if value is a plain object */ isPlainObject(value: any): value is Record; /** Checks if value is a RegExp object */ isRegExp(value: any): value is RegExp; /** Checks if value is a string primitive or object */ isString(value: any): value is string; /** Checks if value is a Symbol primitive */ isSymbol(value: any): value is symbol; /** Checks if value is undefined */ isUndefined(value: any): value is undefined; // ============================================ // Type Conversion Utilities // ============================================ /** Converts string to an integer of the specified radix */ parseInt(string: string | number, radix?: number): number; /** Converts value to a number */ toNumber(value: any): number; /** Converts value to an integer */ toInteger(value: any): number; /** Converts value to a finite number */ toFinite(value: any): number; /** Converts value to a safe integer */ toSafeInteger(value: any): number; /** Converts value to a string */ toString(value: any): string; /** Converts value to an array */ toArray(value: T[] | Iterable | Record | string): T[] | string[]; /** Casts value as an array if it's not one */ castArray(...args: T[]): T[]; /** Converts value to an integer suitable for use as array length */ toLength(value: any): number; /** Converts value to a plain object flattening inherited properties */ toPlainObject(value: any): Record; // ============================================ // Math Utilities // ============================================ /** Adds two numbers */ add(augend: number, addend: number): number; /** Computes number rounded up to precision */ ceil(number: number, precision?: number): number; /** Divide two numbers */ divide(dividend: number, divisor: number): number; /** Computes number rounded down to precision */ floor(number: number, precision?: number): number; /** Computes the maximum value of array */ max(array: number[]): number | undefined; /** Computes the maximum value of array with iteratee */ maxBy(array: T[], iteratee: PropertyIteratee): T | undefined; /** Computes the mean of the values in array */ mean(array: number[]): number; /** Computes the mean using iteratee */ meanBy(array: T[], iteratee: PropertyIteratee): number; /** Computes the minimum value of array */ min(array: number[]): number | undefined; /** Computes the minimum value of array with iteratee */ minBy(array: T[], iteratee: PropertyIteratee): T | undefined; /** Multiply two numbers */ multiply(multiplier: number, multiplicand: number): number; /** Computes number rounded to precision */ round(number: number, precision?: number): number; /** Subtract two numbers */ subtract(minuend: number, subtrahend: number): number; /** Computes the sum of the values in array */ sum(array: number[]): number; /** Computes the sum using iteratee */ sumBy(array: T[], iteratee: PropertyIteratee): number; // ============================================ // Number Utilities // ============================================ /** Clamps number within the inclusive lower and upper bounds */ clamp(number: number, upper: number): number; clamp(number: number, lower: number, upper: number): number; /** Checks if n is between start and up to but not including end */ inRange(number: number, end: number): boolean; inRange(number: number, start: number, end: number): boolean; /** Produces a random number between the inclusive lower and upper bounds */ random(floating?: boolean): number; random(upper: number, floating?: boolean): number; random(lower: number, upper: number, floating?: boolean): number; // ============================================ // String Utilities // ============================================ /** Converts string to camel case */ camelCase(string: string): string; /** Converts the first character to upper case and remaining to lower case */ capitalize(string: string): string; /** Checks if string ends with the given target string */ endsWith(string: string, target: string, position?: number): boolean; /** Converts HTML special characters to HTML entities */ escape(string: string): string; /** Converts string to kebab case */ kebabCase(string: string): string; /** Converts string, as space separated words, to lower case */ lowerCase(string: string): string; /** Converts the first character of string to lower case */ lowerFirst(string: string): string; /** Pads string on the left and right sides if it's shorter than length */ pad(string?: string, length?: number, chars?: string): string; /** Pads string on the right side if it's shorter than length */ padEnd(string?: string, length?: number, chars?: string): string; /** Pads string on the left side if it's shorter than length */ padStart(string?: string, length?: number, chars?: string): string; /** Repeats the given string n times */ repeat(string?: string, n?: number): string; /** Replaces matches for pattern in string with replacement */ replace(string?: string, pattern?: string | RegExp, replacement?: string): string; /** Converts string to snake case */ snakeCase(string: string): string; /** Splits string by separator */ split(string?: string, separator?: string | RegExp, limit?: number): string[]; /** Converts string to start case */ startCase(string: string): string; /** Checks if string starts with the given target string */ startsWith(string: string, target: string, position?: number): boolean; /** Converts string to lowercase */ toLower(string: string): string; /** Converts string to uppercase */ toUpper(string: string): string; /** Removes leading and trailing whitespace or specified characters */ trim(string?: string, chars?: string): string; /** Removes trailing whitespace or specified characters */ trimEnd(string?: string, chars?: string): string; /** Removes leading whitespace or specified characters */ trimStart(string?: string, chars?: string): string; /** Truncates string if it's longer than the given maximum string length */ truncate(string?: string, options?: TruncateOptions): string; /** Converts HTML entities to their corresponding characters */ unescape(string: string): string; /** Converts string, as space separated words, to upper case */ upperCase(string: string): string; /** Converts the first character of string to upper case */ upperFirst(string: string): string; /** Splits string into an array of its words */ words(string?: string, pattern?: string | RegExp): string[]; /** Returns a formatted string using printf-style format specifiers */ sprintf(format: string, ...args: any[]): string; /** Alias for sprintf */ format(format: string, ...args: any[]): string; // ============================================ // Template Engine // ============================================ /** Compiles a template string into a reusable function */ template(template: string, options?: TemplateOptions): (data?: Record) => string; /** Renders a template string with the given data (one-shot) */ render(template: string, data: Record, options?: TemplateOptions): string; } export declare const utils: Utils;