ut2 1.7.0 → 1.7.2

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 (83) hide show
  1. package/README.md +133 -133
  2. package/dist/ut2.js +51 -55
  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/clamp.js +4 -3
  7. package/es/conformsTo.js +4 -3
  8. package/es/countBy.js +4 -3
  9. package/es/defaultTo.js +4 -3
  10. package/es/every.js +4 -3
  11. package/es/filter.js +4 -3
  12. package/es/find.js +4 -3
  13. package/es/fromPairs.js +4 -3
  14. package/es/groupBy.js +4 -3
  15. package/es/internals/baseDebounce.js +2 -8
  16. package/es/internals/createForEach.js +2 -2
  17. package/es/internals/createReduce.js +2 -2
  18. package/es/internals/helpers.js +1 -1
  19. package/es/keyBy.js +4 -3
  20. package/es/map.js +4 -3
  21. package/es/orderBy.js +4 -3
  22. package/es/partial.js +16 -11
  23. package/es/partition.js +4 -3
  24. package/es/range.js +4 -3
  25. package/es/some.js +4 -3
  26. package/es/times.js +4 -3
  27. package/lib/clamp.js +4 -3
  28. package/lib/conformsTo.js +4 -3
  29. package/lib/countBy.js +4 -3
  30. package/lib/defaultTo.js +4 -3
  31. package/lib/every.js +4 -3
  32. package/lib/filter.js +4 -3
  33. package/lib/find.js +4 -3
  34. package/lib/fromPairs.js +4 -3
  35. package/lib/groupBy.js +4 -3
  36. package/lib/index.js +4 -4
  37. package/lib/internals/baseDebounce.js +2 -8
  38. package/lib/internals/createForEach.js +2 -2
  39. package/lib/internals/createReduce.js +2 -2
  40. package/lib/internals/helpers.js +1 -1
  41. package/lib/keyBy.js +4 -3
  42. package/lib/map.js +4 -3
  43. package/lib/orderBy.js +4 -3
  44. package/lib/partial.js +16 -11
  45. package/lib/partition.js +4 -3
  46. package/lib/range.js +4 -3
  47. package/lib/some.js +4 -3
  48. package/lib/times.js +4 -3
  49. package/package.json +26 -24
  50. package/types/after.d.ts +2 -1
  51. package/types/before.d.ts +2 -1
  52. package/types/clamp.d.ts +29 -2
  53. package/types/conformsTo.d.ts +23 -2
  54. package/types/countBy.d.ts +28 -2
  55. package/types/debounce.d.ts +2 -1
  56. package/types/defaultTo.d.ts +6 -3
  57. package/types/delay.d.ts +2 -1
  58. package/types/every.d.ts +28 -4
  59. package/types/filter.d.ts +26 -4
  60. package/types/find.d.ts +26 -4
  61. package/types/forEach.d.ts +1 -6
  62. package/types/forEachRight.d.ts +1 -6
  63. package/types/fromPairs.d.ts +20 -2
  64. package/types/groupBy.d.ts +28 -2
  65. package/types/internals/baseDebounce.d.ts +2 -1
  66. package/types/internals/createForEach.d.ts +7 -6
  67. package/types/internals/createReduce.d.ts +11 -10
  68. package/types/internals/types.d.ts +29 -0
  69. package/types/isFunction.d.ts +2 -1
  70. package/types/keyBy.d.ts +28 -2
  71. package/types/map.d.ts +28 -4
  72. package/types/merge.d.ts +3 -1
  73. package/types/negate.d.ts +2 -1
  74. package/types/once.d.ts +2 -1
  75. package/types/orderBy.d.ts +43 -2
  76. package/types/partial.d.ts +63 -11
  77. package/types/partition.d.ts +38 -2
  78. package/types/range.d.ts +28 -3
  79. package/types/reduce.d.ts +1 -10
  80. package/types/reduceRight.d.ts +1 -10
  81. package/types/some.d.ts +26 -4
  82. package/types/throttle.d.ts +2 -1
  83. package/types/times.d.ts +25 -2
