/** * 向数组末尾追加一个或多个元素并返回 * * @effect 修改原数组 * * @example * //[1, 2, 3, 4] * let ary = [1,2]; * _.append(ary,3,4); * console.log(ary); * //[1, 2, Array(2), 5] * ary = [1,2]; * _.append(ary,[3,4],5); * console.log(ary); * //[1, 2, 3, 4] * ary = [1,2]; * _.append(ary,...[3,4]); * console.log(ary); * * @param array 数组对象。如果非数组类型会自动转为数组 * @param values 1-n个需要插入列表的值 * @returns 插入值后的数组对象 */ declare function append(array: T[] | Set, ...values: any[]): T[]; /** * 把指定数组拆分成多个长度为size的子数组,并返回子数组组成的二维数组 * @example * //[[1,2],[3,4]] * console.log(_.chunk([1,2,3,4],2)) * //[[1,2,3],[4]] * console.log(_.chunk([1,2,3,4],3)) * * @param array 数组,非数组返回空数组 * @param size 子数组长度 * @returns 拆分后的新数组 * @since 0.23.0 */ declare function chunk(array: T[] | Set, size?: number): T[][]; /** * 对集合内的假值进行剔除,并返回剔除后的新数组。假值包括 null/undefined/NaN/0/''/false * @example * //[1,2,4,'a','1'] * console.log(_.compact([0,1,false,2,4,undefined,'a','1','',null])) * * @param array 数组 * @returns 转换后的新数组对象 */ declare function compact(array: T[] | Set): T[]; /** * 合并数组或值并返回新数组,元素可以重复。基于 `Array.prototype.concat` 实现 * * @example * //[a/b/a] * console.log(_.concat([{name:'a'},{name:'b'}],[{name:'a'}])) * //[1, 2, 3, 1, 2] * console.log(_.concat([1,2,3],[1,2])) * //[1, 2, 3, 1, 2, null, 0] * console.log(_.concat([1,2,3],[1,2],null,0)) * //[1, 2, 3, 1, 2, doms..., 0, null] * console.log(_.concat([1,2,3],[1,2],document.body.children,0,null)) * * @param arrays 1-n个数组对象 * @returns 如果参数为空,返回空数组 */ declare function concat(...arrays: any[]): any[]; /** * 对所有集合做差集并返回差集元素组成的新数组 * * @example * //[1] * console.log(_.except([1,2,3],[2,3])) * //[1,4] * console.log(_.except([1,2,3],[2,3],[3,2,1,4])) * //[{name: "b"}] * console.log(_.except([{name:'a'},{name:'b'}],[{name:'a'}],v=>v.name)) * //[2, 3, "2", "3"] '2'和2不相等 * console.log(_.except([1,2,3],[1,'2',3],[2,'3',1])) * * @param params (...arrays[,identifier(v)]) * arrays - 1-n个数组或arraylike对象,非arraylike参数会被忽略; * identifier - 标识函数,用来对每个元素返回唯一标识,标识相同的值会认为相等。使用SameValueZero 算法进行值比较。如果为空,直接使用值自身比较 * @returns 差集元素组成的新数组 */ declare function except(...params: any): T[]; /** * 使用固定值填充arrayLike中从起始索引到终止索引内的全部元素 * * @example * //[6, 6, 6] * console.log(_.fill(new Array(3), 6)) * //[1, 'x', 'x', 'x', 5] * console.log(_.fill([1, 2, 3, 4, 5], 'x', 1, 4)) * * @param array 数组 * @param value 填充值 * @param start 起始索引,包含 * @param end 终止索引,不包含 * @returns 填充后的新数组 */ declare function fill(array: T[], value: any, start?: number, end?: number): T[]; /** * 内部使用类型 * * @packageDocumentation */ /** * 列表类型 */ interface IList { length: number; [Symbol.iterator]?: any; [index: number]: any; } /** * 未知类型的mapKey */ type UnknownMapKey = string | number | symbol; /** * 类数组类型 */ type ArrayLike = Array | string | NodeList | HTMLCollection | IList | NodeListOf; /** * 非函数迭代类型 */ type NonFuncItee = string | Record | Array; /** * 对集合内的所有元素进行断言并返回第一个匹配的元素索引 * * @example * //3 查询数组的索引 * console.log(_.findIndex(['a','b','c',1,3,6],_.isNumber)) * //0 * console.log(_.findIndex([{a:1},{a:2},{a:3}],'a')) * //2 * console.log(_.findIndex([{a:1},{a:2},{a:3}],{a:3})) * * @param array 数组,非数组返回-1 * @param predicate (value[,index[,array]]);断言 *
当断言是函数时回调参数见定义 *
其他类型请参考 {@link utils!iteratee} * @param fromIndex 从0开始的起始索引,设置该参数可以减少实际遍历次数。默认0 * @returns 第一个匹配断言的元素索引或-1 */ declare function findIndex(array: T[], predicate: ((value: T, index: string | number, array: T[]) => boolean) | NonFuncItee, fromIndex?: number): number; /** * 对集合内的所有元素进行断言并返回最后一个匹配的元素索引 * * @example * //5 查询数组的索引 * console.log(_.findLastIndex(['a','b','c',1,3,6],_.isNumber)) * //2 * console.log(_.findLastIndex([{a:1},{a:2},{a:3}],'a')) * * @param array 数组,非数组返回-1 * @param predicate (value[,index[,array]]);断言 *
当断言是函数时回调参数见定义 *
其他类型请参考 {@link utils!iteratee} * @param fromIndex 从集合长度-1开始的起始索引。设置该参数可以减少实际遍历次数 * @returns 最后一个匹配断言的元素索引或-1 * @since 0.19.0 */ declare function findLastIndex(array: T[], predicate: ((value: T, index: string | number, array: T[]) => boolean) | NonFuncItee, fromIndex?: number): number; /** * 按照指定的嵌套深度递归遍历数组,并将所有元素与子数组中的元素合并为一个新数组返回 * * @example * //[1,2,3,4,5] * console.log(_.flat([1,[2,3],[4,5]])) * //[1,2,3,4,5,[6,7]] * console.log(_.flat([1,[2,3],[4,5,[6,7]]])) * //[1,2,3,[4]] * console.log(_.flat([1,[2,[3,[4]]]],2)) * //[1,2,1,3,4] * console.log(_.flat(new Set([1,1,[2,[1,[3,4]]]]),Infinity)) * * @param array 数组 * @param depth 嵌套深度 * @returns 扁平化后的新数组 */ declare function flat(array: any[] | Set, depth?: number): T[]; /** * 无限深度遍历数组,并将所有元素与子数组中的元素合并为一个新数组返回 * * @example * //[1,2,1,3,4] * console.log(_.flatDeep(new Set([1,1,[2,[1,[3,4]]]]))) * //[1,2,3,4] * console.log(_.flatDeep([1,[2,[3,[4]]]])) * * @param array 数组 * @returns 扁平化后的新数组 */ declare function flatDeep(array: any[]): T[]; /** * 向数组中指定位置插入一个或多个元素并返回 * * @effect 修改原数组 * * @example * //[1, 2, Array(1), 'a', 3, 4] * let ary = [1,2,3,4]; * _.insert(ary,2,[1],'a'); * console.log(ary); * //[1, 2, 3, 4] * ary = [3,4]; * _.insert(ary,0,1,2); * console.log(ary); * //func.js * console.log(_.insert('funcjs',4,'.').join('')); * * @param array 数组对象。如果非数组类型会自动转为数组 * @param index 插入位置索引,0 - 列表长度 * @param values 1-n个需要插入列表的值 * @returns 插入值后的数组对象 */ declare function insert(array: T[], index: number, ...values: any[]): T[]; /** * 对所有集合做交集并返回交集元素组成的新数组 *

* 关于算法性能可以查看文章《如何实现高性能集合操作(intersect)》 *

* * @example * //[2] * console.log(_.intersect([1,2,3],[2,3],[1,2])) * //[3] * console.log(_.intersect([1,1,2,2,3],[1,2,3,4,4,4],[3,3,3,3,3,3])) * //[{name: "a"}] 最后一个参数是函数时作为标识函数 * console.log(_.intersect([{name:'a'},{name:'b'}],[{name:'a'}],v=>v.name)) * //[] * console.log(_.intersect()) * //[3] 第三个参数被忽略,然后求交集 * console.log(_.intersect([1,2,3],[3],undefined)) * //[1] "2"和2不相同,3和"3"不相同 * console.log(_.intersect([1,2,3],[1,'2',3],[2,'3',1])) * * @param params (...arrays[,identifier(v)]) * arrays - 1-n个数组或arraylike对象,非arraylike参数会被忽略; * identifier - 标识函数,用来对每个元素返回唯一标识,标识相同的值会认为相等。使用SameValueZero 算法进行值比较。如果为空,直接使用值自身比较 * @returns 交集元素组成的新数组 */ declare function intersect(...params: any): T[]; /** * 把arrayLike中所有元素连接成字符串并返回。对于基本类型元素会直接转为字符值,对象类型会调用toString()方法 * * @example * //'1/2/3/4' * console.log(_.join([1, 2, 3, 4], '/')) * //'1,2,3,4' * console.log(_.join([1, 2, 3, 4])) * * @param array 数组,非数组返回空字符串 * @param separator 分隔符 * @returns 拼接字符串 */ declare function join(array: any[], separator?: string): string; /** * 删除数组末尾或指定索引的一个元素并返回被删除的元素 * * @effect 修改原数组 * @example * //3, [1, 2] * let ary = [1,2,3]; * console.log(_.pop(ary),ary) * //{a: 1}, [{"a":2},{"a":3}] * ary = [{a:1},{a:2},{a:3}]; * console.log(_.pop(ary,0),ary) * * @param array 数组对象。如果非数组类型会直接返回null * @param index 要删除元素的索引。默认删除最后一个元素 * @returns 被删除的值或null */ declare function pop(array: unknown[], index?: number): T | null; /** * 与without相同,但会修改原数组 * @effect 修改原数组 * @example * //[1, 1] true * let ary = [1,2,3,4,3,2,1]; * let newAry = _.pull(ary,2,3,4) * console.log(newAry,ary === newAry) * * @param array 数组对象 * @param values 需要删除的值 * @returns 新数组 * @since 0.19.0 */ declare function pull(array: T[], ...values: T[]): T[]; declare function range(end: number): number[]; declare function range(start: number, end: number): number[]; declare function range(start: number, end: number, step: number): number[]; /** * 删除数组中断言结果为true的元素并返回被删除的元素 * @effect 修改原数组 * @example * //[1, 3] [2, 4] * let ary = [1,2,3,4]; * console.log(_.remove(ary,x=>x%2),ary) * //[2] [1,3] * ary = [{a:1},{a:2},{a:3}]; * console.log(_.remove(ary,v=>v.a===2),ary) * //[3] [1,2] * ary = [{a:1},{a:2},{a:3}]; * console.log(_.remove(ary,{a:3}),ary) * * @param array 数组对象,如果参数非数组直接返回 * @param predicate (value[,index[,array]]);断言 *
当断言是函数时回调参数见定义 *
其他类型请参考 {@link utils!iteratee} * @returns 被删除的元素数组或空数组 * @since 0.19.0 */ declare function remove(array: T[], predicate: ((value: T, index: string | number, array: T[]) => boolean) | NonFuncItee): T[]; /** * 对数组元素位置进行颠倒,返回改变后的数组。 * * @example * //[3, 2, 1] * console.log(_.reverse([1, 2, 3])) * * @param array 数组,类数组或Set * @returns 颠倒后的新数组 */ declare function reverse(array: Set | ArrayLike): T[]; /** * 对数组进行切片,并返回切片后的新数组,原数组不变。新数组内容是对原数组内容的浅拷贝 * * @example * //[2,3,4] * console.log(_.slice([1,2,3,4,5],1,4)) * //[2,3,4,5] * console.log(_.slice([1,2,3,4,5],1)) * * * @param array 数组,非数组返回空数组 * @param begin 切片起始下标,包含下标位置元素,默认0 * @param end 切片结束下标,不包含下标位置元素 * @returns 切片元素组成的新数组 */ declare function slice(array: Set | ArrayLike, begin?: number, end?: number): T[]; /** * 使用二分法确定在array保持排序不变的情况下,value可以插入array的最小索引 * @example * //1 * console.log(_.sortedIndex([1,2,3],1.5)) * //1 * console.log(_.sortedIndex(['a', 'c'], 'b')) * //0 * console.log(_.sortedIndex([{a:1},{a:2},{a:3}], {a:2.5})) * * @param array 对象属性标识符数组 * @param value 需要插入数组的值 * @returns array索引 * @since 1.0.0 */ declare function sortedIndex(array: T[], value: any): number; /** * 同sortedIndex,但支持自定义回调用来获取对比值 * @example * //2 * console.log(_.sortedIndexBy([{a:1},{a:2},{a:3}], {a:2.5},'a')) * * @param array 对象属性标识符数组 * @param value 需要插入数组的值 * @param itee (value)回调函数,返回排序对比值。默认 identity * @returns array索引 * @since 1.0.0 */ declare function sortedIndexBy(array: T[], value: any, itee?: ((value: any) => any) | NonFuncItee): number; /** * 对所有集合做并集并返回并集元素组成的新数组。并集类似concat()但不允许重复值 * * @example * //[1, 2, 3] * console.log(_.union([1,2,3],[2,3])) * //[1, 2, 3, "1", "2"] * console.log(_.union([1,2,3],['1','2'])) * //[{name: "a"},{name: "b"}] * console.log(_.union([{name:'a'},{name:'b'}],[{name:'a'}],v=>v.name)) * //[a/b/a] 没有标识函数无法去重 * console.log(_.union([{name:'a'},{name:'b'}],[{name:'a'}])) * //[1, 2, 3, "3"] "3"和3不相等 * console.log(_.union([1,2,3],[1,3],[2,'3',1])) * * @param params (...arrays[,identifier(v)]) * arrays - 1-n个数组或arraylike对象,非arraylike参数会被忽略; * identifier - 标识函数,用来对每个元素返回唯一标识,标识相同的值会认为相等。使用SameValueZero 算法进行值比较。如果为空,直接使用值自身比较 * @returns 并集元素组成的新数组 */ declare function union(...params: any): T[]; /** * 对数组内的值进行去重 * @example * // [1,2,4,"a","1",null] * console.log(_.unique([1,2,2,4,4,'a','1','a',null,null])) * * @param array 数组,非数组返回空数组 * @returns 转换后的新数组对象 */ declare function uniq(array: T[]): T[]; /** * 同uniq,但支持自定义筛选函数 * @example * // [{"a":1},{"a":"1"},{"a":2},{"a":"2"}] * console.log(_.uniqBy([{a:1},{a:1},{a:'1'},{a:2},{a:'2'},{a:2}],'a')) * // [{"a":1},{"a":2}] * console.log(_.uniqBy([{a:1},{a:1},{a:'1'},{a:2},{a:'2'},{a:2}],v=>v.a>>0)) * * @param array 数组 * @param itee (value,index) 筛选函数,返回需要对比的值。默认identity *
当iteratee是函数时回调参数见定义 *
其他类型请参考 {@link utils.iteratee} * @returns 去重后的新数组对象 * @since 1.0.0 */ declare function uniqBy(array: T[], itee?: ((value: T, index: UnknownMapKey) => boolean) | NonFuncItee): T[]; /** * zip的反操作 * @example * //[[1,2,undefined],['a','b','c']] * console.log(_.unzip([[1, 'a'],[2, 'b'],[undefined, 'c']])) * //[['a', 'b', 'c'], [1, 2, undefined],['1', undefined,undefined]] * console.log(_.unzip([['a', 1, '1'], ['b', 2],['c']])) * * @param array 包含若干分组的数组 * @returns 重新分组后的新数组 * @since 0.23.0 */ declare function unzip(array: any[]): any[][]; /** * 返回删除所有values后的新数组。使用eq函数进行等值判断 * * @example * //[1, 1] * console.log(_.without([1,2,3,4,3,2,1],2,3,4)) * * @param array 数组对象 * @param values 需要删除的值 * @returns 新数组 * @since 0.19.0 */ declare function without(array: T[], ...values: T[]): T[]; /** * 创建一个由指定数组arrays内元素重新分组后组成的二维数组, * 第一个子数组由每个数组内的第一个元素组成,第二个子数组由每个数组内的第二个元素组成,以此类推。 * 子数组的数量由参数中数组内元素最多的数组决定。 * @example * //[[1, 'a'],[2, 'b'],[undefined, 'c']] * console.log(_.zip([1,2],['a','b','c'])) * //[['a', 1, '1'], ['b', 2, undefined],['c', undefined,undefined]] * console.log(_.zip(['a','b','c'],[1,2],['1'])) * * @param arrays 1-n个数组 * @returns 重新分组后的新数组 * @since 0.23.0 */ declare function zip(...arrays: any[][]): any[][]; /** * 创建一个对象,属性名称与属性值分别来自两个数组 * @example * //{a: 1, b: 2} * console.log(_.zipObject(['a','b'],[1,2,3])) * * @param keys 对象属性标识符数组 * @param values 对象值数组 * @returns 组合后的对象 * @since 0.23.0 */ declare function zipObject(keys: Array, values: any[]): Record; /** * 与zip相同,但支持自定义组合逻辑 * @example * //[[1, 3, 5], [2, 4, 6]] * console.log(_.zipWith([1,2],[3,4],[5,6])) * //[9, 12] * console.log(_.zipWith([1,2],[3,4],[5,6],_.sum)) * //[3, 4] * console.log(_.zipWith([1,2],[3,4],[5,6],group=>_.avg(group))) * * @param params (...arrays[,iteratee(group)]) * arrays - 1-n个数组或arraylike对象,非arraylike参数会被忽略; * iteratee - 回调函数,返回组合后的分组值。默认使用identity函数 * * @returns 重新分组后的新数组 * @since 1.0.0 */ declare function zipWith(...params: any[]): any[][]; export { append, chunk, compact, concat, except, fill, findIndex, findLastIndex, flat, flatDeep, insert, intersect, join, pop, pull, range, remove, reverse, slice, sortedIndex, sortedIndexBy, union, uniq, uniqBy, unzip, without, zip, zipObject, zipWith };