/** * Debounce fn, calling it only once if * the given time elapsed between calls. * * @param {Function} fn * @param {Number} timeout * * @return {Function} debounced function */ export function debounce(fn: Function, timeout: number): (...args: any[]) => void; /** * Throttle fn, calling at most once * in the given interval. * * @param {Function} fn * @param {Number} interval * * @return {Function} throttled function */ export function throttle(fn: Function, interval: number): (...args: any[]) => void; /** * Bind function against target . * * @param {Function} fn * @param {Object} target * * @return {Function} bound function */ export function bind(fn: T, target: object): T; /** * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. * @param target The target object to copy to. * @param source The source object from which to copy properties. */ export function assign(target: T, source: U): T & U; /** * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. * @param target The target object to copy to. * @param source1 The first source object from which to copy properties. * @param source2 The second source object from which to copy properties. */ export function assign(target: T, source1: U, source2: V): T & U & V; /** * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. * @param target The target object to copy to. * @param source1 The first source object from which to copy properties. * @param source2 The second source object from which to copy properties. * @param source3 The third source object from which to copy properties. */ export function assign(target: T, source1: U, source2: V, source3: W): T & U & V & W; /** * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. * @param target The target object to copy to. * @param sources One or more source objects from which to copy properties */ export function assign(target: T, ...sources: any[]): T; /** * Gets a nested property of a given object, with an optional default value. * * @param target The target of the get operation. * @param path The path to the nested value. * @param defaultValue The result to return if the property does not exist. */ export function get(target: any, path: (string|number)[], defaultValue?: any): any; /** * Sets a nested property of a given object to the specified value. * * This mutates the object and returns it. * * @param target The target of the set operation. * @param path The path to the nested value. * @param value The value to set. */ export function set(target: T, path: (string|number)[], value: any): T; export function pick(target: T, properties: (keyof T)[]): Pick; /** * Pick all target properties, excluding the given ones. * * @param {Object} target * @param {Array} properties * * @return {Object} target */ export function omit(target: T, properties: (keyof T)[]): Exclude; /** * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. * @param target The target object to copy to. * @param sources One or more source objects from which to copy properties */ export function merge(target: object, ...sources: any[]): any; export function isUndefined(obj: any): obj is null | undefined; export function isDefined(obj: any): obj is Exclude; export function isNil(obj: any): obj is object; export function isArray(obj: any): obj is Array; export function isObject(obj: any): obj is object; export function isNumber(obj: any): obj is number; export function isFunction(obj: any): obj is Function; export function isString(obj: any): obj is string; /** * Ensure collection is an array. * * @param {Object} obj */ export function ensureArray(obj: Collection): void | never; /** * Return true, if target owns a property with the given key. * * @param {Object} target * @param {String} key * * @return {Boolean} */ export function has(target: any, key: string): boolean; export type Matcher = ((e: T) => boolean) | ((e: T, idx: number) => boolean) | keyof T; export type Extractor = ((e: T) => U) | keyof T; export type ArrayCollection = Array; export type StringKeyValueCollection = { [key: string]: T }; export type NumberKeyValueCollection = { [key: number]: T }; export type KeyValueCollection = StringKeyValueCollection | NumberKeyValueCollection; export type Collection = KeyValueCollection | ArrayCollection; /** * Find element in collection. * * @param {Array|Object} collection * @param {Function|Object} matcher * * @return {Object} */ export function find(collection: Collection, matcher: Matcher): T | undefined; /** * Find element index in collection. * * @param {Array|Object} collection * @param {Function} matcher * * @return {Object} */ export function findIndex(collection: Collection, matcher: Matcher): number | undefined; /** * Find element in collection. * * @param {Array|Object} collection * @param {Function} matcher * * @return {Array} result */ export function filter(collection: Collection, matcher: Matcher): T[]; /** * Iterate over collection; returning something * (non-undefined) will stop iteration. * * @param {Array|Object} collection * @param {Function} iterator * * @return {Object} return result that stopped the iteration */ export function forEach(collection: Collection, iterator: (item: T, convertKey: any /* TODO */) => boolean | void): T; /** * Return collection without element. * * @param {Array} arr * @param {Function} matcher * * @return {Array} */ export function without(arr: T[], matcher: Matcher): T[]; /** * Reduce collection, returning a single result. * * @param {Object|Array} collection * @param {Function} iterator * @param {Any} result * * @return {Any} result returned from last iterator */ export function reduce(collection: Collection, iterator: (...args: any[]) => T, result: T): T; /** * Return true if every element in the collection * matches the criteria. * * @param {Object|Array} collection * @param {Function} matcher * * @return {Boolean} */ export function every(collection: Collection, matcher: Matcher): boolean; /** * Return true if some elements in the collection * match the criteria. * * @param {Object|Array} collection * @param {Function} matcher * * @return {Boolean} */ export function some(collection: Collection, matcher: Matcher): boolean; /** * Transform a collection into another collection * by piping each member through the given fn. * * @param {Object|Array} collection * @param {Function} fn * * @return {Array} transformed collection */ export function map(collection: Collection, fn: (value: T, key: number) => U): U[]; /** * Get the collections keys. * * @param {Object|Array} collection * * @return {Array} */ export function keys(collection: Collection): T extends Array ? number[] : (keyof T)[]; /** * Shorthand for `keys(o).length`. * * @param {Object|Array} collection * * @return {Number} */ export function size(collection: Collection): number; /** * Get the values in the collection. * * @param {Object|Array} collection * * @return {Array} */ export function values(collection: Collection): T[]; /** * Group collection members by attribute. * * @param {Object|Array} collection * @param {Function} extractor * * @return {Object} map with { attrValue => [ a, b, c ] } */ export function groupBy(collection: Collection, extractor: Extractor, grouped?: any): { [attrValue: string]: any[] }; export function uniqueBy(extractor: Extractor, ...collections: Collection[]): T[]; export function unionBy(extractor: Extractor, ...collections: Collection[]): T[]; /** * Sort collection by criteria. * * @param {Object|Array} collection * @param {String|Function} extractor * * @return {Array} */ export function sortBy(collection: Collection, extractor: Extractor): T[]; /** * Create an object pattern matcher. * * @example * * const matcher = matchPattern({ id: 1 }); * * let element = find(elements, matcher); * * @param {Object} pattern * * @return {Function} matcherFn */ export function matchPattern(pattern: T): (e: Partial) => boolean; /** * Flatten array, one level deep. * * @param {Array} arr * * @return {Array} */ export function flatten(arr: T[][]): T[];