@@ -1,4 +1,10 @@
1
1
  import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithNullable } from './types';
2
+ export interface ForEach {
3
+ <T>(collection: WithNullable<T[]>, iteratee?: ArrayIterator<T, any>): T[];
4
+ (collection: WithNullable<string>, iteratee?: StringIterator<any>): string;
5
+ <T>(collection: WithNullable<ArrayLike<T>>, iteratee?: ArrayLikeIterator<T, any>): ArrayLike<T>;
6
+ <T extends object>(collection: WithNullable<T>, iteratee?: ObjectIterator<T, any>): T;
7
+ }
2
8
  /**
3
9
  * 创建迭代集合方法
4
10
  *
@@ -6,10 +12,5 @@ import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithN
6
12
  * @param dir 迭代方向
7
13
  * @returns 迭代集合方法
8
14
  */
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
+ declare function createForEach(dir: 1 | -1): ForEach;
15
16
  export default createForEach;
@@ -1,4 +1,14 @@
1
1
  import { ReduceArrayIterator, ReduceArrayLikeIterator, ReduceObjectIterator, ReduceStringIterator, WithNullable } from './types';
2
+ export interface Reduce {
3
+ <T, R>(collection: WithNullable<T[]>, iteratee: ReduceArrayIterator<T, R>, initialValue: R): R;
4
+ <R>(collection: WithNullable<string>, iteratee: ReduceStringIterator<R>, initialValue: R): R;
5
+ <T, R>(collection: WithNullable<ArrayLike<T>>, iteratee: ReduceArrayLikeIterator<T, R>, initialValue: R): R;
6
+ <T extends object, R>(collection: WithNullable<T>, iteratee: ReduceObjectIterator<T, R>, initialValue: R): R;
7
+ <T>(collection: WithNullable<T[]>, iteratee?: ReduceArrayIterator<T, T>): T | undefined;
8
+ (collection: WithNullable<string>, iteratee?: ReduceStringIterator<string>): string | undefined;
9
+ <T>(collection: WithNullable<ArrayLike<T>>, iteratee?: ReduceArrayLikeIterator<T, T>): T | undefined;
10
+ <T extends object>(collection: WithNullable<T>, iteratee?: ReduceObjectIterator<T, T[keyof T]>): T[keyof T] | undefined;
11
+ }
2
12
  /**
3
13
  * 创建 reducer 函数
4
14
  *
@@ -6,14 +16,5 @@ import { ReduceArrayIterator, ReduceArrayLikeIterator, ReduceObjectIterator, Red
6
16
  * @param dir 迭代方向
7
17
  * @returns reduce 方法
8
18
  */
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
+ declare function createReduce(dir: 1 | -1): Reduce;
19
20
  export default createReduce;
