/** * 向数组末尾追加一个或多个元素并返回 * * @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$1 = Array | string | NodeList | HTMLCollection | IList | NodeListOf; /** * 集合类型 */ type Collection = Record, V> | Set | Map | ArrayLike$1; /** * 非函数迭代类型 */ type NonFuncItee = string | Record | Array; /** * 模板选项 */ interface IOptions { delimiters?: string[]; mixins?: Record; globals?: Record; stripWhite?: boolean; } /** * 对集合内的所有元素进行断言并返回第一个匹配的元素索引 * * @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$1): 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$1, 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[][]; 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[]; /** * 对日期时间进行量变处理 * * @example * //2020/5/1 08:00:20 * console.log(_.formatDate(_.addTime(new Date('2020-05-01'),20),'yyyy/MM/dd hh:mm:ss')) * //2020-04-11 08:00 * console.log(_.formatDate(_.addTime(new Date('2020-05-01'),-20,'d'))) * //2022-01-01 00:00 * console.log(_.formatDate(_.addTime(new Date('2020-05-01 0:0'),20,'M'))) * * @param date 原日期时间 * @param amount 变化量,可以为负数 * @param type 量变时间类型 *
    *
  • y
  • *
  • M
  • *
  • d
  • *
  • h
  • *
  • m
  • *
  • s
  • *
* @returns 日期对象 */ declare function addTime(date: Date | string | number, amount: number, type?: string): Date; /** * 比较两个日期,并返回由比较时间单位确定的相差时间。 *

* 使用truncated对比算法 —— 小于指定时间单位的值会被视为相同, * 比如对比月,则两个日期的 日/时/分/秒 会被认为相同,以此类推。 *

* 相差时间为正数表示date1日期晚于(大于)date2,负数相反,0表示时间/日期相同。 *

* 注意,如果对比单位是 h/m/s,务必要保持格式一致,比如 * * ```ts * //实际相差8小时 * new Date('2020-01-01') * //vs * new Date('2020/01/01') * ``` * * @example * //0 * console.log(_.compareDate(new Date('2020/05/01'),'2020/5/1')) * //格式不一致,相差8小时 * console.log(_.compareDate(new Date('2020-05-01'),'2020/5/1','h')) * //-59 * console.log(_.compareDate(new Date('2019/01/01'),'2019/3/1')) * * @param date1 日期对象、时间戳或合法格式的日期时间字符串。 * 对于字符串格式,可以时UTC格式,或者 * RFC2822格式 * @param date2 同date1 * @param type 比较时间单位 *

    *
  • y
  • *
  • M
  • *
  • d
  • *
  • h
  • *
  • m
  • *
  • s
  • *
* @returns 根据比较时间单位返回的比较值。正数为date1日期晚于(大于)date2,负数相反,0表示相同。 */ declare function compareDate(date1: Date | string | number, date2: Date | string | number, type?: string): number; /** * 通过表达式格式化日期时间 * * ``` * yyyy-MM-dd hh:mm:ss => 2020-12-11 10:09:08 * ``` * * pattern解释: * * - `yy` 2位年 - 22 * - `yyyy` 4位年 - 2022 * - `M` 1位月(1-12) * - `MM` 2位月(01-12) * - `MMM` 月描述(一月 - 十二月) * - `d` 1位日(1-30/31/29/28) - `dd` 2位日(01-30/31/29/28) - `ddd` 一年中的日(1-365) - `dddd` 一年中的日(001-365) - `h` 1位小时(1-12) - `hh` 2位小时(01-12) - `H` 1位小时(0-23) - `HH` 2位小时(00-23) - `m` 1位分钟(0-59) - `mm` 2位分钟(00-59) - `s` 1位秒(0-59) - `ss` 2位秒(00-59) - `Q` 季度(1-4) - `QQ` 季度描述(春-冬) - `W` 一年中的周(1-53) - `WW` 一年中的周(01-53) - `w` 一月中的周(1-6) - `ww` 一月中的周描述(第一周 - 第六周) - `E` 星期(1-7) - `EE` 星期描述(星期一 - 星期日) - `S` 毫秒 - `a` AM/PM * * @example * //now time * console.log(_.formatDate(_.now(),'yyyy-MM-dd hh:mm')) * //2/1/2021 * console.log(_.formatDate('2021-2-1','M/d/yyyy')) * //2/1/21 * console.log(_.formatDate('2021-2-1','M/d/yy')) * //02/01/21 * console.log(_.formatDate('2021-2-1','MM/dd/yy')) * //02/01/2021 * console.log(_.formatDate('2021-2-1','MM/dd/yyyy')) * //21/02/01 * console.log(_.formatDate('2021-2-1','yy/MM/dd')) * //2021-02-01 * console.log(_.formatDate('2021-2-1','yyyy-MM-dd')) * //21-12-11 10:09:08 * console.log(_.formatDate('2021-12-11T10:09:08','yy-MM-dd HH:mm:ss')) * //12/11/2020 1009 * console.log(_.formatDate('2020-12-11 10:09:08','MM/dd/yyyy hhmm')) * //2020-12-11 08:00 * console.log(_.formatDate(1607644800000)) * //'' * console.log(_.formatDate('13:02')) * //'' * console.log(_.formatDate(null)) * //现在时间:(20-12-11 10:09:08) * console.log(_.formatDate('2020-12-11 10:09:08','现在时间:(yy-MM-dd hh:mm:ss)')) * * @param val 需要格式化的值,可以是日期对象或时间字符串或日期毫秒数 * @param pattern 格式化模式 * @returns 格式化后的日期字符串,无效日期返回空字符串 */ declare function formatDate(val: string | Date | number, pattern?: string): string; declare namespace formatDate { var locale: (lang: string, options: { quarters: string[]; months: string[]; weeks: string[]; days: string[]; meridiems: string[]; }) => void; var lang: (lang: string) => void; } /** * 获取指定日期在当前年中的天数并返回 * @param date 日期对象 * @returns 当前年中的第几天 */ declare function getDayOfYear(date: Date | string | number): number; /** * 获取指定日期在当前月中的周数并返回 * @param date 日期对象 * @returns 当前月中的第几周 */ declare function getWeekOfMonth(date: Date | string | number): number; /** * 获取指定日期在当前年中的周数并返回 * @param date 日期对象 * @returns 当前年中的第几周 */ declare function getWeekOfYear(date: Date | string | number): number; /** * 指定日期是否是闰年 * @param date 日期对象 * @returns 闰年返回true */ declare function isLeapYear(date: Date): boolean; /** * 比较两个日期是否为同一天 * @example * //true * console.log(_.isSameDay(new Date('2020-05-01'),'2020/5/1')) * //false * console.log(_.isSameDay(new Date('2020-05-01 23:59:59.999'),'2020/5/2 0:0:0.000')) * * @param date1 日期对象或合法格式的日期时间字符串 * @param date2 同date1 * @returns */ declare function isSameDay(date1: Date | string | number, date2: Date | string | number): boolean; /** * 返回13位日期毫秒数,表示从1970 年 1 月 1 日 00:00:00 (UTC)起到当前时间 * * @example * //now time * console.log(_.now()) * * @returns 带毫秒数的时间戳 */ declare function now(): number; /** * 通过指定参数得到日期对象。支持多种签名 * * ```js * _.toDate(1320940800); //timestamp unix style * _.toDate(1320940800123); //timestamp javascript style * _.toDate([year,month,day]); //注意,month的索引从1开始 * _.toDate([year,month,day,hour,min,sec]); //注意,month的索引从1开始 * _.toDate(datetimeStr); * ``` * * @example * //'2011/11/11 00:00:00' * console.log(_.toDate(1320940800).toLocaleString()) * //'2011/11/11 00:01:39' * console.log(_.toDate(1320940899999).toLocaleString()) * //'2022/12/12 00:00:00' * console.log(_.toDate([2022,11,12]).toLocaleString()) * //'2022/12/12 12:12:12' * console.log(_.toDate([2022,11,12,12,12,12]).toLocaleString()) * //'2022/2/2 00:00:00' * console.log(_.toDate('2022/2/2').toLocaleString()) * //'2022/2/2 08:00:00' * console.log(_.toDate('2022-02-02').toLocaleString()) * * @param value 转换参数 * * @returns 转换后的日期。无效日期统一返回1970/1/1 */ declare function toDate(value: number | [year: number, monthIndex: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number] | string | Date): Date; /** * 创建一个包含指定函数逻辑且内置计数的包装函数并返回。 * 该函数每调用一次计数会减一,直到计数为0后生效。可用于异步结果汇总时只调用一次的场景 * * @example * //undefined, undefined, 'data saved' * let saveTip = _.after(()=>'data saved',2); * console.log(saveTip(),saveTip(),saveTip()) * * @param fn 需要调用的函数 * @param count 计数 * @returns 包装后的函数 */ declare function after any>(fn: T, count?: number): T; /** * 传递v为参数执行interceptor1函数,如果该函数返回值未定义(undefined)则执行interceptor2函数,并返回函数返回值。 * 用于函数链中的分支操作 * @example * //false * console.log(_.alt(9,v=>false,v=>20)) * * @param v * @param interceptor1 (v) * @param interceptor2 (v) * @returns 函数返回值 */ declare function alt(v: unknown, interceptor1: Function, interceptor2: Function): any; /** * 创建一个新的函数,并且绑定函数的this上下文。默认参数部分同partial() * * @example * const obj = { * text:'Func.js', * click:function(a,b,c){console.log('welcome to '+this.text,a,b,c)}, * blur:function(){console.log('bye '+this.text)} * } * //自动填充参数 * let click = _.bind(obj.click,obj,'a',undefined,'c'); * click('hi') * //1秒后执行,无参数 * setTimeout(click,1000) * * @param fn 需要调用的函数 * @param thisArg fn函数内this所指向的值 * @param args 参数可以使用undefined作为占位符,以此来确定不同的实参位置 * @returns 绑定thisArg的新函数 * @since 0.17.0 */ declare function bind any>(fn: any, thisArg: any, ...args: any[]): T; /** * 批量绑定对象内的函数属性,将这些函数的this上下文指向绑定对象。经常用于模型中的函数用于外部场景,比如setTimeout/事件绑定等 * * @example * const obj = { * text:'Func.js', * click:function(a,b,c){console.log('welcome to '+this.text,a,b,c)}, * click2:function(){console.log('hi '+this.text)} * } * //自动填充参数 * _.bindAll(obj,'click',['click2']); * //1秒后执行,无参数 * setTimeout(obj.click,1000) * //事件 * top.onclick = obj.click2 * * @param object 绑定对象 * @param methodNames 属性名或path * @returns 绑定对象 * @since 0.17.0 */ declare function bindAll>(object: T, ...methodNames: (string | string[])[]): T; /** * 通过给定参数调用fn并返回执行结果 * * @example * //自动填充参数 * _.call(fn,1,2); * //事件 * _.call(fn,1,2); * * @param fn 需要执行的函数 * @param args 可变参数 * @returns 执行结果。如果函数无效或无返回值返回undefined * @since 1.0.0 */ declare function call(fn: any, ...args: any): any; /** * 创建一个新的函数,该函数的参数会传递给第一个fns函数来计算结果,而结果又是第二个fns函数的参数,以此类推, * 直到所有函数执行完成。常用于封装不同的可重用函数模块组成新的函数或实现惰性计算,比如 * *

 * let checkName = _.compose(_.trim,v=>v.length>6);
 * checkName(' holyhigh') //=> true
 * checkName(' ') //=> false
 * 
* * @example * // Holyhigh * let formatName = _.compose(_.lowerCase,_.capitalize); * console.log(formatName('HOLYHIGH')) * * @param fns 多个函数 * @returns 组合后的入口函数 */ declare function compose any>(...fns: any[]): T; /** * 创建一个包含指定函数逻辑的防抖函数并返回。在防抖函数执行后的下一次调用会在 `wait` 间隔结束后执行,如果等待期间调用函数则会重置wait时间。 * 对于一些需要等待过程停止后执行的场景非常有用,如输入结束时的查询、窗口resize后的计算等等 * * @example * //2 * let log = _.debounce(console.log); * console.log(log(1),log(2)) * * @param fn 需要调用的函数 * @param wait 抖动间隔,ms * @param immediate 立即执行一次,默认false * @returns 包装后的函数 * @since 1.4.0 */ declare function debounce any>(fn: T, wait: number, immediate?: boolean): T; /** * 启动计时器,并在倒计时为0后调用函数。 * 内部使用setTimeout进行倒计时,如需中断延迟可以使用clearTimeout函数。*注意,该函数并不提供防抖逻辑* * * @example * //1000ms 后显示some text ! * _.delay(console.log,1000,'some text','!'); * * @param fn 需要调用的函数 * @param wait 倒计时。单位ms * @param args 传入定时函数的参数 * @returns 计时器id */ declare function delay(fn: any, wait?: number, ...args: any[]): any; /** * 类似eval,对表达式进行求值并返回结果。不同于eval,fval()执行在严格模式下 * * > 注意,如果页面设置了CSP可能会导致该函数失效 * * @example * //5 * console.log(_.fval('3+2')); * //{name:"func.js"} * console.log(_.fval("{name:'func.js'}")); * //0 * console.log(_.fval('1+x-b',{x:2,b:3})) * * @param expression 计算表达式 * @param args 可选参数对象 * @param context 可选上下文 * @returns 表达式计算结果 */ declare function fval(expression: string, args?: Record, context?: any): T; /** * 创建一个包含指定函数逻辑的包装函数并返回。该函数仅执行一次 * * @example * //2748, undefined * let parseInt2 = _.once(parseInt); * console.log(parseInt2('abc',16),parseInt2('abc',16)) * * @param fn 需要调用的函数 * @returns 包装后的函数 */ declare function once any>(fn: T): T; /** * 创建一个新的函数,该函数会调用fn,并传入指定的部分参数。 * * `partial()`常用来创建函数模板或扩展核心函数,比如 * * ```js * let delay2 = _.partial(setTimeout,undefined,2000); * delay2(()=>\{console.log('2秒后调用')\}) * ``` * * @example * //2748 * let hax2num = _.partial(parseInt,undefined,16); * console.log(hax2num('abc')) * //9 * let square = _.partial(Math.pow,undefined,2); * console.log(square(3)) * //¥12,345.00元 * let formatYuan = _.partial(_.formatNumber,undefined,'¥,000.00元'); * console.log(formatYuan(12345)) * //[func.js] hi... * let log = _.partial((...args)=>args.join(' '),'[func.js][',undefined,']',undefined); * console.log(log('info','hi...')) * * @param fn 需要调用的函数 * @param args 参数可以使用undefined作为占位符,以此来确定不同的实参位置 * @returns 部分应用后的新函数 */ declare function partial any>(fn: T, ...args: any[]): T; /** * 传递v为参数执行interceptor函数,然后返回v。常用于函数链的过程调试,比如在filter后执行日志操作 *

* 注意,一旦函数链执行了shortcut fusion,tap函数的执行会延迟到一个数组推导完成后执行 *

* * @example * //shortut fusion中的tap只保留最后一个 * _([1,2,3,4]) * .map(v=>v*3).tap(v=>console.log(v))//被覆盖 * .filter(v=>v%2===0).tap(v=>console.log(v))//会延迟,并输出结果[6,12] * .join('-') * .value() * * @param v * @param interceptor (v);如果v是引用值,改变v将影响后续函数流 * @returns v */ declare function tap(v: T, interceptor: Function): T; /** * 创建一个包含指定函数逻辑的节流函数并返回。每当节流函数执行后都会等待`wait`间隔归零才可再次调用,等待期间调用函数无效。 * 对于一些需要降低执行频率的场景非常有用,如onmousemove、onscroll等事件中 * * @example * //每隔1秒输出当前时间 * let log = _.throttle(console.log,1000); * setInterval(()=>log(new Date().toTimeString()),100) * * @param fn 需要调用的函数 * @param wait 抖动间隔,ms * @param options 执行选项 * @param options.leading 首次是否执行,默认true * @param options.trailing 最后一次是否执行,默认true * @returns 包装后的函数 * @since 1.4.0 */ declare function throttle any>(fn: T, wait: number, options?: { leading?: boolean; trailing?: boolean; }): T; /** * 判断参数是否全部为字母或数字字符串 * * @example * //true * console.log(_.isAlnum('123')) * //true * console.log(_.isAlnum('123abc')) * //false * console.log(_.isAlnum(1)) * * @param v * @returns * @since 1.15.0 */ declare function isAlnum(v: unknown): v is string; /** * 判断参数是否全部为字母,含国际字母表 * * @example * //true * console.log(_.isAlpha('𰻞𰻞mian')) * //false * console.log(_.isAlpha(1)) * * @param v * @returns * @since 1.15.0 */ declare function isAlpha(v: unknown): v is string; /** * 判断参数是否为Array对象的实例 * * @example * //true * console.log(_.isArray([])) * //false * console.log(_.isArray(document.body.children)) * * @param v * @returns */ declare function isArray(v: unknown): v is T[]; /** * 判断参数是否为类数组对象 * * @example * //true * console.log(_.isArrayLike('abc123')) * //true * console.log(_.isArrayLike([])) * //true * console.log(_.isArrayLike(document.body.children)) * * @param v * @returns */ declare function isArrayLike(v: unknown): v is ArrayLike$1; /** * 对字符串进行trim后进行验证。如果非字符串,转为字符串后进行验证 * @example * //true * console.log(_.isBlank(' ')) * //true * console.log(_.isBlank(null)) * //false * console.log(_.isBlank({})) * //false * console.log(_.isBlank(' 1')) * * @param v 字符串 * @returns 如果字符串是null/undefined/\t \n \f \r或trim后长度为0,返回true * @since 0.16.0 */ declare function isBlank(v: unknown): boolean; /** * 判断值是不是一个布尔值 * * @example * //true * console.log(_.isBoolean(false)) * //false * console.log(_.isBoolean('true')) * //false * console.log(_.isBoolean(1)) * * @param v * @returns */ declare function isBoolean(v: unknown): v is boolean; /** * 判断值是不是自定义Element * * @example * //false * console.log(_.isCustomElement(document.body)) * //true * console.log(_.isCustomElement(document.body.querySelector('l-ele'))) * * @param v * @returns * @since 1.14.0 */ declare function isCustomElement(v: unknown): v is HTMLElement; /** * 判断值是不是一个Date实例 * * @example * //true * console.log(_.isDate(new Date())) * //false * console.log(_.isDate('2020/1/1')) * * @param v * @returns */ declare function isDate(v: unknown): v is Date; /** * isUndefined()的反向验证函数,在需要验证是否变量存在的场景下非常有用 * @example * //true * console.log(_.isDefined(null)) * //false * console.log(_.isDefined(undefined)) * * @param v * @returns */ declare function isDefined(v: unknown): boolean; /** * 判断值是不是Element的实例 * * @example * //true * console.log(_.isElement(document.body)) * //false * console.log(_.isElement(document)) * * @param v * @returns * @since 1.0.0 */ declare function isElement(v: unknown): v is globalThis.Element; /** * 判断参数是否为空,包括`null/undefined/空字符串/0/[]/{}`都表示空 * * 注意:相比isBlank,isEmpty只判断字符串长度是否为0 * * @example * //true * console.log(_.isEmpty(null)) * //true * console.log(_.isEmpty([])) * //false * console.log(_.isEmpty({x:1})) * * @param v * @returns */ declare function isEmpty(v: unknown): boolean; /** * 判断两个值是否相等,对于非基本类型会进行深度比较,可以比较日期/正则/数组/对象等 * * @example * //false * console.log(_.isEqual(1,'1')) * //true,false * let o = {a:1,b:[2,{c:['3','x']}]} * let oo = {a:1,b:[2,{c:['3','x']}]} * console.log(_.isEqual(o,oo),o == oo) * //true * console.log(_.isEqual([new Date('2010-2-1'),/12/],[new Date(1264953600000),new RegExp('12')])) * //false * console.log(_.isEqual([new Date('2010-2-1'),'abcd'],['2010/2/1','Abcd'])) * * @param a * @param b * @returns * @since 1.0.0 */ declare function isEqual(a: unknown, b: unknown): boolean; /** * 同isEqual,但支持自定义比较器。如果未指定比较器则使用内置逻辑处理 * 内置逻辑: * - 如果是日期使用getTime对比 * - 如果是正则使用toString对比 * - 如果是元素节点使用tagName+id+class对比 * - 如果是函数使用name对比 * @example * //true * console.log(_.isEqualWith([new Date('2010-2-1'),'abcd'],['2010/2/1','Abcd'],(av,bv)=>_.isDate(av)?av.toLocaleDateString() == bv:_.test(av,bv,'i'))) * * @param a * @param b * @param [comparator] 比较器,参数(v1,v2),返回true表示匹配。如果返回undefined使用对应内置比较器处理 * @returns * @since 1.0.0 */ declare function isEqualWith(a: any, b: any, comparator?: Function): boolean; /** * 判断值是不是异常对象 * * @example * //true * console.log(_.isError(new TypeError)) * //false * console.log(_.isError(Error)) * //true * try{a=b}catch(e){console.log(_.isError(e))} * * @param v * @returns * @since 1.0.0 */ declare function isError(v: unknown): v is Error; /** * 判断值是不是有限数字 * * @example * //false * console.log(_.isFinite('0')) * //true * console.log(_.isFinite(0)) * //true * console.log(_.isFinite(Number.MAX_VALUE)) * //true * console.log(_.isFinite(99999999999999999999999999999999999999999999999999999999999999999999999)) * //false * console.log(_.isFinite(Infinity)) * * @param v * @returns * @since 1.0.0 */ declare function isFinite(v: unknown): boolean; /** * 判断参数是否为函数对象 * * @example * //true * console.log(_.isFunction(new Function())) * //true * console.log(_.isFunction(()=>{})) * * @param v * @returns */ declare function isFunction(v: unknown): v is Function; /** * 判断值是不是一个整数 * * @example * //true * console.log(_.isInteger(-0)) * //true * console.log(_.isInteger(5.0)) * //false * console.log(_.isSafeInteger(5.000000000000001)) * //true * console.log(_.isSafeInteger(5.0000000000000001)) * //false * console.log(_.isInteger('5')) * //true * console.log(_.isInteger(Number.MAX_SAFE_INTEGER)) * //true * console.log(_.isInteger(Number.MAX_VALUE)) * * @param v * @returns */ declare function isInteger(v: unknown): v is number; /** * 判断值是不是迭代器对象 * * @example * //true * console.log(_.isIterator(new Map())) * //true * console.log(_.isIterator(new Map().values())) * //false * console.log(_.isIterator({a:1})) * * @param v * @returns * @since 1.10.0 */ declare function isIterator(v: unknown): v is Iterable; /** * 判断参数是否为小写字母 * @example * //false * console.log(_.isLowerCaseChar('A')) * //true * console.log(_.isLowerCaseChar('a')) * //false * console.log(_.isLowerCaseChar(null)) * * @param v * @returns * @since 1.13.0 */ declare function isLowerCaseChar(v: string): v is Lowercase; /** * 判断值是不是一个Map对象 * * @example * //true * console.log(_.isMap(new Map())) * //false * console.log(_.isMap(new WeakMap())) * * @param v * @returns */ declare function isMap(v: unknown): v is Map; /** * 检测props对象中的所有属性是否在object中存在,可用于对象的深度对比。 * 使用eq作为值对比逻辑 * * @example * let target = {a:{x:1,y:2},b:1} * //true * console.log(_.isMatch(target,{b:1})) * //true * console.log(_.isMatch(target,{a:{x:1}})) * * target = [{x:1,y:2},{b:1}] * //true * console.log(_.isMatch(target,{1:{b:1}})) * //true * console.log(_.isMatch(target,[{x:1}])) * * @param object * @param props 对比属性对象,如果是null,返回true * @returns 匹配所有props返回true * @since 0.17.0 */ declare function isMatch>(object: T, props: T): boolean; /** * 检测props对象中的所有属性是否在object中存在并使用自定义比较器对属性值进行对比。可以用于对象的深度对比。 * 当comparator参数是默认值时,与isMath函数相同 * * @example * let target = {a:{x:1,y:2},b:1} * //true * console.log(_.isMatchWith(target,{b:1},_.eq)) * //false * console.log(_.isMatchWith(target,{b:'1'},_.eq)) * * target = {a:null,b:0} * //true * console.log(_.isMatchWith(target,{a:'',b:'0'},(a,b)=>_.isEmpty(a) && _.isEmpty(b)?true:a==b)) * * @param target 如果不是对象类型,返回false * @param props 对比属性对象,如果是nil,返回true * @param comparator 比较器。参数(object[k],props[k],k,object,props),返回true表示匹配 * @returns 匹配所有props返回true * @since 0.18.1 */ declare function isMatchWith>(target: T, props: T, comparator: (v1: any, v2: any, k?: string, target?: T, props?: T) => boolean): boolean; /** * 判断值是否NaN本身。与全局isNaN函数相比,只有NaN值本身才会返回true *

* isNaN(undefined) => true
* _.isNaN(undefined) => false *

* * @example * //true * console.log(_.isNaN(NaN)) * //false * console.log(_.isNaN(null)) * //false * console.log(_.isNaN(undefined)) * * @param v * @returns */ declare function isNaN(v: unknown): boolean; /** * 判断参数是否为本地函数 * * @example * //true * console.log(_.isNative(Array)) * //false * console.log(_.isNative(()=>{})) * * @param v * @returns */ declare function isNative(v: unknown): boolean; /** * 判断值是否为null或undefined * * @example * //true * console.log(_.isNil(undefined)) * //false * console.log(_.isNil(0)) * //true * console.log(_.isNil(null)) * //false * console.log(_.isNil(NaN)) * * @param v * @returns * @since 1.0.0 */ declare function isNil(v: unknown): v is null | undefined; /** * 判断值是不是Node的实例 * * @example * //true * console.log(_.isNode(document.body.attributes[0])) * //true * console.log(_.isNode(document)) * * @param v * @returns * @since 1.5.0 */ declare function isNode(v: unknown): v is globalThis.Node; /** * 判断参数是否为null * * @example * //true * console.log(_.isNull(null)) * //false * console.log(_.isNull(undefined)) * * @param v * @returns */ declare function isNull(v: unknown): v is null; /** * 判断参数是否为数字类型值 * * @example * //true * console.log(_.isNumber(1)) * //true * console.log(_.isNumber(Number.MAX_VALUE)) * //false * console.log(_.isNumber('1')) * * @param v * @returns */ declare function isNumber(v: unknown): v is number; /** * 判断参数是否为数字或数字字符串。不能判断BigInt * * @example * //true * console.log(_.isNumeric(1)) * //true * console.log(_.isNumeric('-1.1')) * //false * console.log(_.isNumber('-1.1a')) * * @param v * @returns */ declare function isNumeric(v: unknown): v is number | string; /** * 判断值是不是一个非基本类型外的值,如果true则认为值是一个对象 * 同样,该方法还可以用来判断一个值是不是基本类型 * * @example * //false * console.log(_.isObject(1)) * //true * console.log(_.isObject(new String())) * //false * console.log(_.isObject(true)) * //false * console.log(_.isObject(null)) * * @param v value * @returns 是否对象。如果值是null返回false,即使typeof null === 'object' */ declare function isObject(v: unknown): v is T; /** * 判断值是不是一个朴素对象,即通过Object创建的对象 * * @example * //false * console.log(_.isPlainObject(1)) * //false * console.log(_.isPlainObject(new String())) * //true * console.log(_.isPlainObject({})) * //false * console.log(_.isPlainObject(null)) * //true * console.log(_.isPlainObject(new Object)) * function Obj(){} * //false * console.log(_.isPlainObject(new Obj)) * * @param v value * @returns 是否朴素对象 * @since 0.19.0 */ declare function isPlainObject(v: unknown): boolean; /** * 判断参数是否为原始类型 * * @example * //true * console.log(_.isPrimitive(1)) * //true * console.log(_.isPrimitive(null) * //false * console.log(_.isPrimitive(new String())) * //true * console.log(_.isPrimitive(123n) * * @param v * @returns */ declare function isPrimitive(v: unknown): boolean; /** * 判断值是不是一个正则对象 * * @example * //true * console.log(_.isRegExp(new RegExp)) * //true * console.log(_.isRegExp(/1/)) * * @param v * @returns * @since 0.19.0 */ declare function isRegExp(v: unknown): v is RegExp; /** * 判断值是不是一个安全整数 * * @example * //true * console.log(_.isSafeInteger(-0)) * //true * console.log(_.isSafeInteger(5.0)) * //false * console.log(_.isSafeInteger(5.000000000000001)) * //true * console.log(_.isSafeInteger(5.0000000000000001)) * //false * console.log(_.isSafeInteger('5')) * //true * console.log(_.isSafeInteger(Number.MAX_SAFE_INTEGER)) * //false * console.log(_.isSafeInteger(Number.MAX_VALUE)) * * @param v * @returns */ declare function isSafeInteger(v: unknown): v is number; /** * 判断值是不是一个Set对象 * * @example * //false * console.log(_.isSet(new WeakSet)) * //true * console.log(_.isSet(new Set)) * * @param v * @returns */ declare function isSet(v: unknown): v is Set; /** * 判断参数是否为字符串,包括String类的实例以及基本类型string的值 * * @example * //true * console.log(_.isString(new String(''))) * //true * console.log(_.isString('')) * * @param v * @returns */ declare function isString(v: unknown): v is string; /** * 判断值是不是Symbol * * @example * //true * console.log(_.isSymbol(Symbol())) * * @param v * @returns * @since 1.0.0 */ declare function isSymbol(v: unknown): v is symbol; /** * 判断参数是否为undefined * @example * //true * console.log(_.isUndefined(undefined)) * //false * console.log(_.isUndefined(null)) * * @param v * @returns */ declare function isUndefined(v: unknown): v is undefined; /** * 判断参数是否为大写字母 * @example * //true * console.log(_.isUpperCaseChar('A')) * //false * console.log(_.isUpperCaseChar(null)) * * @param v * @returns * @since 1.13.0 */ declare function isUpperCaseChar(v: string): v is Uppercase; /** * 判断值是不是一个WeakMap对象 * * @example * //true * console.log(_.isWeakMap(new WeakMap)) * //false * console.log(_.isWeakMap(new Map)) * * @param v * @returns */ declare function isWeakMap(v: unknown): v is WeakMap; /** * 判断值是不是一个WeakSet对象 * * @example * //true * console.log(_.isWeakSet(new WeakSet)) * //false * console.log(_.isWeakSet(new Set)) * * @param v * @returns */ declare function isWeakSet(v: unknown): v is WeakSet; /** * a + b * @example * //3 * console.log(_.add(1,2)) * //1 * console.log(_.add(1,null)) * //NaN * console.log(_.add(1,NaN)) * * @param a * @param b * @returns a+b * @since 1.0.0 */ declare function add(a: number, b: number): number; /** * a / b * @example * //0.5 * console.log(_.divide(1,2)) * //Infinity * console.log(_.divide(1,null)) * //NaN * console.log(_.divide(1,NaN)) * * @param a * @param b * @returns a/b * @since 1.0.0 */ declare function divide(a: number, b: number): number; /** * 返回给定数字序列中最大的一个。忽略NaN,null,undefined * @example * //7 * console.log(_.max([2,3,1,NaN,7,4,null])) * //6 * console.log(_.max([4,5,6,'x','y'])) * //Infinity * console.log(_.max([4,5,6,Infinity])) * * @param values 数字/字符数组/Set * @returns * @since 1.0.0 */ declare function max(values: Set | Array): number; /** * 对多个数字或数字列表计算平均值并返回结果 * @example * //2.5 * console.log(_.mean([1,2,'3',4])) * //NaN * console.log(_.mean([1,'2',3,'a',4])) * //2 * console.log(_.mean([1,'2',3,null,4])) * * @param values 数字/字符数组/Set * @returns mean value * @since 1.0.0 */ declare function mean(values: Set | Array): number; /** * 对多个数字或数字列表计算中间值并返回结果 * @example * //2.5 * console.log(_.median([1,2,'3',4])) * //2 * console.log(_.median([1,'2',3])) * //1 * console.log(_.median([1,'2',-3])) * * @param values 数字/字符数组/Set * @returns median value * @since 1.12.0 */ declare function median(values: Set | Array): number; /** * 返回给定数字序列中最小的一个。忽略NaN,null,undefined * @example * //-1 * console.log(_.min([2,3,1,7,'-1'])) * //0 * console.log(_.min([4,3,6,0,'x','y'])) * //-Infinity * console.log(_.min([-Infinity,-9999,0,null])) * @param values 数字/字符数组/Set * @returns 如果参数不是数组/Set,返回NaN * @since 1.0.0 */ declare function min(values: Set | Array): number; /** * 返回min/max如果value超出范围 * @example * //1 * console.log(_.minmax([1,10,0])) * //6 * console.log(_.minmax([4,8,6])) * * @param min * @param max * @param value * @returns */ declare function minmax(min: number, max: number, value: number): number; /** * a * b * @example * //2 * console.log(_.multiply(1,2)) * //0 * console.log(_.multiply(1,null)) * //NaN * console.log(_.multiply(1,NaN)) * * @param a * @param b * @returns a*b * @since 1.0.0 */ declare function multiply(a: number, b: number): number; /** * 返回一个大于等于min,小于max的随机浮点数。支持单参数/无参数签名 * * ```js * _.randf(max);//单参数签名,此时min为0 * _.randf();//无参数签名,此时返回0-1的随机浮点数。效果与Math.random()相同 * ``` * * @example * //0-1随机浮点数 * console.log(_.randf()) * //0-9随机浮点数 * console.log(_.randf(10)) * //10-19随机浮点数 * console.log(_.randf(10,20)) * * @param min 最小边界值,包含。会进行浮点数转换,如果非数字会变为0 * @param max 最大边界值,不包含。会进行整数转换,如果非数字会变为0 * @returns */ declare function randf(): number; declare function randf(max: number): number; declare function randf(min?: number, max?: number): number; /** * 返回一个大于等于min,小于max的随机整数。支持单参数签名 * * ```js * _.randi(max);//此时min为0 * ``` * * @example * //0-9随机整数 * console.log(_.randi(10)) * //10-19随机整数 * console.log(_.randi(10,20)) * * @param min 最小边界值,包含。会进行整数转换,如果非数字会变为0,如果是小数会舍弃取整 * @param max 最大边界值,不包含。会进行整数转换,如果非数字会变为0,如果是小数会舍弃取整 * @returns */ declare function randi(max: number): number; declare function randi(min: number, max?: number): number; /** * a - b * @example * //-1 * console.log(_.subtract(1,2)) * //1 * console.log(_.subtract(1,null)) * //NaN * console.log(_.subtract(1,NaN)) * * @param a * @param b * @returns a - b * @since 1.0.0 */ declare function subtract(a: number, b: number): number; /** * 对字符/数字数组/Set进行求和并返回结果 * - 对nil值,自动转为0 * - 对NaN值,返回NaN * - 对Infinity值,返回Infinity * * @example * //10 * console.log(_.sum([1,'2',3,4])) * //10 * console.log(_.sum([1,'2',3,4,null,undefined])) * //9 * console.log(_.sum([NaN,'2',3,4])) * //Infinity * console.log(_.sum([Infinity,'2',3,4])) * //6 * console.log(_.sum(new Set([1,2,3]))) * * @param values 数字/字符数组/Set * @since 1.0.0 * @returns */ declare function sum(values: Set | Array): number; /** * 通过表达式格式化数字 * * ``` * #,##0.00 => 1,234.00 * * #,##0.00;(#,##0.00) => 1,234.00 / (1,234.00) * ``` * * pattern解释: * * - `0` 如果对应位置上没有数字,则用零代替。用于整数位时在位数不足时补0,用于小数位时,如果超长会截取限位并四舍五入;如果位数不足则补0 * - `#` 如果对应位置上没有数字,不显示。用于整数位时在位数不足时原样显示,用于小数位时,如果超长会截取限位并四舍五入;如果位数不足原样显示 * - `.` 小数分隔符,只能出现一个 * - `,` 分组符号,如果出现多个分组符号,以最右侧为准 * - `%` 后缀符号,数字乘100,并追加% * - `\u2030` 后缀符号,数字乘1000,并追加‰ * - `E` 后缀符号,转为科学计数法格式 * - `;` 正/负数子模式分隔符 * * @example * //小数位截取时会自动四舍五入 * console.log(_.formatNumber(123.678,'0.00')) * //在整数位中,0不能出现在#左侧;在小数位中,0不能出现在#右侧。 * console.log(_.formatNumber(12.1,'0##.#0')) //格式错误,返回原值 * //当有分组出现时,0只会影响短于表达式的数字 * console.log(_.formatNumber(12.1,',000.00'))//012.10 * console.log(_.formatNumber(1234.1,',000.00'))//1,234.10 * //非表达式字符会原样保留 * console.log(_.formatNumber(1234.1,'¥,000.00元'))//¥1,234.10元 * //转为科学计数法 * console.log(_.formatNumber(-0.01234,'##.0000E'))//-1.2340e-2 * //#号在小数位中会限位,整数位中不会 * console.log(_.formatNumber(123.456,'#.##'))//123.46 * * @param v 需要格式化的值,可以是数字或字符串类型 * @param pattern 格式化模式 * * @returns 格式化后的字符串或原始值字符串(如果格式无效时)或特殊值(Infinity\u221E、NaN\uFFFD) */ declare function formatNumber(v: string | number, pattern?: string): string; /** * 判断a是否大于b * * @example * //true * console.log(_.gt(2,1)) * //false * console.log(_.gt(5,'5')) * * @param a * @param b * @returns * @since 1.0.0 */ declare function gt(a: any, b: any): boolean; /** * 判断a是否大于等于b * * @example * //true * console.log(_.gte(2,1)) * //true * console.log(_.gte(5,'5')) * //false * console.log(_.gte(5,'b')) * * @param a * @param b * @returns * @since 1.0.0 */ declare function gte(a: any, b: any): boolean; /** * 验证数字v是否大于等于start并且小于end * 根据参数个数不同,分为两种签名 *

 * _.inRange(v,end);
 * _.inRange(v,start,end);
 * 
* 如果start大于end,则会交换位置 * * @example * //true * console.log(_.inRange(1,1,2)) * //true * console.log(_.inRange(2,3)) * //false * console.log(_.inRange(2,0,2)) * //true * console.log(_.inRange(-2,-2,0)) * //true * console.log(_.inRange(-1,-2)) * * @param v * @param start 最小值 * @param end 最大值 * @returns * @since 1.0.0 */ declare function inRange(v: any, end: number): boolean; declare function inRange(v: any, start: number, end: number): boolean; /** * 判断a是否小于b * * @example * //true * console.log(_.lt(1,2)) * //false * console.log(_.lt(5,'5')) * * @param a * @param b * @returns * @since 1.0.0 */ declare function lt(a: any, b: any): boolean; /** * 判断a是否小于等于b * * @example * //true * console.log(_.lte(1,2)) * //true * console.log(_.lte(5,'5')) * //false * console.log(_.lte(5,'b')) * * @param a * @param b * @returns * @since 1.0.0 */ declare function lte(a: any, b: any): boolean; /** * 转换整数。小数部分会直接丢弃 * * @example * //9 * console.log(_.toInteger(9.99)) * //12 * console.log(_.toInteger('12.34')) * //0 * console.log(_.toInteger(null)) * //0 * console.log(_.toInteger(new Error)) * * @param v * @returns * @since 1.0.0 */ declare function toInteger(v: any): number; /** * 转换任何对象为数字类型 * * @example * //NaN * console.log(_.toNumber(null)) * //1 * console.log(_.toNumber('1')) * //NaN * console.log(_.toNumber([3,6,9])) * //-0 * console.log(_.toNumber(-0)) * //NaN * console.log(_.toNumber(NaN)) * //NaN * console.log(_.toNumber('123a')) * * @param v 任何值 * @returns 对于null/undefined会返回NaN */ declare function toNumber(v: any): number; /** * 将一个或多个源对象的可枚举属性值分配到目标对象。如果源对象有多个,则按照从左到右的顺序依次对target赋值,相同属性会被覆盖 * * > 该函数会修改目标对象 * *
    *
  • 当目标对象是null/undefined时,返回空对象
  • *
  • 当目标对象是基本类型时,返回对应的包装对象
  • *
  • 当目标对象是不可扩展/冻结/封闭状态时,返回目标对象
  • *
* @example * //{x:1,y:3} * console.log(_.assign({x:1},{y:3})) * * @param target 目标对象 * @param sources 源对象 * @returns 返回target */ declare function assign>(target: T, ...sources: any[]): T; /** * 与assign相同,但支持自定义处理器 * * > 该函数会修改目标对象 * * @example * //{x: 1, y: '3y', z: null} * console.log(_.assignWith({x:1},{y:3,z:4},(sv,tv,k)=>k=='z'?null:sv+k)) * * @param target 目标对象 * @param sources 源对象,可变参数。最后一个参数为函数时,签名为(src[k],target[k],k,src,target) 自定义赋值处理器,返回赋予target[k]的值 * @returns 返回target */ declare function assignWith>(target: T, ...sources: any[]): T; declare function clone>(obj: T): T; declare function clone, U>(obj: T): U; declare function cloneDeep>(obj: T): T; declare function cloneDeep, U>(obj: T): U; declare function cloneDeepWith>(obj: T, handler?: (v: any, k: UnknownMapKey, obj: T) => any, skip?: (v: any, k: string | number | symbol) => boolean): T; declare function cloneDeepWith, U>(obj: T, handler?: (v: any, k: UnknownMapKey, obj: T) => any, skip?: (v: any, k: string | number | symbol) => boolean): U; declare function cloneWith>(obj: T, handler: (v: any, k?: string | number | symbol) => any, skip?: (v: any, k: string | number | symbol) => boolean): T; declare function cloneWith, U>(obj: T, handler: (v: any, k?: string | number | symbol) => any, skip?: (v: any, k: string | number | symbol) => boolean): U; /** * 将一个或多个源对象的可枚举属性值分配到目标对象中属性值为undefined的属性上。 * 如果源对象有多个,则按照从左到右的顺序依次对target赋值,相同属性会被忽略 * * > 该函数会修改目标对象 * * - 当目标对象是null/undefined时,返回空对象 * - 当目标对象是基本类型时,返回对应的包装对象 * - 当目标对象是不可扩展/冻结/封闭状态时,返回目标对象 * * @example * //{a: 1, b: 2, c: 3} * console.log(_.defaults({a:1},{b:2},{c:3,b:1,a:2})) * * @param target 目标对象 * @param sources 1-n个源对象 * @returns 返回target * @since 0.21.0 */ declare function defaults>(target: T, ...sources: any[]): T; /** * 与defaults相同,但会递归对象属性 * * > 该函数会修改目标对象 * * @example * //{a: {x: 1, y: 2, z: 3}, b: 2} * console.log(_.defaultsDeep({a:{x:1}},{b:2},{a:{x:3,y:2}},{a:{z:3,x:4}})) * * @param target 目标对象 * @param sources 1-n个源对象 * @returns 返回target * @since 0.21.0 */ declare function defaultsDeep>(target: T, ...sources: any[]): T; /** * 判断两个值是否相等。使用SameValueZero * 算法进行值比较。 * * @example * //true * console.log(_.eq(NaN,NaN)) * //false * console.log(_.eq(1,'1')) * * @param a * @param b * @returns * @since 1.0.0 */ declare function eq(a: unknown, b: unknown): boolean; /** * 对`object`内的所有属性进行断言并返回第一个匹配的属性key * * @example * const libs = { * 'func.js':{platform:['web','nodejs'],tags:{utils:true}}, * 'juth2':{platform:['web','java'],tags:{utils:false,middleware:true}}, * 'soya2d':{platform:['web'],tags:{utils:true}} * } * * //func.js 查询对象的key * console.log(_.findKey(libs,'tags.utils')) * //juth2 * console.log(_.findKey(libs,{'tags.utils':false})) * //tags * console.log(_.findKey(libs['soya2d'],'utils')) * //2 * console.log(_.findKey([{a:1,b:2},{c:2},{d:3}],'d')) * * @param object 所有集合对象array / arrayLike / map / object / ... * @param predicate (value[,index|key[,collection]]) 断言 *
当断言是函数时回调参数见定义 *
其他类型请参考 {@link utils!iteratee} * @returns 第一个匹配断言的元素的key或undefined */ declare function findKey(object: any, predicate: ((value: V, index: UnknownMapKey, collection: any) => boolean) | NonFuncItee): string | number | symbol | undefined; /** * toPairs反函数,创建一个由键值对数组组成的对象 * * @example * //{a:1,b:2,c:3} * console.log(_.fromPairs([['a', 1], ['b', 2], ['c', 3]])) * * @param pairs 键值对数组 * @returns 对象 */ declare function fromPairs(pairs: any[][]): Record; /** * 返回对象中的函数属性key数组 * @example * const funcs = { * a(){}, * b(){} * }; * //[a,b] * console.log(_.functions(funcs)) * //[....] * console.log(_.functions(_)) * * @param obj * @returns 函数名数组 * @since 0.18.0 */ declare function functions(obj: Record): string[]; /** * 通过path获取对象属性值 * * @example * //2 * console.log(_.get([1,2,3],1)) * //Holyhigh * console.log(_.get({a:{b:[{x:'Holyhigh'}]}},['a','b',0,'x'])) * //Holyhigh2 * console.log(_.get({a:{b:[{x:'Holyhigh2'}]}},'a.b.0.x')) * //Holyhigh * console.log(_.get({a:{b:[{x:'Holyhigh'}]}},'a.b[0].x')) * //hi * console.log(_.get([[null,[null,null,'hi']]],'[0][1][2]')) * //not find * console.log(_.get({},'a.b[0].x','not find')) * * @param obj 需要获取属性值的对象,如果obj不是对象(isObject返回false),则返回defaultValue * @param path 属性路径,可以是索引数字,字符串key,或者多级属性数组 * @param defaultValue 如果path未定义,返回默认值 * @returns 属性值或默认值 */ declare function get(obj: any, path: Array | string | number, defaultValue?: any): V; /** * 检查指定key是否存在于指定的obj中(不含prototype中) * * @example * //true * console.log(_.has({a:12},'a')) * * @param obj * @param key * @returns 如果key存在返回true */ declare function has(obj: Record, key: UnknownMapKey): boolean; declare function keys(obj: Map): K[]; declare function keys(obj: Record | object): K[]; declare function keysIn(obj: Map): K[]; declare function keysIn(obj: Record | object): K[]; /** * 类似assign,但会递归源对象的属性合并到目标对象。 *
如果目标对象属性值存在,但对应源对象的属性值为undefined,跳过合并操作。 * 支持自定义处理器,如果处理器返回值为undefined,启用默认合并。 * 该函数在对可选配置项与默认配置项进行合并时非常有用 * * > 该函数会修改目标对象 * * - 当目标对象是null/undefined时,返回空对象 * - 当目标对象是基本类型时,返回对应的包装对象 * - 当目标对象是不可扩展/冻结/封闭状态时,返回目标对象 * * @example * //{x: 0, y: {a: 1, b: 2, c: 3, d: 4}} * console.log(_.merge({x:1,y:{a:1,b:2}},{x:2,y:{c:5,d:4}},{x:0,y:{c:3}})) * //[{x: 0, y: {a: 1, b: 2, c: 3, d: 4}}] * console.log(_.merge([{x:1,y:{a:1,b:2}}],[{x:2,y:{c:5,d:4}}],[{x:0,y:{c:3}}])) * * @param target 目标对象 * @param sources 1-n个源对象 * @returns 返回target * @since 0.22.0 */ declare function merge>(target: T, ...sources: any[]): T; /** * 与merge相同,但支持自定义处理器 * * > 该函数会修改目标对象 * * @example * //{x: 2, y: {a: 2, b: 4, c: 3, d: 27}} * console.log(_.mergeWith({x:1,y:{a:1,b:2,c:3}},{x:2,y:{a:2,d:3}},{y:{b:4}},(sv,tv,k)=>k=='d'?sv*9:undefined)) * * @param target 目标对象 * @param sources (...src[,handler(src[k],target[k],k,src,target,chain)]) * src - 1-n个源对象; * handler - 自定义赋值处理器,返回赋予target[k]的值。默认使用noop * @returns 返回target * @since 0.22.0 */ declare function mergeWith>(target: T, ...sources: any[]): T; /** * 创建一个剔除指定属性的对象子集并返回。与pick()刚好相反 * @example * //{a: 1, c: '3'} * console.log(_.omit({a:1,b:2,c:'3'},'b')) * //{a: 1} * console.log(_.omit({a:1,b:2,c:'3'},'b','c')) * //{c: '3'} * console.log(_.omit({a:1,b:2,c:'3'},['b','a'])) * * @param obj 选取对象 * @param props 属性集合 * @returns 对象子集 * @since 0.16.0 */ declare function omit(obj: Record, ...props: (string | string[])[]): Record; /** * 同omit,但支持断言函数进行剔除 * @example * //{c: '3'} * console.log(_.omitBy({a:1,b:2,c:'3'},_.isNumber)) * * @param obj 选取对象 * @param predicate (v,k)断言函数 * @returns 对象子集 * @since 0.23.0 */ declare function omitBy(obj: Record, predicate?: (v: V, k: K) => boolean): Record; /** * 解析标准/非标准JSON字符串 * 如果str非字符串类型,返回原值 * 如果str是无效JSON字符串,返回原值 * * @example * //{a:1,b:2,c:'3'} * console.log(_.parseJSON("{a:1,b:2,c:'3'}")) * //{a:1,b:2,c:'3"'} * console.log(_.parseJSON(`[{"a":1,"b":2,"c":"3\\""}]`)) * //true * console.log(_.parseJSON('true')) * //12 * console.log(_.parseJSON('12')) * * * @param str JSON字符串 * @param ignore 如果为true,当值为 NaN/Infinity 时忽略该属性,否则返回值对应字符串。默认false * @returns 解析后的对象或空对象 * @since 1.9.0 */ declare function parseJSON>(str: string, ignore?: boolean): T; /** * 创建一个指定属性的对象子集并返回 * @example * //{b: 2} * console.log(_.pick({a:1,b:2,c:'3'},'b')) * //{b: 2,c:'3'} * console.log(_.pick({a:1,b:2,c:'3'},'b','c')) * //{a: 1, b: 2} * console.log(_.pick({a:1,b:2,c:'3'},['b','a'])) * * @param obj 选取对象 * @param props 属性集合 * @returns 对象子集 * @since 0.16.0 */ declare function pick>(obj: T, ...props: (string | string[])[]): T; /** * 同pick,但支持断言函数进行选取 * @example * //{a: 1, b: 2} * console.log(_.pickBy({a:1,b:2,c:'3'},_.isNumber)) * * @param obj 选取对象 * @param predicate (v,k)断言函数 * @returns 对象子集 * @since 0.23.0 */ declare function pickBy(obj: Record, predicate?: (v: V, k: K) => boolean): Record; /** * 创建一个函数,该函数返回指定对象的path属性值 * @example * const libs = [ * {name:'func.js',platform:['web','nodejs'],tags:{utils:true},js:false}, * {name:'juth2',platform:['web','java'],tags:{utils:false,middleware:true},js:true}, * {name:'soya2d',platform:['web'],tags:{utils:true},js:true} * ]; * //[true,false,true] * console.log(_.map(libs,_.prop('tags.utils'))) * //nodejs * console.log(_.prop(['platform',1])(libs[0])) * * @param path * @returns 接收一个对象作为参数的函数 * @since 0.17.0 */ declare function prop(path: string | string[]): (obj: Record) => V; /** * 通过path设置对象属性值。如果路径不存在则创建,索引会创建数组,属性会创建对象 *
该函数会修改源对象
@example * //{"a":1,"b":{"c":[undefined,{"x":10}]}} * console.log(_.set({a:1},'b.c.1.x',10)) * * @param obj 需要设置属性值的对象,如果obj不是对象(isObject返回false),直接返回obj * @param path 属性路径,可以是索引数字,字符串key,或者多级属性数组 * @param value 任何值 * @returns obj 修改后的源对象 * @since 0.16.0 */ declare function set>(obj: T, path: Array | string | number, value: any): T; /** * 解析传递参数并返回一个根据参数值创建的Object实例。 * 支持数组对、k/v对、对象、混合方式等创建 * 是 toPairs 的反函数 * * @example * //{a:1,b:2} * console.log(_.toObject('a',1,'b',2)) * //如果参数没有成对匹配,最后一个属性值则为undefined * //{a:1,b:2,c:undefined} * console.log(_.toObject('a',1,'b',2,'c')) * //{a:1,b:4,c:3} 重复属性会覆盖 * console.log(_.toObject(['a',1,'b',2],['c',3],['b',4])) * //{a:1,b:2} 对象类型返回clone * console.log(_.toObject({a:1,b:2})) * //{1:now time,a:{}} 混合方式 * console.log(_.toObject([1,new Date],'a',{})) * * @param vals 对象创建参数,可以是一个数组/对象或者多个成对匹配的基本类型或者多个不定的数组/对象 * @returns 如果没有参数返回空对象 */ declare function toObject>(...vals: any[]): V; /** * 返回指定对象的所有[key,value]组成的二维数组 * * @example * //[['a', 1], ['b', 2], ['c', 3]] * console.log(_.toPairs({a:1,b:2,c:3})) * * @param obj * @returns 二维数组 */ declare function toPairs(obj: Record): any[][]; /** * 删除obj上path路径对应属性 * @param obj 需要设置属性值的对象,如果obj不是对象(isObject返回false),直接返回obj * @param path 属性路径,可以是索引数字,字符串key,或者多级属性数组 * @since 1.0.0 * @returns 成功返回true,失败或路径不存在返回false */ declare function unset(obj: Record, path: Array | string | number): boolean; /** * 返回对象/Map的所有value数组 *
只返回对象的自身可枚举属性
* * * @example * let f = new Function("this.a=1;this.b=2;"); * f.prototype.c = 3; * //[1,2] * console.log(_.values(new f())) * * @param obj * @returns 值列表 */ declare function values(obj: Map | Record | object): V[]; /** * 返回对象/Map的所有value数组 * 包括原型链中的属性 * * @example * let f = new Function("this.a=1;this.b=2;"); * f.prototype.c = 3; * //[1,2,3] * console.log(_.valuesIn(new f())) * * @param obj * @returns 值列表 */ declare function valuesIn(obj: Map | Record | object): V[]; /** * 返回驼峰风格的字符串 * * @example * //'aBC' * console.log(_.camelCase('a-b c'))//mixCase * //'loveLovesToLoveLove' * console.log(_.camelCase('Love loves to love Love'))//spaces * //'aBC' * console.log(_.camelCase('a B-c'))//camelCase * //'getMyUrl' * console.log(_.camelCase('getMyURL'))//camelCase * * @param str * @returns 返回新字符串 */ declare function camelCase(str: string): string; /** * 把字符串的首字母大写,如果首字母不是ascii中的a-z则返回原值 * * @example * //Abc * console.log(_.capitalize('abc')) * //'' * console.log(_.capitalize(null)) * //1 * console.log(_.capitalize(1)) * * * @param str 字符串 * @returns 对于null/undefined会返回空字符串 */ declare function capitalize(str: any): string; /** * 验证字符串是否以查询子字符串结尾 * * @example * //true * console.log(_.endsWith('func.js','js')) * //true * console.log(_.endsWith('func.js','c',4)) * * @param str * @param searchStr 查询字符串 * @param position 索引 * @returns 如果以查询子字符串开头返回true,否则返回false */ declare function endsWith(str: any, searchStr: string, position?: number): boolean; /** * 转义正则字符串中的特殊字符,包括 '\', '$', '(', ')', '*', '+', '.', '[', ']', '?', '^', '\{', '\}', '|' * * @example * //\^\[func\.js\] \+ \{crud-vue\} = \.\*\?\$ * console.log(_.escapeRegExp('^[func.js] + {crud-vue} = .*?$')) * * @param str 需要转义的字符串 * @returns 转义后的新字符串 * @since 1.0.0 */ declare function escapeRegExp(str: any): string; /** * 查找指定值在字符串中首次出现的位置索引 * * @example * //10 * console.log(_.indexOf('cyberfunc.js','js')) * //10 * console.log(_.indexOf('cyberfunc.js','js',5)) * * @param str * @param search 指定字符串 * @param fromIndex 起始索引 * @returns 第一个匹配搜索字符串的位置索引或-1 */ declare function indexOf(str: any, search: string, fromIndex?: number): number; /** * 返回短横线风格的字符串 * * @example * //'a-b-c' * console.log(_.kebabCase('a_b_c'))//snakeCase * //'webkit-perspective-origin-x' * console.log(_.kebabCase('webkitPerspectiveOriginX'))//camelCase * //'a-b-c' * console.log(_.kebabCase('a B-c'))//mixCase * //'get-my-url' * console.log(_.kebabCase('getMyURL'))//camelCase * * @param str * @returns 返回新字符串 */ declare function kebabCase(str: any): string; /** * 查找指定值在字符串中最后出现的位置索引 * * @example * //10 * console.log(_.lastIndexOf('cyberfunc.js','js')) * //-1 * console.log(_.lastIndexOf('cyberfunc.js','js',5)) * * @param str * @param search 指定字符串 * @param fromIndex 起始索引,从起始索引位置向左查找指定字符串 * @returns 最后一个匹配搜索字符串的位置索引或-1 */ declare function lastIndexOf(str: any, search: string, fromIndex?: number): number; /** * 返回所有字母是小写格式的字符串 * * @example * //'' * console.log(_.lowerCase()) * //'func.js' * console.log(_.lowerCase('FUNC.JS')) * * @param str * @returns 返回新字符串 */ declare function lowerCase(str: any): string; /** * 转换字符串第一个字符为小写并返回 * * @example * //'fIRST' * console.log(_.lowerFirst('FIRST'))//mixCase * //'love loves to love Love' * console.log(_.lowerFirst('Love loves to love Love'))//spaces * * @param str * @returns 返回新字符串 */ declare function lowerFirst(str: any): string; /** * 使用填充字符串填充原字符串达到指定长度。从原字符串末尾开始填充。 * * @example * //100 * console.log(_.padEnd('1',3,'0')) * //1-0-0- * console.log(_.padEnd('1',6,'-0')) * //1 * console.log(_.padEnd('1',0,'-0')) * * @param str 原字符串 * @param len 填充后的字符串长度,如果长度小于原字符串长度,返回原字符串 * @param padString 填充字符串,如果填充后超出指定长度,会自动截取并保留左侧字符串 * @returns 在原字符串末尾填充至指定长度后的字符串 */ declare function padEnd(str: any, len: number, padString?: string): string; /** * 使用填充字符串填充原字符串达到指定长度。从原字符串起始开始填充。 * * @example * //001 * console.log(_.padStart('1',3,'0')) * * @param str 原字符串。如果非字符串则会自动转换成字符串 * @param len 填充后的字符串长度,如果长度小于原字符串长度,返回原字符串 * @param padString 填充字符串,如果填充后超出指定长度,会自动截取并保留右侧字符串 * @returns 在原字符串起始填充至指定长度后的字符串 */ declare function padStart(str: any, len: number, padString?: string): string; /** * 使用字符0填充原字符串达到指定长度。从原字符串起始位置开始填充。 * * @example * //001 * console.log(_.padZ('1',3)) * * @param str 原字符串 * @param len 填充后的字符串长度 * @returns 填充后的字符串 */ declare function padZ(str: any, len: number): string; /** * 返回帕斯卡风格的字符串 * * @example * //'LoveLovesToLoveLove' * console.log(_.pascalCase('Love loves to love Love'))//spaces * //'ABC' * console.log(_.pascalCase('a B-c'))//mixCase * //'GetMyUrl' * console.log(_.pascalCase('getMyURL'))//camelCase * //'AbCdEf' * console.log(_.pascalCase('AB_CD_EF'))//snakeCase * //'ABcDEfGhXy' * console.log(_.pascalCase('aBc D__EF_GH----XY_'))//mixCase * * @param str * @returns 返回新字符串 */ declare function pascalCase(str: string): string; /** * 创建一个以原字符串为模板,重复指定次数的新字符串 * * @example * //funcfuncfunc * console.log(_.repeat('func',3)) * * @param str 原字符串 * @param count 重复次数 * @returns 对于null/undefined会返回空字符串 */ declare function repeat(str: any, count: number): string; /** * 使用replaceValue替换str中的首个searchValue部分 * * @example * //'func-js' * console.log(_.replace('func.js','.','-')) * //'' * console.log(_.replace(null,'.','-')) * //'kelikeli' * console.log(_.replace('geligeli',/ge/g,'ke')) * //'geligeli' * console.log(_.replace('kelikeli',/ke/g,()=>'ge')) * * @param str 字符串。非字符串值会自动转换成字符串 * @param searchValue 查找内容,正则或者字符串 * @param replaceValue 替换内容,字符串或处理函数。函数的返回值将用于替换 * @returns 替换后的新字符串 */ declare function replace(str: any, searchValue: RegExp | string, replaceValue: string | ((substring: string, ...args: any[]) => string)): string; /** * 使用replaceValue替换str中的所有searchValue部分 * * @example * //'a-b-c' * console.log(_.replaceAll('a.b.c','.','-')) * //'' * console.log(_.replaceAll(null,'.','-')) * //'kelikeli' * console.log(_.replaceAll('geligeli',/ge/,'ke')) * //'geligeli' * console.log(_.replaceAll('kelikeli',/ke/g,()=>'ge')) * * @param str 字符串。非字符串值会自动转换成字符串 * @param searchValue 查找内容,正则或者字符串。非global模式的正则对象会自动转为global模式 * @param replaceValue 替换内容,字符串或处理函数。函数的返回值将用于替换 * @returns 替换后的新字符串 * @since 1.0.0 */ declare function replaceAll(str: any, searchValue: RegExp | string, replaceValue: string | ((substring: string, ...args: any[]) => string)): string; declare function replaceAll(str: any, replacement: Record): string; /** * 返回下划线风格的字符串 * * @example * //'a_b_c' * console.log(_.snakeCase('a-b c'))//mixCase * //'love_loves_to_love_love' * console.log(_.snakeCase('Love loves to love Love'))//spaces * //'a_b_c' * console.log(_.snakeCase('a B-c'))//camelCase * //'get_my_url' * console.log(_.snakeCase('getMyURL'))//camelCase * * @param str * @returns 返回新字符串 */ declare function snakeCase(str: string): string; /** * 使用分隔符将字符串分割为多段数组 * * @example * //["func", "js"] * console.log(_.split('func.js','.')) * //["func"] * console.log(_.split('func.js','.',1)) * * @param str 原字符串。如果非字符串则会自动转换成字符串 * @param separator 分隔符 * @param limit 限制返回的结果数量,为空返回所有结果 * @returns 分割后的数组 */ declare function split(str: any, separator: RegExp | string, limit?: number): string[]; /** * 验证字符串是否以查询子字符串开头 * * @example * //true * console.log(_.startsWith('func.js','func')) * //false * console.log(_.startsWith('func.js','func',3)) * //true * console.log(_.startsWith('func.js','c',3)) * * @param str * @param searchStr 查询字符串 * @param position 索引 * @returns 如果以查询子字符串开头返回true,否则返回false */ declare function startsWith(str: any, searchStr: string, position?: number): boolean; /** * 对字符串进行截取,返回从起始索引到结束索引间的新字符串。 * * @example * //"34567" * console.log(_.substring('12345678',2,7)) * //"345678" * console.log(_.substring('12345678',2)) * //"" * console.log(_.substring()) * * @param str 需要截取的字符串,如果非字符串对象会进行字符化处理。基本类型会直接转为字符值,对象类型会调用toString()方法 * @param indexStart 起始索引,包含 * @param indexEnd 结束索引,不包含 * @returns */ declare function substring(str: any, indexStart?: number, indexEnd?: number): string; /** * 检测字符串是否与指定的正则匹配 * * @example * //true 忽略大小写包含判断 * console.log(_.test('func.js','Func','i')) * //true 忽略大小写相等判断 * console.log(_.test('func.js',/^FUNC\.js$/i)) * //false * console.log(_.test('func.js',/FUNC/)) * * @param str * @param pattern 指定正则。如果非正则类型会自动转换为正则再进行匹配 * @param flags 如果pattern参数不是正则类型,会使用该标记作为正则构造的第二个参数 * @returns 匹配返回true * @since 0.19.0 */ declare function test(str: any, pattern: RegExp | string, flags?: string): boolean; /** * 截取数字小数位。用来修复原生toFixed函数的bug * * @example * //14.05 * console.log(_.toFixed(14.049,2)) * //-15 * console.log(_.toFixed(-14.6)) * //14.0001 * console.log(_.toFixed(14.00005,4)) * //0.101 * console.log(_.toFixed(0.1009,3)) * //2.47 * console.log(_.toFixed(2.465,2)) * //2.46 原生 * console.log((2.465).toFixed(2)) * * @param v 数字或数字字符串 * @param scale 小数位长度 * @returns 截取后的字符串 */ declare function toFixed(v: string | number, scale?: number): string; /** * 转换任何对象为字符串。如果对象本身为string类型的值/对象,则返回该对象的字符串形式。否则返回对象的toString()方法的返回值 * * @example * //'' * console.log(_.toString(null)) * //1 * console.log(_.toString(1)) * //3,6,9 * console.log(_.toString([3,6,9])) * //-0 * console.log(_.toString(-0)) * //[object Set] * console.log(_.toString(new Set([3,6,9]))) * //{a:1} * console.log(_.toString({a:1,toString:()=>'{a:1}'})) * * @param v 任何值 * @returns 对于null/undefined会返回空字符串 */ declare function toString(v: any): string; /** * 从字符串的两端删除空白字符。 * * @example * //holyhigh * console.log(_.trim(' holyhigh ')) * * @param str * @returns 对于null/undefined会返回空字符串 */ declare function trim(str: any): string; /** * 从字符串末尾删除空白字符。 * * @example * //' holyhigh' * console.log(_.trimEnd(' holyhigh ')) * * @param str * @returns 对于null/undefined会返回空字符串 */ declare function trimEnd(str: any): string; /** * 从字符串起始位置删除空白字符。 * * @example * //'holyhigh ' * console.log(_.trimStart(' holyhigh ')) * * @param str * @returns 对于null/undefined会返回空字符串 */ declare function trimStart(str: any): string; /** * 对超过指定长度的字符串进行截取并在末尾追加代替字符 * * @example * //func... * console.log(_.truncate('func.js',4)) * //func... * console.log(_.truncate('func.js',6,{separator:/\.\w+/g})) * //func.js.com... * console.log(_.truncate('func.js.com.cn',13,{separator:'.'})) * //func.js * console.log(_.truncate('func.js',10)) * //fun!!! * console.log(_.truncate('func.js',3,{omission:'!!!'})) * * @param str * @param len 最大长度。如果长度大于str长度,直接返回str * @param options 可选项 * @param options.omission 替代字符,默认 '...' * @param options.separator 截断符。如果截取后的字符串中包含截断符,则最终只会返回截断符之前的内容 * @returns 返回新字符串 * @since 1.0.0 */ declare function truncate(str: any, len: number, options?: { omission?: '...'; separator?: string | RegExp; }): string; /** * 返回所有字母是大写格式的字符串 * * @example * //'' * console.log(_.upperCase()) * //'FUNC.JS' * console.log(_.upperCase('func.js')) * * @param str * @returns 返回新字符串 */ declare function upperCase(str: any): string; /** * 转换字符串第一个字符为大写并返回 * * @example * //'First' * console.log(_.upperFirst('first'))//mixCase * //'GetMyURL' * console.log(_.upperFirst('getMyURL'))//camelCase * * @param str * @returns 返回新字符串 */ declare function upperFirst(str: any): string; /** * 模板函数 * * @packageDocumentation */ /** * 使用MTL(Myfx Template Language)编译字符串模板,并返回编译后的render函数 * * ### 一个MTL模板由如下部分组成: * - **文本** 原样内容输出 * - **注释** `[%-- 注释 --%]` 仅在模板中显示,编译后不存在也不会输出 * - **插值** `[%= 插值内容 %]` 输出表达式的结果,支持js语法 * - **混入** `[%@名称 {参数} %]` 可以混入模板片段。被混入的片段具有独立作用域,可以通过JSON格式的对象传递参数给片段 * - **语句** `[% _.each(xxxx... %]` 原生js语句 * * @example * let render = _.template("1 [%= a %] 3"); * //1 4 3 * console.log(render({a:4})) * * render = _.template("1 [% print(_.range(2,5)) %] 5"); * //1 2,3,4 5 * console.log(render()) * * render = _.template("[%-- 注释1 --%] [%@mix {x:5}%] [%-- 注释2 --%]",{ * mixins:{ * mix:'
[%= x %]
' * } * }); * //
5
* console.log(render()) * * @param string 模板字符串 * @param options MTL参数 * @param options.delimiters 分隔符,默认 ['[%' , '%]'] * @param options.mixins 混入对象。\{名称:模板字符串\} * @param options.globals 全局变量对象,可以在任意位置引用。模板内置的全局对象有两个:`print(content)`函数、`_` 对象,Myfx的命名空间 * @param options.stripWhite 是否剔除空白,默认false。剔除发生在编译期间,渲染时不会受到影响。剔除规则:如果一行只有一个MTL注释或语句,则该行所占空白会被移除。 * @returns 编译后的执行函数。该函数需要传递一个对象类型的参数作为运行时参数 * @since 1.0.0 */ declare function template(string: string, options?: IOptions): Function; declare namespace template { var settings: { /** * @defaultValue ['[%', '%]'] */ delimiters: string[]; interpolate: string; comment: string; mixin: string; evaluate: string; }; } /** * 使用高性能算法,将array结构数据变为tree结构数据。*注意,会修改原始数据* * @example * //生成测试数据 * function addChildren(count,parent){ * const data = []; * const pid = parent?parent.id:null; * const parentName = parent?parent.name+'-':''; * _.each(_.range(0,count),i=>{ * const sortNo = _.randi(0,count); * data.push({id:_.alphaId(),pid,name:parentName+i,sortNo}) * }); * return data; * } * * function genTree(depth,parents,data){ * _.each(parents,r=>{ * const children = addChildren(_.randi(1,4),r); * if(depth-1>0){ * genTree(depth-1,children,data); * } * _.append(data,...children); * }); * } * * const roots = addChildren(2); * const data = []; * genTree(2,roots,data); * _.insert(data,0,...roots); * * const tree = _.arrayToTree(data,'id','pid',{attrMap:{text:'name'}}); * _.walkTree(tree,(parentNode,node,chain)=>console.log('node',node.text,'sortNo',node.sortNo,'chain',_.map(chain,n=>n.name))); * * * @param array 原始数据集。如果非Array类型,返回空数组 * @param idKey id标识 * @param pidKey 父id标识 * @param options 自定义选项 * @param options.rootParentValue 根节点的parentValue,用于识别根节点。默认null * @param options.childrenKey 包含子节点容器的key。默认'children' * @param options.attrMap 转换tree节点时的属性映射,如\{text:'name'\}表示把array中一条记录的name属性映射为tree节点的text属性 * @param options.sortKey 如果指定排序字段,则会在转换tree时自动排序。字段值可以是数字或字符等可直接进行比较的类型。性能高于转换后再排序 * @returns 返回转换好的顶级节点数组或空数组 * @since 1.0.0 */ declare function arrayToTree>(array: V[], idKey?: string, pidKey?: string, options?: { rootParentValue?: any; attrMap?: Record; childrenKey?: string; sortKey?: string; }): V[]; declare function closest, U extends Record>(node: V, predicate: (node: V, times: number, cancel: () => void) => boolean, parentKey: string, composed?: boolean): U | null; declare function closest>(node: Record, predicate: (node: Record, times: number, cancel: () => void) => boolean, parentKey: string, composed?: boolean): U | null; /** * 类似findTreeNodes,但会返回包含所有父节点的节点副本数组,已做去重处理。 * 结果集可用于重新构建tree * @example * //生成测试数据 * function addChildren(count,parent){ * const data = []; * const pid = parent?parent.id:null; * const parentName = parent?parent.name+'-':''; * _.each(_.range(0,count),i=>{ * const sortNo = _.randi(1,4); * data.push({id:_.alphaId(),pid,name:parentName+i,sortNo}) * }); * return data; * } * * function genTree(depth,parents,data){ * _.each(parents,r=>{ * const children = addChildren(_.randi(1,4),r); * if(depth-1>0){ * genTree(depth-1,children,data); * } * _.append(data,...children); * }); * } * * const roots = addChildren(2); * const data = []; * genTree(2,roots,data); * _.insert(data,0,...roots); * const tree = _.arrayToTree(data,'id','pid',{sortKey:'sortNo'}); * * _.each(_.filterTree(tree,node=>node.sortNo>1),node=>console.log(_.omit(node,'children','id','pid'))) * * * @param treeNodes 一组节点或一个节点 * @param predicate (node,parentNode,chain,level) 断言 *
当断言是函数时回调参数见定义 *
其他类型请参考 {@link utils!iteratee} * @param options 自定义选项 * @param options.childrenKey 包含子节点容器的key。默认'children' * @returns 找到的符合条件的所有节点副本或空数组 * @since 1.0.0 */ declare function filterTree>(treeNodes: V | V[], predicate: (node: V, parentNode: V, chain: V[], level: number) => boolean | NonFuncItee, options?: { childrenKey?: string; }): V[]; /** * 查找给定节点及所有子孙节点中符合断言的第一个节点并返回 * @example * //生成测试数据 * function addChildren(count,parent){ * const data = []; * const pid = parent?parent.id:null; * const parentName = parent?parent.name+'-':''; * _.each(_.range(0,count),i=>{ * const sortNo = _.randi(0,count); * data.push({id:_.alphaId(),pid,name:parentName+i,sortNo}) * }); * return data; * } * * function genTree(depth,parents,data){ * _.each(parents,r=>{ * const children = addChildren(_.randi(2,5),r); * if(depth-1>0){ * genTree(depth-1,children,data); * } * _.append(data,...children); * }); * } * * const roots = addChildren(2); * const data = []; * genTree(4,roots,data); * _.insert(data,0,...roots); * const tree = _.arrayToTree(data,'id','pid',{sortKey:'sortNo'}); * * console.log(_.omit(_.findTreeNode(tree,node=>node.sortNo>2),'children','id','pid')) * * * @param treeNodes 一组节点或一个节点 * @param predicate (node,parentNode,chain,level,index) 断言 *
当断言是函数时回调参数见定义 *
其他类型请参考 {@link utils!iteratee} * @param options 自定义选项 * @param options.childrenKey 包含子节点容器的key。默认'children' * @returns 第一个匹配断言的节点或undefined * @since 1.0.0 */ declare function findTreeNode>(treeNodes: Record | Record[], predicate: (node: Record, parentNode: Record, chain: Record[], level: number, index: number) => boolean | NonFuncItee, options?: { childrenKey?: string; }): U | undefined; declare function findTreeNode, U extends Record>(treeNodes: V | V[], predicate: (node: V, parentNode: V, chain: V[], level: number, index: number) => boolean | NonFuncItee, options?: { childrenKey?: string; }): U | undefined; /** * 查找给定节点及所有子孙节点中符合断言的所有节点并返回 * @example * //生成测试数据 * function addChildren(count,parent){ * const data = []; * const pid = parent?parent.id:null; * const parentName = parent?parent.name+'-':''; * _.each(_.range(0,count),i=>{ * const sortNo = _.randi(0,count); * data.push({id:_.alphaId(),pid,name:parentName+i,sortNo}) * }); * return data; * } * * function genTree(depth,parents,data){ * _.each(parents,r=>{ * const children = addChildren(_.randi(2,5),r); * if(depth-1>0){ * genTree(depth-1,children,data); * } * _.append(data,...children); * }); * } * * const roots = addChildren(2); * const data = []; * genTree(3,roots,data); * _.insert(data,0,...roots); * const tree = _.arrayToTree(data,'id','pid',{sortKey:'sortNo'}); * * _.each(_.findTreeNodes(tree,node=>node.sortNo>2),node=>console.log(_.omit(node,'children','id','pid'))) * * * @param treeNodes 一组节点或一个节点 * @param predicate (node,parentNode,chain,level,index) 断言 *
当断言是函数时回调参数见定义 *
其他类型请参考 {@link utils!iteratee} * @param options 自定义选项 * @param options.childrenKey 包含子节点容器的key。默认'children' * @returns 找到的符合条件的所有节点或空数组 * @since 1.0.0 */ declare function findTreeNodes>(treeNodes: Record | Record[], predicate: (node: Record, parentNode: Record, chain: Record[], level: number, index: number) => boolean | NonFuncItee, options?: { childrenKey?: string; }): U[]; declare function findTreeNodes, U extends Record>(treeNodes: V | V[], predicate: (node: V, parentNode: V, chain: V[], level: number, index: number) => boolean | NonFuncItee, options?: { childrenKey?: string; }): U[]; /** * 对给定节点及所有子孙节点(同级)排序 * @example * //生成测试数据 * function addChildren(count,parent){ * const data = []; * const pid = parent?parent.id:null; * const parentName = parent?parent.name+'-':''; * _.each(_.range(0,count),i=>{ * const sortNo = _.randi(0,9); * data.push({id:_.alphaId(),pid,name:parentName+i,sortNo}) * }); * return data; * } * * function genTree(depth,parents,data){ * _.each(parents,r=>{ * const children = addChildren(_.randi(1,4),r); * if(depth-1>0){ * genTree(depth-1,children,data); * } * _.append(data,...children); * }); * } * * const roots = addChildren(1); * const data = []; * genTree(2,roots,data); * _.insert(data,0,...roots); * let tree = _.arrayToTree(data,'id','pid'); * * console.log('Before sort---------------'); * _.walkTree(_.cloneDeep(tree),(parentNode,node,chain)=>console.log('node',node.name,'sortNo',node.sortNo)) * _.sortTree(tree,(a,b)=>a.sortNo - b.sortNo); * console.log('After sort---------------'); * _.walkTree(tree,(parentNode,node,chain)=>console.log('node',node.name,'sortNo',node.sortNo)) * * @param treeNodes 一组节点或一个节点 * @param comparator (a,b) 排序函数 * @param options 自定义选项 * @param options.childrenKey 包含子节点容器的key。默认'children' * * @since 1.0.0 */ declare function sortTree>(treeNodes: V | V[], comparator: (a: V, b: V) => number, options?: { childrenKey?: string; }): void; /** * 以给定节点为根遍历所有子孙节点。深度优先 * @example * //生成测试数据 * function addChildren(count,parent){ * const data = []; * const pid = parent?parent.id:null; * const parentName = parent?parent.name+'-':''; * _.each(_.range(0,count),i=>{ * const sortNo = _.randi(0,count); * data.push({id:_.alphaId(),pid,name:parentName+i,sortNo}) * }); * return data; * } * * function genTree(depth,parents,data){ * _.each(parents,r=>{ * const children = addChildren(_.randi(1,4),r); * if(depth-1>0){ * genTree(depth-1,children,data); * } * _.append(data,...children); * }); * } * * const roots = addChildren(2); * const data = []; * genTree(2,roots,data); * _.insert(data,0,...roots); * const tree = _.arrayToTree(data,'id','pid',{sortKey:'sortNo'}); * * _.walkTree(tree,(node,parentNode,chain)=>console.log('node',node.name,'sortNo',node.sortNo,'chain',_.map(chain,n=>n.name))) * * @param treeNodes 一组节点或一个节点 * @param callback (node,parentNode,chain,level,index)回调函数,如果返回false则中断遍历,如果返回-1则停止分支遍历 * @param options 自定义选项 * @param options.childrenKey 包含子节点容器的key。默认'children' * @since 1.0.0 */ declare function walkTree>(treeNodes: V | V[], callback: (node: V, parentNode: V, chain: V[], level: number, index: number) => boolean | number | void, options?: Record): void; /** * 生成一个指定长度的alphaId并返回。id内容由随机字母表字符组成 * @example * // urN-k0mpetBwboeQ * console.log(_.alphaId()) * // Ii6cPyfw-Ql5YC8OIhVwH1lpGY9x * console.log(_.alphaId(28)) * * @param len id长度 * @returns alphaId * @since 1.0.0 */ declare function alphaId(len?: number): string; /** * 如果v是null/undefined/NaN中的一个,返回defaultValue * @example * //"x" * console.log(_.defaultTo(null,'x')) * //0 * console.log(_.defaultTo(0,'y')) * * @param v 任何值 * @param defaultValue 任何值 * @returns v或defaultValue * @since 0.16.0 */ declare function defaultTo(v: T, defaultValue: V): T | V; /** * 返回参数列表中的第一个值,即f(x) = x。该函数可以用来为高阶函数提供数据如过滤列表或map,也用作默认迭代器 * @example * //[1,2,4,'a','1'] * console.log(_.filter([0,1,false,2,4,undefined,'a','1','',null],_.identity)) * const list = [ * {name:'a',value:1}, * {name:'b',value:2}, * {name:'c',value:3} * ] * //list * console.log(_.map(list,_.identity)) * * @param v * @returns 第一个参数 * @since 0.17.0 */ declare function identity(v: any): any; /** * 创建一个函数,函数类型根据参数值类型而定。创建的函数常用于迭代回调,在Func.js内部被大量使用 * * @example * const libs = [ * {name:'func.js',platform:['web','nodejs'],tags:{utils:true},js:true}, * {name:'juth2',platform:['web','java'],tags:{utils:false,middleware:true},js:false}, * {name:'soya2d',platform:['web'],tags:{utils:true},js:false} * ]; * * //[{func.js...}] 如果参数是object,返回_.matcher * console.log(_.filter(libs,_.iteratee({tags:{utils:true},js:true}))) * //[func.js,juth2,soya2d] 如果参数是字符串,返回_.prop * console.log(_.map(libs,_.iteratee('name'))) * //[true,false,true] 如果参数是数组,内容会转为path,并返回_.prop * console.log(_.map(libs,_.iteratee(['tags','utils']))) * //[1,3,5] 如果参数是函数,返回这个函数 * console.log(_.filter([1,2,3,4,5],_.iteratee(n=>n%2))) * //[1,2,4,'a','1'] 无参返回_.identity * console.log(_.filter([0,1,false,2,4,undefined,'a','1','',null],_.iteratee())) * * * @param value 迭代模式 *
当value是字符串类型时,返回_.prop *
当value是对象类型时,返回_.matcher *
当value是数组类型时,内容会转为path,并返回_.prop *
当value是函数时,返回这个函数 *
当value未定义时,返回_.identity *
其他类型返回f() = false * @returns 不同类型的返回函数 * @since 0.17.0 */ declare function iteratee(value: Function | NonFuncItee): Function; /** * 创建一个函数,该函数接收一个对象为参数并返回对该对象使用props进行验证的的断言结果。 * * * @example * const libs = [ * {name:'func.js',platform:['web','nodejs'],tags:{utils:true},js:true}, * {name:'juth2',platform:['web','java'],tags:{utils:false,middleware:true},js:false}, * {name:'soya2d',platform:['web'],tags:{utils:true},js:false} * ]; * * //[{func.js...}] * console.log(_.filter(libs,_.matcher({tags:{utils:true},js:true}))) * * @param props 断言条件对象 * @returns matcher(v)函数 * @since 0.17.0 */ declare function matcher(props: T): (obj: T) => boolean; /** * 为 myfx 扩展额外函数,扩展后的函数同样具有函数链访问能力 * * @example * //增加扩展 * _.mixin({ * select:_.get, * from:_.chain, * where:_.filter, * top:_.first * }); * * const libs = [ * {name:'myfx',platform:['web','nodejs'],tags:{utils:true},js:true}, * {name:'juth2',platform:['web','java'],tags:{utils:false,middleware:true},js:false}, * {name:'soya2d',platform:['web'],tags:{utils:true},js:true} * ]; * //查询utils是true的第一行数据的name值 * console.log(_.from(libs).where({tags:{utils:true}}).top().select('name').value()) * * @param obj 扩展的函数声明 */ declare function mixin(target: Record, obj: Record): void; /** * 当通过非esm方式引用函数库时,函数库会默认挂载全局变量_。 * 如果项目中存在其它以该变量为命名空间的函数库(如lodash、underscore等)则会发生命名冲突。 * 该函数可恢复全局变量为挂载前的引用,并返回myfuncs命名空间 * @example * // 返回myfuncs并重置全局命名空间 _ * console.log(_.noConflict()) * * @returns 返回myfuncs命名空间 * @since 1.0.0 */ declare function noConflict(): Record; /** * 永远返回undefined * @example * //undefined * console.log(_.noop('func')) * //undefined * console.log(_.noop()) * * @returns undefined * @since 0.16.0 */ declare function noop(): undefined; /** * 生成一个64bit整数的雪花id并返回,具体格式如下: * * 0 - timestamp - nodeId - sequence
* 0 - [0000000000 0000000000 0000000000 0000000000 0] - [0000000000] - [000000000000] *
* 可用于客户端生成可跟踪统计的id,如定制终端 * @example * // 343155438738309188 * console.log(_.snowflakeId(123)) * // 78249955004317758 * console.log(_.snowflakeId(456,new Date(2022,1,1).getTime())) * * @param nodeId 节点id,10bit整数 * @param epoch 时间起点,用于计算相对时间戳 * @returns snowflakeId 由于js精度问题,直接返回字符串而不是number,如果nodeId为空返回 '0000000000000000000' * @since 1.0.0 */ declare function snowflakeId(nodeId: number, epoch?: number): string; /** * 调用iteratee函数n次,并将历次调用的返回值数组作为结果返回 * @example * //['0',...,'4'] * console.log(_.times(5,String)) * //[[0],[1]] * console.log(_.times(2,_.toArray)) * * @param n 迭代次数 * @param iteratee 每次迭代调用函数 * @returns 返回值数组 * @since 0.17.0 */ declare function times(n: number, iteratee: (n: number) => V): V[]; /** * 解析path并返回数组 * @example * //['a', 'b', '2', 'c'] * console.log(_.toPath('a.b[2].c')) * //['a', 'b', 'c', '1'] * console.log(_.toPath(['a','b','c[1]'])) * //['1'] * console.log(_.toPath(1)) * * @param path 属性路径,可以是数字索引,字符串key,或者多级属性数组 * @returns path数组 * @since 0.16.0 */ declare function toPath(path: Array | string | number): string[]; /** * 返回一个全局的整数id,序号从0开始。可以用于前端列表编号等用途 * * @example * //func_0 * console.log(_.uniqueId('func')) * //1 * console.log(_.uniqueId()) * * @param prefix id前缀 * @returns 唯一id * @since 0.16.0 */ declare function uniqueId(prefix?: string): string; /** * 生成一个32/36个字符组件的随机uuid(v4)并返回 * @example * // ddfd73a5-62ac-4412-ad2b-fd495f766caf * console.log(_.uuid(true)) * // ddfd73a562ac4412ad2bfd495f766caf * console.log(_.uuid()) * * @param delimiter 是否生成分隔符 * @returns uuid * @since 1.0.0 */ declare function uuid(delimiter?: boolean): string; /** * 函数链操作相关函数 * @author holyhigh */ /** * chain 函数集 */ declare class ChainFx { append(...values: any[]): FuncChain; chunk(size?: number): FuncChain; compact(): FuncChain; concat(): FuncChain; except(): FuncChain; fill(value: any, start?: number, end?: number): FuncChain; findIndex(predicate: ((value: T, index: string | number, array: T[]) => boolean) | NonFuncItee, fromIndex?: number): FuncChain; findLastIndex(predicate: ((value: T, index: string | number, array: T[]) => boolean) | NonFuncItee, fromIndex?: number): FuncChain; flat(depth?: number): FuncChain; flatDeep(): FuncChain; insert(index: number, ...values: any[]): FuncChain; intersect(): FuncChain; join(separator?: string): FuncChain; pop(index?: number): FuncChain; pull(...values: T[]): FuncChain; range(end?: number, step?: number): FuncChain; remove(predicate: ((value: T, index: string | number, array: T[]) => boolean) | NonFuncItee): FuncChain; reverse(): FuncChain; slice(begin?: number, end?: number): FuncChain; sortedIndex(value: any): FuncChain; sortedIndexBy(value: any, itee?: ((value: any) => any) | NonFuncItee): FuncChain; union(): FuncChain; uniq(): FuncChain; uniqBy(itee?: ((value: T, index: UnknownMapKey) => boolean) | NonFuncItee): FuncChain; unzip(): FuncChain; without(...values: T[]): FuncChain; zip(): FuncChain; zipObject(values: any[]): FuncChain; zipWith(): FuncChain; countBy(itee?: ((value: V) => K) | NonFuncItee): FuncChain; every(predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): FuncChain; filter(predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): FuncChain; find(predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): FuncChain; findLast(predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): FuncChain; first(): FuncChain; flatMap(itee?: ((value: V, index: K, collection: Collection) => U | Promise) | NonFuncItee, depth?: number): FuncChain; flatMapDeep(iteratee?: ((value: V, index: K, collection: Collection) => U) | NonFuncItee): FuncChain; groupBy(iteratee?: ((value: V) => UnknownMapKey) | NonFuncItee): FuncChain; includes(value: any, fromIndex?: number): FuncChain; initial(): FuncChain; keyBy(iteratee?: ((value: V) => K) | NonFuncItee): FuncChain; last(): FuncChain; map(iteratee?: ((value: V, index: K, collection: Collection) => U | Promise) | NonFuncItee): FuncChain; partition(predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): FuncChain; reduce(callback: (accumulator: U, value: V, key: K, collection: Collection) => U, initialValue?: U): FuncChain; reject(predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): FuncChain; sample(): FuncChain; sampleSize(count?: number): FuncChain; shuffle(): FuncChain; size(): FuncChain; some(predicate: ((value: V, index: K, collection: Collection) => boolean) | NonFuncItee): FuncChain; sort(comparator?: (a: T, b: T) => number): FuncChain; sortBy(iteratee?: ((value: V, index: K) => any) | NonFuncItee): FuncChain; tail(): FuncChain; take(length?: number): FuncChain; takeRight(length?: number): FuncChain; toArray(): FuncChain; addTime(amount: number, type?: string): FuncChain; compareDate(date2: Date | string | number, type?: string): FuncChain; formatDate(pattern?: string): FuncChain; getDayOfYear(): FuncChain; getWeekOfMonth(): FuncChain; getWeekOfYear(): FuncChain; isLeapYear(): FuncChain; isSameDay(date2: Date | string | number): FuncChain; now(): FuncChain; toDate(): FuncChain; after any>(count?: number): FuncChain; alt(interceptor1: Function, interceptor2: Function): FuncChain; bind any>(thisArg: any, ...args: any[]): FuncChain; bindAll>(...methodNames: (string | string[])[]): FuncChain; call(...args: any): FuncChain; compose any>(): FuncChain; debounce any>(wait: number, immediate?: boolean): FuncChain; delay(wait?: number, ...args: any[]): FuncChain; fval(args?: Record, context?: any): FuncChain; once any>(): FuncChain; partial any>(...args: any[]): FuncChain; tap(interceptor: Function): FuncChain; throttle any>(wait: number, options?: { leading?: boolean; trailing?: boolean; }): FuncChain; isAlnum(): FuncChain; isAlpha(): FuncChain; isArray(): FuncChain; isArrayLike(): FuncChain; isBlank(): FuncChain; isBoolean(): FuncChain; isCustomElement(): FuncChain; isDate(): FuncChain; isDefined(): FuncChain; isElement(): FuncChain; isEmpty(): FuncChain; isEqual(b: unknown): FuncChain; isEqualWith(b: any, comparator?: Function): FuncChain; isError(): FuncChain; isFinite(): FuncChain; isFunction(): FuncChain; isInteger(): FuncChain; isIterator(): FuncChain; isLowerCaseChar(): FuncChain; isMap(): FuncChain; isMatch>(props: T): FuncChain; isMatchWith>(props: T, comparator: (v1: any, v2: any, k?: string, target?: T, props?: T) => boolean): FuncChain; isNaN(): FuncChain; isNative(): FuncChain; isNil(): FuncChain; isNode(): FuncChain; isNull(): FuncChain; isNumber(): FuncChain; isNumeric(): FuncChain; isObject(): FuncChain; isPlainObject(): FuncChain; isPrimitive(): FuncChain; isRegExp(): FuncChain; isSafeInteger(): FuncChain; isSet(): FuncChain; isString(): FuncChain; isSymbol(): FuncChain; isUndefined(): FuncChain; isUpperCaseChar(): FuncChain; isWeakMap(): FuncChain; isWeakSet(): FuncChain; add(b: number): FuncChain; divide(b: number): FuncChain; max(): FuncChain; mean(): FuncChain; median(): FuncChain; min(): FuncChain; minmax(max: number, value: number): FuncChain; multiply(b: number): FuncChain; randf(max?: number): FuncChain; randi(max?: number): FuncChain; subtract(b: number): FuncChain; sum(): FuncChain; formatNumber(pattern?: string): FuncChain; gt(b: any): FuncChain; gte(b: any): FuncChain; inRange(start?: number, end?: number): FuncChain; lt(b: any): FuncChain; lte(b: any): FuncChain; toInteger(): FuncChain; toNumber(): FuncChain; assign>(...sources: any[]): FuncChain; assignWith>(...sources: any[]): FuncChain; clone, U>(): FuncChain; cloneDeep>(): FuncChain; cloneDeepWith, U>(handler?: (v: any, k: UnknownMapKey, obj: T) => any, skip?: (v: any, k: string | number | symbol) => boolean): FuncChain; cloneWith>(handler: (v: any, k?: string | number | symbol) => any, skip?: (v: any, k: string | number | symbol) => boolean): FuncChain; defaults>(...sources: any[]): FuncChain; defaultsDeep>(...sources: any[]): FuncChain; eq(b: unknown): FuncChain; findKey(predicate: ((value: V, index: UnknownMapKey, collection: any) => boolean) | NonFuncItee): FuncChain; fromPairs(): FuncChain; functions(): FuncChain; get(path: Array | string | number, defaultValue?: any): FuncChain; has(key: UnknownMapKey): FuncChain; keys(): FuncChain; keysIn(): FuncChain; merge>(...sources: any[]): FuncChain; mergeWith>(...sources: any[]): FuncChain; omit(...props: (string | string[])[]): FuncChain; omitBy(predicate?: (v: V, k: K) => boolean): FuncChain; parseJSON>(ignore?: boolean): FuncChain; pick>(...props: (string | string[])[]): FuncChain; pickBy(predicate?: (v: V, k: K) => boolean): FuncChain; prop(): FuncChain; set>(path: Array | string | number, value: any): FuncChain; toObject>(): FuncChain; toPairs(): FuncChain; unset(path: Array | string | number): FuncChain; values(): FuncChain; valuesIn(): FuncChain; camelCase(): FuncChain; capitalize(): FuncChain; endsWith(searchStr: string, position?: number): FuncChain; escapeRegExp(): FuncChain; indexOf(search: string, fromIndex?: number): FuncChain; kebabCase(): FuncChain; lastIndexOf(search: string, fromIndex?: number): FuncChain; lowerCase(): FuncChain; lowerFirst(): FuncChain; padEnd(len: number, padString?: string): FuncChain; padStart(len: number, padString?: string): FuncChain; padZ(len: number): FuncChain; pascalCase(): FuncChain; repeat(count: number): FuncChain; replace(searchValue: RegExp | string, replaceValue: string | ((substring: string, ...args: any[]) => string)): FuncChain; replaceAll(searchValue: RegExp | string | Record, replaceValue?: string | ((substring: string, ...args: any[]) => string)): FuncChain; snakeCase(): FuncChain; split(separator: RegExp | string, limit?: number): FuncChain; startsWith(searchStr: string, position?: number): FuncChain; substring(indexStart?: number, indexEnd?: number): FuncChain; test(pattern: RegExp | string, flags?: string): FuncChain; toFixed(scale?: number): FuncChain; toString(): FuncChain; trim(): FuncChain; trimEnd(): FuncChain; trimStart(): FuncChain; truncate(len: number, options?: { omission?: '...'; separator?: string | RegExp; }): FuncChain; upperCase(): FuncChain; upperFirst(): FuncChain; arrayToTree>(idKey?: string, pidKey?: string, options?: { rootParentValue?: any; attrMap?: Record; childrenKey?: string; sortKey?: string; }): FuncChain; closest>(predicate: (node: Record, times: number, cancel: () => void) => boolean, parentKey: string, composed?: boolean): FuncChain; filterTree>(predicate: (node: V, parentNode: V, chain: V[], level: number) => boolean | NonFuncItee, options?: { childrenKey?: string; }): FuncChain; findTreeNode, U extends Record>(predicate: (node: V, parentNode: V, chain: V[], level: number, index: number) => boolean | NonFuncItee, options?: { childrenKey?: string; }): FuncChain; findTreeNodes, U extends Record>(predicate: (node: V, parentNode: V, chain: V[], level: number, index: number) => boolean | NonFuncItee, options?: { childrenKey?: string; }): FuncChain; alphaId(): FuncChain; defaultTo(defaultValue: V): FuncChain; matcher(): FuncChain; noConflict(): FuncChain; snowflakeId(epoch?: number): FuncChain; times(iteratee: (n: number) => V): FuncChain; uniqueId(): FuncChain; uuid(): FuncChain; } /** * 用于定义FuncChain对象并构造函数链 * 注意,该类仅用于内部构造函数链 */ declare class FuncChain extends ChainFx { /** * @internal */ private _wrappedValue; /** * @internal */ private _chain; /** * @internal */ constructor(v: T); /** * 惰性计算。执行函数链并返回计算结果 * @example * //2-4 * console.log(_([1,2,3,4]).map(v=>v+1).filter(v=>v%2===0).take(2).join('-').value()) * //[1,2,2,1] * console.log(_(["{a:1,b:2}","{a:2,b:1}"]).map((v) => _.fval(v)).map(v=>[v.a,v.b]).join().value()) * //[1,2,3,4] * console.log(_([1,2,3,4]).value()) * * @returns 执行函数链返回的值 */ value(): T; } declare const VERSION = "1.15.10"; /** * 显式开启myfx的函数链,返回一个包裹了参数v的myfx链式对象。函数链可以链接Myfx提供的所有函数,如

* 函数链使用惰性计算 —— 直到显示调用value()方法时,函数链才会进行计算并返回结果 *

```js _.chain([1,2,3,4]).map(v=>v+1).filter(v=>v%2===0).take(2).join('-').value() ``` * 函数链与直接调用方法的区别不仅在于可以链式调用,更在于函数链是基于惰性求值的。 * 上式中必须通过显式调用`value()`方法才能获取结果, * 而只有在`value()`方法调用时整个函数链才进行求值。 * * * 惰性求值允许FuncChain实现捷径融合(shortcut fusion) —— 一项基于已有函数对数组循环次数进行大幅减少以提升性能的优化技术。 * 下面的例子演示了原生函数链和Myfx函数链的性能差异 * @example * let ary = _.range(20000000); console.time('native'); let c = 0; let a = ary.map((v)=>{ c++; return v+1; }).filter((v) => { c++; return v%2==0; }) .reverse() .slice(1, 4) console.timeEnd('native'); console.log(a, c, '次');//大约600ms左右,循环 40000000 次 //Myfx ary = _.range(20000000); console.time('Myfx'); let x = 0; let targets = _(ary) .map((v) => { x++; return v+1; }) .filter((v) => { x++; return v%2==0; }) .reverse() .slice(1, 4) .value(); console.timeEnd('Myfx'); console.log(targets, x, '次');//大约0.5ms左右,循环 18 次 * * @param v * @returns Myfx对象 */ declare function chain(v: any): FuncChain; declare const myfx: { arrayToTree: typeof arrayToTree; closest: typeof closest; filterTree: typeof filterTree; findTreeNode: typeof findTreeNode; findTreeNodes: typeof findTreeNodes; sortTree: typeof sortTree; walkTree: typeof walkTree; template: typeof template; append: typeof append; chunk: typeof chunk; compact: typeof compact; concat: typeof concat; except: typeof except; fill: typeof fill; findIndex: typeof findIndex; findLastIndex: typeof findLastIndex; flat: typeof flat; flatDeep: typeof flatDeep; insert: typeof insert; intersect: typeof intersect; join: typeof join; pop: typeof pop; pull: typeof pull; range: typeof range; remove: typeof remove; reverse: typeof reverse; slice: typeof slice; sortedIndex: typeof sortedIndex; sortedIndexBy: typeof sortedIndexBy; union: typeof union; uniq: typeof uniq; uniqBy: typeof uniqBy; unzip: typeof unzip; without: typeof without; zip: typeof zip; zipObject: typeof zipObject; zipWith: typeof zipWith; after: typeof after; alt: typeof alt; bind: typeof bind; bindAll: typeof bindAll; call: typeof call; compose: typeof compose; debounce: typeof debounce; delay: typeof delay; fval: typeof fval; once: typeof once; partial: typeof partial; tap: typeof tap; throttle: typeof throttle; alphaId: typeof alphaId; defaultTo: typeof defaultTo; identity: typeof identity; iteratee: typeof iteratee; matcher: typeof matcher; mixin: typeof mixin; noConflict: typeof noConflict; noop: typeof noop; snowflakeId: typeof snowflakeId; times: typeof times; toPath: typeof toPath; uniqueId: typeof uniqueId; uuid: typeof uuid; add: typeof add; divide: typeof divide; max: typeof max; mean: typeof mean; median: typeof median; min: typeof min; minmax: typeof minmax; multiply: typeof multiply; randf: typeof randf; randi: typeof randi; subtract: typeof subtract; sum: typeof sum; countBy: typeof countBy; each: typeof each; eachRight: typeof eachRight; every: typeof every; filter: typeof filter; find: typeof find; findLast: typeof findLast; first: typeof first; flatMap: typeof flatMap; flatMapDeep: typeof flatMapDeep; groupBy: typeof groupBy; includes: typeof includes; initial: typeof initial; keyBy: typeof keyBy; last: typeof last; map: typeof map; partition: typeof partition; reduce: typeof reduce; reject: typeof reject; sample: typeof sample; sampleSize: typeof sampleSize; shuffle: typeof shuffle; size: typeof size; some: typeof some; sort: typeof sort; sortBy: typeof sortBy; tail: typeof tail; take: typeof take; takeRight: typeof takeRight; toArray: typeof toArray; assign: typeof assign; assignWith: typeof assignWith; clone: typeof clone; cloneDeep: typeof cloneDeep; cloneDeepWith: typeof cloneDeepWith; cloneWith: typeof cloneWith; defaults: typeof defaults; defaultsDeep: typeof defaultsDeep; eq: typeof eq; findKey: typeof findKey; fromPairs: typeof fromPairs; functions: typeof functions; get: typeof get; has: typeof has; keys: typeof keys; keysIn: typeof keysIn; merge: typeof merge; mergeWith: typeof mergeWith; omit: typeof omit; omitBy: typeof omitBy; parseJSON: typeof parseJSON; pick: typeof pick; pickBy: typeof pickBy; prop: typeof prop; set: typeof set; toObject: typeof toObject; toPairs: typeof toPairs; unset: typeof unset; values: typeof values; valuesIn: typeof valuesIn; isAlnum: typeof isAlnum; isAlpha: typeof isAlpha; isArray: typeof isArray; isArrayLike: typeof isArrayLike; isBlank: typeof isBlank; isBoolean: typeof isBoolean; isCustomElement: typeof isCustomElement; isDate: typeof isDate; isDefined: typeof isDefined; isElement: typeof isElement; isEmpty: typeof isEmpty; isEqual: typeof isEqual; isEqualWith: typeof isEqualWith; isError: typeof isError; isFinite: typeof isFinite; isFunction: typeof isFunction; isInteger: typeof isInteger; isIterator: typeof isIterator; isLowerCaseChar: typeof isLowerCaseChar; isMap: typeof isMap; isMatch: typeof isMatch; isMatchWith: typeof isMatchWith; isNaN: typeof isNaN; isNative: typeof isNative; isNil: typeof isNil; isNode: typeof isNode; isNull: typeof isNull; isNumber: typeof isNumber; isNumeric: typeof isNumeric; isObject: typeof isObject; isPlainObject: typeof isPlainObject; isPrimitive: typeof isPrimitive; isRegExp: typeof isRegExp; isSafeInteger: typeof isSafeInteger; isSet: typeof isSet; isString: typeof isString; isSymbol: typeof isSymbol; isUndefined: typeof isUndefined; isUpperCaseChar: typeof isUpperCaseChar; isWeakMap: typeof isWeakMap; isWeakSet: typeof isWeakSet; addTime: typeof addTime; compareDate: typeof compareDate; formatDate: typeof formatDate; getDayOfYear: typeof getDayOfYear; getWeekOfMonth: typeof getWeekOfMonth; getWeekOfYear: typeof getWeekOfYear; isLeapYear: typeof isLeapYear; isSameDay: typeof isSameDay; now: typeof now; toDate: typeof toDate; formatNumber: typeof formatNumber; gt: typeof gt; gte: typeof gte; inRange: typeof inRange; lt: typeof lt; lte: typeof lte; toInteger: typeof toInteger; toNumber: typeof toNumber; camelCase: typeof camelCase; capitalize: typeof capitalize; endsWith: typeof endsWith; escapeRegExp: typeof escapeRegExp; indexOf: typeof indexOf; kebabCase: typeof kebabCase; lastIndexOf: typeof lastIndexOf; lowerCase: typeof lowerCase; lowerFirst: typeof lowerFirst; padEnd: typeof padEnd; padStart: typeof padStart; padZ: typeof padZ; pascalCase: typeof pascalCase; repeat: typeof repeat; replace: typeof replace; replaceAll: typeof replaceAll; snakeCase: typeof snakeCase; split: typeof split; startsWith: typeof startsWith; substring: typeof substring; test: typeof test; toFixed: typeof toFixed; toString: typeof toString; trim: typeof trim; trimEnd: typeof trimEnd; trimStart: typeof trimStart; truncate: typeof truncate; upperCase: typeof upperCase; upperFirst: typeof upperFirst; VERSION: string; chain: typeof chain; }; export { VERSION, add, addTime, after, alphaId, alt, append, arrayToTree, assign, assignWith, bind, bindAll, call, camelCase, capitalize, chain, chunk, clone, cloneDeep, cloneDeepWith, cloneWith, closest, compact, compareDate, compose, concat, countBy, debounce, myfx as default, defaultTo, defaults, defaultsDeep, delay, divide, each, eachRight, endsWith, eq, escapeRegExp, every, except, fill, filter, filterTree, find, findIndex, findKey, findLast, findLastIndex, findTreeNode, findTreeNodes, first, flat, flatDeep, flatMap, flatMapDeep, formatDate, formatNumber, fromPairs, functions, fval, get, getDayOfYear, getWeekOfMonth, getWeekOfYear, groupBy, gt, gte, has, identity, inRange, includes, indexOf, initial, insert, intersect, isAlnum, isAlpha, isArray, isArrayLike, isBlank, isBoolean, isCustomElement, isDate, isDefined, isElement, isEmpty, isEqual, isEqualWith, isError, isFinite, isFunction, isInteger, isIterator, isLeapYear, isLowerCaseChar, isMap, isMatch, isMatchWith, isNaN, isNative, isNil, isNode, isNull, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isRegExp, isSafeInteger, isSameDay, isSet, isString, isSymbol, isUndefined, isUpperCaseChar, isWeakMap, isWeakSet, iteratee, join, kebabCase, keyBy, keys, keysIn, last, lastIndexOf, lowerCase, lowerFirst, lt, lte, map, matcher, max, mean, median, merge, mergeWith, min, minmax, mixin, multiply, noConflict, noop, now, omit, omitBy, once, padEnd, padStart, padZ, parseJSON, partial, partition, pascalCase, pick, pickBy, pop, prop, pull, randf, randi, range, reduce, reject, remove, repeat, replace, replaceAll, reverse, sample, sampleSize, set, shuffle, size, slice, snakeCase, snowflakeId, some, sort, sortBy, sortTree, sortedIndex, sortedIndexBy, split, startsWith, substring, subtract, sum, tail, take, takeRight, tap, template, test, throttle, times, toArray, toDate, toFixed, toInteger, toNumber, toObject, toPairs, toPath, toString, trim, trimEnd, trimStart, truncate, union, uniq, uniqBy, uniqueId, unset, unzip, upperCase, upperFirst, uuid, values, valuesIn, walkTree, without, zip, zipObject, zipWith };