ut2 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/ut2.js +189 -84
- package/dist/ut2.js.map +1 -1
- package/dist/ut2.min.js +1 -1
- package/dist/ut2.min.js.map +1 -1
- package/es/countBy.js +11 -13
- package/es/difference.js +2 -0
- package/es/every.js +16 -0
- package/es/filter.js +15 -0
- package/es/find.js +16 -0
- package/es/forEach.js +6 -0
- package/es/forEachRight.js +6 -0
- package/es/groupBy.js +13 -13
- package/es/index.js +10 -0
- package/es/internals/createExtremum.js +8 -18
- package/es/internals/createForEach.js +23 -0
- package/es/internals/createReduce.js +29 -0
- package/es/internals/helpers.js +1 -1
- package/es/intersection.js +2 -0
- package/es/isEmpty.js +1 -1
- package/es/keyBy.js +8 -8
- package/es/keys.js +11 -0
- package/es/map.js +13 -0
- package/es/merge.js +7 -6
- package/es/orderBy.js +9 -9
- package/es/partition.js +7 -7
- package/es/reduce.js +6 -0
- package/es/reduceRight.js +6 -0
- package/es/some.js +16 -0
- package/es/uniq.js +5 -13
- package/es/xor.js +2 -0
- package/lib/countBy.js +11 -13
- package/lib/difference.js +2 -0
- package/lib/every.js +18 -0
- package/lib/filter.js +17 -0
- package/lib/find.js +18 -0
- package/lib/forEach.js +8 -0
- package/lib/forEachRight.js +8 -0
- package/lib/groupBy.js +13 -13
- package/lib/index.js +20 -0
- package/lib/internals/createExtremum.js +8 -18
- package/lib/internals/createForEach.js +25 -0
- package/lib/internals/createReduce.js +31 -0
- package/lib/internals/helpers.js +1 -1
- package/lib/intersection.js +2 -0
- package/lib/isEmpty.js +2 -2
- package/lib/keyBy.js +8 -8
- package/lib/keys.js +13 -0
- package/lib/map.js +15 -0
- package/lib/merge.js +7 -6
- package/lib/orderBy.js +9 -9
- package/lib/partition.js +7 -7
- package/lib/reduce.js +8 -0
- package/lib/reduceRight.js +8 -0
- package/lib/some.js +18 -0
- package/lib/uniq.js +5 -13
- package/lib/xor.js +2 -0
- package/package.json +1 -1
- package/types/allKeys.d.ts +1 -1
- package/types/allKeysIn.d.ts +1 -1
- package/types/conformsTo.d.ts +2 -1
- package/types/countBy.d.ts +3 -24
- package/types/difference.d.ts +3 -2
- package/types/every.d.ts +6 -0
- package/types/filter.d.ts +6 -0
- package/types/find.d.ts +6 -0
- package/types/forEach.d.ts +36 -0
- package/types/forEachRight.d.ts +36 -0
- package/types/groupBy.d.ts +3 -24
- package/types/index.d.ts +10 -0
- package/types/internals/compare.d.ts +2 -1
- package/types/internals/createExtremum.d.ts +2 -1
- package/types/internals/createForEach.d.ts +15 -0
- package/types/internals/createIteratee.d.ts +2 -2
- package/types/internals/createReduce.d.ts +19 -0
- package/types/intersection.d.ts +3 -2
- package/types/isArrayBuffer.d.ts +1 -1
- package/types/isArrayLike.d.ts +1 -1
- package/types/isError.d.ts +1 -1
- package/types/isWeakMap.d.ts +1 -1
- package/types/isWeakSet.d.ts +1 -1
- package/types/keyBy.d.ts +3 -24
- package/types/keys.d.ts +24 -0
- package/types/keysIn.d.ts +1 -1
- package/types/map.d.ts +6 -0
- package/types/max.d.ts +3 -2
- package/types/merge.d.ts +6 -2
- package/types/min.d.ts +3 -2
- package/types/orderBy.d.ts +3 -39
- package/types/partition.d.ts +3 -34
- package/types/reduce.d.ts +38 -0
- package/types/reduceRight.d.ts +38 -0
- package/types/some.d.ts +6 -0
- package/types/union.d.ts +2 -1
- package/types/uniq.d.ts +2 -1
- package/types/xor.d.ts +3 -2
- /package/es/internals/{keys.js → specialKeys.js} +0 -0
- /package/lib/internals/{keys.js → specialKeys.js} +0 -0
- /package/types/internals/{keys.d.ts → specialKeys.d.ts} +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 迭代集合元素(从右往左的顺序),为每个元素调用 `iteratee` 。
|
|
3
|
+
*
|
|
4
|
+
* `iteratee` 函数可以通过显式返回 `false` 来提前退出迭代。
|
|
5
|
+
*
|
|
6
|
+
* `iteratee` 调用时会传入三个参数 `value` `index|key` `collection` 。
|
|
7
|
+
*
|
|
8
|
+
* @function
|
|
9
|
+
* @alias module:Collection.forEachRight
|
|
10
|
+
* @since 1.7.0
|
|
11
|
+
* @param {ArrayLike<any> | Object} collection 要迭代的集合。
|
|
12
|
+
* @param {Function} [iteratee=identity] 每次迭代调用的函数。
|
|
13
|
+
* @returns {ArrayLike<any> | Object} 迭代集合本身。
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* forEachRight([1,2,3], function(item){
|
|
17
|
+
* console.log(item);
|
|
18
|
+
* });
|
|
19
|
+
* // 3
|
|
20
|
+
* // 2
|
|
21
|
+
* // 1
|
|
22
|
+
*
|
|
23
|
+
* forEachRight({a: 1, b: 2}, function(value, key){
|
|
24
|
+
* console.log(value, key);
|
|
25
|
+
* });
|
|
26
|
+
* // 2 'b'
|
|
27
|
+
* // 1 'a'
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
declare const forEachRight: {
|
|
31
|
+
<T>(collection: import("./internals/types").WithNullable<T[]>, iteratee?: import("./internals/types").ArrayIterator<T, any> | undefined): T[];
|
|
32
|
+
(collection: import("./internals/types").WithNullable<string>, iteratee?: import("./internals/types").StringIterator<any> | undefined): string;
|
|
33
|
+
<T_1>(collection: import("./internals/types").WithNullable<ArrayLike<T_1>>, iteratee?: import("./internals/types").ArrayLikeIterator<T_1, any> | undefined): ArrayLike<T_1>;
|
|
34
|
+
<T_2 extends object>(collection: import("./internals/types").WithNullable<T_2>, iteratee?: import("./internals/types").ObjectIterator<T_2, any> | undefined): T_2;
|
|
35
|
+
};
|
|
36
|
+
export default forEachRight;
|
package/types/groupBy.d.ts
CHANGED
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* `iteratee` 调用时会传入 1 个参数 `value` 。
|
|
5
|
-
*
|
|
6
|
-
* @static
|
|
7
|
-
* @alias module:Collection.groupBy
|
|
8
|
-
* @since 1.0.0
|
|
9
|
-
* @param {Array} collection 一个用来迭代的集合。
|
|
10
|
-
* @param {Function | string} [iteratee] 迭代函数,用来转换键。
|
|
11
|
-
* @returns {Object} 组成聚合对象。
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* groupBy([6, 4, 6]); // {'6': [6, 6], '4': [4]}
|
|
15
|
-
*
|
|
16
|
-
* groupBy([6.1, 4.2, 6.3], Math.floor); // {'6': [6.1, 6.3], '4': [4.2]}
|
|
17
|
-
*
|
|
18
|
-
* groupBy([{n: 6.1}, {n: 4.2}, {n: 6.3}], item=>Math.floor(item.n)); // {'6': [{n: 6.1}, {n: 6.3}], '4': [{n: 4.2}]}
|
|
19
|
-
*
|
|
20
|
-
* // 迭代函数可以直接写入属性。
|
|
21
|
-
* groupBy(['one', 'two', 'three'], 'length'); // {'3': ['one', 'two'], '5': ['three']}
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
declare function groupBy<T, F extends (value: T) => any, K extends keyof T>(collection: T[], iteratee?: F | K): Record<string | number | symbol, T[]>;
|
|
1
|
+
import { CollectionList, CollectionObject, IterateeParam } from './internals/types';
|
|
2
|
+
declare function groupBy<T>(collection: CollectionList<T>, iteratee?: IterateeParam<T>): Record<string, T[]>;
|
|
3
|
+
declare function groupBy<T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: IterateeParam<V>): Record<string, V[]>;
|
|
25
4
|
export default groupBy;
|
package/types/index.d.ts
CHANGED
|
@@ -23,10 +23,19 @@ export { default as zip } from './zip';
|
|
|
23
23
|
* @since 1.0.0
|
|
24
24
|
*/
|
|
25
25
|
export { default as countBy } from './countBy';
|
|
26
|
+
export { default as every } from './every';
|
|
27
|
+
export { default as find } from './find';
|
|
28
|
+
export { default as filter } from './filter';
|
|
29
|
+
export { default as forEach } from './forEach';
|
|
30
|
+
export { default as forEachRight } from './forEachRight';
|
|
26
31
|
export { default as groupBy } from './groupBy';
|
|
27
32
|
export { default as keyBy } from './keyBy';
|
|
28
33
|
export { default as orderBy } from './orderBy';
|
|
34
|
+
export { default as map } from './map';
|
|
29
35
|
export { default as partition } from './partition';
|
|
36
|
+
export { default as reduce } from './reduce';
|
|
37
|
+
export { default as reduceRight } from './reduceRight';
|
|
38
|
+
export { default as some } from './some';
|
|
30
39
|
/**
|
|
31
40
|
* 函数
|
|
32
41
|
*
|
|
@@ -113,6 +122,7 @@ export { default as randomInt } from './randomInt';
|
|
|
113
122
|
*/
|
|
114
123
|
export { default as allKeys } from './allKeys';
|
|
115
124
|
export { default as allKeysIn } from './allKeysIn';
|
|
125
|
+
export { default as keys } from './keys';
|
|
116
126
|
export { default as keysIn } from './keysIn';
|
|
117
127
|
export { default as merge } from './merge';
|
|
118
128
|
export { default as omit } from './omit';
|
|
@@ -5,5 +5,6 @@ export type OrderData<T> = {
|
|
|
5
5
|
index: number;
|
|
6
6
|
value: T;
|
|
7
7
|
};
|
|
8
|
-
export type
|
|
8
|
+
export type OrderBase = 'asc' | 'desc';
|
|
9
|
+
export type Order = OrderBase | ((a: any, b: any) => number);
|
|
9
10
|
export declare function compareMultiple<T>(object: OrderData<T>, other: OrderData<T>, orders: Order[]): number;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { IterateeParam } from './types';
|
|
2
|
+
declare function createExtremum<T>(array: T[], comparator: (value: any, other: any) => boolean, iteratee?: IterateeParam<T>): T | undefined;
|
|
2
3
|
export default createExtremum;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithNullable } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 创建迭代集合方法
|
|
4
|
+
*
|
|
5
|
+
* @private
|
|
6
|
+
* @param dir 迭代方向
|
|
7
|
+
* @returns 迭代集合方法
|
|
8
|
+
*/
|
|
9
|
+
declare function createForEach(dir: 1 | -1): {
|
|
10
|
+
<T>(collection: WithNullable<T[]>, iteratee?: ArrayIterator<T, any> | undefined): T[];
|
|
11
|
+
(collection: WithNullable<string>, iteratee?: StringIterator<any>): string;
|
|
12
|
+
<T_1>(collection: WithNullable<ArrayLike<T_1>>, iteratee?: ArrayLikeIterator<T_1, any> | undefined): ArrayLike<T_1>;
|
|
13
|
+
<T_2 extends object>(collection: WithNullable<T_2>, iteratee?: ObjectIterator<T_2, any> | undefined): T_2;
|
|
14
|
+
};
|
|
15
|
+
export default createForEach;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IterateeParam } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* 创建迭代函数。
|
|
4
4
|
*
|
|
@@ -6,5 +6,5 @@ import identity from '../identity';
|
|
|
6
6
|
* @param {Function} iteratee 迭代函数或对象属性。
|
|
7
7
|
* @returns {Function} 如果参数为函数,返回该函数,否则包装一个返回对象属性的函数。
|
|
8
8
|
*/
|
|
9
|
-
declare function createIteratee<T
|
|
9
|
+
declare function createIteratee<T>(iteratee?: IterateeParam<T>): (value: T, ...args: any[]) => any;
|
|
10
10
|
export default createIteratee;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ReduceArrayIterator, ReduceArrayLikeIterator, ReduceObjectIterator, ReduceStringIterator, WithNullable } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 创建 reducer 函数
|
|
4
|
+
*
|
|
5
|
+
* @private
|
|
6
|
+
* @param dir 迭代方向
|
|
7
|
+
* @returns reduce 方法
|
|
8
|
+
*/
|
|
9
|
+
declare function createReduce(dir: 1 | -1): {
|
|
10
|
+
<T, R>(collection: WithNullable<T[]>, iteratee: ReduceArrayIterator<T, R>, initialValue: R): R;
|
|
11
|
+
<R_1>(collection: WithNullable<string>, iteratee: ReduceStringIterator<R_1>, initialValue: R_1): R_1;
|
|
12
|
+
<T_1, R_2>(collection: WithNullable<ArrayLike<T_1>>, iteratee: ReduceArrayLikeIterator<T_1, R_2>, initialValue: R_2): R_2;
|
|
13
|
+
<T_2 extends object, R_3>(collection: WithNullable<T_2>, iteratee: ReduceObjectIterator<T_2, R_3>, initialValue: R_3): R_3;
|
|
14
|
+
<T_3>(collection: WithNullable<T_3[]>, iteratee?: ReduceArrayIterator<T_3, T_3> | undefined): T_3 | undefined;
|
|
15
|
+
(collection: WithNullable<string>, iteratee?: ReduceStringIterator<string>): string | undefined;
|
|
16
|
+
<T_4>(collection: WithNullable<ArrayLike<T_4>>, iteratee?: ReduceArrayLikeIterator<T_4, T_4> | undefined): T_4 | undefined;
|
|
17
|
+
<T_5 extends object>(collection: WithNullable<T_5>, iteratee?: ReduceObjectIterator<T_5, T_5[keyof T_5]> | undefined): T_5[keyof T_5] | undefined;
|
|
18
|
+
};
|
|
19
|
+
export default createReduce;
|
package/types/intersection.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IterateeParam } from './internals/types';
|
|
1
2
|
/**
|
|
2
3
|
* 创建唯一值的数组,该数组包含 2 个数组参数都包含的元素(交集)。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。
|
|
3
4
|
*
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
* @since 1.0.0
|
|
11
12
|
* @param {Array} array 要检查的数组。
|
|
12
13
|
* @param {Array} other 另一个要检查的数组。
|
|
13
|
-
* @param {Function | string} [iteratee] 迭代函数,调用每个元素。
|
|
14
|
+
* @param {Function | string} [iteratee=identity] 迭代函数,调用每个元素。
|
|
14
15
|
* @param {boolean} [strictCheck=false] 严格比较,区分 `0` `-0`,默认 `false` 。
|
|
15
16
|
* @returns {Array} 包含所有传入数组交集元素的新数组。
|
|
16
17
|
* @example
|
|
@@ -29,5 +30,5 @@
|
|
|
29
30
|
* intersection([-0, 0], [0], undefined, true); // [0]
|
|
30
31
|
*
|
|
31
32
|
*/
|
|
32
|
-
declare function intersection<T
|
|
33
|
+
declare function intersection<T>(array: T[], other: T[], iteratee?: IterateeParam<T>, strictCheck?: boolean): T[];
|
|
33
34
|
export default intersection;
|
package/types/isArrayBuffer.d.ts
CHANGED
package/types/isArrayLike.d.ts
CHANGED
package/types/isError.d.ts
CHANGED
package/types/isWeakMap.d.ts
CHANGED
package/types/isWeakSet.d.ts
CHANGED
package/types/keyBy.d.ts
CHANGED
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* `iteratee` 调用时会传入 1 个参数 `value` 。
|
|
5
|
-
*
|
|
6
|
-
* @static
|
|
7
|
-
* @alias module:Collection.keyBy
|
|
8
|
-
* @since 1.0.0
|
|
9
|
-
* @param {Array} collection 一个用来迭代的集合。
|
|
10
|
-
* @param {Function | string} [iteratee] 迭代函数,用来转换键。
|
|
11
|
-
* @returns {Object} 组成聚合对象。
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* keyBy([6, 4, 6]); // {'6': 6, '4': 4}
|
|
15
|
-
*
|
|
16
|
-
* keyBy([6.1, 4.2, 6.3], Math.floor); // {'6': 6.3, '4': 4.2}
|
|
17
|
-
*
|
|
18
|
-
* keyBy([{n: 6.1}, {n: 4.2}, {n: 6.3}], item=>Math.floor(item.n)); // {'6': {n: 6.3}, '4': {n: 4.2}}
|
|
19
|
-
*
|
|
20
|
-
* // 迭代函数可以直接写入属性。
|
|
21
|
-
* keyBy(['one', 'two', 'three'], 'length'); // {'3': 'two', '5': 'three'}
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
declare function keyBy<T, F extends (value: T) => any, K extends keyof T>(collection: T[], iteratee?: F | K): Record<string | number | symbol, T>;
|
|
1
|
+
import { CollectionList, CollectionObject, IterateeParam } from './internals/types';
|
|
2
|
+
declare function keyBy<T>(collection: CollectionList<T>, iteratee?: IterateeParam<T>): Record<string, T>;
|
|
3
|
+
declare function keyBy<T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: IterateeParam<V>): Record<string, V>;
|
|
25
4
|
export default keyBy;
|
package/types/keys.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建一个数组,包含对象自身的可枚举属性(不包含 `Symbol` 属性)。
|
|
3
|
+
*
|
|
4
|
+
* 同 `Object.keys` 。
|
|
5
|
+
*
|
|
6
|
+
* @static
|
|
7
|
+
* @alias module:Object.keys
|
|
8
|
+
* @since 1.7.0
|
|
9
|
+
* @param {Object} object 要查询的对象。
|
|
10
|
+
* @returns {string[]} 对象自身的可枚举属性(不包含 `Symbol` 属性)。
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* function Foo(){
|
|
14
|
+
* this.a = 1;
|
|
15
|
+
* this[Symbol.for('b')] = 2;
|
|
16
|
+
* }
|
|
17
|
+
* Foo.prototype.c = 3;
|
|
18
|
+
* Foo.prototype[Symbol.for('d')] = 4;
|
|
19
|
+
*
|
|
20
|
+
* keys(new Foo); // ['a']
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
declare function keys<T extends object>(object: T): string[];
|
|
24
|
+
export default keys;
|
package/types/keysIn.d.ts
CHANGED
package/types/map.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithNullable } from './internals/types';
|
|
2
|
+
declare function map<T>(collection: WithNullable<T[]>, iteratee?: ArrayIterator<T, any>): T[];
|
|
3
|
+
declare function map(collection: WithNullable<string>, iteratee?: StringIterator<any>): string[];
|
|
4
|
+
declare function map<T>(collection: WithNullable<ArrayLike<T>>, iteratee?: ArrayLikeIterator<T, any>): T[];
|
|
5
|
+
declare function map<T extends object>(collection: WithNullable<T>, iteratee?: ObjectIterator<T, any>): Array<T[keyof T]>;
|
|
6
|
+
export default map;
|
package/types/max.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IterateeParam } from './internals/types';
|
|
1
2
|
/**
|
|
2
3
|
* 调用 `array` 中的每一个元素,来生成其值排序的标准,返回最大的值。
|
|
3
4
|
*
|
|
@@ -7,7 +8,7 @@
|
|
|
7
8
|
* @alias module:Math.max
|
|
8
9
|
* @since 1.0.0
|
|
9
10
|
* @param {Array} array 要迭代的数组。
|
|
10
|
-
* @param {Function | string} [iteratee
|
|
11
|
+
* @param {Function | string} [iteratee] 调用每个元素的迭代函数。
|
|
11
12
|
* @returns {*} 最大的值。
|
|
12
13
|
* @example
|
|
13
14
|
*
|
|
@@ -23,5 +24,5 @@
|
|
|
23
24
|
* max(objects, 'n'); // {n: 2};
|
|
24
25
|
*
|
|
25
26
|
*/
|
|
26
|
-
declare function max<T
|
|
27
|
+
declare function max<T>(array: T[], iteratee?: IterateeParam<T>): T | undefined;
|
|
27
28
|
export default max;
|
package/types/merge.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
type GetKeysMethod = <T extends object>(object: T) => (symbol | string)[];
|
|
1
2
|
type Customizer = (objValue: any, srcValue: any, key: string | symbol, object: any, source: any) => any;
|
|
2
3
|
/**
|
|
3
|
-
* 递归合并 `source`
|
|
4
|
+
* 递归合并 `source` 来源对象自身和继承的可枚举属性(不包含 `Symbol` 属性)到 `object` 目标对象。
|
|
4
5
|
*
|
|
5
6
|
* 如果目标值存在,被解析为 `undefined` 的 `source` 来源对象属性将被跳过。数组和普通对象会递归合并,其他对象和值会被直接分配覆盖。
|
|
6
7
|
*
|
|
8
|
+
* 如果你需要合并 `Symbol` 属性,可以传入 {@link https://caijf.github.io/ut2/module-Object.html#.allKeysIn | allKeysIn} 方法。
|
|
9
|
+
*
|
|
7
10
|
* @static
|
|
8
11
|
* @alias module:Object.merge
|
|
9
12
|
* @since 1.0.0
|
|
10
13
|
* @param {Object | Array} object 目标对象。
|
|
11
14
|
* @param {Object | Array} source 来源对象。
|
|
12
15
|
* @param {Function} [customizer] 自定义赋值函数。
|
|
16
|
+
* @param {Function} [getKeys=keysIn] 自定义获取对象键方法。
|
|
13
17
|
* @returns {Object} 目标对象。
|
|
14
18
|
* @example
|
|
15
19
|
*
|
|
@@ -24,5 +28,5 @@ type Customizer = (objValue: any, srcValue: any, key: string | symbol, object: a
|
|
|
24
28
|
* merge(object, other); // { a: [{b: 2, c: 3}, {d: 4, e: 5}] }
|
|
25
29
|
*
|
|
26
30
|
*/
|
|
27
|
-
declare function merge<TObject, TSource>(object: TObject, source: TSource, customizer?: Customizer): TObject & TSource;
|
|
31
|
+
declare function merge<TObject, TSource>(object: TObject, source: TSource, customizer?: Customizer, getKeys?: GetKeysMethod): TObject & TSource;
|
|
28
32
|
export default merge;
|
package/types/min.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IterateeParam } from './internals/types';
|
|
1
2
|
/**
|
|
2
3
|
* 调用 `array` 中的每一个元素,来生成其值排序的标准,返回最小的值。
|
|
3
4
|
*
|
|
@@ -7,7 +8,7 @@
|
|
|
7
8
|
* @alias module:Math.min
|
|
8
9
|
* @since 1.0.0
|
|
9
10
|
* @param {Array} array 要迭代的数组。
|
|
10
|
-
* @param {Function | string} [iteratee
|
|
11
|
+
* @param {Function | string} [iteratee] 调用每个元素的迭代函数。
|
|
11
12
|
* @returns {*} 最小的值。
|
|
12
13
|
* @example
|
|
13
14
|
*
|
|
@@ -22,5 +23,5 @@
|
|
|
22
23
|
* // 迭代函数可以直接写入属性。
|
|
23
24
|
* min(objects, 'n'); // {n: 1};
|
|
24
25
|
*/
|
|
25
|
-
declare function min<T
|
|
26
|
+
declare function min<T>(array: T[], iteratee?: IterateeParam<T>): T | undefined;
|
|
26
27
|
export default min;
|
package/types/orderBy.d.ts
CHANGED
|
@@ -1,41 +1,5 @@
|
|
|
1
1
|
import { Order } from './internals/compare';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* `asc` 升序, `desc` 降序,默认执行稳定排序,也就是说相同元素会保持原始排序。
|
|
6
|
-
*
|
|
7
|
-
* `iteratee` 调用时会传入 1 个参数 `value` 。
|
|
8
|
-
*
|
|
9
|
-
* @static
|
|
10
|
-
* @alias module:Collection.orderBy
|
|
11
|
-
* @since 1.0.0
|
|
12
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort | sort}
|
|
13
|
-
* @param {Array} collection 一个用来迭代的集合。
|
|
14
|
-
* @param {Function | string | Array} [iteratees] 排序的迭代函数。
|
|
15
|
-
* @param {'asc' | 'desc' | Array} [orders] 迭代函数的排序顺序。
|
|
16
|
-
* @returns {Array} 排序后的新数组。
|
|
17
|
-
* @example
|
|
18
|
-
*
|
|
19
|
-
* const array = [2, 1, 3, 5, 4];
|
|
20
|
-
*
|
|
21
|
-
* orderBy(array);; // [1, 2, 3, 4, 5]
|
|
22
|
-
*
|
|
23
|
-
* orderBy(array, item=>item, 'desc');; // [5, 4, 3, 2, 1]
|
|
24
|
-
*
|
|
25
|
-
* const objects = [
|
|
26
|
-
* { a: 'x', b: 3 },
|
|
27
|
-
* { a: 'y', b: 4 },
|
|
28
|
-
* { a: 'x', b: 1 },
|
|
29
|
-
* { a: 'y', b: 2 }
|
|
30
|
-
* ];
|
|
31
|
-
*
|
|
32
|
-
* orderBy(objects, 'b');
|
|
33
|
-
* // [{ a: 'x', b: 1 },{ a: 'y', b: 2 },{ a: 'x', b: 3 },{ a: 'y', b: 4 }]
|
|
34
|
-
*
|
|
35
|
-
* // 迭代函数可以直接写入属性。
|
|
36
|
-
* orderBy(objects, ['a', 'b'], ['asc', 'desc']);
|
|
37
|
-
* // [{ a: 'x', b: 3 },{ a: 'x', b: 1 },{ a: 'y', b: 4 },{ a: 'y', b: 2 }]
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
declare function orderBy<T, F extends (value: T) => any, K extends keyof T>(collection: T[], iteratees?: F | K | (F | K)[], orders?: Order | Order[]): T[];
|
|
2
|
+
import { CollectionList, CollectionObject, IterateeParam, Many } from './internals/types';
|
|
3
|
+
declare function orderBy<T>(collection: CollectionList<T>, iteratee?: Many<IterateeParam<T>>, orders?: Many<Order>): T[];
|
|
4
|
+
declare function orderBy<T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: Many<IterateeParam<V>>, orders?: Many<Order>): V[];
|
|
41
5
|
export default orderBy;
|
package/types/partition.d.ts
CHANGED
|
@@ -1,35 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* `predicate` 调用时会传入 1 个参数 `value`。
|
|
5
|
-
*
|
|
6
|
-
* @static
|
|
7
|
-
* @alias module:Collection.partition
|
|
8
|
-
* @since 1.0.0
|
|
9
|
-
* @param {Array} collection 一个用来迭代的集合。
|
|
10
|
-
* @param {Function | string} [predicate=identity] 每次迭代调用的断言函数。
|
|
11
|
-
* @returns {Array} 分组后的数组。
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* const users = [
|
|
15
|
-
* { user: 'barney', age: 36, active: false },
|
|
16
|
-
* { user: 'fred', age: 40, active: true },
|
|
17
|
-
* { user: 'pebbles', age: 1, active: false }
|
|
18
|
-
* ];
|
|
19
|
-
*
|
|
20
|
-
* partition(users, item => item.active);
|
|
21
|
-
* // [
|
|
22
|
-
* // [{ user: 'fred', age: 40, active: true }],
|
|
23
|
-
* // [{ user: 'barney', age: 36, active: false }, { user: 'pebbles', age: 1, active: false }]
|
|
24
|
-
* // ]
|
|
25
|
-
*
|
|
26
|
-
* // 迭代函数可以直接写入属性。
|
|
27
|
-
* partition(users, 'active');
|
|
28
|
-
* // [
|
|
29
|
-
* // [{ user: 'fred', age: 40, active: true }],
|
|
30
|
-
* // [{ user: 'barney', age: 36, active: false }, { user: 'pebbles', age: 1, active: false }]
|
|
31
|
-
* // ]
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
declare function partition<T, F extends (value: T) => any, K extends keyof T>(collection: T[], predicate?: F | K): [T[], T[]];
|
|
1
|
+
import { CollectionList, CollectionObject, IterateeParam } from './internals/types';
|
|
2
|
+
declare function partition<T>(collection: CollectionList<T>, iteratee?: IterateeParam<T>): [T[], T[]];
|
|
3
|
+
declare function partition<T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: IterateeParam<V>): [V[], V[]];
|
|
35
4
|
export default partition;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对每个元素调用 `iteratee` 函数,每一次运行 `iteratee` 会将元素的计算结果作为参数传入,最后将其结果汇总为单个返回值。
|
|
3
|
+
*
|
|
4
|
+
* 如果没有提供第三个参数值,则集合中的第一个元素将用作初始值。
|
|
5
|
+
*
|
|
6
|
+
* `iteratee` 调用时会传入四个参数 `accumulator`、`value`、`index|key`、`collection` 。
|
|
7
|
+
*
|
|
8
|
+
* @function
|
|
9
|
+
* @alias module:Collection.reduce
|
|
10
|
+
* @since 1.7.0
|
|
11
|
+
* @param {ArrayLike<any> | Object} collection 要迭代的集合。
|
|
12
|
+
* @param {Function} [iteratee=identity] 每次迭代调用的函数。
|
|
13
|
+
* @param {*} [initialValue] 初始值。
|
|
14
|
+
* @returns {*} 累计值。
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* reduce([1,2,3], function(accumulator, current, index){
|
|
18
|
+
* return accumulator + current;
|
|
19
|
+
* }, 0);
|
|
20
|
+
* // 6
|
|
21
|
+
*
|
|
22
|
+
* reduce({a: 1, b: 2, c: 3}, function(accumulator, current, key){
|
|
23
|
+
* return accumulator + current;
|
|
24
|
+
* }, 0);
|
|
25
|
+
* // 6
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
declare const reduce: {
|
|
29
|
+
<T, R>(collection: import("./internals/types").WithNullable<T[]>, iteratee: import("./internals/types").ReduceArrayIterator<T, R>, initialValue: R): R;
|
|
30
|
+
<R_1>(collection: import("./internals/types").WithNullable<string>, iteratee: import("./internals/types").ReduceStringIterator<R_1>, initialValue: R_1): R_1;
|
|
31
|
+
<T_1, R_2>(collection: import("./internals/types").WithNullable<ArrayLike<T_1>>, iteratee: import("./internals/types").ReduceArrayLikeIterator<T_1, R_2>, initialValue: R_2): R_2;
|
|
32
|
+
<T_2 extends object, R_3>(collection: import("./internals/types").WithNullable<T_2>, iteratee: import("./internals/types").ReduceObjectIterator<T_2, R_3>, initialValue: R_3): R_3;
|
|
33
|
+
<T_3>(collection: import("./internals/types").WithNullable<T_3[]>, iteratee?: import("./internals/types").ReduceArrayIterator<T_3, T_3> | undefined): T_3 | undefined;
|
|
34
|
+
(collection: import("./internals/types").WithNullable<string>, iteratee?: import("./internals/types").ReduceStringIterator<string> | undefined): string | undefined;
|
|
35
|
+
<T_4>(collection: import("./internals/types").WithNullable<ArrayLike<T_4>>, iteratee?: import("./internals/types").ReduceArrayLikeIterator<T_4, T_4> | undefined): T_4 | undefined;
|
|
36
|
+
<T_5 extends object>(collection: import("./internals/types").WithNullable<T_5>, iteratee?: import("./internals/types").ReduceObjectIterator<T_5, T_5[keyof T_5]> | undefined): T_5[keyof T_5] | undefined;
|
|
37
|
+
};
|
|
38
|
+
export default reduce;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对每个元素(从右往左的顺序)调用 `iteratee` 函数,每一次运行 `iteratee` 会将元素的计算结果作为参数传入,最后将其结果汇总为单个返回值。
|
|
3
|
+
*
|
|
4
|
+
* 如果没有提供第三个参数值,则集合中的第一个元素将用作初始值。
|
|
5
|
+
*
|
|
6
|
+
* `iteratee` 调用时会传入四个参数 `accumulator`、`value`、`index|key`、`collection` 。
|
|
7
|
+
*
|
|
8
|
+
* @function
|
|
9
|
+
* @alias module:Collection.reduceRight
|
|
10
|
+
* @since 1.7.0
|
|
11
|
+
* @param {ArrayLike<any> | Object} collection 要迭代的集合。
|
|
12
|
+
* @param {Function} [iteratee=identity] 每次迭代调用的函数。
|
|
13
|
+
* @param {*} [initialValue] 初始值。
|
|
14
|
+
* @returns {*} 累计值。
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* reduceRight([1,2,3], function(accumulator, current, index){
|
|
18
|
+
* return accumulator + current;
|
|
19
|
+
* }, 0);
|
|
20
|
+
* // 6
|
|
21
|
+
*
|
|
22
|
+
* reduceRight({a: 1, b: 2, c: 3}, function(accumulator, current, key){
|
|
23
|
+
* return accumulator + current;
|
|
24
|
+
* }, 0);
|
|
25
|
+
* // 6
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
declare const reduceRight: {
|
|
29
|
+
<T, R>(collection: import("./internals/types").WithNullable<T[]>, iteratee: import("./internals/types").ReduceArrayIterator<T, R>, initialValue: R): R;
|
|
30
|
+
<R_1>(collection: import("./internals/types").WithNullable<string>, iteratee: import("./internals/types").ReduceStringIterator<R_1>, initialValue: R_1): R_1;
|
|
31
|
+
<T_1, R_2>(collection: import("./internals/types").WithNullable<ArrayLike<T_1>>, iteratee: import("./internals/types").ReduceArrayLikeIterator<T_1, R_2>, initialValue: R_2): R_2;
|
|
32
|
+
<T_2 extends object, R_3>(collection: import("./internals/types").WithNullable<T_2>, iteratee: import("./internals/types").ReduceObjectIterator<T_2, R_3>, initialValue: R_3): R_3;
|
|
33
|
+
<T_3>(collection: import("./internals/types").WithNullable<T_3[]>, iteratee?: import("./internals/types").ReduceArrayIterator<T_3, T_3> | undefined): T_3 | undefined;
|
|
34
|
+
(collection: import("./internals/types").WithNullable<string>, iteratee?: import("./internals/types").ReduceStringIterator<string> | undefined): string | undefined;
|
|
35
|
+
<T_4>(collection: import("./internals/types").WithNullable<ArrayLike<T_4>>, iteratee?: import("./internals/types").ReduceArrayLikeIterator<T_4, T_4> | undefined): T_4 | undefined;
|
|
36
|
+
<T_5 extends object>(collection: import("./internals/types").WithNullable<T_5>, iteratee?: import("./internals/types").ReduceObjectIterator<T_5, T_5[keyof T_5]> | undefined): T_5[keyof T_5] | undefined;
|
|
37
|
+
};
|
|
38
|
+
export default reduceRight;
|
package/types/some.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithNullable } from './internals/types';
|
|
2
|
+
declare function some<T>(collection: WithNullable<T[]>, predicate?: ArrayIterator<T, any>): boolean;
|
|
3
|
+
declare function some(collection: WithNullable<string>, predicate?: StringIterator<any>): boolean;
|
|
4
|
+
declare function some<T>(collection: WithNullable<ArrayLike<T>>, predicate?: ArrayLikeIterator<T, any>): boolean;
|
|
5
|
+
declare function some<T extends object>(collection: WithNullable<T>, predicate?: ObjectIterator<T, any>): boolean;
|
|
6
|
+
export default some;
|
package/types/union.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IterateeParam } from './internals/types';
|
|
1
2
|
/**
|
|
2
3
|
* 创建一个按顺序排列的唯一值的数组(并集)。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。与 [`uniq`](#.uniq) 相似。
|
|
3
4
|
*
|
|
@@ -29,5 +30,5 @@
|
|
|
29
30
|
* union([-0, 0], [-0], undefined, true); // [-0, 0]
|
|
30
31
|
*
|
|
31
32
|
*/
|
|
32
|
-
declare function union<T
|
|
33
|
+
declare function union<T>(array: T[], other?: T[], iteratee?: IterateeParam<T>, strickCheck?: boolean): T[];
|
|
33
34
|
export default union;
|
package/types/uniq.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IterateeParam } from './internals/types';
|
|
1
2
|
/**
|
|
2
3
|
* 创建一个去重后的数组副本。只有第一次出现的元素才会被保留。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。
|
|
3
4
|
*
|
|
@@ -28,5 +29,5 @@
|
|
|
28
29
|
* uniq([-0, 0], undefined, true); // [-0, 0]
|
|
29
30
|
*
|
|
30
31
|
*/
|
|
31
|
-
declare function uniq<T
|
|
32
|
+
declare function uniq<T>(array: T[], iteratee?: IterateeParam<T>, strickCheck?: boolean): T[];
|
|
32
33
|
export default uniq;
|
package/types/xor.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IterateeParam } from './internals/types';
|
|
1
2
|
/**
|
|
2
3
|
* 创建一个唯一值的数组(并集-交集),该数组包含 2 个数组参数中不相同的元素。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。
|
|
3
4
|
*
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
* @since 1.0.0
|
|
11
12
|
* @param {Array} array 要检查的数组。
|
|
12
13
|
* @param {Array} [other=[]] 另一个要检查的数组。
|
|
13
|
-
* @param {Function | string} [iteratee] 迭代函数,调用每个元素。
|
|
14
|
+
* @param {Function | string} [iteratee={@link https://caijf.github.io/ut2/module-Util.html#.identity | identity}] 迭代函数,调用每个元素。
|
|
14
15
|
* @param {boolean} [strictCheck=false] 严格比较,区分 `0` `-0`,默认 `false` 。
|
|
15
16
|
* @returns {Array} 过滤值后的新数组。
|
|
16
17
|
* @example
|
|
@@ -29,5 +30,5 @@
|
|
|
29
30
|
* xor([-0, 0],[0], undefined, true); // [-0]
|
|
30
31
|
*
|
|
31
32
|
*/
|
|
32
|
-
declare function xor<T
|
|
33
|
+
declare function xor<T>(array: T[], other?: T[], iteratee?: IterateeParam<T>, strickCheck?: boolean): T[];
|
|
33
34
|
export default xor;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|