@@ -0,0 +1,29 @@
1
+ export type FunctionAny = (...args: any[]) => any;
2
+ /**
3
+ * 工具辅助类型
4
+ */
5
+ export type Many<T> = T | T[];
6
+ export type WithNullable<T> = T | null | undefined;
7
+ /**
8
+ * 迭代参数
9
+ */
10
+ export type IterateeParam<T> = ((value: T, ...args: any[]) => any) | keyof T;
11
+ /**
12
+ * 迭代方法
13
+ */
14
+ export type StringIterator<R> = (char: string, index: number, string: string) => R;
15
+ export type ArrayIterator<T, R> = (item: T, index: number, list: T[]) => R;
16
+ export type ArrayLikeIterator<T, R> = (item: T, index: number, list: ArrayLike<T>) => R;
17
+ export type ObjectIterator<T, R> = (value: T[keyof T], key: string, object: T) => R;
18
+ export type ReduceStringIterator<R> = (accumulator: R, currentValue: string, currentIndex: number, string: string) => R;
19
+ export type ReduceArrayIterator<T, R> = (accumulator: R, currentValue: T, currentIndex: number, list: T[]) => R;
20
+ export type ReduceArrayLikeIterator<T, R> = (accumulator: R, currentValue: T, currentIndex: number, list: ArrayLike<T>) => R;
21
+ export type ReduceObjectIterator<T, R> = (accumulator: R, currentValue: T[keyof T], currentKey: string, object: T) => R;
22
+ /**
23
+ * 集合类数组
24
+ */
25
+ export type CollectionList<T> = WithNullable<ArrayLike<T>>;
26
+ /**
27
+ * 集合对象
28
+ */
29
+ export type CollectionObject<T extends object> = WithNullable<T>;
@@ -1,3 +1,4 @@
1
+ import { FunctionAny } from './internals/types';
1
2
  /**
2
3
  * 检查值是否为 `Function` 对象 。
3
4
  *
@@ -15,5 +16,5 @@
15
16
  * isFunction(/x/); // false
16
17
  *
17
18
  */
18
- declare function isFunction(value: any): value is (...args: any[]) => any;
19
+ declare function isFunction(value: any): value is FunctionAny;
19
20
  export default isFunction;
package/types/keyBy.d.ts CHANGED
@@ -1,4 +1,30 @@
1
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>;
2
+ interface KeyBy {
3
+ <T>(collection: CollectionList<T>, iteratee?: IterateeParam<T>): Record<string, T>;
4
+ <T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: IterateeParam<V>): Record<string, V>;
5
+ }
6
+ /**
7
+ * 创建一个组成聚合对象, `key` 是经过 `iteratee` 执行处理 `collection` 中每个元素后返回的结果。每个 `key` 对应的值是生成 `key` 的最后一个元素。
8
+ *
9
+ * `iteratee` 调用时会传入 1 个参数 `value` 。
10
+ *
11
+ * @function
12
+ * @alias module:Collection.keyBy
13
+ * @since 1.0.0
14
+ * @param {ArrayLike<any> | Object} collection 一个用来迭代的集合。
15
+ * @param {Function | string} [iteratee=identity] 迭代函数,用来转换键。
16
+ * @returns {Object} 组成聚合对象。
17
+ * @example
18
+ *
19
+ * keyBy([6, 4, 6]); // {'6': 6, '4': 4}
20
+ *
21
+ * keyBy([6.1, 4.2, 6.3], Math.floor); // {'6': 6.3, '4': 4.2}
22
+ *
23
+ * keyBy([{n: 6.1}, {n: 4.2}, {n: 6.3}], item=>Math.floor(item.n)); // {'6': {n: 6.3}, '4': {n: 4.2}}
24
+ *
25
+ * // 迭代函数可以直接写入属性。
26
+ * keyBy(['one', 'two', 'three'], 'length'); // {'3': 'two', '5': 'three'}
27
+ *
28
+ */
29
+ declare const keyBy: KeyBy;
4
30
  export default keyBy;
