/** * General utility functions */ import { identity } from "../internal/utils.js"; /** * Attempts to invoke func, returning either the result or the caught error object. * * @param func - The function to attempt * @returns Returns the func result or error object * * @example * attempt(() => { * return selector(object); * }); * // => Returns selector result or error object */ export declare function attempt(func: () => T): T | Error; /** * Creates a function that returns value. * * @param value - The value to return from the new function * @returns Returns the new constant function * * @example * const objects = times(2, constant({ 'a': 1 })); * * console.log(objects); * // => [{ 'a': 1 }, { 'a': 1 }] * * console.log(objects[0] === objects[1]); * // => true */ export declare function constant(value: T): () => T; /** * Checks value to determine whether a default value should be returned in its place. * * @param value - The value to check * @param defaultValue - The default value * @returns Returns the resolved value * * @example * defaultTo(1, 10); * // => 1 * * defaultTo(undefined, 10); * // => 10 */ export declare function defaultTo(value: T | null | undefined, defaultValue: U): T | U; /** * This method returns the first argument it receives. * * @param value - Any value * @returns Returns value * * @example * const object = { 'a': 1 }; * * console.log(identity(object) === object); * // => true */ export { identity }; /** * Creates a function that performs a partial deep comparison between a given * object and source, returning true if the given object has equivalent * property values, else false. * * @param source - The object of property values to match * @returns Returns the new spec function * * @example * const objects = [ * { 'a': 1, 'b': 2, 'c': 3 }, * { 'a': 4, 'b': 5, 'c': 6 } * ]; * * objects.filter(matches({ 'a': 4, 'c': 6 })); * // => [{ 'a': 4, 'b': 5, 'c': 6 }] */ export declare function matches>(source: Partial): (object: T) => boolean; /** * Creates a function that performs a partial deep comparison between the * value at path of a given object to srcValue, returning true if the * object value is equivalent, else false. * * @param path - The path of the property to get * @param srcValue - The value to match * @returns Returns the new spec function * * @example * const objects = [ * { 'a': 1, 'b': 2, 'c': 3 }, * { 'a': 4, 'b': 5, 'c': 6 } * ]; * * objects.filter(matchesProperty('a', 4)); * // => [{ 'a': 4, 'b': 5, 'c': 6 }] */ export declare function matchesProperty(path: keyof T, srcValue: any): (object: T) => boolean; /** * Creates a function that returns the value at path of a given object. * * @param path - The path of the property to get * @returns Returns the new accessor function * * @example * const objects = [ * { 'a': { 'b': 2 } }, * { 'a': { 'b': 1 } } * ]; * * objects.map(property('a.b')); * // => [2, 1] * * objects.map(property(['a', 'b'])); * // => [2, 1] */ export declare function property(path: keyof T): (object: T) => T[keyof T]; export declare function property(path: string | string[]): (object: any) => any; /** * The opposite of property; this method creates a function that returns * the value at a given path of object. * * @param object - The object to query * @returns Returns the new accessor function * * @example * const array = [0, 1, 2]; * const object = { 'a': array, 'b': array, 'c': array }; * * ['a[2]', 'c[0]'].map(propertyOf(object)); * // => [2, 0] */ export declare function propertyOf(object: any): (path: string | string[]) => any; /** * Creates an array of numbers (positive and/or negative) progressing from * start up to, but not including, end. * * @param start - The start of the range * @param end - The end of the range * @param step - The value to increment or decrement by * @returns Returns the range of numbers * * @example * range(4); * // => [0, 1, 2, 3] * * range(-4); * // => [0, -1, -2, -3] * * range(1, 5); * // => [1, 2, 3, 4] * * range(0, 20, 5); * // => [0, 5, 10, 15] */ export declare function range(start: number): number[]; export declare function range(start: number, end: number, step?: number): number[]; /** * This method is like range except that it populates values in * descending order. * * @param start - The start of the range * @param end - The end of the range * @param step - The value to increment or decrement by * @returns Returns the range of numbers * * @example * rangeRight(4); * // => [3, 2, 1, 0] * * rangeRight(-4); * // => [-3, -2, -1, 0] * * rangeRight(1, 5); * // => [4, 3, 2, 1] */ export declare function rangeRight(start: number): number[]; export declare function rangeRight(start: number, end: number, step?: number): number[]; /** * Invokes the iteratee n times, returning an array of the results of * each invocation. * * @param n - The number of times to invoke iteratee * @param iteratee - The function invoked per iteration * @returns Returns the array of results * * @example * times(3, String); * // => ['0', '1', '2'] * * times(4, constant(0)); * // => [0, 0, 0, 0] */ export declare function times(n: number, iteratee: (index: number) => T): T[]; /** * Converts value to a property path array. * * @param value - The value to convert * @returns Returns the new property path array * * @example * toPath('a.b.c'); * // => ['a', 'b', 'c'] * * toPath('a[0].b.c'); * // => ['a', '0', 'b', 'c'] */ export declare function toPath(value: string): string[]; export declare function uniqueId(prefix?: string): string;