ut2 1.7.1 → 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.
- package/README.md +133 -133
- package/dist/ut2.js +51 -55
- package/dist/ut2.js.map +1 -1
- package/dist/ut2.min.js +1 -1
- package/dist/ut2.min.js.map +1 -1
- package/es/clamp.js +4 -3
- package/es/conformsTo.js +4 -3
- package/es/countBy.js +4 -3
- package/es/defaultTo.js +4 -3
- package/es/every.js +4 -3
- package/es/filter.js +4 -3
- package/es/find.js +4 -3
- package/es/fromPairs.js +4 -3
- package/es/groupBy.js +4 -3
- package/es/internals/baseDebounce.js +2 -8
- package/es/internals/createForEach.js +2 -2
- package/es/internals/createReduce.js +2 -2
- package/es/internals/helpers.js +1 -1
- package/es/keyBy.js +4 -3
- package/es/map.js +4 -3
- package/es/orderBy.js +4 -3
- package/es/partial.js +16 -11
- package/es/partition.js +4 -3
- package/es/range.js +4 -3
- package/es/some.js +4 -3
- package/es/times.js +4 -3
- package/lib/clamp.js +4 -3
- package/lib/conformsTo.js +4 -3
- package/lib/countBy.js +4 -3
- package/lib/defaultTo.js +4 -3
- package/lib/every.js +4 -3
- package/lib/filter.js +4 -3
- package/lib/find.js +4 -3
- package/lib/fromPairs.js +4 -3
- package/lib/groupBy.js +4 -3
- package/lib/index.js +4 -4
- package/lib/internals/baseDebounce.js +2 -8
- package/lib/internals/createForEach.js +2 -2
- package/lib/internals/createReduce.js +2 -2
- package/lib/internals/helpers.js +1 -1
- package/lib/keyBy.js +4 -3
- package/lib/map.js +4 -3
- package/lib/orderBy.js +4 -3
- package/lib/partial.js +16 -11
- package/lib/partition.js +4 -3
- package/lib/range.js +4 -3
- package/lib/some.js +4 -3
- package/lib/times.js +4 -3
- package/package.json +26 -24
- package/types/after.d.ts +2 -1
- package/types/before.d.ts +2 -1
- package/types/clamp.d.ts +29 -2
- package/types/conformsTo.d.ts +23 -2
- package/types/countBy.d.ts +28 -2
- package/types/debounce.d.ts +2 -1
- package/types/defaultTo.d.ts +6 -3
- package/types/delay.d.ts +2 -1
- package/types/every.d.ts +28 -4
- package/types/filter.d.ts +26 -4
- package/types/find.d.ts +26 -4
- package/types/forEach.d.ts +1 -6
- package/types/forEachRight.d.ts +1 -6
- package/types/fromPairs.d.ts +20 -2
- package/types/groupBy.d.ts +28 -2
- package/types/internals/baseDebounce.d.ts +2 -1
- package/types/internals/createForEach.d.ts +7 -6
- package/types/internals/createReduce.d.ts +11 -10
- package/types/internals/types.d.ts +1 -0
- package/types/isFunction.d.ts +2 -1
- package/types/keyBy.d.ts +28 -2
- package/types/map.d.ts +28 -4
- package/types/negate.d.ts +2 -1
- package/types/once.d.ts +2 -1
- package/types/orderBy.d.ts +43 -2
- package/types/partial.d.ts +63 -11
- package/types/partition.d.ts +38 -2
- package/types/range.d.ts +28 -3
- package/types/reduce.d.ts +1 -10
- package/types/reduceRight.d.ts +1 -10
- package/types/some.d.ts +26 -4
- package/types/throttle.d.ts +2 -1
- package/types/times.d.ts +25 -2
package/lib/internals/helpers.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var getTag = require('./getTag.js');
|
|
4
4
|
var native = require('./native.js');
|
|
5
5
|
|
|
6
|
-
exports.VERSION = "1.7.
|
|
6
|
+
exports.VERSION = "1.7.2";
|
|
7
7
|
exports.supportedArgumentsType = getTag((function () { return arguments; })()) === native.argumentsTag;
|
|
8
8
|
exports.FUNC_ERROR_TEXT = 'Expected a function';
|
|
9
9
|
function toSource(func) {
|
package/lib/keyBy.js
CHANGED
|
@@ -4,7 +4,7 @@ var forEach = require('./forEach.js');
|
|
|
4
4
|
var identity = require('./identity.js');
|
|
5
5
|
var createIteratee = require('./internals/createIteratee.js');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
var keyBy = function (collection, iteratee) {
|
|
8
8
|
if (iteratee === void 0) { iteratee = identity; }
|
|
9
9
|
var result = {};
|
|
10
10
|
var internalIteratee = createIteratee(iteratee);
|
|
@@ -13,6 +13,7 @@ function keyBy(collection, iteratee) {
|
|
|
13
13
|
result[key] = item;
|
|
14
14
|
});
|
|
15
15
|
return result;
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
|
+
var keyBy$1 = keyBy;
|
|
17
18
|
|
|
18
|
-
module.exports = keyBy;
|
|
19
|
+
module.exports = keyBy$1;
|
package/lib/map.js
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
var forEach = require('./forEach.js');
|
|
4
4
|
var identity = require('./identity.js');
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
var map = function (collection, iteratee) {
|
|
7
7
|
if (iteratee === void 0) { iteratee = identity; }
|
|
8
8
|
var result = [];
|
|
9
9
|
forEach(collection, function (item, index, arr) {
|
|
10
10
|
result.push(iteratee(item, index, arr));
|
|
11
11
|
});
|
|
12
12
|
return result;
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
|
+
var map$1 = map;
|
|
14
15
|
|
|
15
|
-
module.exports = map;
|
|
16
|
+
module.exports = map$1;
|
package/lib/orderBy.js
CHANGED
|
@@ -6,7 +6,7 @@ var compare = require('./internals/compare.js');
|
|
|
6
6
|
var isArray = require('./isArray.js');
|
|
7
7
|
var forEach = require('./forEach.js');
|
|
8
8
|
|
|
9
|
-
function
|
|
9
|
+
var orderBy = function (collection, iteratees, orders) {
|
|
10
10
|
var result = [];
|
|
11
11
|
iteratees = (isArray(iteratees) ? iteratees : iteratees !== undefined ? [iteratees] : [identity]);
|
|
12
12
|
orders = (isArray(orders) ? orders : orders !== undefined ? [orders] : []);
|
|
@@ -20,6 +20,7 @@ function orderBy(collection, iteratees, orders) {
|
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
22
|
return result.sort(function (a, b) { return compare.compareMultiple(a, b, orders); }).map(function (item) { return item.value; });
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
|
+
var orderBy$1 = orderBy;
|
|
24
25
|
|
|
25
|
-
module.exports = orderBy;
|
|
26
|
+
module.exports = orderBy$1;
|
package/lib/partial.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
var native = require('./internals/native.js');
|
|
4
|
+
|
|
5
|
+
var PLACEHOLDER = {
|
|
6
|
+
__ut2_partial__: 1
|
|
7
|
+
};
|
|
8
|
+
var partial = function (func) {
|
|
9
|
+
var argsOrig = native.arrayProtoSlice.call(arguments, 1);
|
|
8
10
|
return function () {
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
var args = [];
|
|
12
|
+
var argsPartial = native.arrayProtoSlice.call(arguments);
|
|
13
|
+
for (var i = 0; i < argsOrig.length; i++) {
|
|
14
|
+
args[i] = argsOrig[i] === PLACEHOLDER ? argsPartial.shift() : argsOrig[i];
|
|
12
15
|
}
|
|
13
|
-
return func.apply(this, args.concat(
|
|
16
|
+
return func.apply(this, args.concat(argsPartial));
|
|
14
17
|
};
|
|
15
|
-
}
|
|
18
|
+
};
|
|
19
|
+
partial.placeholder = partial._ = PLACEHOLDER;
|
|
20
|
+
var partial$1 = partial;
|
|
16
21
|
|
|
17
|
-
module.exports = partial;
|
|
22
|
+
module.exports = partial$1;
|
package/lib/partition.js
CHANGED
|
@@ -4,7 +4,7 @@ var forEach = require('./forEach.js');
|
|
|
4
4
|
var identity = require('./identity.js');
|
|
5
5
|
var createIteratee = require('./internals/createIteratee.js');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
var partition = function (collection, predicate) {
|
|
8
8
|
if (predicate === void 0) { predicate = identity; }
|
|
9
9
|
var result = [[], []];
|
|
10
10
|
var internalIteratee = createIteratee(predicate);
|
|
@@ -12,6 +12,7 @@ function partition(collection, predicate) {
|
|
|
12
12
|
result[internalIteratee(item) ? 0 : 1].push(item);
|
|
13
13
|
});
|
|
14
14
|
return result;
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
|
+
var partition$1 = partition;
|
|
16
17
|
|
|
17
|
-
module.exports = partition;
|
|
18
|
+
module.exports = partition$1;
|
package/lib/range.js
CHANGED
|
@@ -4,7 +4,7 @@ var native = require('./internals/native.js');
|
|
|
4
4
|
var isNil = require('./isNil.js');
|
|
5
5
|
var toFinite = require('./toFinite.js');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
var range = function (start, end, step) {
|
|
8
8
|
start = toFinite(start);
|
|
9
9
|
if (isNil(end)) {
|
|
10
10
|
end = start;
|
|
@@ -25,6 +25,7 @@ function range(start, end, step) {
|
|
|
25
25
|
start += step;
|
|
26
26
|
}
|
|
27
27
|
return result;
|
|
28
|
-
}
|
|
28
|
+
};
|
|
29
|
+
var range$1 = range;
|
|
29
30
|
|
|
30
|
-
module.exports = range;
|
|
31
|
+
module.exports = range$1;
|
package/lib/some.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var forEach = require('./forEach.js');
|
|
4
4
|
var identity = require('./identity.js');
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
var some = function (collection, predicate) {
|
|
7
7
|
if (predicate === void 0) { predicate = identity; }
|
|
8
8
|
var result = false;
|
|
9
9
|
forEach(collection, function (item, index, arr) {
|
|
@@ -13,6 +13,7 @@ function some(collection, predicate) {
|
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
15
|
return result;
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
|
+
var some$1 = some;
|
|
17
18
|
|
|
18
|
-
module.exports = some;
|
|
19
|
+
module.exports = some$1;
|
package/lib/times.js
CHANGED
|
@@ -5,7 +5,7 @@ var native = require('./internals/native.js');
|
|
|
5
5
|
var isInteger = require('./isInteger.js');
|
|
6
6
|
var isFinite = require('./isFinite.js');
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
var times = function (n, iteratee) {
|
|
9
9
|
if (iteratee === void 0) { iteratee = identity; }
|
|
10
10
|
if (n < 1 || n > native.MAX_SAFE_INTEGER) {
|
|
11
11
|
return [];
|
|
@@ -19,6 +19,7 @@ function times(n, iteratee) {
|
|
|
19
19
|
index++;
|
|
20
20
|
}
|
|
21
21
|
return result;
|
|
22
|
-
}
|
|
22
|
+
};
|
|
23
|
+
var times$1 = times;
|
|
23
24
|
|
|
24
|
-
module.exports = times;
|
|
25
|
+
module.exports = times$1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ut2",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"author": "caijf",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"commit": "cz",
|
|
27
27
|
"prepublishOnly": "npm test && npm run build",
|
|
28
28
|
"tsc": "tsc --noEmit",
|
|
29
|
-
"prepare": "husky
|
|
29
|
+
"prepare": "husky"
|
|
30
30
|
},
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
@@ -54,41 +54,43 @@
|
|
|
54
54
|
},
|
|
55
55
|
"config": {
|
|
56
56
|
"commitizen": {
|
|
57
|
-
"path": "
|
|
57
|
+
"path": "@commitlint/cz-commitlint"
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"registry": "https://registry.npmjs.org/"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@commitlint/cli": "^
|
|
65
|
-
"@commitlint/config-conventional": "^
|
|
66
|
-
"@
|
|
67
|
-
"@rollup/plugin-
|
|
68
|
-
"@rollup/plugin-
|
|
69
|
-
"@rollup/plugin-
|
|
70
|
-
"@rollup/plugin-
|
|
71
|
-
"@
|
|
72
|
-
"@types/
|
|
73
|
-
"@
|
|
74
|
-
"@typescript-eslint/
|
|
64
|
+
"@commitlint/cli": "^19.2.1",
|
|
65
|
+
"@commitlint/config-conventional": "^19.1.0",
|
|
66
|
+
"@commitlint/cz-commitlint": "^19.2.0",
|
|
67
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
68
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
69
|
+
"@rollup/plugin-replace": "^5.0.5",
|
|
70
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
71
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
72
|
+
"@types/jest": "^29.5.12",
|
|
73
|
+
"@types/node": "^20.11.30",
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
75
|
+
"@typescript-eslint/parser": "^7.3.1",
|
|
75
76
|
"benchmark": "^2.1.4",
|
|
77
|
+
"commitizen": "^4.3.0",
|
|
76
78
|
"cross-env": "^7.0.3",
|
|
77
|
-
"cz-conventional-changelog": "^3.3.0",
|
|
78
79
|
"dayjs": "^1.11.10",
|
|
79
80
|
"docdash": "^2.0.2",
|
|
80
|
-
"eslint": "^8.
|
|
81
|
-
"husky": "^
|
|
82
|
-
"
|
|
83
|
-
"jest
|
|
81
|
+
"eslint": "^8.57.0",
|
|
82
|
+
"husky": "^9.0.11",
|
|
83
|
+
"inquirer": "9",
|
|
84
|
+
"jest": "^29.7.0",
|
|
85
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
84
86
|
"jsdoc": "^4.0.2",
|
|
85
|
-
"lint-staged": "^
|
|
87
|
+
"lint-staged": "^15.2.2",
|
|
86
88
|
"lodash": "^4.17.21",
|
|
87
|
-
"prettier": "^2.
|
|
88
|
-
"rollup": "^
|
|
89
|
-
"ts-jest": "^29.1.
|
|
89
|
+
"prettier": "^3.2.5",
|
|
90
|
+
"rollup": "^4.13.0",
|
|
91
|
+
"ts-jest": "^29.1.2",
|
|
90
92
|
"tslib": "^2.6.2",
|
|
91
|
-
"typescript": "^5.
|
|
93
|
+
"typescript": "^5.4.3",
|
|
92
94
|
"underscore": "^1.13.6"
|
|
93
95
|
},
|
|
94
96
|
"engines": {
|
package/types/after.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FunctionAny } from './internals/types';
|
|
1
2
|
/**
|
|
2
3
|
* 创建一个函数,当它被调用 `n` 或更多次之后触发 `func` 。
|
|
3
4
|
*
|
|
@@ -21,5 +22,5 @@
|
|
|
21
22
|
* // 'done saving!'
|
|
22
23
|
*
|
|
23
24
|
*/
|
|
24
|
-
declare function after<T extends
|
|
25
|
+
declare function after<T extends FunctionAny>(n: number, func: T): T;
|
|
25
26
|
export default after;
|
package/types/before.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FunctionAny } from './internals/types';
|
|
1
2
|
/**
|
|
2
3
|
* 创建一个调用 `func` 的函数,调用次数少于 `n` 次。之后再调用这个函数,将返回最后一次调用 `func` 的结果。
|
|
3
4
|
*
|
|
@@ -20,5 +21,5 @@
|
|
|
20
21
|
* increment(); // 2 返回之前的结果
|
|
21
22
|
*
|
|
22
23
|
*/
|
|
23
|
-
declare function before<T extends
|
|
24
|
+
declare function before<T extends FunctionAny>(n: number, func: T): T;
|
|
24
25
|
export default before;
|
package/types/clamp.d.ts
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface Clamp {
|
|
2
|
+
(number: number, upper: number): number;
|
|
3
|
+
(number: number, lower: number, upper: number): number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 数字限制在 `lower` 和 `upper` 之间的值。
|
|
7
|
+
*
|
|
8
|
+
* @function
|
|
9
|
+
* @alias module:Number.clamp
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
* @param {number} number 被限制的值。
|
|
12
|
+
* @param {number} [lower] 下限。
|
|
13
|
+
* @param {number} upper 上限。
|
|
14
|
+
* @returns {number} 被限制的值。
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* clamp(-10, -5, 5); // -5
|
|
18
|
+
*
|
|
19
|
+
* clamp(-10, 0, 5); // 0
|
|
20
|
+
*
|
|
21
|
+
* clamp(10, -5, 5); // 5
|
|
22
|
+
*
|
|
23
|
+
* // 仅限制上限
|
|
24
|
+
* clamp(10, 5); // 5
|
|
25
|
+
*
|
|
26
|
+
* clamp(-10, 5); // -10
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
declare const clamp: Clamp;
|
|
3
30
|
export default clamp;
|
package/types/conformsTo.d.ts
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import { WithNullable } from './internals/types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
interface ConformsTo {
|
|
3
|
+
<T extends object, K extends keyof T>(object: T, source: Record<K, (value: T[K]) => any>): boolean;
|
|
4
|
+
<T extends WithNullable<object>>(object: T, source: Record<string | symbol, (value: any) => any>): boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 通过调用断言 `source` 的属性与 `object` 的相应属性值,检查 `object` 是否符合 `source` 。
|
|
8
|
+
*
|
|
9
|
+
* @function
|
|
10
|
+
* @alias module:Util.conformsTo
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
* @param {Object} object 要检查的对象。
|
|
13
|
+
* @param {Object} source 要断言属性是否符合的对象。
|
|
14
|
+
* @returns {boolean} 如果 `object` 符合,返回 `true` ,否则返回 `false` 。
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* const object = { a: 1, b: 2 }
|
|
18
|
+
*
|
|
19
|
+
* conformsTo(object, { b: value => value > 1 }); // true
|
|
20
|
+
*
|
|
21
|
+
* conformsTo(object, { b: value => value > 2 }); // false
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
declare const conformsTo: ConformsTo;
|
|
4
25
|
export default conformsTo;
|
package/types/countBy.d.ts
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
import { CollectionList, CollectionObject, IterateeParam } from './internals/types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
interface CountBy {
|
|
3
|
+
<T>(collection: CollectionList<T>, iteratee?: IterateeParam<T>): Record<string, number>;
|
|
4
|
+
<T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: IterateeParam<V>): Record<string, number>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 创建一个组成对象, `key` 是经过 `iteratee` 执行处理 `collection` 中每个元素后返回的结果,每个 `key` 对应的值是 `iteratee` 返回该 `key` 的次数。
|
|
8
|
+
*
|
|
9
|
+
* `iteratee` 调用时会传入 1 个参数 `value` 。
|
|
10
|
+
*
|
|
11
|
+
* @function
|
|
12
|
+
* @alias module:Collection.countBy
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
* @param {ArrayLike<any> | object} collection 一个用来迭代的集合。
|
|
15
|
+
* @param {Function | string} [iteratee=identity] 迭代函数,用来转换键。
|
|
16
|
+
* @returns {Object} 组成集合对象。
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* countBy([6, 4, 6]); // {'6': 2, '4': 1}
|
|
20
|
+
*
|
|
21
|
+
* countBy([6.1, 4.2, 6.3], Math.floor); // {'6': 2, '4': 1}
|
|
22
|
+
*
|
|
23
|
+
* countBy([{n: 6.1}, {n: 4.2}, {n: 6.3}], item=>Math.floor(item.n)); // {'6': 2, '4': 1}
|
|
24
|
+
*
|
|
25
|
+
* // 迭代函数可以直接写入属性。
|
|
26
|
+
* countBy(['one', 'two', 'three'], 'length'); // {'3': 2, '5': 1}
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
declare const countBy: CountBy;
|
|
4
30
|
export default countBy;
|
package/types/debounce.d.ts
CHANGED
|
@@ -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.addEventListener('popstate', debounced.cancel);
|
|
34
35
|
*
|
|
35
36
|
*/
|
|
36
|
-
declare function debounce<T extends
|
|
37
|
+
declare function debounce<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/defaultTo.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
interface DefaultTo {
|
|
2
|
+
<T>(value: T | null | undefined, defaultValue: T): T;
|
|
3
|
+
<T, D>(value: T | null | undefined, defaultValue: D): T | D;
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
6
|
* 检查值以确定是否应在其位置返回默认值。如果值为 `NaN` `null` 或 `undefined` ,返回 `defaultValue` 。
|
|
3
7
|
*
|
|
4
|
-
* @
|
|
8
|
+
* @function
|
|
5
9
|
* @alias module:Util.defaultTo
|
|
6
10
|
* @since 1.0.0
|
|
7
11
|
* @param {*} value 要检查的值。
|
|
@@ -16,6 +20,5 @@
|
|
|
16
20
|
* defaultTo(null, undefined); // undefined
|
|
17
21
|
*
|
|
18
22
|
*/
|
|
19
|
-
declare
|
|
20
|
-
declare function defaultTo<T, D>(value: T | null | undefined, defaultValue: D): T | D;
|
|
23
|
+
declare const defaultTo: DefaultTo;
|
|
21
24
|
export default defaultTo;
|
package/types/delay.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { FunctionAny } from './internals/types';
|
|
2
3
|
/**
|
|
3
4
|
* 延迟 `wait` 毫秒后调用 `func` 。
|
|
4
5
|
*
|
|
@@ -19,5 +20,5 @@
|
|
|
19
20
|
* // 'hello world'
|
|
20
21
|
*
|
|
21
22
|
*/
|
|
22
|
-
declare function delay<T extends
|
|
23
|
+
declare function delay<T extends FunctionAny>(func: T, wait: number, ...args: Parameters<T>): NodeJS.Timeout;
|
|
23
24
|
export default delay;
|
package/types/every.d.ts
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithNullable } from './internals/types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
interface Every {
|
|
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.every
|
|
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
|
+
* every(arr, item => item % 2 === 0); // false
|
|
23
|
+
* every(arr); // true
|
|
24
|
+
*
|
|
25
|
+
* const obj = { one: 1, two: 2, three: 3 };
|
|
26
|
+
* every(obj, item => item > 1); // false
|
|
27
|
+
* every(obj, item => item > 0); // true
|
|
28
|
+
*/
|
|
29
|
+
declare const every: Every;
|
|
6
30
|
export default every;
|
package/types/filter.d.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithNullable } from './internals/types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
interface Filter {
|
|
3
|
+
<T>(collection: WithNullable<T[]>, predicate?: ArrayIterator<T, any>): T[];
|
|
4
|
+
(collection: WithNullable<string>, predicate?: StringIterator<any>): string[];
|
|
5
|
+
<T>(collection: WithNullable<ArrayLike<T>>, predicate?: ArrayLikeIterator<T, any>): T[];
|
|
6
|
+
<T extends object>(collection: WithNullable<T>, predicate?: ObjectIterator<T, any>): Array<T[keyof T]>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 过滤集合元素,为每个元素执行 `predicate` 函数,返回真值的元素将保留在结果数组中(不改变原值)。
|
|
10
|
+
*
|
|
11
|
+
* `predicate` 调用时会传入三个参数 `value` `index|key` `collection` 。
|
|
12
|
+
*
|
|
13
|
+
* @static
|
|
14
|
+
* @alias module:Collection.filter
|
|
15
|
+
* @since 1.7.0
|
|
16
|
+
* @param {ArrayLike<any> | Object} collection 要迭代的集合。
|
|
17
|
+
* @param {function} [predicate=identity] 每次迭代调用的函数。
|
|
18
|
+
* @returns {Array} 返回新的过滤数组。
|
|
19
|
+
* @example
|
|
20
|
+
*
|
|
21
|
+
* const arr = [1, 2, 3, 4, 5, 6];
|
|
22
|
+
* filter(arr, item => item % 2 === 0); // [2, 4, 6]
|
|
23
|
+
*
|
|
24
|
+
* const obj = { one: 1, two: 2, three: 3 };
|
|
25
|
+
* filter(obj, item => item > 1); // [2, 3]
|
|
26
|
+
*/
|
|
27
|
+
declare const filter: Filter;
|
|
6
28
|
export default filter;
|
package/types/find.d.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { ArrayIterator, ArrayLikeIterator, ObjectIterator, StringIterator, WithNullable } from './internals/types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
interface Find {
|
|
3
|
+
<T>(collection: WithNullable<T[]>, predicate?: ArrayIterator<T, any>): T | undefined;
|
|
4
|
+
(collection: WithNullable<string>, predicate?: StringIterator<any>): string | undefined;
|
|
5
|
+
<T>(collection: WithNullable<ArrayLike<T>>, predicate?: ArrayLikeIterator<T, any>): T | undefined;
|
|
6
|
+
<T extends object>(collection: WithNullable<T>, predicate?: ObjectIterator<T, any>): T[keyof T] | undefined;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 迭代集合中的元素执行 `predicate` 函数,返回第一个通过 `predicate` 返回真值的元素(停止迭代),如果都不通过返回 `undefined` 。
|
|
10
|
+
*
|
|
11
|
+
* `predicate` 调用时会传入三个参数 `value` `index|key` `collection` 。
|
|
12
|
+
*
|
|
13
|
+
* @function
|
|
14
|
+
* @alias module:Collection.find
|
|
15
|
+
* @since 1.7.0
|
|
16
|
+
* @param {ArrayLike<any> | Object} collection 要迭代的集合。
|
|
17
|
+
* @param {function} [predicate=identity] 每次迭代调用的函数。
|
|
18
|
+
* @returns {ArrayLike<any> | Object} 返回第一个通过 `predicate` 返回真值的元素,否则返回 `undefined`。
|
|
19
|
+
* @example
|
|
20
|
+
*
|
|
21
|
+
* const arr = [1, 2, 3, 4, 5, 6];
|
|
22
|
+
* find(arr, item => item % 2 === 0); // 2
|
|
23
|
+
*
|
|
24
|
+
* const obj = { one: 1, two: 2, three: 3 };
|
|
25
|
+
* find(obj, item => item > 1); // 2
|
|
26
|
+
*/
|
|
27
|
+
declare const find: Find;
|
|
6
28
|
export default find;
|
package/types/forEach.d.ts
CHANGED
|
@@ -27,10 +27,5 @@
|
|
|
27
27
|
* // 2 'b'
|
|
28
28
|
*
|
|
29
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
|
-
};
|
|
30
|
+
declare const forEach: import("./internals/createForEach").ForEach;
|
|
36
31
|
export default forEach;
|
package/types/forEachRight.d.ts
CHANGED
|
@@ -27,10 +27,5 @@
|
|
|
27
27
|
* // 1 'a'
|
|
28
28
|
*
|
|
29
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
|
-
};
|
|
30
|
+
declare const forEachRight: import("./internals/createForEach").ForEach;
|
|
36
31
|
export default forEachRight;
|
package/types/fromPairs.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface FromPairs {
|
|
2
|
+
<P extends string | number | symbol, V = any>(array: [P, V][]): Record<P, V>;
|
|
3
|
+
<P extends string | number | symbol>(array: any[][]): Record<P, any>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 将键值对数组转为对象。
|
|
7
|
+
*
|
|
8
|
+
* 与 [Object.entries](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) 正好相反。
|
|
9
|
+
*
|
|
10
|
+
* @static
|
|
11
|
+
* @alias module:Array.fromPairs
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
* @param {Array} array 键值对数组。
|
|
14
|
+
* @returns {Object} 新对象。
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* fromPairs([['foo', 'bar'], ['baz', 42]]); // {foo: 'bar', baz: 42}
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
declare const fromPairs: FromPairs;
|
|
3
21
|
export default fromPairs;
|
package/types/groupBy.d.ts
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
import { CollectionList, CollectionObject, IterateeParam } from './internals/types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
interface GroupBy {
|
|
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` 中每个元素后返回的结果。分组值的顺序是由他们出现在 `collection` 的顺序确定的。每个键对应的值负责生成 `key` 的元素组成的数组。
|
|
8
|
+
*
|
|
9
|
+
* `iteratee` 调用时会传入 1 个参数 `value` 。
|
|
10
|
+
*
|
|
11
|
+
* @static
|
|
12
|
+
* @alias module:Collection.groupBy
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
* @param {ArrayLike<any> | Object} collection 一个用来迭代的集合。
|
|
15
|
+
* @param {Function | string} [iteratee=identity] 迭代函数,用来转换键。
|
|
16
|
+
* @returns {Object} 组成聚合对象。
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* groupBy([6, 4, 6]); // {'6': [6, 6], '4': [4]}
|
|
20
|
+
*
|
|
21
|
+
* groupBy([6.1, 4.2, 6.3], Math.floor); // {'6': [6.1, 6.3], '4': [4.2]}
|
|
22
|
+
*
|
|
23
|
+
* 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}]}
|
|
24
|
+
*
|
|
25
|
+
* // 迭代函数可以直接写入属性。
|
|
26
|
+
* groupBy(['one', 'two', 'three'], 'length'); // {'3': ['one', 'two'], '5': ['three']}
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
declare const groupBy: GroupBy;
|
|
4
30
|
export default groupBy;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { FunctionAny } from './types';
|
|
2
|
+
declare function baseDebounce<T extends FunctionAny>(func: T, wait: number, immediate: boolean, __throttle__?: boolean): {
|
|
2
3
|
(this: any, ...args: Parameters<T>): ReturnType<T>;
|
|
3
4
|
cancel: () => void;
|
|
4
5
|
flush: () => ReturnType<T>;
|