package/types/map.d.ts CHANGED
@@ -1,6 +1,30 @@
1
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]>;
2
+ interface Map {
3
+ <T>(collection: WithNullable<T[]>, iteratee?: ArrayIterator<T, any>): T[];
4
+ (collection: WithNullable<string>, iteratee?: StringIterator<any>): string[];
5
+ <T>(collection: WithNullable<ArrayLike<T>>, iteratee?: ArrayLikeIterator<T, any>): T[];
6
+ <T extends object>(collection: WithNullable<T>, iteratee?: ObjectIterator<T, any>): Array<T[keyof T]>;
7
+ }
8
+ /**
9
+ * 创建一个新数组,这个数组的值由迭代集合每个元素调用 `iteratee` 函数的返回值组成。
10
+ *
11
+ * `iteratee` 调用时会传入三个参数 `value` `index|key` `collection` 。
12
+ *
13
+ * @static
14
+ * @alias module:Collection.map
15
+ * @since 1.7.0
16
+ * @param {ArrayLike<any> | Object} collection 要迭代的集合。
17
+ * @param {function} [iteratee=identity] 每次迭代调用的函数。
18
+ * @returns {Array} 一个新数组。
19
+ * @example
20
+ *
21
+ * const arr = [1, 2, 3];
22
+ * map(arr, item => item * 3); // [3, 6, 9]
23
+ *
24
+ * const obj = { one: 1, two: 2, three: 3 };
25
+ * map(obj, item => item * 3); // [3, 6, 9]
26
+ *
27
+ * map([[1, 2], [3, 4]], item=>item[0]); // [1, 3]
28
+ */
29
+ declare const map: Map;
6
30
  export default map;
