ut2 1.5.6 → 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.
Files changed (104) hide show
  1. package/README.md +11 -0
  2. package/dist/ut2.js +239 -101
  3. package/dist/ut2.js.map +1 -1
  4. package/dist/ut2.min.js +1 -1
  5. package/dist/ut2.min.js.map +1 -1
  6. package/es/countBy.js +11 -13
  7. package/es/difference.js +2 -0
  8. package/es/every.js +16 -0
  9. package/es/filter.js +15 -0
  10. package/es/find.js +16 -0
  11. package/es/forEach.js +6 -0
  12. package/es/forEachRight.js +6 -0
  13. package/es/groupBy.js +13 -13
  14. package/es/index.js +11 -0
  15. package/es/internals/createExtremum.js +8 -18
  16. package/es/internals/createForEach.js +23 -0
  17. package/es/internals/createReduce.js +29 -0
  18. package/es/internals/helpers.js +1 -1
  19. package/es/intersection.js +2 -0
  20. package/es/isEmpty.js +1 -1
  21. package/es/keyBy.js +8 -8
  22. package/es/keys.js +11 -0
  23. package/es/map.js +13 -0
  24. package/es/merge.js +32 -22
  25. package/es/orderBy.js +9 -9
  26. package/es/partition.js +7 -7
  27. package/es/range.js +28 -0
  28. package/es/reduce.js +6 -0
  29. package/es/reduceRight.js +6 -0
  30. package/es/some.js +16 -0
  31. package/es/toString.js +1 -1
  32. package/es/uniq.js +5 -13
  33. package/es/xor.js +2 -0
  34. package/lib/countBy.js +11 -13
  35. package/lib/difference.js +2 -0
  36. package/lib/every.js +18 -0
  37. package/lib/filter.js +17 -0
  38. package/lib/find.js +18 -0
  39. package/lib/forEach.js +8 -0
  40. package/lib/forEachRight.js +8 -0
  41. package/lib/groupBy.js +13 -13
  42. package/lib/index.js +22 -0
  43. package/lib/internals/createExtremum.js +8 -18
  44. package/lib/internals/createForEach.js +25 -0
  45. package/lib/internals/createReduce.js +31 -0
  46. package/lib/internals/helpers.js +1 -1
  47. package/lib/intersection.js +2 -0
  48. package/lib/isEmpty.js +2 -2
  49. package/lib/keyBy.js +8 -8
  50. package/lib/keys.js +13 -0
  51. package/lib/map.js +15 -0
  52. package/lib/merge.js +32 -22
  53. package/lib/orderBy.js +9 -9
  54. package/lib/partition.js +7 -7
  55. package/lib/range.js +30 -0
  56. package/lib/reduce.js +8 -0
  57. package/lib/reduceRight.js +8 -0
  58. package/lib/some.js +18 -0
  59. package/lib/toString.js +1 -1
  60. package/lib/uniq.js +5 -13
  61. package/lib/xor.js +2 -0
  62. package/package.json +1 -1
  63. package/types/allKeys.d.ts +1 -1
  64. package/types/allKeysIn.d.ts +1 -1
  65. package/types/conformsTo.d.ts +2 -1
  66. package/types/countBy.d.ts +3 -24
  67. package/types/difference.d.ts +3 -2
  68. package/types/every.d.ts +6 -0
  69. package/types/filter.d.ts +6 -0
  70. package/types/find.d.ts +6 -0
  71. package/types/forEach.d.ts +36 -0
  72. package/types/forEachRight.d.ts +36 -0
  73. package/types/groupBy.d.ts +3 -24
  74. package/types/index.d.ts +11 -0
  75. package/types/internals/compare.d.ts +2 -1
  76. package/types/internals/createExtremum.d.ts +2 -1
  77. package/types/internals/createForEach.d.ts +15 -0
  78. package/types/internals/createIteratee.d.ts +2 -2
  79. package/types/internals/createReduce.d.ts +19 -0
  80. package/types/intersection.d.ts +3 -2
  81. package/types/isArrayBuffer.d.ts +1 -1
  82. package/types/isArrayLike.d.ts +1 -1
  83. package/types/isError.d.ts +1 -1
  84. package/types/isWeakMap.d.ts +1 -1
  85. package/types/isWeakSet.d.ts +1 -1
  86. package/types/keyBy.d.ts +3 -24
  87. package/types/keys.d.ts +24 -0
  88. package/types/keysIn.d.ts +1 -1
  89. package/types/map.d.ts +6 -0
  90. package/types/max.d.ts +3 -2
  91. package/types/merge.d.ts +6 -2
  92. package/types/min.d.ts +3 -2
  93. package/types/orderBy.d.ts +3 -39
  94. package/types/partition.d.ts +3 -34
  95. package/types/range.d.ts +4 -0
  96. package/types/reduce.d.ts +38 -0
  97. package/types/reduceRight.d.ts +38 -0
  98. package/types/some.d.ts +6 -0
  99. package/types/union.d.ts +2 -1
  100. package/types/uniq.d.ts +2 -1
  101. package/types/xor.d.ts +3 -2
  102. /package/es/internals/{keys.js → specialKeys.js} +0 -0
  103. /package/lib/internals/{keys.js → specialKeys.js} +0 -0
  104. /package/types/internals/{keys.d.ts → specialKeys.d.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ut2",
3
- "version": "1.5.6",
3
+ "version": "1.7.0",
4
4
  "author": "caijf",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -7,7 +7,7 @@
7
7
  * @alias module:Object.allKeys
8
8
  * @since 1.1.0
9
9
  * @param {Object} object 要查询的对象。
10
- * @returns {Array<string|symbol>} 对象自身的可枚举属性名(包含 `Symbol` 属性)数组。
10
+ * @returns {Array<string|symbol>} 对象自身的可枚举属性(包含 `Symbol` 属性)
11
11
  * @example
12
12
  *
13
13
  * function Foo(){
@@ -7,7 +7,7 @@
7
7
  * @alias module:Object.allKeysIn
8
8
  * @since 1.1.0
9
9
  * @param {Object} object 要查询的对象。
10
- * @returns {Array<string|symbol>} 对象自身及继承的可枚举属性名(包含 `Symbol` 属性)数组。
10
+ * @returns {Array<string|symbol>} 对象自身及继承的可枚举属性(包含 `Symbol` 属性)
11
11
  * @example
12
12
  *
13
13
  * function Foo(){
@@ -1,3 +1,4 @@
1
+ import { WithNullable } from './internals/types';
1
2
  declare function conformsTo<T extends object, K extends keyof T>(object: T, source: Record<K, (value: T[K]) => any>): boolean;
2
- declare function conformsTo<T extends object | null | undefined>(object: T, source: Record<string | symbol, (value: any) => any>): boolean;
3
+ declare function conformsTo<T extends WithNullable<object>>(object: T, source: Record<string | symbol, (value: any) => any>): boolean;
3
4
  export default conformsTo;
@@ -1,25 +1,4 @@
1
- /**
2
- * 创建一个组成对象, `key` 是经过 `iteratee` 执行处理 `collection` 中每个元素后返回的结果,每个 `key` 对应的值是 `iteratee` 返回该 `key` 的次数。
3
- *
4
- * `iteratee` 调用时会传入 1 个参数 `value` 。
5
- *
6
- * @static
7
- * @alias module:Collection.countBy
8
- * @since 1.0.0
9
- * @param {Array} collection 一个用来迭代的集合。
10
- * @param {Function | string} [iteratee] 迭代函数,用来转换键。
11
- * @returns {Object} 组成集合对象。
12
- * @example
13
- *
14
- * countBy([6, 4, 6]); // {'6': 2, '4': 1}
15
- *
16
- * countBy([6.1, 4.2, 6.3], Math.floor); // {'6': 2, '4': 1}
17
- *
18
- * countBy([{n: 6.1}, {n: 4.2}, {n: 6.3}], item=>Math.floor(item.n)); // {'6': 2, '4': 1}
19
- *
20
- * // 迭代函数可以直接写入属性。
21
- * countBy(['one', 'two', 'three'], 'length'); // {'3': 2, '5': 1}
22
- *
23
- */
24
- declare function countBy<T, F extends (value: T) => any, K extends keyof T>(collection: T[], iteratee?: F | K): Record<string | number | symbol, number>;
1
+ import { CollectionList, CollectionObject, IterateeParam } from './internals/types';
2
+ declare function countBy<T>(collection: CollectionList<T>, iteratee?: IterateeParam<T>): Record<string, number>;
3
+ declare function countBy<T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: IterateeParam<V>): Record<string, number>;
25
4
  export default countBy;
@@ -1,3 +1,4 @@
1
+ import { IterateeParam } from './internals/types';
1
2
  /**
2
3
  * 创建一个 `array` 排除 `values` 值的新数组。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。
3
4
  *
@@ -10,7 +11,7 @@
10
11
  * @since 1.0.0
11
12
  * @param {Array} array 要检查的数组。
12
13
  * @param {Array} values 排除的值。
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
  * difference([-0, 0], [0], undefined, true); // [-0]
30
31
  *
31
32
  */
32
- declare function difference<T, F extends (value: T) => any, K extends keyof T>(array: T[], values: any[], iteratee?: F | K, strictCheck?: boolean): T[];
33
+ declare function difference<T>(array: T[], values: any[], iteratee?: IterateeParam<T>, strictCheck?: boolean): T[];
33
34
  export default difference;
@@ -0,0 +1,6 @@
1
+ import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithNullable } from './internals/types';
2
+ declare function every<T>(collection: WithNullable<T[]>, predicate?: ArrayIterator<T, any>): boolean;
3
+ declare function every(collection: WithNullable<string>, predicate?: StringIterator<any>): boolean;
4
+ declare function every<T>(collection: WithNullable<ArrayLike<T>>, predicate?: ArrayLikeIterator<T, any>): boolean;
5
+ declare function every<T extends object>(collection: WithNullable<T>, predicate?: ObjectIterator<T, any>): boolean;
6
+ export default every;
@@ -0,0 +1,6 @@
1
+ import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithNullable } from './internals/types';
2
+ declare function filter<T>(collection: WithNullable<T[]>, predicate?: ArrayIterator<T, any>): T[];
3
+ declare function filter(collection: WithNullable<string>, predicate?: StringIterator<any>): string[];
4
+ declare function filter<T>(collection: WithNullable<ArrayLike<T>>, predicate?: ArrayLikeIterator<T, any>): T[];
5
+ declare function filter<T extends object>(collection: WithNullable<T>, predicate?: ObjectIterator<T, any>): Array<T[keyof T]>;
6
+ export default filter;
@@ -0,0 +1,6 @@
1
+ import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithNullable } from './internals/types';
2
+ declare function find<T>(collection: WithNullable<T[]>, predicate?: ArrayIterator<T, any>): T | undefined;
3
+ declare function find(collection: WithNullable<string>, predicate?: StringIterator<any>): string | undefined;
4
+ declare function find<T>(collection: WithNullable<ArrayLike<T>>, predicate?: ArrayLikeIterator<T, any>): T | undefined;
5
+ declare function find<T extends object>(collection: WithNullable<T>, predicate?: ObjectIterator<T, any>): T[keyof T] | undefined;
6
+ export default find;
@@ -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.forEach
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
+ * forEach([1,2,3], function(item){
17
+ * console.log(item);
18
+ * });
19
+ * // 1
20
+ * // 2
21
+ * // 3
22
+ *
23
+ * forEach({a: 1, b: 2}, function(value, key){
24
+ * console.log(value, key);
25
+ * });
26
+ * // 1 'a'
27
+ * // 2 'b'
28
+ *
29
+ */
30
+ declare const forEach: {
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 forEach;
@@ -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;
@@ -1,25 +1,4 @@
1
- /**
2
- * 创建一个组成聚合对象, `key` 是经过 `iteratee` 执行处理 `collection` 中每个元素后返回的结果。分组值的顺序是由他们出现在 `collection` 的顺序确定的。每个键对应的值负责生成 `key` 的元素组成的数组。
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';
@@ -156,6 +166,7 @@ export { default as lt } from './lt';
156
166
  export { default as lte } from './lte';
157
167
  export { default as noop } from './noop';
158
168
  export { default as nthArg } from './nthArg';
169
+ export { default as range } from './range';
159
170
  export { default as sleep } from './sleep';
160
171
  export { default as times } from './times';
161
172
  export { default as toFinite } from './toFinite';
@@ -5,5 +5,6 @@ export type OrderData<T> = {
5
5
  index: number;
6
6
  value: T;
7
7
  };
8
- export type Order = 'asc' | 'desc' | ((a: any, b: any) => number);
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
- declare function createExtremum<T, F extends (item: T) => any, K extends keyof T>(array: T[], comparator: (value: any, other: any) => boolean, iteratee?: F | K): T | undefined;
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 identity from '../identity';
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, F extends (value: T) => any, K extends keyof T>(iteratee?: F | K): typeof identity | F;
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;
@@ -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, F extends (value: T) => any, K extends keyof T>(array: T[], other: T[], iteratee?: F | K, strictCheck?: boolean): T[];
33
+ declare function intersection<T>(array: T[], other: T[], iteratee?: IterateeParam<T>, strictCheck?: boolean): T[];
33
34
  export default intersection;
@@ -15,5 +15,5 @@
15
15
  * isArrayBuffer('2012'); // false
16
16
  *
17
17
  */
18
- declare function isArrayBuffer(value: any): boolean;
18
+ declare function isArrayBuffer(value: any): value is ArrayBuffer;
19
19
  export default isArrayBuffer;
@@ -19,5 +19,5 @@
19
19
  * isArrayLike(()=>{}); // false
20
20
  *
21
21
  */
22
- declare function isArrayLike(value: any): boolean;
22
+ declare function isArrayLike(value: any): value is ArrayLike<any>;
23
23
  export default isArrayLike;
@@ -15,5 +15,5 @@
15
15
  * isError(Error); // false
16
16
  *
17
17
  */
18
- declare function isError(value: any): boolean;
18
+ declare function isError(value: any): value is Error;
19
19
  export default isError;
@@ -13,5 +13,5 @@
13
13
  * isWeakMap(new Map); // false
14
14
  *
15
15
  */
16
- declare function isWeakMap(value: any): value is WeakMap<any, any>;
16
+ declare function isWeakMap(value: any): value is WeakMap<object, any>;
17
17
  export default isWeakMap;
@@ -13,5 +13,5 @@
13
13
  * isWeakSet(new Set); // false
14
14
  *
15
15
  */
16
- declare function isWeakSet(value: any): value is WeakSet<any>;
16
+ declare function isWeakSet(value: any): value is WeakSet<object>;
17
17
  export default isWeakSet;
package/types/keyBy.d.ts CHANGED
@@ -1,25 +1,4 @@
1
- /**
2
- * 创建一个组成聚合对象, `key` 是经过 `iteratee` 执行处理 `collection` 中每个元素后返回的结果。每个 `key` 对应的值是生成 `key` 的最后一个元素。
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;
@@ -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
@@ -7,7 +7,7 @@
7
7
  * @alias module:Object.keysIn
8
8
  * @since 1.1.0
9
9
  * @param {Object} object 要查询的对象。
10
- * @returns {string[]} 对象自身及继承的可枚举属性名(不包含 `Symbol` 属性)数组。
10
+ * @returns {string[]} 对象自身及继承的可枚举属性(不包含 `Symbol` 属性)
11
11
  * @example
12
12
  *
13
13
  * function Foo(){
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=identity] 调用每个元素的迭代函数。
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, F extends (item: T) => any, K extends keyof T>(array: T[], iteratee?: F | K): T | undefined;
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` 来源对象自身和继承的可枚举属性(包含 `Symbol` 属性)到 `object` 目标对象。
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=identity] 调用每个元素的迭代函数。
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, F extends (item: T) => any, K extends keyof T>(array: T[], iteratee?: F | K): T | undefined;
26
+ declare function min<T>(array: T[], iteratee?: IterateeParam<T>): T | undefined;
26
27
  export default min;
@@ -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;
@@ -1,35 +1,4 @@
1
- /**
2
- * 创建一个分成两组的元素数组,第一组包含 `predicate`(断言函数)返回为 [`truthy`](https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy)(真值)的元素,第二组包含 `predicate`(断言函数)返回为 [`falsy`](https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy)(假值)的元素。
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,4 @@
1
+ declare function range(start: number, end: number, step: number): number[];
2
+ declare function range(start: number, end: number): number[];
3
+ declare function range(end: number): number[];
4
+ export default range;