@webdeveric/utils 0.11.0 → 0.12.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/dist/cjs/clamp.js +10 -0
- package/dist/cjs/clamp.js.map +1 -0
- package/dist/cjs/getMaxValue.js +14 -0
- package/dist/cjs/getMaxValue.js.map +1 -0
- package/dist/cjs/getMinValue.js +14 -0
- package/dist/cjs/getMinValue.js.map +1 -0
- package/dist/cjs/index.js +11 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/isObject.js +8 -0
- package/dist/cjs/isObject.js.map +1 -0
- package/dist/cjs/node/index.js +5 -1
- package/dist/cjs/node/index.js.map +1 -1
- package/dist/cjs/normalize.js +12 -13
- package/dist/cjs/normalize.js.map +1 -1
- package/dist/cjs/type-assertion.js +16 -0
- package/dist/cjs/type-assertion.js.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/until.js.map +1 -1
- package/dist/mjs/clamp.js +6 -0
- package/dist/mjs/clamp.js.map +1 -0
- package/dist/mjs/compose.js +1 -2
- package/dist/mjs/compose.js.map +1 -1
- package/dist/mjs/getMaxValue.js +10 -0
- package/dist/mjs/getMaxValue.js.map +1 -0
- package/dist/mjs/getMinValue.js +10 -0
- package/dist/mjs/getMinValue.js.map +1 -0
- package/dist/mjs/index.js +6 -0
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/isObject.js +4 -0
- package/dist/mjs/isObject.js.map +1 -0
- package/dist/mjs/normalize.js +12 -13
- package/dist/mjs/normalize.js.map +1 -1
- package/dist/mjs/type-assertion.js +11 -0
- package/dist/mjs/type-assertion.js.map +1 -0
- package/dist/mjs/types.js +2 -0
- package/dist/mjs/types.js.map +1 -0
- package/dist/mjs/until.js.map +1 -1
- package/dist/types/clamp.d.ts +3 -0
- package/dist/types/clamp.d.ts.map +1 -0
- package/dist/types/getMaxValue.d.ts +3 -0
- package/dist/types/getMaxValue.d.ts.map +1 -0
- package/dist/types/getMinValue.d.ts +3 -0
- package/dist/types/getMinValue.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/isObject.d.ts +2 -0
- package/dist/types/isObject.d.ts.map +1 -0
- package/dist/types/normalize.d.ts +8 -6
- package/dist/types/normalize.d.ts.map +1 -1
- package/dist/types/type-assertion.d.ts +3 -0
- package/dist/types/type-assertion.d.ts.map +1 -0
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/until.d.ts +2 -1
- package/dist/types/until.d.ts.map +1 -1
- package/package.json +13 -6
- package/src/clamp.ts +7 -0
- package/src/getMaxValue.ts +16 -0
- package/src/getMinValue.ts +16 -0
- package/src/index.ts +6 -0
- package/src/isObject.ts +3 -0
- package/src/normalize.ts +34 -27
- package/src/type-assertion.ts +11 -0
- package/src/types.ts +12 -0
- package/src/until.ts +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clamp = void 0;
|
|
4
|
+
const getMaxValue_js_1 = require("./getMaxValue.js");
|
|
5
|
+
const getMinValue_js_1 = require("./getMinValue.js");
|
|
6
|
+
function clamp(min, value, max) {
|
|
7
|
+
return (0, getMaxValue_js_1.getMaxValue)(min, (0, getMinValue_js_1.getMinValue)(value, max));
|
|
8
|
+
}
|
|
9
|
+
exports.clamp = clamp;
|
|
10
|
+
//# sourceMappingURL=clamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp.js","sourceRoot":"","sources":["../../src/clamp.ts"],"names":[],"mappings":";;;AAAA,qDAA+C;AAC/C,qDAA+C;AAG/C,SAAgB,KAAK,CAAC,GAAiB,EAAE,KAAmB,EAAE,GAAiB;IAC7E,OAAO,IAAA,4BAAW,EAAC,GAAG,EAAE,IAAA,4BAAW,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC;AAFD,sBAEC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMaxValue = void 0;
|
|
4
|
+
function getMaxValue(...values) {
|
|
5
|
+
if (values.length === 0) {
|
|
6
|
+
throw new Error('Expected at least one numeric value');
|
|
7
|
+
}
|
|
8
|
+
return values.reduce((high, current) => {
|
|
9
|
+
const value = typeof current === 'string' ? Number(current) : current;
|
|
10
|
+
return value > high ? current : high;
|
|
11
|
+
}, values[0]);
|
|
12
|
+
}
|
|
13
|
+
exports.getMaxValue = getMaxValue;
|
|
14
|
+
//# sourceMappingURL=getMaxValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMaxValue.js","sourceRoot":"","sources":["../../src/getMaxValue.ts"],"names":[],"mappings":";;;AAEA,SAAgB,WAAW,CAAC,GAAG,MAAsB;IACnD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACxD;IAED,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,IAAkB,EAAE,OAAqB,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAEtE,OAAO,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACvC,CAAC,EACD,MAAM,CAAE,CAAC,CAAE,CACZ,CAAC;AACJ,CAAC;AAbD,kCAaC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMinValue = void 0;
|
|
4
|
+
function getMinValue(...values) {
|
|
5
|
+
if (values.length === 0) {
|
|
6
|
+
throw new Error('Expected at least one numeric value');
|
|
7
|
+
}
|
|
8
|
+
return values.reduce((low, current) => {
|
|
9
|
+
const value = typeof current === 'string' ? Number(current) : current;
|
|
10
|
+
return value < low ? current : low;
|
|
11
|
+
}, values[0]);
|
|
12
|
+
}
|
|
13
|
+
exports.getMinValue = getMinValue;
|
|
14
|
+
//# sourceMappingURL=getMinValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMinValue.js","sourceRoot":"","sources":["../../src/getMinValue.ts"],"names":[],"mappings":";;;AAEA,SAAgB,WAAW,CAAC,GAAG,MAAsB;IACnD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACxD;IAED,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,GAAiB,EAAE,OAAqB,EAAE,EAAE;QAC3C,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAEtE,OAAO,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IACrC,CAAC,EACD,MAAM,CAAE,CAAC,CAAE,CACZ,CAAC;AACJ,CAAC;AAbD,kCAaC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -11,20 +15,26 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./asArray.js"), exports);
|
|
18
|
+
__exportStar(require("./clamp.js"), exports);
|
|
14
19
|
__exportStar(require("./compose.js"), exports);
|
|
15
20
|
__exportStar(require("./convert.js"), exports);
|
|
16
21
|
__exportStar(require("./delay.js"), exports);
|
|
17
22
|
__exportStar(require("./delayAnimationFrame.js"), exports);
|
|
23
|
+
__exportStar(require("./getMaxValue.js"), exports);
|
|
24
|
+
__exportStar(require("./getMinValue.js"), exports);
|
|
18
25
|
__exportStar(require("./getOwnKeys.js"), exports);
|
|
19
26
|
__exportStar(require("./getOwnProperties.js"), exports);
|
|
20
27
|
__exportStar(require("./getType.js"), exports);
|
|
21
28
|
__exportStar(require("./isEmpty.js"), exports);
|
|
29
|
+
__exportStar(require("./isObject.js"), exports);
|
|
22
30
|
__exportStar(require("./joinStrings.js"), exports);
|
|
23
31
|
__exportStar(require("./normalize.js"), exports);
|
|
24
32
|
__exportStar(require("./secToString.js"), exports);
|
|
25
33
|
__exportStar(require("./toPascalCase.js"), exports);
|
|
26
34
|
__exportStar(require("./trimEnd.js"), exports);
|
|
27
35
|
__exportStar(require("./trimStart.js"), exports);
|
|
36
|
+
__exportStar(require("./type-assertion.js"), exports);
|
|
37
|
+
__exportStar(require("./types.js"), exports);
|
|
28
38
|
__exportStar(require("./uniqueItems.js"), exports);
|
|
29
39
|
__exportStar(require("./until.js"), exports);
|
|
30
40
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,6CAA2B;AAC3B,2DAAyC;AACzC,mDAAiC;AACjC,mDAAiC;AACjC,kDAAgC;AAChC,wDAAsC;AACtC,+CAA6B;AAC7B,+CAA6B;AAC7B,gDAA8B;AAC9B,mDAAiC;AACjC,iDAA+B;AAC/B,mDAAiC;AACjC,oDAAkC;AAClC,+CAA6B;AAC7B,iDAA+B;AAC/B,sDAAoC;AACpC,6CAA2B;AAC3B,mDAAiC;AACjC,6CAA2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isObject.js","sourceRoot":"","sources":["../../src/isObject.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAFD,4BAEC"}
|
package/dist/cjs/node/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B"}
|
package/dist/cjs/normalize.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.normalize = void 0;
|
|
7
7
|
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
8
8
|
const getOwnProperties_js_1 = require("./getOwnProperties.js");
|
|
9
|
-
const
|
|
9
|
+
const isObject_js_1 = require("./isObject.js");
|
|
10
10
|
/**
|
|
11
11
|
* @example
|
|
12
12
|
*
|
|
@@ -22,34 +22,33 @@ const getType_js_1 = require("./getType.js");
|
|
|
22
22
|
* normalize(true, () => false );
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
function normalize(input, normalizers) {
|
|
26
|
-
const
|
|
25
|
+
function normalize(input, normalizers, initContextData = () => ({})) {
|
|
26
|
+
const current = (0, lodash_clonedeep_1.default)(input);
|
|
27
27
|
const context = Object.seal({
|
|
28
28
|
original: input,
|
|
29
|
-
current
|
|
30
|
-
data:
|
|
29
|
+
current,
|
|
30
|
+
data: initContextData(input, normalizers),
|
|
31
31
|
});
|
|
32
32
|
const walk = (currentRecord, currentNormalizers) => {
|
|
33
|
-
if (typeof currentNormalizers === 'undefined') {
|
|
34
|
-
return currentRecord;
|
|
35
|
-
}
|
|
36
33
|
if (typeof currentNormalizers === 'function') {
|
|
37
34
|
return currentNormalizers(currentRecord, context);
|
|
38
35
|
}
|
|
39
36
|
if (typeof currentNormalizers === 'object' && currentNormalizers !== null) {
|
|
40
37
|
if (typeof currentRecord === 'object' && currentRecord !== null) {
|
|
41
38
|
return (0, getOwnProperties_js_1.getOwnProperties)(currentNormalizers).reduce((data, key) => {
|
|
42
|
-
|
|
39
|
+
const normalizers = currentNormalizers[key];
|
|
40
|
+
// If the value is undefined but there is a normalizer record, set value to empty object.
|
|
41
|
+
const value = typeof data[key] === 'undefined' && (0, isObject_js_1.isObject)(normalizers)
|
|
42
|
+
? {}
|
|
43
|
+
: data[key];
|
|
44
|
+
data[key] = walk(value, normalizers);
|
|
43
45
|
return data;
|
|
44
46
|
}, currentRecord);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
|
-
else {
|
|
48
|
-
throw new TypeError(`normalizers must be function or object. ${(0, getType_js_1.getType)(currentNormalizers)} was received.`);
|
|
49
|
-
}
|
|
50
49
|
return currentRecord;
|
|
51
50
|
};
|
|
52
|
-
return walk(
|
|
51
|
+
return walk(current, normalizers);
|
|
53
52
|
}
|
|
54
53
|
exports.normalize = normalize;
|
|
55
54
|
//# sourceMappingURL=normalize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":";;;;;;AAAA,wEAAyC;AAIzC,+DAAyD;AACzD
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":";;;;;;AAAA,wEAAyC;AAIzC,+DAAyD;AACzD,+CAAyC;AAyBzC;;;;;;;;;;;;;;GAcG;AACH,SAAgB,SAAS,CACvB,KAAqB,EACrB,WAAoD,EACpD,kBAA4F,GAAc,EAAE,CAAC,CAAC,EAAE,CAAC;IAEjH,MAAM,OAAO,GAAG,IAAA,0BAAS,EAAC,KAAK,CAAC,CAAC;IAEjC,MAAM,OAAO,GAAwC,MAAM,CAAC,IAAI,CAAC;QAC/D,QAAQ,EAAE,KAAK;QACf,OAAO;QACP,IAAI,EAAE,eAAe,CAAC,KAAK,EAAE,WAAW,CAAC;KAC1C,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,CACX,aAA4B,EAC5B,kBAAyH,EAC1G,EAAE;QACjB,IAAI,OAAO,kBAAkB,KAAK,UAAU,EAAE;YAC5C,OAAO,kBAAkB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;SACnD;QAED,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,KAAK,IAAI,EAAE;YACzE,IAAI,OAAO,aAAa,KAAK,QAAQ,IAAI,aAAa,KAAK,IAAI,EAAE;gBAC/D,OAAO,IAAA,sCAAgB,EAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;oBAC/D,MAAM,WAAW,GAAG,kBAAkB,CAAE,GAAG,CAAE,CAAC;oBAC9C,yFAAyF;oBACzF,MAAM,KAAK,GAAG,OAAO,IAAI,CAAE,GAAG,CAAE,KAAK,WAAW,IAAI,IAAA,sBAAQ,EAAC,WAAW,CAAC;wBACvE,CAAC,CAAC,EAAwC;wBAC1C,CAAC,CAAC,IAAI,CAAE,GAAG,CAAE,CAAC;oBAEhB,IAAI,CAAE,GAAG,CAAE,GAAG,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;oBAEvC,OAAO,IAAI,CAAC;gBACd,CAAC,EAAE,aAAa,CAAC,CAAC;aACnB;SACF;QAED,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AACpC,CAAC;AAzCD,8BAyCC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertsIsFiniteNumber = exports.assertsIsInteger = void 0;
|
|
4
|
+
function assertsIsInteger(input) {
|
|
5
|
+
if (!Number.isInteger(input)) {
|
|
6
|
+
throw new TypeError('input is not an integer');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.assertsIsInteger = assertsIsInteger;
|
|
10
|
+
function assertsIsFiniteNumber(input) {
|
|
11
|
+
if (!Number.isFinite(input)) {
|
|
12
|
+
throw new TypeError('input is not a finite number');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.assertsIsFiniteNumber = assertsIsFiniteNumber;
|
|
16
|
+
//# sourceMappingURL=type-assertion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-assertion.js","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":";;;AAAA,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,IAAI,CAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;QAC7B,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;KAChD;AACH,CAAC;AAJD,4CAIC;AAED,SAAgB,qBAAqB,CAAC,KAAc;IAClD,IAAI,CAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC5B,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;KACrD;AACH,CAAC;AAJD,sDAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/dist/cjs/until.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"until.js","sourceRoot":"","sources":["../../src/until.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"until.js","sourceRoot":"","sources":["../../src/until.ts"],"names":[],"mappings":";;;AACA,6CAAuC;AA2BvC,MAAM,cAAc,GAA2B;IAC7C,KAAK,EAAE,EAAE;CACV,CAAC;AAEF;;GAEG;AACH,SAAgB,KAAK,CAAK,EAAoB,EAAE,UAAwB,cAAc;IAEpF,IAAK,OAAO,EAAE,KAAK,UAAU,EAAG;QAC9B,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC;KAC3D;IAED,IAAK,CAAE,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAG;QAC9C,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,IAAA,oBAAO,EAAC,OAAO,CAAC,YAAY,C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CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,EAAE,CAAC,CAAE,CAAC;aAClE;QACH,CAAC,CAAC;QAEF,aAAa,CAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAE,CAAC;QAE5C,IAAK,CAAE,IAAI,IAAI,OAAO,KAAK,SAAS,EAAG;YACrC,YAAY,GAAG,UAAU,CACvB,GAAG,EAAE;gBACH,MAAM,CAAE,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAE,CAAC;YAC1C,CAAC,EACD,QAAQ,CAAE,OAAO,EAAE,OAAO,CAAE,CAC7B,CAAC;SACH;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAjGD,sBAiGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp.js","sourceRoot":"","sources":["../../src/clamp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,MAAM,UAAU,KAAK,CAAC,GAAiB,EAAE,KAAmB,EAAE,GAAiB;IAC7E,OAAO,WAAW,CAAC,GAAG,EAAE,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC"}
|
package/dist/mjs/compose.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export function compose(...functions) {
|
|
2
2
|
return functions.reduce((prev, next) => (data, ...args) => {
|
|
3
|
-
var _a;
|
|
4
3
|
const updatedData = prev(data, ...args);
|
|
5
|
-
return (
|
|
4
|
+
return (next(updatedData, ...args) ?? updatedData);
|
|
6
5
|
}, (data) => data);
|
|
7
6
|
}
|
|
8
7
|
//# sourceMappingURL=compose.js.map
|
package/dist/mjs/compose.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/compose.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CAAyB,GAAG,SAAsC;IACvF,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CACb,CAAC,IAAO,EAAE,GAAG,IAAO,EAAK,EAAE
|
|
1
|
+
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/compose.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CAAyB,GAAG,SAAsC;IACvF,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CACb,CAAC,IAAO,EAAE,GAAG,IAAO,EAAK,EAAE;QACzB,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QAExC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,IAAI,WAAW,CAAM,CAAC;IAC1D,CAAC,EACH,CAAC,IAAO,EAAE,EAAE,CAAC,IAAI,CAClB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function getMaxValue(...values) {
|
|
2
|
+
if (values.length === 0) {
|
|
3
|
+
throw new Error('Expected at least one numeric value');
|
|
4
|
+
}
|
|
5
|
+
return values.reduce((high, current) => {
|
|
6
|
+
const value = typeof current === 'string' ? Number(current) : current;
|
|
7
|
+
return value > high ? current : high;
|
|
8
|
+
}, values[0]);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=getMaxValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMaxValue.js","sourceRoot":"","sources":["../../src/getMaxValue.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CAAC,GAAG,MAAsB;IACnD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACxD;IAED,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,IAAkB,EAAE,OAAqB,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAEtE,OAAO,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACvC,CAAC,EACD,MAAM,CAAE,CAAC,CAAE,CACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function getMinValue(...values) {
|
|
2
|
+
if (values.length === 0) {
|
|
3
|
+
throw new Error('Expected at least one numeric value');
|
|
4
|
+
}
|
|
5
|
+
return values.reduce((low, current) => {
|
|
6
|
+
const value = typeof current === 'string' ? Number(current) : current;
|
|
7
|
+
return value < low ? current : low;
|
|
8
|
+
}, values[0]);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=getMinValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMinValue.js","sourceRoot":"","sources":["../../src/getMinValue.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CAAC,GAAG,MAAsB;IACnD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACxD;IAED,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,GAAiB,EAAE,OAAqB,EAAE,EAAE;QAC3C,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAEtE,OAAO,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IACrC,CAAC,EACD,MAAM,CAAE,CAAC,CAAE,CACZ,CAAC;AACJ,CAAC"}
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
export * from './asArray.js';
|
|
2
|
+
export * from './clamp.js';
|
|
2
3
|
export * from './compose.js';
|
|
3
4
|
export * from './convert.js';
|
|
4
5
|
export * from './delay.js';
|
|
5
6
|
export * from './delayAnimationFrame.js';
|
|
7
|
+
export * from './getMaxValue.js';
|
|
8
|
+
export * from './getMinValue.js';
|
|
6
9
|
export * from './getOwnKeys.js';
|
|
7
10
|
export * from './getOwnProperties.js';
|
|
8
11
|
export * from './getType.js';
|
|
9
12
|
export * from './isEmpty.js';
|
|
13
|
+
export * from './isObject.js';
|
|
10
14
|
export * from './joinStrings.js';
|
|
11
15
|
export * from './normalize.js';
|
|
12
16
|
export * from './secToString.js';
|
|
13
17
|
export * from './toPascalCase.js';
|
|
14
18
|
export * from './trimEnd.js';
|
|
15
19
|
export * from './trimStart.js';
|
|
20
|
+
export * from './type-assertion.js';
|
|
21
|
+
export * from './types.js';
|
|
16
22
|
export * from './uniqueItems.js';
|
|
17
23
|
export * from './until.js';
|
|
18
24
|
//# sourceMappingURL=index.js.map
|
package/dist/mjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isObject.js","sourceRoot":"","sources":["../../src/isObject.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC"}
|
package/dist/mjs/normalize.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cloneDeep from 'lodash.clonedeep';
|
|
2
2
|
import { getOwnProperties } from './getOwnProperties.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isObject } from './isObject.js';
|
|
4
4
|
/**
|
|
5
5
|
* @example
|
|
6
6
|
*
|
|
@@ -16,33 +16,32 @@ import { getType } from './getType.js';
|
|
|
16
16
|
* normalize(true, () => false );
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
export function normalize(input, normalizers) {
|
|
20
|
-
const
|
|
19
|
+
export function normalize(input, normalizers, initContextData = () => ({})) {
|
|
20
|
+
const current = cloneDeep(input);
|
|
21
21
|
const context = Object.seal({
|
|
22
22
|
original: input,
|
|
23
|
-
current
|
|
24
|
-
data:
|
|
23
|
+
current,
|
|
24
|
+
data: initContextData(input, normalizers),
|
|
25
25
|
});
|
|
26
26
|
const walk = (currentRecord, currentNormalizers) => {
|
|
27
|
-
if (typeof currentNormalizers === 'undefined') {
|
|
28
|
-
return currentRecord;
|
|
29
|
-
}
|
|
30
27
|
if (typeof currentNormalizers === 'function') {
|
|
31
28
|
return currentNormalizers(currentRecord, context);
|
|
32
29
|
}
|
|
33
30
|
if (typeof currentNormalizers === 'object' && currentNormalizers !== null) {
|
|
34
31
|
if (typeof currentRecord === 'object' && currentRecord !== null) {
|
|
35
32
|
return getOwnProperties(currentNormalizers).reduce((data, key) => {
|
|
36
|
-
|
|
33
|
+
const normalizers = currentNormalizers[key];
|
|
34
|
+
// If the value is undefined but there is a normalizer record, set value to empty object.
|
|
35
|
+
const value = typeof data[key] === 'undefined' && isObject(normalizers)
|
|
36
|
+
? {}
|
|
37
|
+
: data[key];
|
|
38
|
+
data[key] = walk(value, normalizers);
|
|
37
39
|
return data;
|
|
38
40
|
}, currentRecord);
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
|
-
else {
|
|
42
|
-
throw new TypeError(`normalizers must be function or object. ${getType(currentNormalizers)} was received.`);
|
|
43
|
-
}
|
|
44
43
|
return currentRecord;
|
|
45
44
|
};
|
|
46
|
-
return walk(
|
|
45
|
+
return walk(current, normalizers);
|
|
47
46
|
}
|
|
48
47
|
//# sourceMappingURL=normalize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAC;AAIzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,
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AAI,CAAE,GAAG,CAAE,GAAG,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;oBAEvC,OAAO,IAAI,CAAC;gBACd,CAAC,EAAE,aAAa,CAAC,CAAC;aACnB;SACF;QAED,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function assertsIsInteger(input) {
|
|
2
|
+
if (!Number.isInteger(input)) {
|
|
3
|
+
throw new TypeError('input is not an integer');
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export function assertsIsFiniteNumber(input) {
|
|
7
|
+
if (!Number.isFinite(input)) {
|
|
8
|
+
throw new TypeError('input is not a finite number');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=type-assertion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-assertion.js","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,CAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;QAC7B,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;KAChD;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,IAAI,CAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC5B,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;KACrD;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/dist/mjs/until.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"until.js","sourceRoot":"","sources":["../../src/until.ts"],"names":[],"mappings":"
|
|
1
|
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-0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMaxValue.d.ts","sourceRoot":"","sources":["../../src/getMaxValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,wBAAgB,WAAW,CAAC,GAAG,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAanE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMinValue.d.ts","sourceRoot":"","sources":["../../src/getMinValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,wBAAgB,WAAW,CAAC,GAAG,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAanE"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
export * from './asArray.js';
|
|
2
|
+
export * from './clamp.js';
|
|
2
3
|
export * from './compose.js';
|
|
3
4
|
export * from './convert.js';
|
|
4
5
|
export * from './delay.js';
|
|
5
6
|
export * from './delayAnimationFrame.js';
|
|
7
|
+
export * from './getMaxValue.js';
|
|
8
|
+
export * from './getMinValue.js';
|
|
6
9
|
export * from './getOwnKeys.js';
|
|
7
10
|
export * from './getOwnProperties.js';
|
|
8
11
|
export * from './getType.js';
|
|
9
12
|
export * from './isEmpty.js';
|
|
13
|
+
export * from './isObject.js';
|
|
10
14
|
export * from './joinStrings.js';
|
|
11
15
|
export * from './normalize.js';
|
|
12
16
|
export * from './secToString.js';
|
|
13
17
|
export * from './toPascalCase.js';
|
|
14
18
|
export * from './trimEnd.js';
|
|
15
19
|
export * from './trimStart.js';
|
|
20
|
+
export * from './type-assertion.js';
|
|
21
|
+
export * from './types.js';
|
|
16
22
|
export * from './uniqueItems.js';
|
|
17
23
|
export * from './until.js';
|
|
18
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isObject.d.ts","sourceRoot":"","sources":["../../src/isObject.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEhD"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Builtin } from 'ts-essentials';
|
|
2
|
-
|
|
2
|
+
import type { AnyRecord } from './types';
|
|
3
|
+
export declare type NormalizeContext<OwnerRecordType, ContextData extends AnyRecord> = {
|
|
3
4
|
original: Readonly<OwnerRecordType>;
|
|
4
5
|
current: OwnerRecordType;
|
|
5
|
-
data:
|
|
6
|
+
data: ContextData;
|
|
6
7
|
};
|
|
7
|
-
export declare type NormalizerFn<
|
|
8
|
-
export declare type NormalizersRecord<RecordType, OwnerRecordType =
|
|
9
|
-
[Property in keyof RecordType]?: RecordType[Property] extends Builtin ? NormalizerFn<RecordType[Property], OwnerRecordType> :
|
|
8
|
+
export declare type NormalizerFn<PropertyType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = (input: PropertyType, context: NormalizeContext<OwnerRecordType, ContextData>) => PropertyType;
|
|
9
|
+
export declare type NormalizersRecord<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = {
|
|
10
|
+
readonly [Property in keyof RecordType]?: RecordType[Property] extends Builtin ? NormalizerFn<RecordType[Property], OwnerRecordType, ContextData> : AnyNormalizer<RecordType[Property], OwnerRecordType, ContextData>;
|
|
10
11
|
};
|
|
12
|
+
export declare type AnyNormalizer<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = NormalizerFn<RecordType, OwnerRecordType, ContextData> | NormalizersRecord<RecordType, OwnerRecordType, ContextData>;
|
|
11
13
|
/**
|
|
12
14
|
* @example
|
|
13
15
|
*
|
|
@@ -23,5 +25,5 @@ export declare type NormalizersRecord<RecordType, OwnerRecordType = RecordType>
|
|
|
23
25
|
* normalize(true, () => false );
|
|
24
26
|
* ```
|
|
25
27
|
*/
|
|
26
|
-
export declare function normalize<Data>(input: Data
|
|
28
|
+
export declare function normalize<Data, ContextData extends AnyRecord = AnyRecord>(input: Readonly<Data>, normalizers?: AnyNormalizer<Data, Data, ContextData>, initContextData?: (data: typeof input, dataNormalizers: typeof normalizers) => ContextData): Data;
|
|
27
29
|
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAK7C,oBAAY,gBAAgB,CAAC,eAAe,IAAI;
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAK7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,oBAAY,gBAAgB,CAAC,eAAe,EAAE,WAAW,SAAS,SAAS,IAAI;IAC7E,QAAQ,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACpC,OAAO,EAAE,eAAe,CAAC;IACzB,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF,oBAAY,YAAY,CAAC,YAAY,EAAE,eAAe,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,IAAI,CACnG,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,gBAAgB,CAAC,eAAe,EAAE,WAAW,CAAC,KACpD,YAAY,CAAC;AAElB,oBAAY,iBAAiB,CAAC,UAAU,EAAE,eAAe,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,IAAI;IACtG,QAAQ,EAAE,QAAQ,IAAI,MAAM,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,SAAS,OAAO,GAC1E,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,WAAW,CAAC,GAChE,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,WAAW,CAAC;CACtE,CAAC;AAEF,oBAAY,aAAa,CAAC,UAAU,EAAE,eAAe,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,IAC5F,YAAY,CAAC,UAAU,EAAE,eAAe,EAAE,WAAW,CAAC,GACtD,iBAAiB,CAAC,UAAU,EAAE,eAAe,EAAE,WAAW,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,EACvE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EACrB,WAAW,CAAC,EAAE,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,EACpD,eAAe,GAAE,CAAC,IAAI,EAAE,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,WAAW,KAAK,WAAmC,GAChH,IAAI,CAqCN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-assertion.d.ts","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAIxE;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAI7E"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare type AnyRecord = Record<PropertyKey, any>;
|
|
2
|
+
export declare type UnknownRecord = Record<PropertyKey, unknown>;
|
|
3
|
+
export declare type NumericString<T extends string | number = number> = `${T}` extends `${number}` ? `${T}` : never;
|
|
4
|
+
export declare type NumericValue = number | bigint | NumericString;
|
|
5
|
+
export declare type MaybePlural<T extends string> = T | `${T}s`;
|
|
6
|
+
export declare type StringKeys<T> = keyof T & string;
|
|
7
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AACA,oBAAY,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AAEjD,oBAAY,aAAa,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAEzD,oBAAY,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI,GAAG,CAAC,EAAE,SAAS,GAAG,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC;AAE5G,oBAAY,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,CAAC;AAE3D,oBAAY,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC;AAExD,oBAAY,UAAU,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC"}
|
package/dist/types/until.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { AnyRecord } from './types';
|
|
1
2
|
export interface UntilContext {
|
|
2
3
|
callCount: number;
|
|
3
4
|
lastCall?: number;
|
|
4
|
-
data:
|
|
5
|
+
data: AnyRecord;
|
|
5
6
|
options: UntilOptions;
|
|
6
7
|
}
|
|
7
8
|
export declare type DelayFn = (context: Readonly<UntilContext>) => number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../src/until.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../src/until.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,oBAAY,OAAO,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,KAAK,MAAM,CAAC;AAElE,oBAAY,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAErC,oBAAY,YAAY,GAAG;IACzB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,oBAAY,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAElD,oBAAY,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAE7D,oBAAY,QAAQ,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;AAE/C,oBAAY,aAAa,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;AAMlH;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAG,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,YAA6B,GAAK,OAAO,CAAC,CAAC,CAAC,CAiGpG"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdeveric/utils",
|
|
3
3
|
"description": "Just another collection of utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -9,21 +9,27 @@
|
|
|
9
9
|
"keywords": [
|
|
10
10
|
"utilities",
|
|
11
11
|
"asArray",
|
|
12
|
+
"clamp",
|
|
12
13
|
"compose",
|
|
13
14
|
"convert",
|
|
14
15
|
"delay",
|
|
15
16
|
"delayAnimationFrame",
|
|
16
17
|
"fcrdns",
|
|
18
|
+
"getMaxValue",
|
|
19
|
+
"getMinValue",
|
|
17
20
|
"getOwnKeys",
|
|
18
21
|
"getOwnProperties",
|
|
19
22
|
"getType",
|
|
20
23
|
"isEmpty",
|
|
24
|
+
"isObject",
|
|
21
25
|
"joinStrings",
|
|
22
26
|
"normalize",
|
|
23
27
|
"secToString",
|
|
24
28
|
"toPascalCase",
|
|
25
29
|
"trimEnd",
|
|
26
30
|
"trimStart",
|
|
31
|
+
"type-assertion",
|
|
32
|
+
"types",
|
|
27
33
|
"uniqueItems",
|
|
28
34
|
"until"
|
|
29
35
|
],
|
|
@@ -46,7 +52,8 @@
|
|
|
46
52
|
"./*": {
|
|
47
53
|
"require": "./dist/cjs/*",
|
|
48
54
|
"import": "./dist/mjs/*"
|
|
49
|
-
}
|
|
55
|
+
},
|
|
56
|
+
"./package.json": "./package.json"
|
|
50
57
|
},
|
|
51
58
|
"files": [
|
|
52
59
|
"dist",
|
|
@@ -74,7 +81,7 @@
|
|
|
74
81
|
"test": "NODE_ENV=test jest",
|
|
75
82
|
"validate": "./bin/validate.cjs",
|
|
76
83
|
"update-keywords": "./bin/update-keywords.mjs",
|
|
77
|
-
"spellcheck": "cspell './{.github,src,test}/**/*.{ts,json}' './*.{md,js}' './package.json'",
|
|
84
|
+
"spellcheck": "cspell './{.github,src,test}/**/*.{ts,json}' './*.{md,js}' './package.json' --no-progress",
|
|
78
85
|
"prepublishOnly": "npm run typecheck && npm run spellcheck && npm run lint && npm test && npm run build"
|
|
79
86
|
},
|
|
80
87
|
"dependencies": {
|
|
@@ -90,7 +97,7 @@
|
|
|
90
97
|
"@webdeveric/eslint-config-ts": "^0.4.1",
|
|
91
98
|
"core-js": "^3.11.1",
|
|
92
99
|
"cspell": "^5.3.12",
|
|
93
|
-
"eslint": "^8.
|
|
100
|
+
"eslint": "^8.10.0",
|
|
94
101
|
"eslint-import-resolver-typescript": "^2.5.0",
|
|
95
102
|
"eslint-plugin-import": "^2.25.4",
|
|
96
103
|
"eslint-plugin-jest": "^26.0.0",
|
|
@@ -98,7 +105,7 @@
|
|
|
98
105
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
99
106
|
"rimraf": "^3.0.2",
|
|
100
107
|
"ts-jest": "^27.0.7",
|
|
101
|
-
"ts-node": "^10.
|
|
102
|
-
"typescript": "^4.
|
|
108
|
+
"ts-node": "^10.6.0",
|
|
109
|
+
"typescript": "^4.6.2"
|
|
103
110
|
}
|
|
104
111
|
}
|
package/src/clamp.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getMaxValue } from './getMaxValue.js';
|
|
2
|
+
import { getMinValue } from './getMinValue.js';
|
|
3
|
+
import type { NumericValue } from './types';
|
|
4
|
+
|
|
5
|
+
export function clamp(min: NumericValue, value: NumericValue, max: NumericValue): NumericValue {
|
|
6
|
+
return getMaxValue(min, getMinValue(value, max));
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NumericValue } from './types';
|
|
2
|
+
|
|
3
|
+
export function getMaxValue(...values: NumericValue[]): NumericValue {
|
|
4
|
+
if (values.length === 0) {
|
|
5
|
+
throw new Error('Expected at least one numeric value');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return values.reduce(
|
|
9
|
+
(high: NumericValue, current: NumericValue) => {
|
|
10
|
+
const value = typeof current === 'string' ? Number(current) : current;
|
|
11
|
+
|
|
12
|
+
return value > high ? current : high;
|
|
13
|
+
},
|
|
14
|
+
values[ 0 ],
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NumericValue } from './types';
|
|
2
|
+
|
|
3
|
+
export function getMinValue(...values: NumericValue[]): NumericValue {
|
|
4
|
+
if (values.length === 0) {
|
|
5
|
+
throw new Error('Expected at least one numeric value');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return values.reduce(
|
|
9
|
+
(low: NumericValue, current: NumericValue) => {
|
|
10
|
+
const value = typeof current === 'string' ? Number(current) : current;
|
|
11
|
+
|
|
12
|
+
return value < low ? current : low;
|
|
13
|
+
},
|
|
14
|
+
values[ 0 ],
|
|
15
|
+
);
|
|
16
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
export * from './asArray.js';
|
|
2
|
+
export * from './clamp.js';
|
|
2
3
|
export * from './compose.js';
|
|
3
4
|
export * from './convert.js';
|
|
4
5
|
export * from './delay.js';
|
|
5
6
|
export * from './delayAnimationFrame.js';
|
|
7
|
+
export * from './getMaxValue.js';
|
|
8
|
+
export * from './getMinValue.js';
|
|
6
9
|
export * from './getOwnKeys.js';
|
|
7
10
|
export * from './getOwnProperties.js';
|
|
8
11
|
export * from './getType.js';
|
|
9
12
|
export * from './isEmpty.js';
|
|
13
|
+
export * from './isObject.js';
|
|
10
14
|
export * from './joinStrings.js';
|
|
11
15
|
export * from './normalize.js';
|
|
12
16
|
export * from './secToString.js';
|
|
13
17
|
export * from './toPascalCase.js';
|
|
14
18
|
export * from './trimEnd.js';
|
|
15
19
|
export * from './trimStart.js';
|
|
20
|
+
export * from './type-assertion.js';
|
|
21
|
+
export * from './types.js';
|
|
16
22
|
export * from './uniqueItems.js';
|
|
17
23
|
export * from './until.js';
|
package/src/isObject.ts
ADDED
package/src/normalize.ts
CHANGED
|
@@ -3,25 +3,31 @@ import cloneDeep from 'lodash.clonedeep';
|
|
|
3
3
|
import type { Builtin } from 'ts-essentials';
|
|
4
4
|
|
|
5
5
|
import { getOwnProperties } from './getOwnProperties.js';
|
|
6
|
-
import {
|
|
6
|
+
import { isObject } from './isObject.js';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import type { AnyRecord } from './types';
|
|
9
|
+
|
|
10
|
+
export type NormalizeContext<OwnerRecordType, ContextData extends AnyRecord> = {
|
|
9
11
|
original: Readonly<OwnerRecordType>;
|
|
10
12
|
current: OwnerRecordType;
|
|
11
|
-
data:
|
|
13
|
+
data: ContextData;
|
|
12
14
|
};
|
|
13
15
|
|
|
14
|
-
export type NormalizerFn<
|
|
15
|
-
input:
|
|
16
|
-
context: NormalizeContext<OwnerRecordType>,
|
|
17
|
-
) =>
|
|
16
|
+
export type NormalizerFn<PropertyType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = (
|
|
17
|
+
input: PropertyType,
|
|
18
|
+
context: NormalizeContext<OwnerRecordType, ContextData>,
|
|
19
|
+
) => PropertyType;
|
|
18
20
|
|
|
19
|
-
export type NormalizersRecord<RecordType, OwnerRecordType =
|
|
20
|
-
[Property in keyof RecordType]?: RecordType[Property] extends Builtin
|
|
21
|
-
? NormalizerFn<RecordType[Property], OwnerRecordType>
|
|
22
|
-
:
|
|
21
|
+
export type NormalizersRecord<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = {
|
|
22
|
+
readonly [Property in keyof RecordType]?: RecordType[Property] extends Builtin
|
|
23
|
+
? NormalizerFn<RecordType[Property], OwnerRecordType, ContextData>
|
|
24
|
+
: AnyNormalizer<RecordType[Property], OwnerRecordType, ContextData>
|
|
23
25
|
};
|
|
24
26
|
|
|
27
|
+
export type AnyNormalizer<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> =
|
|
28
|
+
| NormalizerFn<RecordType, OwnerRecordType, ContextData>
|
|
29
|
+
| NormalizersRecord<RecordType, OwnerRecordType, ContextData>;
|
|
30
|
+
|
|
25
31
|
/**
|
|
26
32
|
* @example
|
|
27
33
|
*
|
|
@@ -37,26 +43,23 @@ export type NormalizersRecord<RecordType, OwnerRecordType = RecordType> = {
|
|
|
37
43
|
* normalize(true, () => false );
|
|
38
44
|
* ```
|
|
39
45
|
*/
|
|
40
|
-
export function normalize<Data>(
|
|
41
|
-
input: Data
|
|
42
|
-
normalizers?:
|
|
46
|
+
export function normalize<Data, ContextData extends AnyRecord = AnyRecord>(
|
|
47
|
+
input: Readonly<Data>,
|
|
48
|
+
normalizers?: AnyNormalizer<Data, Data, ContextData>,
|
|
49
|
+
initContextData: (data: typeof input, dataNormalizers: typeof normalizers) => ContextData = (): AnyRecord => ({}),
|
|
43
50
|
): Data {
|
|
44
|
-
const
|
|
51
|
+
const current = cloneDeep(input);
|
|
45
52
|
|
|
46
|
-
const context: NormalizeContext<Data> = Object.seal({
|
|
53
|
+
const context: NormalizeContext<Data, ContextData> = Object.seal({
|
|
47
54
|
original: input,
|
|
48
|
-
current
|
|
49
|
-
data:
|
|
55
|
+
current,
|
|
56
|
+
data: initContextData(input, normalizers),
|
|
50
57
|
});
|
|
51
58
|
|
|
52
59
|
const walk = <CurrentRecord>(
|
|
53
60
|
currentRecord: CurrentRecord,
|
|
54
|
-
currentNormalizers?: NormalizerFn<CurrentRecord, Data> | NormalizersRecord<CurrentRecord, Data>,
|
|
61
|
+
currentNormalizers?: NormalizerFn<CurrentRecord, Data, ContextData> | NormalizersRecord<CurrentRecord, Data, ContextData>,
|
|
55
62
|
): CurrentRecord => {
|
|
56
|
-
if (typeof currentNormalizers === 'undefined') {
|
|
57
|
-
return currentRecord;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
63
|
if (typeof currentNormalizers === 'function') {
|
|
61
64
|
return currentNormalizers(currentRecord, context);
|
|
62
65
|
}
|
|
@@ -64,17 +67,21 @@ export function normalize<Data>(
|
|
|
64
67
|
if (typeof currentNormalizers === 'object' && currentNormalizers !== null) {
|
|
65
68
|
if (typeof currentRecord === 'object' && currentRecord !== null) {
|
|
66
69
|
return getOwnProperties(currentNormalizers).reduce((data, key) => {
|
|
67
|
-
|
|
70
|
+
const normalizers = currentNormalizers[ key ];
|
|
71
|
+
// If the value is undefined but there is a normalizer record, set value to empty object.
|
|
72
|
+
const value = typeof data[ key ] === 'undefined' && isObject(normalizers)
|
|
73
|
+
? {} as CurrentRecord[keyof CurrentRecord]
|
|
74
|
+
: data[ key ];
|
|
75
|
+
|
|
76
|
+
data[ key ] = walk(value, normalizers);
|
|
68
77
|
|
|
69
78
|
return data;
|
|
70
79
|
}, currentRecord);
|
|
71
80
|
}
|
|
72
|
-
} else {
|
|
73
|
-
throw new TypeError(`normalizers must be function or object. ${getType(currentNormalizers)} was received.`);
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
return currentRecord;
|
|
77
84
|
};
|
|
78
85
|
|
|
79
|
-
return walk(
|
|
86
|
+
return walk(current, normalizers);
|
|
80
87
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function assertsIsInteger(input: unknown): asserts input is number {
|
|
2
|
+
if (! Number.isInteger(input)) {
|
|
3
|
+
throw new TypeError('input is not an integer');
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function assertsIsFiniteNumber(input: unknown): asserts input is number {
|
|
8
|
+
if (! Number.isFinite(input)) {
|
|
9
|
+
throw new TypeError('input is not a finite number');
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
export type AnyRecord = Record<PropertyKey, any>;
|
|
3
|
+
|
|
4
|
+
export type UnknownRecord = Record<PropertyKey, unknown>;
|
|
5
|
+
|
|
6
|
+
export type NumericString<T extends string | number = number> = `${T}` extends `${number}` ? `${T}` : never;
|
|
7
|
+
|
|
8
|
+
export type NumericValue = number | bigint | NumericString;
|
|
9
|
+
|
|
10
|
+
export type MaybePlural<T extends string> = T | `${T}s`;
|
|
11
|
+
|
|
12
|
+
export type StringKeys<T> = keyof T & string;
|
package/src/until.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { AnyRecord } from './types';
|
|
1
2
|
import { getType } from './getType.js';
|
|
2
3
|
|
|
3
4
|
export interface UntilContext {
|
|
4
5
|
callCount: number;
|
|
5
6
|
lastCall?: number;
|
|
6
|
-
|
|
7
|
-
data: Record<PropertyKey, any>;
|
|
7
|
+
data: AnyRecord;
|
|
8
8
|
options: UntilOptions;
|
|
9
9
|
}
|
|
10
10
|
|