package/types/merge.d.ts CHANGED
@@ -5,7 +5,7 @@ type Customizer = (objValue: any, srcValue: any, key: string | symbol, object: a
5
5
  *
6
6
  * 如果目标值存在,被解析为 `undefined` 的 `source` 来源对象属性将被跳过。数组和普通对象会递归合并,其他对象和值会被直接分配覆盖。
7
7
  *
8
- * 如果你需要合并 `Symbol` 属性,可以传入 {@link https://caijf.github.io/ut2/module-Object.html#.allKeysIn | allKeysIn} 方法。
8
+ * 如果你需要合并 `Symbol` 属性,第四个参数传入 {@link https://caijf.github.io/ut2/module-Object.html#.allKeysIn | allKeysIn} 方法, `merge(object, source, undefined, allKeysIn)` 。
9
9
  *
10
10
  * @static
11
11
  * @alias module:Object.merge
@@ -27,6 +27,8 @@ type Customizer = (objValue: any, srcValue: any, key: string | symbol, object: a
27
27
  *
28
28
  * merge(object, other); // { a: [{b: 2, c: 3}, {d: 4, e: 5}] }
29
29
  *
30
+ * // 自定义,数组不合并
31
+ * merge(object, other, (objValue, srcValue) => Array.isArray(srcValue) ? srcValue : undefined); // { a: [{c: 3},{e: 5}] }
30
32
  */
31
33
  declare function merge<TObject, TSource>(object: TObject, source: TSource, customizer?: Customizer, getKeys?: GetKeysMethod): TObject & TSource;
32
34
  export default merge;
package/types/negate.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { FunctionAny } from './internals/types';
1
2
  /**
2
3
  * 创建一个断言函数结果取反的函数。
3
4
  *
@@ -19,5 +20,5 @@
19
20
  * nums.filter(ne); // [1, 3, 5]
20
21
  *
21
22
  */
22
- declare function negate<T extends (...args: any[]) => any>(this: any, predicate: T): (...args: Parameters<T>) => boolean;
23
+ declare function negate<T extends FunctionAny>(this: any, predicate: T): (...args: Parameters<T>) => boolean;
23
24
  export default negate;
package/types/once.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { FunctionAny } from './internals/types';
1
2
  /**
2
3
  * 创建一个只能调用 `func` 一次的函数。重复调用将返回第一次调用 `func` 的结果。
3
4
  *
@@ -20,5 +21,5 @@
20
21
  * increment(); // 1
21
22
  *
22
23
  */
23
- declare function once<T extends (...args: any[]) => any>(func: T): T;
24
+ declare function once<T extends FunctionAny>(func: T): T;
24
25
  export default once;
@@ -1,5 +1,46 @@
1
1
  import { Order } from './internals/compare';
2
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[];
3
+ interface OrderBy {
4
+ <T>(collection: CollectionList<T>, iteratee?: Many<IterateeParam<T>>, orders?: Many<Order>): T[];
5
+ <T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: Many<IterateeParam<V>>, orders?: Many<Order>): V[];
6
+ }
7
+ /**
8
+ * 创建一个元素数组,以迭代函数处理的结果排序。如果没有指定排序,默认为升序排序。
9
+ *
10
+ * `asc` 升序, `desc` 降序,默认执行稳定排序,也就是说相同元素会保持原始排序。
11
+ *
12
+ * `iteratee` 调用时会传入 1 个参数 `value` 。
13
+ *
14
+ * @function
15
+ * @alias module:Collection.orderBy
16
+ * @since 1.0.0
17
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort | sort}
18
+ * @param {ArrayLike<any> | Object} collection 一个用来迭代的集合。
19
+ * @param {Function | string | Array} [iteratees] 排序的迭代函数。
20
+ * @param {'asc' | 'desc' | Array} [orders] 迭代函数的排序顺序。
21
+ * @returns {Array} 排序后的新数组。
22
+ * @example
23
+ *
24
+ * const array = [2, 1, 3, 5, 4];
25
+ *
26
+ * orderBy(array);; // [1, 2, 3, 4, 5]
27
+ *
28
+ * orderBy(array, item=>item, 'desc');; // [5, 4, 3, 2, 1]
29
+ *
30
+ * const objects = [
31
+ * { a: 'x', b: 3 },
32
+ * { a: 'y', b: 4 },
33
+ * { a: 'x', b: 1 },
34
+ * { a: 'y', b: 2 }
35
+ * ];
36
+ *
37
+ * orderBy(objects, 'b');
38
+ * // [{ a: 'x', b: 1 },{ a: 'y', b: 2 },{ a: 'x', b: 3 },{ a: 'y', b: 4 }]
39
+ *
40
+ * // 迭代函数可以直接写入属性。
41
+ * orderBy(objects, ['a', 'b'], ['asc', 'desc']);
42
+ * // [{ a: 'x', b: 3 },{ a: 'x', b: 1 },{ a: 'y', b: 4 },{ a: 'y', b: 2 }]
43
+ *
44
+ */
45
+ declare const orderBy: OrderBy;
5
46
  export default orderBy;
@@ -1,12 +1,64 @@
1
- declare function partial<TS extends any[], R>(func: (...ts: TS) => R): (...ts: TS) => R;
2
- declare function partial<TS extends any[], T1, R>(func: (t1: T1, ...ts: TS) => R, arg1: T1): (...ts: TS) => R;
3
- declare function partial<TS extends any[], T1, T2, R>(func: (t1: T1, t2: T2, ...ts: TS) => R, t1: T1, t2: T2): (...ts: TS) => R;
4
- declare function partial<TS extends any[], T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3, ...ts: TS) => R, t1: T1, t2: T2, t3: T3): (...ts: TS) => R;
5
- declare function partial<TS extends any[], T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4): (...ts: TS) => R;
6
- declare function partial<TS extends any[], T1, T2, T3, T4, T5, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): (...ts: TS) => R;
7
- declare function partial<TS extends any[], T1, T2, T3, T4, T5, T6, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6): (...ts: TS) => R;
8
- declare function partial<TS extends any[], T1, T2, T3, T4, T5, T6, T7, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7): (...ts: TS) => R;
9
- declare function partial<TS extends any[], T1, T2, T3, T4, T5, T6, T7, T8, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8): (...ts: TS) => R;
10
- declare function partial<TS extends any[], T1, T2, T3, T4, T5, T6, T7, T8, T9, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9): (...ts: TS) => R;
11
- declare function partial<TS extends any[], T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10): (...ts: TS) => R;
1
+ interface PartialPlaceholder {
2
+ __ut2_partial__: number;
3
+ }
4
+ type Placeholder = PartialPlaceholder;
5
+ type Function0<R> = () => R;
6
+ type Function1<T1, R> = (t1: T1) => R;
7
+ type Function2<T1, T2, R> = (t1: T1, t2: T2) => R;
8
+ type Function3<T1, T2, T3, R> = (t1: T1, t2: T2, t3: T3) => R;
9
+ type Function4<T1, T2, T3, T4, R> = (t1: T1, t2: T2, t3: T3, t4: T4) => R;
10
+ interface Partial {
11
+ <T1, T2, R>(func: Function2<T1, T2, R>, plc1: Placeholder, arg2: T2): Function1<T1, R>;
12
+ <T1, T2, R>(func: Function2<T1, T2, R>, arg1: T1, arg2: T2): Function0<R>;
13
+ <T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, plc1: Placeholder, arg2: T2): Function2<T1, T3, R>;
14
+ <T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, plc1: Placeholder, plc2: Placeholder, arg3: T3): Function2<T1, T2, R>;
15
+ <T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, arg1: T1, plc2: Placeholder, arg3: T3): Function1<T2, R>;
16
+ <T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, plc1: Placeholder, arg2: T2, arg3: T3): Function1<T1, R>;
17
+ <T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, arg1: T1, arg2: T2, arg3: T3): Function0<R>;
18
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: Placeholder, arg2: T2): Function3<T1, T3, T4, R>;
19
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: Placeholder, plc2: Placeholder, arg3: T3): Function3<T1, T2, T4, R>;
20
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: Placeholder, arg3: T3): Function2<T2, T4, R>;
21
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: Placeholder, arg2: T2, arg3: T3): Function2<T1, T4, R>;
22
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, arg3: T3): Function1<T4, R>;
23
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: Placeholder, plc2: Placeholder, plc3: Placeholder, arg4: T4): Function3<T1, T2, T3, R>;
24
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: Placeholder, plc3: Placeholder, arg4: T4): Function2<T2, T3, R>;
25
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: Placeholder, arg2: T2, plc3: Placeholder, arg4: T4): Function2<T1, T3, R>;
26
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, plc3: Placeholder, arg4: T4): Function1<T3, R>;
27
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: Placeholder, plc2: Placeholder, arg3: T3, arg4: T4): Function2<T1, T2, R>;
28
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: Placeholder, arg3: T3, arg4: T4): Function1<T2, R>;
29
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: Placeholder, arg2: T2, arg3: T3, arg4: T4): Function1<T1, R>;
30
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, arg3: T3, arg4: T4): Function0<R>;
31
+ <TS extends any[], R>(func: (...ts: TS) => R): (...ts: TS) => R;
32
+ <TS extends any[], T1, R>(func: (t1: T1, ...ts: TS) => R, arg1: T1): (...ts: TS) => R;
33
+ <TS extends any[], T1, T2, R>(func: (t1: T1, t2: T2, ...ts: TS) => R, t1: T1, t2: T2): (...ts: TS) => R;
34
+ <TS extends any[], T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3, ...ts: TS) => R, t1: T1, t2: T2, t3: T3): (...ts: TS) => R;
35
+ <TS extends any[], T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4): (...ts: TS) => R;
36
+ placeholder: Placeholder;
37
+ _: Placeholder;
38
+ }
39
+ /**
40
+ * 创建一个函数。该函数调用 `func` ,并传入预设的 `args` 参数。
41
+ *
42
+ * `partial._` 或 `partial.placeholder` 可用作部分参数的占位符。
43
+ *
44
+ * @function
45
+ * @alias module:Function.partial
46
+ * @since 1.0.0
47
+ * @param {Function} func 需要预设的函数。
48
+ * @param {...*} [args] 预设的参数。
49
+ * @returns {Function} 预设参数的函数。
50
+ * @example
51
+ *
52
+ * function greet(greeting, name){
53
+ * return greeting + ' ' + name;
54
+ * }
55
+ *
56
+ * const sayHelloTo = partial(greet, 'hello');
57
+ * sayHelloTo('jeff'); // 'hello jeff'
58
+ *
59
+ * const greetJeff = partial(greet, partial._, 'jeff');
60
+ * greetJeff('hi'); // 'hi jeff'
61
+ *
62
+ */
63
+ declare const partial: Partial;
12
64
  export default partial;
