/** * When undefined or null is passed as the predicate, it will * return true on all iterations. * * @typedef {null|undefined} NullPredicate * @global */ /** * When a string is passed as a predicate, it is compared to the iterate * value based upon the type of the value. * * Array: iValue.includes(predicate) * Map: iValue.get(predicate) * Set: iValue.has(predicate) * Object: get(iValue, predicate) * string: iValue == predicate * number: iValue == predicate * boolean: iValue == predicate * * Otherwise it returns false * * @typedef {string} StringPredicate * @global */ /** * When a number is passed as a predicate, it is compared to the iterate * value based upon the type of the value. * * Array: iValue.includes(predicate) * Map: iValue.get(predicate) * Set: iValue.has(predicate) * Object: iValue[predicate] * string: Number(iValue) === predicate * number: iValue === predicate * * Otherwise it returns false * * @typedef {number} NumberPredicate * @global */ /** * When passing an array as a predicate, it's behavior varies according * to the data type of the iterate value to be matched against. * * When matching against an array, an ES Map, or an object, the predicate * is treated as a key/value pair. A comparison value is pulled from * the iterate value using the first element of the array, and strict tested * against the second element in the array. * * ``` * get(iValue, predicate[0]) === predicate[1] * ``` * * When matching against a string, number, or boolean, the predicate * will return true if the array contains the iterate value. * * When matching against an ES Set, it will return true if any of the * array's values exist in the set. * * For any other type it returns false * * @typedef {Array} ArrayPredicate * @global */ /** * When a plain object is provided, it is treated as a set of keys * and values to match against on the iterate values. Each key/value * pair will be tested against the iterate value. If the iterate value * is not an array, object or ES Map, the predicate returns false. * * Array: iValue[key] === value * Object: get(iValue, key) === value * Map: iValue.get(key) === value * * @typedef {Object} ObjectPredicate * @global */ /** * When a function is passed as a predicate, it is invoked for each * iterate value with three arguments provided. * * @callback FunctionPredicate * @param {any} value The iterate value * @param {any} key The key for the iterate value. When iterating Sets, * Arrays, Iterables or strings, this will be the same as the index. * @param {number} index The incrementing index of the iterate value, * starting from 0. * @global */ /** * A function or value that will be used to match against the contents of * a collection. * * @typedef {( * NullPredicate * |StringPredicate * |NumberPredicate * |ArrayPredicate * |ObjectPredicate * |FunctionPredicate * )} Predicate * @global */ /** * Produces a predicate callback function for use with iterative utilities. * * @param {Predicate} match Iteratee predicate descriptor * * @returns {Function} * @category Collections */ export default function iteratee(match: Predicate): Function; /** * When undefined or null is passed as the predicate, it will * return true on all iterations. */ export type NullPredicate = null | undefined; /** * When a string is passed as a predicate, it is compared to the iterate * value based upon the type of the value. * * Array: iValue.includes(predicate) * Map: iValue.get(predicate) * Set: iValue.has(predicate) * Object: get(iValue, predicate) * string: iValue == predicate * number: iValue == predicate * boolean: iValue == predicate * * Otherwise it returns false */ export type StringPredicate = string; /** * When a number is passed as a predicate, it is compared to the iterate * value based upon the type of the value. * * Array: iValue.includes(predicate) * Map: iValue.get(predicate) * Set: iValue.has(predicate) * Object: iValue[predicate] * string: Number(iValue) === predicate * number: iValue === predicate * * Otherwise it returns false */ export type NumberPredicate = number; /** * When passing an array as a predicate, it's behavior varies according * to the data type of the iterate value to be matched against. * * When matching against an array, an ES Map, or an object, the predicate * is treated as a key/value pair. A comparison value is pulled from * the iterate value using the first element of the array, and strict tested * against the second element in the array. * * ``` * get(iValue, predicate[0]) === predicate[1] * ``` * * When matching against a string, number, or boolean, the predicate * will return true if the array contains the iterate value. * * When matching against an ES Set, it will return true if any of the * array's values exist in the set. * * For any other type it returns false */ export type ArrayPredicate = any[]; /** * When a plain object is provided, it is treated as a set of keys * and values to match against on the iterate values. Each key/value * pair will be tested against the iterate value. If the iterate value * is not an array, object or ES Map, the predicate returns false. * * Array: iValue[key] === value * Object: get(iValue, key) === value * Map: iValue.get(key) === value */ export type ObjectPredicate = any; /** * When a function is passed as a predicate, it is invoked for each * iterate value with three arguments provided. */ export type FunctionPredicate = (value: any, key: any, index: number) => any; /** * A function or value that will be used to match against the contents of * a collection. */ export type Predicate = (NullPredicate | StringPredicate | NumberPredicate | any[] | ObjectPredicate | FunctionPredicate);