/** * 内部使用类型 * * @packageDocumentation */ /** * 列表类型 */ interface IList { length: number; [Symbol.iterator]?: any; [index: number]: any; } /** * 未知类型的mapKey */ type UnknownMapKey = string | number | symbol; /** * 类数组类型 */ type ArrayLike$1 = Array | string | NodeList | HTMLCollection | IList | NodeListOf; /** * 集合类型 */ type Collection = Record, V> | Set | Map | ArrayLike$1; /** * 非函数迭代类型 */ type NonFuncItee = string | Record | Array; declare function countBy(collection: Collection, itee?: ((value: V) => string) | NonFuncItee): Record; declare function countBy(collection: Collection, itee?: ((value: V) => K) | NonFuncItee): Record, number>; declare function each(collection: Set | ArrayLike, callback: (value: V, index: number, collection: Collection, i: number) => any, startIndex?: number): void; declare function each(collection: Record | Map, callback: (value: V, index: string, collection: Collection, i: number) => any, startIndex?: number): void; declare function each(collection: Collection, callback: (value: V, index: K, collection: Collection, i: number) => any, startIndex?: number): void; declare function eachRight(collection: Set | ArrayLike$1, callback: (value: V, index: number, collection: Collection, i: number) => boolean | void | Promise): void; declare function eachRight(collection: Record | Map, callback: (value: V, index: string, collection: Collection, i: number) => boolean | void | Promise): void; declare function eachRight(collection: Collection, callback: (value: V, index: K, collection: Collection, i: number) => boolean | void | Promise): void; declare function every(collection: Set | ArrayLike, predicate: ((value: V, index: number, collection: Collection) => boolean) | NonFuncItee): boolean; declare function every(collection: Record | Map, predicate: ((value: V, index: string, collection: Collection) => boolean) | NonFuncItee): boolean; declare function every(collection: Collection, predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): boolean; declare function filter(collection: Set | ArrayLike$1, predicate: ((value: V, index: number, collection: Collection) => boolean) | NonFuncItee): V[]; declare function filter(collection: Record | Map, predicate: ((value: V, index: string, collection: Collection) => boolean) | NonFuncItee): V[]; declare function filter(collection: Collection, predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): V[]; declare function find(collection: Set | ArrayLike, predicate: ((value: V, index: number, collection: Collection) => boolean) | NonFuncItee): U | undefined; declare function find(collection: Record | Map, predicate: ((value: V, index: string, collection: Collection) => boolean) | NonFuncItee): U | undefined; declare function find(collection: Set | ArrayLike, predicate: ((value: V, index: number, collection: Collection) => boolean) | NonFuncItee): V | undefined; declare function find(collection: Record | Map, predicate: ((value: V, index: string, collection: Collection) => boolean) | NonFuncItee): V | undefined; declare function find(collection: Collection, predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): V | undefined; declare function findLast(collection: Set | ArrayLike, predicate: ((value: V, index: number, collection: Collection) => boolean) | NonFuncItee): V | undefined; declare function findLast(collection: Record | Map, predicate: ((value: V, index: string, collection: Collection) => boolean) | NonFuncItee): V | undefined; declare function findLast(collection: Collection, predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): V | undefined; declare function first(array: Collection): T; declare function first(array: Collection): U; declare function flatMap(collection: Set | ArrayLike, itee: ((value: V, index: number, collection: Collection) => V | Promise) | NonFuncItee, depth?: number): V[]; declare function flatMap(collection: Record | Map, itee: ((value: V, index: string, collection: Collection) => V | Promise) | NonFuncItee, depth?: number): V[]; declare function flatMap(collection: Set | ArrayLike, itee: ((value: V, index: number, collection: Collection) => U | Promise) | NonFuncItee, depth?: number): U[]; declare function flatMap(collection: Record | Map, itee: ((value: V, index: string, collection: Collection) => U | Promise) | NonFuncItee, depth?: number): U[]; declare function flatMap(collection: Collection, itee: ((value: V, index: K, collection: Collection) => V | Promise) | NonFuncItee, depth?: number): V[]; declare function flatMap(collection: Collection, itee: ((value: V, index: K, collection: Collection) => U | Promise) | NonFuncItee, depth?: number): U[]; declare function flatMapDeep(collection: Set | ArrayLike, itee: ((value: V, index: number, collection: Collection) => V | Promise) | NonFuncItee): V[]; declare function flatMapDeep(collection: Record | Map, itee: ((value: V, index: string, collection: Collection) => V | Promise) | NonFuncItee): V[]; declare function flatMapDeep(collection: Set | ArrayLike, itee: ((value: V, index: number, collection: Collection) => U | Promise) | NonFuncItee): U[]; declare function flatMapDeep(collection: Record | Map, itee: ((value: V, index: string, collection: Collection) => U | Promise) | NonFuncItee): U[]; declare function flatMapDeep(collection: Collection, itee: ((value: V, index: K, collection: Collection) => V) | NonFuncItee): V[]; declare function flatMapDeep(collection: Collection, itee: ((value: V, index: K, collection: Collection) => U) | NonFuncItee): U[]; declare function groupBy(collection: Collection, itee?: ((value: V) => UnknownMapKey) | NonFuncItee): Record; declare function groupBy(collection: Collection, itee?: ((value: V) => UnknownMapKey) | NonFuncItee): Record; /** * 判断集合中是否包含给定的值。使用eq函数进行等值判断。 * * @example * //true * console.log(_.includes({a:1,b:2},2)) * //false * console.log(_.includes([1,3,5,7,[2]],2)) * //true * console.log(_.includes([1,3,5,7,[2]],3)) * //false * console.log(_.includes([1,3,5,7,[2]],3,2)) * //true * console.log(_.includes([0,null,undefined,NaN],NaN)) * //true * console.log(_.includes('abcdefg','abc')) * //false * console.log(_.includes('abcdefg','abc',2)) * //false * console.log(_.includes('aBcDeFg','abc')) * * @param collection 如果集合是map/object对象,则只对value进行比对 * @param value * @param fromIndex 从集合的fromIndex 索引处开始查找。如果集合是map/object对象,无效 * @returns 如果包含返回true否则返回false */ declare function includes(collection: Collection, value: any, fromIndex?: number): boolean; /** * 返回除最后一个元素外的所有元素组成的新数组 * * @example * //[1, 2] * console.log(_.initial([1, 2, 3])) * * @param array 数组 * @returns 新数组 * @since 0.19.0 */ declare function initial(array: Collection): T[]; declare function keyBy(collection: Collection, itee?: ((value: unknown) => K) | NonFuncItee): Record; declare function keyBy(collection: Collection, itee?: ((value: V) => K) | NonFuncItee): Record; declare function last(array: Collection): T; declare function last(array: Collection): U; declare function map(collection: Set | ArrayLike, itee: ((value: any, index: number, collection: Collection) => U | Promise) | NonFuncItee): U[]; declare function map(collection: Record | Map, itee: ((value: any, index: string, collection: Collection) => U | Promise) | NonFuncItee): U[]; declare function map(collection: Set | ArrayLike, itee: ((value: V, index: number, collection: Collection) => U | Promise) | NonFuncItee): U[]; declare function map(collection: Record | Map, itee: ((value: V, index: string, collection: Collection) => U | Promise) | NonFuncItee): U[]; declare function map(collection: Collection, itee: ((value: V, index: K, collection: Collection) => V | Promise) | NonFuncItee): V[]; declare function map(collection: Collection, itee: ((value: V, index: K, collection: Collection) => U | Promise) | NonFuncItee): U[]; declare function partition(collection: Set | ArrayLike, predicate: ((value: V, index: number, collection: Collection) => boolean) | NonFuncItee): V[][]; declare function partition(collection: Record | Map, predicate: ((value: V, index: string, collection: Collection) => boolean) | NonFuncItee): V[][]; declare function partition(collection: Collection, predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): V[][]; declare function reduce(collection: Set | ArrayLike, callback: (accumulator: U, value: V, key: number, collection: Collection) => U, initialValue: U): U; declare function reduce(collection: Record | Map, callback: (accumulator: U, value: V, key: number, collection: Collection) => U, initialValue: U): U; declare function reduce(collection: Set | ArrayLike, callback: (accumulator: V, value: V, key: number, collection: Collection) => V, initialValue: V): V; declare function reduce(collection: Record | Map, callback: (accumulator: V, value: V, key: string, collection: Collection) => V, initialValue: V): V; declare function reduce(collection: Collection, callback: (accumulator: U, value: V, key: K, collection: Collection) => U, initialValue: U): U; declare function reject(collection: Set | ArrayLike, predicate: ((value: V, index: number, collection: Collection) => boolean) | NonFuncItee): V[]; declare function reject(collection: Record | Map, predicate: ((value: V, index: string, collection: Collection) => boolean) | NonFuncItee): V[]; declare function reject(collection: Collection, predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): V[]; /** * 返回对指定列表的唯一随机采样结果 * @example * //随机值 * console.log(_.sample([1,2,3,4,5,6,7,8,9,0])) * //随机值 * console.log(_.sample({a:1,b:2,c:3,d:4,e:5})) * * @param collection 任何可遍历的集合类型,比如array / arraylike / set / map / object / ... * @returns 采样结果 * @since 0.16.0 */ declare function sample(collection: Collection): T; /** * 返回对指定列表的指定数量随机采样结果 * @example * //[随机值] * console.log(_.sampleSize([1,2,3,4,5,6,7,8,9,0])) * //[随机值1,随机值2] * console.log(_.sampleSize([{a:1},{b:2},{c:3},{d:4},{e:5}],2)) * * @param collection 任何可遍历的集合类型,比如array / arraylike / set / map / object / ... * @param count 采样数量 * @returns 采样结果 * @since 0.16.0 */ declare function sampleSize(collection: Collection, count?: number): T[]; /** * 返回指定数组的一个随机乱序副本 * @example * //[随机内容] * console.log(_.shuffle([1,2,3,4,5,6,7,8,9,0])) * //[随机内容] * console.log(_.shuffle([{a:1},{a:2},{a:3},{a:4},{a:5}])) * //[随机内容] * console.log(_.shuffle({a:1,b:2,c:3,d:4,e:5})) * * @param collection 任何可遍历的集合类型,比如array / arraylike / set / map / object / ... * @returns 乱序副本 * @since 0.16.0 */ declare function shuffle(collection: Collection): T[]; /** * 获取集合对象的内容数量,对于map/object对象获取的是键/值对的数量 * * @example * //3 * console.log(_.size({a:1,b:2,c:{x:1}})) * //0 * console.log(_.size(null)) * //3 * console.log(_.size(new Set([1,2,3]))) * //2 * console.log(_.size([1,[2,[3]]])) * //2 * console.log(_.size(document.body.children)) * //4 * console.log(_.size(document.body.childNodes)) * //3 arguments已不推荐使用,请使用Rest参数 * console.log((function(){return _.size(arguments)})('a',2,'b')) * //7 * console.log(_.size('func.js')) * * @param collection * @returns 集合长度,对于null/undefined/WeakMap/WeakSet返回0 */ declare function size(collection: any): number; declare function some(collection: Set | ArrayLike, predicate: ((value: V, index: number, collection: Collection) => boolean) | NonFuncItee): boolean; declare function some(collection: Record | Map, predicate: ((value: V, index: string, collection: Collection) => boolean) | NonFuncItee): boolean; declare function some(collection: Collection, predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): boolean; /** * 对集合进行排序,并返回排序后的数组副本。 * * @example * //字符排序 ['lao1', 'lao2', 'lao3'] * console.log(_.sort(['lao1','lao3','lao2'])) * //数字排序[7, 9, 80] * console.log(_.sort([9,80,7])) * //日期排序["3/1/2019", "2020/1/1", Wed Apr 01 2020...] * console.log(_.sort([new Date(2020,3,1),'2020/1/1','3/1/2019'])) * //第一个元素不是日期对象,需要转换 * console.log(_.sort(_.map(['2020/1/1',new Date(2020,3,1),'3/1/2019'],v=>new Date(v)))) * //对象排序 * const users = [ * {name:'zhangsan',age:53}, * {name:'lisi',age:44}, * {name:'wangwu',age:25}, * {name:'zhaoliu',age:36} * ]; * //[25,36,44,53] * console.log(_.sort(users,(a,b)=>a.age-b.age)) * // 倒排 * console.log(_.sort(users,(a,b)=>b.age-a.age)) * * @param collection 任何可遍历的集合类型,比如array / arraylike / set / map / object / ... * @param comparator (a,b) 排序函数,如果为空使用sortBy逻辑 * @returns 排序后的数组 */ declare function sort(collection: Collection, comparator?: (a: T, b: T) => number): T[]; declare function sortBy(collection: Set | ArrayLike, itee?: ((value: V, index: number) => any) | NonFuncItee): V[]; declare function sortBy(collection: Record | Map, itee?: ((value: V, index: string) => any) | NonFuncItee): V[]; declare function sortBy(collection: Collection, itee?: ((value: V, index: K) => any) | NonFuncItee): V[]; /** * 返回除第一个元素外的所有元素组成的新数组 * * @example * //[2, 3] * console.log(_.tail([1, 2, 3])) * * @param array 数组 * @returns 新数组 */ declare function tail(array: Collection): T[]; /** * 从起始位置获取指定数量的元素并放入新数组后返回 * * @example * //[1, 2, 3] * console.log(_.take([1, 2, 3, 4, 5],3)) * //[1, 2, 3, 4, 5] * console.log(_.take([1, 2, 3, 4, 5])) * * @param array 数组 * @param length 获取元素数量,默认数组长度 * @returns 新数组 */ declare function take(array: Collection, length?: number): T[]; /** * 从数组末尾位置获取指定数量的元素放入新数组并返回 * * @example * //[3, 4, 5] * console.log(_.takeRight([1, 2, 3, 4, 5],3)) * //[1, 2, 3, 4, 5] * console.log(_.takeRight([1, 2, 3, 4, 5])) * * @param array 数组 * @param length * @returns 新数组 * @since 1.0.0 */ declare function takeRight(array: Collection, length?: number): T[]; /** * 把一个集合对象转为array对象。对于非集合对象, *
    *
  • 字符串 - 每个字符都会变成数组的元素
  • *
  • 其他情况 - 返回包含一个collection元素的数组
  • *
* * @example * //[1,2,3] * console.log(_.toArray(new Set([1,2,3]))) * //['a','b','c'] * console.log(_.toArray('abc')) * //[1,2,'b'] * console.log(_.toArray({x:1,y:2,z:'b'})) * //[[1, 'a'], [3, 'b'], ['a', 5]] * console.log(_.toArray(new Map([[1,'a'],[3,'b'],['a',5]]))) * //[1, 3, 'a'] * console.log(_.toArray(new Map([[1,'a'],[3,'b'],['a',5]])).keys()) * * @param collection 如果是Map/Object对象会转换为值列表 * * @returns 转换后的数组对象 */ declare function toArray(collection: any): T[]; export { countBy, each, eachRight, every, filter, find, findLast, first, flatMap, flatMapDeep, groupBy, includes, initial, keyBy, last, map, partition, reduce, reject, sample, sampleSize, shuffle, size, some, sort, sortBy, tail, take, takeRight, toArray };