@@ -1,4 +1,40 @@
1
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[]];
2
+ interface Partition {
3
+ <T>(collection: CollectionList<T>, iteratee?: IterateeParam<T>): [T[], T[]];
4
+ <T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: IterateeParam<V>): [V[], V[]];
5
+ }
6
+ /**
7
+ * 创建一个分成两组的元素数组,第一组包含 `predicate`(断言函数)返回为 [`truthy`](https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy)(真值)的元素,第二组包含 `predicate`(断言函数)返回为 [`falsy`](https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy)(假值)的元素。
8
+ *
9
+ * `predicate` 调用时会传入 1 个参数 `value`。
10
+ *
11
+ * @static
12
+ * @alias module:Collection.partition
13
+ * @since 1.0.0
14
+ * @param {ArrayLike<any> | Object} collection 一个用来迭代的集合。
15
+ * @param {Function | string} [predicate=identity] 每次迭代调用的断言函数。
16
+ * @returns {Array} 分组后的数组。
17
+ * @example
18
+ *
19
+ * const users = [
20
+ * { user: 'barney', age: 36, active: false },
21
+ * { user: 'fred', age: 40, active: true },
22
+ * { user: 'pebbles', age: 1, active: false }
23
+ * ];
24
+ *
25
+ * partition(users, item => item.active);
26
+ * // [
27
+ * // [{ user: 'fred', age: 40, active: true }],
28
+ * // [{ user: 'barney', age: 36, active: false }, { user: 'pebbles', age: 1, active: false }]
29
+ * // ]
30
+ *
31
+ * // 迭代函数可以直接写入属性。
32
+ * partition(users, 'active');
33
+ * // [
34
+ * // [{ user: 'fred', age: 40, active: true }],
35
+ * // [{ user: 'barney', age: 36, active: false }, { user: 'pebbles', age: 1, active: false }]
36
+ * // ]
37
+ *
38
+ */
39
+ declare const partition: Partition;
4
40
  export default partition;
package/types/range.d.ts CHANGED
@@ -1,4 +1,29 @@
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[];
1
+ interface Range {
2
+ (start: number, end: number, step: number): number[];
3
+ (start: number, end: number): number[];
4
+ (end: number): number[];
5
+ }
6
+ /**
7
+ * 创建一个升序或降序的数字数组。
8
+ *
9
+ * 如果省略 `start` 默认为 0 。
10
+ *
11
+ * @function
12
+ * @alias module:Util.range
13
+ * @since 1.6.0
14
+ * @param {number} [start=0] 开始值。
15
+ * @param {number} end 结束值。
16
+ * @param {number} [step] 要增加或减少的值。如果值为 `0` ,将视为无效参数。如果 `start` 在 `end` 之前,默认为 1 ,否则默认为 -1。
17
+ * @return {number[]} 从开始值(包含)到结束值(不包含)逐步递增或递减的数字数组。
18
+ * @example
19
+ *
20
+ * range(4); // [0, 1, 2, 3]
21
+ * range(-4); // [0, -1, -2, -3]
22
+ * range(1, 5); // [1, 2, 3, 4]
23
+ * range(0, 20, 5); // [0, 5, 10, 15]
24
+ * range(0, -4, -1); // [1, 2, 3]
25
+ * range(1, 4, 0); // [1, 2, 3]
26
+ * range(0); // []
27
+ */
28
+ declare const range: Range;
4
29
  export default range;
package/types/reduce.d.ts CHANGED
@@ -25,14 +25,5 @@
25
25
  * // 6
26
26
  *
27
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
- };
28
+ declare const reduce: import("./internals/createReduce").Reduce;
38
29
  export default reduce;
@@ -25,14 +25,5 @@
25
25
  * // 6
26
26
  *
27
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
- };
28
+ declare const reduceRight: import("./internals/createReduce").Reduce;
38
29
  export default reduceRight;
package/types/some.d.ts CHANGED
@@ -1,6 +1,28 @@
1
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;
2
+ interface Some {
3
+ <T>(collection: WithNullable<T[]>, predicate?: ArrayIterator<T, any>): boolean;
4
+ (collection: WithNullable<string>, predicate?: StringIterator<any>): boolean;
5
+ <T>(collection: WithNullable<ArrayLike<T>>, predicate?: ArrayLikeIterator<T, any>): boolean;
6
+ <T extends object>(collection: WithNullable<T>, predicate?: ObjectIterator<T, any>): boolean;
7
+ }
8
+ /**
9
+ * 迭代集合中的元素执行 `predicate` 函数,如果任一元素通过 `predicate` 返回真值,则停止迭代并返回 `true` ,否则返回 `false` 。
10
+ *
11
+ * `predicate` 调用时会传入三个参数 `value` `index|key` `collection` 。
12
+ *
13
+ * @function
14
+ * @alias module:Collection.some
15
+ * @since 1.7.0
16
+ * @param {ArrayLike<any> | Object} collection 要迭代的集合。
17
+ * @param {function} [predicate=identity] 每次迭代调用的函数。
18
+ * @returns {boolean} 如果任一元素通过 `predicate` 测试,则返回 `true` ,否则返回 `false` 。
19
+ * @example
20
+ *
21
+ * const arr = [1, 2, 3, 4, 5, 6];
22
+ * some(arr, item => item % 2 === 0); // false
23
+ *
24
+ * const obj = { one: 1, two: 2, three: 3 };
25
+ * some(obj, item => item > 1); // true
26
+ */
27
+ declare const some: Some;
6
28
  export default some;
@@ -1,3 +1,4 @@
1
+ import { FunctionAny } from './internals/types';
1
2
  /**
2
3
  * 创建一个节流函数,该函数在 `wait` 毫秒数内最多执行一次 `func` 方法。
3
4
  *
@@ -33,7 +34,7 @@
33
34
  * window.addEvenetListener('popstate', throttled.cancel);
34
35
  *
35
36
  */
36
- declare function throttle<T extends (...args: any[]) => any>(func: T, wait?: number, immediate?: boolean): {
37
+ declare function throttle<T extends FunctionAny>(func: T, wait?: number, immediate?: boolean): {
37
38
  (this: any, ...args: Parameters<T>): ReturnType<T>;
38
39
  cancel: () => void;
39
40
  flush: () => ReturnType<T>;
package/types/times.d.ts CHANGED
@@ -1,3 +1,26 @@
1
- declare function times<T>(n: number, iteratee: (index: number) => T): T[];
2
- declare function times(n: number): number[];
1
+ interface Times {
2
+ <T>(n: number, iteratee: (index: number) => T): T[];
3
+ (n: number): number[];
4
+ }
5
+ /**
6
+ * 调用 `iteratee` `n` 次,每次调用返回的结果存入到数组中。
7
+ *
8
+ * `iteratee` 调用传入 1 个参数 `index` 。
9
+ *
10
+ * @function
11
+ * @alias module:Util.times
12
+ * @since 1.0.0
13
+ * @param {number} n 调用 `iteratee` 的次数。
14
+ * @param {Function} [iteratee=identity] 每次迭代调用的函数。
15
+ * @returns {Array} 调用结果的数组。
16
+ * @example
17
+ *
18
+ * times(3); // [0, 1, 2]
19
+ *
20
+ * times(3, String); // ['0', '1', '2']
21
+ *
22
+ * times(4, () => 0); // [0, 0, 0, 0]
23
+ *
24
+ */
25
+ declare const times: Times;
3
26
  export default times;