@webdeveric/utils 0.8.0 → 0.11.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/asArray.js.map +1 -1
- package/dist/cjs/convert.js +19 -0
- package/dist/cjs/convert.js.map +1 -0
- package/dist/cjs/delayAnimationFrame.js +3 -3
- package/dist/cjs/delayAnimationFrame.js.map +1 -1
- package/dist/cjs/getOwnKeys.js +1 -4
- package/dist/cjs/getOwnKeys.js.map +1 -1
- package/dist/cjs/getOwnProperties.js +11 -0
- package/dist/cjs/getOwnProperties.js.map +1 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/isEmpty.js +17 -0
- package/dist/cjs/isEmpty.js.map +1 -0
- package/dist/cjs/node/fcrdns.js +7 -8
- package/dist/cjs/node/fcrdns.js.map +1 -1
- package/dist/cjs/normalize.js +37 -37
- package/dist/cjs/normalize.js.map +1 -1
- package/dist/cjs/secToString.js +36 -23
- package/dist/cjs/secToString.js.map +1 -1
- package/dist/cjs/toPascalCase.js +2 -2
- package/dist/cjs/toPascalCase.js.map +1 -1
- package/dist/cjs/uniqueItems.js.map +1 -1
- package/dist/cjs/until.js +10 -13
- package/dist/cjs/until.js.map +1 -1
- package/dist/mjs/asArray.js.map +1 -1
- package/dist/mjs/convert.js +15 -0
- package/dist/mjs/convert.js.map +1 -0
- package/dist/mjs/delayAnimationFrame.js +3 -3
- package/dist/mjs/delayAnimationFrame.js.map +1 -1
- package/dist/mjs/getOwnKeys.js +1 -4
- package/dist/mjs/getOwnKeys.js.map +1 -1
- package/dist/mjs/getOwnProperties.js +7 -0
- package/dist/mjs/getOwnProperties.js.map +1 -0
- package/dist/mjs/index.js +3 -0
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/isEmpty.js +13 -0
- package/dist/mjs/isEmpty.js.map +1 -0
- package/dist/mjs/node/fcrdns.js +4 -5
- package/dist/mjs/node/fcrdns.js.map +1 -1
- package/dist/mjs/normalize.js +37 -37
- package/dist/mjs/normalize.js.map +1 -1
- package/dist/mjs/secToString.js +35 -22
- package/dist/mjs/secToString.js.map +1 -1
- package/dist/mjs/toPascalCase.js +2 -2
- package/dist/mjs/toPascalCase.js.map +1 -1
- package/dist/mjs/uniqueItems.js.map +1 -1
- package/dist/mjs/until.js +10 -13
- package/dist/mjs/until.js.map +1 -1
- package/dist/types/asArray.d.ts +1 -1
- package/dist/types/asArray.d.ts.map +1 -1
- package/dist/types/convert.d.ts +8 -0
- package/dist/types/convert.d.ts.map +1 -0
- package/dist/types/getOwnKeys.d.ts +1 -1
- package/dist/types/getOwnKeys.d.ts.map +1 -1
- package/dist/types/getOwnProperties.d.ts +2 -0
- package/dist/types/getOwnProperties.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/isEmpty.d.ts +2 -0
- package/dist/types/isEmpty.d.ts.map +1 -0
- package/dist/types/node/fcrdns.d.ts.map +1 -1
- package/dist/types/normalize.d.ts +23 -9
- package/dist/types/normalize.d.ts.map +1 -1
- package/dist/types/secToString.d.ts +13 -1
- package/dist/types/secToString.d.ts.map +1 -1
- package/dist/types/uniqueItems.d.ts +1 -1
- package/dist/types/uniqueItems.d.ts.map +1 -1
- package/dist/types/until.d.ts +7 -10
- package/dist/types/until.d.ts.map +1 -1
- package/package.json +17 -9
- package/src/asArray.ts +1 -1
- package/src/convert.ts +30 -0
- package/src/delayAnimationFrame.ts +3 -3
- package/src/getOwnKeys.ts +2 -5
- package/src/getOwnProperties.ts +6 -0
- package/src/index.ts +3 -0
- package/src/isEmpty.ts +15 -0
- package/src/node/fcrdns.ts +7 -8
- package/src/normalize.ts +56 -59
- package/src/secToString.ts +39 -24
- package/src/toPascalCase.ts +2 -2
- package/src/uniqueItems.ts +1 -1
- package/src/until.ts +21 -28
package/dist/mjs/normalize.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
import cloneDeep from 'lodash.clonedeep';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
import { getOwnProperties } from './getOwnProperties.js';
|
|
3
|
+
import { getType } from './getType.js';
|
|
4
|
+
/**
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* normalize({ demo: true }, { demo: () => false });
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* normalize({ demo: true }, () => ({ demo: false }) });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* normalize(true, () => false );
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function normalize(input, normalizers) {
|
|
20
|
+
const normalized = cloneDeep(input);
|
|
21
|
+
const context = Object.seal({
|
|
22
|
+
original: input,
|
|
23
|
+
current: normalized,
|
|
15
24
|
data: {},
|
|
16
|
-
};
|
|
25
|
+
});
|
|
17
26
|
const walk = (currentRecord, currentNormalizers) => {
|
|
18
|
-
if (
|
|
19
|
-
const [initialize, normalizers] = currentNormalizers;
|
|
20
|
-
if (typeof initialize !== 'function') {
|
|
21
|
-
throw new TypeError(`initialize is not a function: ${typeof initialize} was provided.`);
|
|
22
|
-
}
|
|
23
|
-
return walk(currentRecord !== null && currentRecord !== void 0 ? currentRecord : initialize(currentRecord, context), normalizers);
|
|
24
|
-
}
|
|
25
|
-
if (typeof currentRecord === 'undefined') {
|
|
27
|
+
if (typeof currentNormalizers === 'undefined') {
|
|
26
28
|
return currentRecord;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
else if (isNormalizersTuple(normalizer)) {
|
|
38
|
-
currentRecord[key] = walk(currentRecord[key], normalizer);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
throw new TypeError(`Unknown normalizer: ${typeof normalizer}`);
|
|
30
|
+
if (typeof currentNormalizers === 'function') {
|
|
31
|
+
return currentNormalizers(currentRecord, context);
|
|
32
|
+
}
|
|
33
|
+
if (typeof currentNormalizers === 'object' && currentNormalizers !== null) {
|
|
34
|
+
if (typeof currentRecord === 'object' && currentRecord !== null) {
|
|
35
|
+
return getOwnProperties(currentNormalizers).reduce((data, key) => {
|
|
36
|
+
data[key] = walk(data[key], currentNormalizers[key]);
|
|
37
|
+
return data;
|
|
38
|
+
}, currentRecord);
|
|
42
39
|
}
|
|
43
40
|
}
|
|
41
|
+
else {
|
|
42
|
+
throw new TypeError(`normalizers must be function or object. ${getType(currentNormalizers)} was received.`);
|
|
43
|
+
}
|
|
44
44
|
return currentRecord;
|
|
45
45
|
};
|
|
46
|
-
return walk(
|
|
46
|
+
return walk(normalized, normalizers);
|
|
47
47
|
}
|
|
48
48
|
//# 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,
|
|
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,OAAO,EAAE,MAAM,cAAc,CAAC;AAmBvC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,SAAS,CACvB,KAAW,EACX,WAAsE;IAEtE,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAEpC,MAAM,OAAO,GAA2B,MAAM,CAAC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
|
1
|
+
export var Seconds;
|
|
2
|
+
(function (Seconds) {
|
|
3
|
+
Seconds[Seconds["Second"] = 1] = "Second";
|
|
4
|
+
Seconds[Seconds["Minute"] = 60] = "Minute";
|
|
5
|
+
Seconds[Seconds["Hour"] = 3600] = "Hour";
|
|
6
|
+
Seconds[Seconds["Day"] = 86400] = "Day";
|
|
7
|
+
Seconds[Seconds["Week"] = 604800] = "Week";
|
|
8
|
+
Seconds[Seconds["Month"] = 2629800] = "Month";
|
|
9
|
+
Seconds[Seconds["Year"] = 31557600] = "Year";
|
|
10
|
+
Seconds[Seconds["Decade"] = 315576000] = "Decade";
|
|
11
|
+
Seconds[Seconds["Century"] = 3155760000] = "Century";
|
|
12
|
+
Seconds[Seconds["Millennium"] = 31557600000] = "Millennium";
|
|
13
|
+
})(Seconds || (Seconds = {}));
|
|
14
|
+
export function secToString(time, joinString = ' ') {
|
|
15
|
+
const secTime = [
|
|
16
|
+
['millennium', Seconds.Millennium],
|
|
17
|
+
['century', Seconds.Century],
|
|
18
|
+
['decade', Seconds.Decade],
|
|
19
|
+
['year', Seconds.Year],
|
|
20
|
+
['month', Seconds.Month],
|
|
21
|
+
['week', Seconds.Week],
|
|
22
|
+
['day', Seconds.Day],
|
|
23
|
+
['hour', Seconds.Hour],
|
|
24
|
+
['minute', Seconds.Minute],
|
|
25
|
+
['second', Seconds.Second],
|
|
26
|
+
];
|
|
27
|
+
const parts = secTime.reduce((output, [units, seconds]) => {
|
|
28
|
+
if (seconds <= time) {
|
|
29
|
+
const currentValue = Math.floor(time / seconds);
|
|
30
|
+
const suffix = currentValue === 1 ? units : `${units}s`;
|
|
31
|
+
time %= seconds;
|
|
32
|
+
output.push(`${currentValue} ${suffix}`);
|
|
17
33
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
str = `${str} ${currentValue} ${suffix}`;
|
|
21
|
-
time %= seconds;
|
|
22
|
-
}
|
|
34
|
+
return output;
|
|
35
|
+
}, []);
|
|
23
36
|
// cSpell:ignore centurys
|
|
24
|
-
return
|
|
37
|
+
return parts.join(joinString).replace('centurys', 'centuries');
|
|
25
38
|
}
|
|
26
39
|
//# sourceMappingURL=secToString.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secToString.js","sourceRoot":"","sources":["../../src/secToString.ts"],"names":[],"mappings":"AAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"secToString.js","sourceRoot":"","sources":["../../src/secToString.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,OAWX;AAXD,WAAY,OAAO;IACjB,yCAAU,CAAA;IACV,0CAAoB,CAAA;IACpB,wCAAkB,CAAA;IAClB,uCAAe,CAAA;IACf,0CAAc,CAAA;IACd,6CAA2B,CAAA;IAC3B,4CAAiB,CAAA;IACjB,iDAAkB,CAAA;IAClB,oDAAqB,CAAA;IACrB,2DAAyB,CAAA;AAC3B,CAAC,EAXW,OAAO,KAAP,OAAO,QAWlB;AAID,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,UAAU,GAAG,GAAG;IACxD,MAAM,OAAO,GAAmB;QAC9B,CAAE,YAAY,EAAE,OAAO,CAAC,UAAU,CAAE;QACpC,CAAE,SAAS,EAAE,OAAO,CAAC,OAAO,CAAE;QAC9B,CAAE,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAE;QAC5B,CAAE,MAAM,EAAE,OAAO,CAAC,IAAI,CAAE;QACxB,CAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAE;QAC1B,CAAE,MAAM,EAAE,OAAO,CAAC,IAAI,CAAE;QACxB,CAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAE;QACtB,CAAE,MAAM,EAAE,OAAO,CAAC,IAAI,CAAE;QACxB,CAAE,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAE;QAC5B,CAAE,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAE;KAC7B,CAAC;IAEF,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAC1B,CAAC,MAAM,EAAE,CAAE,KAAK,EAAE,OAAO,CAAE,EAAE,EAAE;QAC7B,IAAI,OAAO,IAAI,IAAI,EAAE;YACnB,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC;YAChD,MAAM,MAAM,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;YAExD,IAAI,IAAI,OAAO,CAAC;YAEhB,MAAM,CAAC,IAAI,CAAC,GAAG,YAAY,IAAI,MAAM,EAAE,CAAC,CAAC;SAC1C;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,EACD,EAAE,CACH,CAAC;IAEF,yBAAyB;IACzB,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACjE,CAAC"}
|
package/dist/mjs/toPascalCase.js
CHANGED
|
@@ -6,8 +6,8 @@ export function toPascalCase(text, customWords) {
|
|
|
6
6
|
}
|
|
7
7
|
// Remove apostrophes then uppercase the first letter of each word.
|
|
8
8
|
words = words.map(word => {
|
|
9
|
-
const
|
|
10
|
-
return
|
|
9
|
+
const fixedWord = word.replace(/'/g, '');
|
|
10
|
+
return fixedWord[0].toUpperCase() + fixedWord.substring(1);
|
|
11
11
|
});
|
|
12
12
|
if (customWords && getType(customWords) === 'Object') {
|
|
13
13
|
const replacements = Object.entries(customWords).map(([key, value]) => [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toPascalCase.js","sourceRoot":"","sources":["../../src/toPascalCase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,WAAoC;IAE7E,IAAI,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAE,2BAA2B,CAAE,CAAC;IAE9D,IAAK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IAAI,GAAG,KAAK,SAAS,EAAE;wBACrB,OAAO,KAAK,CAAC;qBACd;iBACF;gBAED,OAAO,IAAI,CAAC;YACd,CAAC,CAAC;YAEF,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;SACvC;KACF;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniqueItems.js","sourceRoot":"","sources":["../../src/uniqueItems.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,
|
|
1
|
+
{"version":3,"file":"uniqueItems.js","sourceRoot":"","sources":["../../src/uniqueItems.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAK,IAAS;IAEvC,OAAO,CAAE,GAAG,IAAI,GAAG,CAAK,IAAI,CAAE,CAAE,CAAC;AACnC,CAAC"}
|
package/dist/mjs/until.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
return Number.isInteger(delay) || typeof delay === 'function';
|
|
3
|
-
}
|
|
4
|
-
function getDelay(delay, context) {
|
|
5
|
-
return typeof delay === 'function' ? delay(context) : delay;
|
|
6
|
-
}
|
|
1
|
+
import { getType } from './getType.js';
|
|
7
2
|
const defaultOptions = {
|
|
8
3
|
delay: 10,
|
|
9
4
|
};
|
|
@@ -12,20 +7,22 @@ const defaultOptions = {
|
|
|
12
7
|
*/
|
|
13
8
|
export function until(fn, options = defaultOptions) {
|
|
14
9
|
if (typeof fn !== 'function') {
|
|
15
|
-
|
|
10
|
+
return Promise.reject(new Error('fn must be a function'));
|
|
16
11
|
}
|
|
17
12
|
if (!options || typeof options !== 'object') {
|
|
18
|
-
|
|
13
|
+
return Promise.reject(new Error(`options must be an object. ${getType(options)} provided.`));
|
|
19
14
|
}
|
|
20
15
|
const { delay, timeout, callLimit } = Object.assign({}, defaultOptions, options);
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const isDelay = (input) => Number.isInteger(input) || typeof input === 'function';
|
|
17
|
+
const getDelay = (delay, context) => typeof delay === 'function' ? delay(context) : delay;
|
|
18
|
+
if (!isDelay(delay)) {
|
|
19
|
+
return Promise.reject(new Error('invalid delay value'));
|
|
23
20
|
}
|
|
24
|
-
if (timeout !== undefined && !
|
|
25
|
-
|
|
21
|
+
if (timeout !== undefined && !isDelay(timeout)) {
|
|
22
|
+
return Promise.reject(new Error('invalid timeout value'));
|
|
26
23
|
}
|
|
27
24
|
if (callLimit !== undefined && !Number.isInteger(callLimit)) {
|
|
28
|
-
|
|
25
|
+
return Promise.reject(new Error('invalid callLimit value'));
|
|
29
26
|
}
|
|
30
27
|
return new Promise((resolutionFn, rejectionFn) => {
|
|
31
28
|
let callCount = 0;
|
package/dist/mjs/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":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA4BvC,MAAM,cAAc,GAA2B;IAC7C,KAAK,EAAE,EAAE;CACV,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,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,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;KAC9F;IAED,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,M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AEF,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"}
|
package/dist/types/asArray.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function asArray<T
|
|
1
|
+
export declare function asArray<T>(data: T | T[]): T[];
|
|
2
2
|
//# sourceMappingURL=asArray.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asArray.d.ts","sourceRoot":"","sources":["../../src/asArray.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"asArray.d.ts","sourceRoot":"","sources":["../../src/asArray.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,CAAC,EAAG,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,GAAK,CAAC,EAAE,CAGhD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Builtin } from 'ts-essentials';
|
|
2
|
+
export declare type ConvertFn<SourceType, ReturnType> = (source: Readonly<SourceType>) => ReturnType;
|
|
3
|
+
export declare type ConvertRecord<Input, Output> = {
|
|
4
|
+
[Property in keyof Output]: Output[Property] extends Builtin ? ConvertFn<Input, Output[Property]> : AnyConverter<Input, Output[Property]>;
|
|
5
|
+
};
|
|
6
|
+
export declare type AnyConverter<Input, Output> = ConvertRecord<Input, Output> | ConvertFn<Input, Output>;
|
|
7
|
+
export declare const convert: <Input, Output>(input: Readonly<Input>, converter: AnyConverter<Input, Output>) => Output;
|
|
8
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/convert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,oBAAY,SAAS,CAAC,UAAU,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,KAAK,UAAU,CAAC;AAE7F,oBAAY,aAAa,CAAC,KAAK,EAAE,MAAM,IAAI;KACxC,QAAQ,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,OAAO,GACxD,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,GAClC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;CAC1C,CAAC;AAEF,oBAAY,YAAY,CAAC,KAAK,EAAE,MAAM,IAAI,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAElG,eAAO,MAAM,OAAO,2FAcnB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function getOwnKeys<T>(data: T):
|
|
1
|
+
export declare function getOwnKeys<T extends Parameters<typeof Object.keys>[0], K extends keyof T>(data: T): K[];
|
|
2
2
|
//# sourceMappingURL=getOwnKeys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOwnKeys.d.ts","sourceRoot":"","sources":["../../src/getOwnKeys.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"getOwnKeys.d.ts","sourceRoot":"","sources":["../../src/getOwnKeys.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAEvG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOwnProperties.d.ts","sourceRoot":"","sources":["../../src/getOwnProperties.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAKnE"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export * from './asArray.js';
|
|
2
2
|
export * from './compose.js';
|
|
3
|
+
export * from './convert.js';
|
|
3
4
|
export * from './delay.js';
|
|
4
5
|
export * from './delayAnimationFrame.js';
|
|
5
6
|
export * from './getOwnKeys.js';
|
|
7
|
+
export * from './getOwnProperties.js';
|
|
6
8
|
export * from './getType.js';
|
|
9
|
+
export * from './isEmpty.js';
|
|
7
10
|
export * from './joinStrings.js';
|
|
8
11
|
export * from './normalize.js';
|
|
9
12
|
export * from './secToString.js';
|
|
@@ -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,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,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,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isEmpty.d.ts","sourceRoot":"","sources":["../../src/isEmpty.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAc/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fcrdns.d.ts","sourceRoot":"","sources":["../../../src/node/fcrdns.ts"],"names":[],"mappings":"AAGA,wBAAsB,oBAAoB,CAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAK,OAAO,CAAC,OAAO,CAAC,CAa5F;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAK,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"fcrdns.d.ts","sourceRoot":"","sources":["../../../src/node/fcrdns.ts"],"names":[],"mappings":"AAGA,wBAAsB,oBAAoB,CAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAK,OAAO,CAAC,OAAO,CAAC,CAa5F;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAK,OAAO,CAAC,OAAO,CAAC,CAmB9E"}
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import type { Builtin } from 'ts-essentials';
|
|
2
|
-
export declare type NormalizeContext<
|
|
3
|
-
|
|
4
|
-
current:
|
|
5
|
-
data: Record<
|
|
2
|
+
export declare type NormalizeContext<OwnerRecordType> = {
|
|
3
|
+
original: Readonly<OwnerRecordType>;
|
|
4
|
+
current: OwnerRecordType;
|
|
5
|
+
data: Record<PropertyKey, unknown>;
|
|
6
6
|
};
|
|
7
|
-
export declare type NormalizerFn<
|
|
8
|
-
export declare type
|
|
9
|
-
|
|
10
|
-
[P in keyof T]?: T[P] extends Builtin ? NormalizerFn<T[P], R> : (NormalizerFn<T[P], R> | NormalizersRecord<T[P], T> | NormalizersTuple<T[P], R>);
|
|
7
|
+
export declare type NormalizerFn<OutputType, OwnerRecordType> = (input: unknown, context: NormalizeContext<OwnerRecordType>) => OutputType;
|
|
8
|
+
export declare type NormalizersRecord<RecordType, OwnerRecordType = RecordType> = {
|
|
9
|
+
[Property in keyof RecordType]?: RecordType[Property] extends Builtin ? NormalizerFn<RecordType[Property], OwnerRecordType> : NormalizerFn<RecordType[Property], OwnerRecordType> | NormalizersRecord<RecordType[Property], OwnerRecordType>;
|
|
11
10
|
};
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* normalize({ demo: true }, { demo: () => false });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* normalize({ demo: true }, () => ({ demo: false }) });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* normalize(true, () => false );
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function normalize<Data>(input: Data, normalizers?: NormalizerFn<Data, Data> | NormalizersRecord<Data, Data>): Data;
|
|
13
27
|
//# 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;
|
|
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;IAC9C,QAAQ,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACpC,OAAO,EAAE,eAAe,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC;AAEF,oBAAY,YAAY,CAAC,UAAU,EAAE,eAAe,IAAI,CACtD,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,gBAAgB,CAAC,eAAe,CAAC,KACvC,UAAU,CAAC;AAEhB,oBAAY,iBAAiB,CAAC,UAAU,EAAE,eAAe,GAAG,UAAU,IAAI;KACvE,QAAQ,IAAI,MAAM,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,SAAS,OAAO,GACjE,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC,GACnD,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC,GAAG,iBAAiB,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;CACnH,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAC5B,KAAK,EAAE,IAAI,EACX,WAAW,CAAC,EAAE,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,GACrE,IAAI,CAqCN"}
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare enum Seconds {
|
|
2
|
+
Second = 1,
|
|
3
|
+
Minute = 60,
|
|
4
|
+
Hour = 3600,
|
|
5
|
+
Day = 86400,
|
|
6
|
+
Week = 604800,
|
|
7
|
+
Month = 2629800,
|
|
8
|
+
Year = 31557600,
|
|
9
|
+
Decade = 315576000,
|
|
10
|
+
Century = 3155760000,
|
|
11
|
+
Millennium = 31557600000
|
|
12
|
+
}
|
|
13
|
+
export declare function secToString(time: number, joinString?: string): string;
|
|
2
14
|
//# sourceMappingURL=secToString.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secToString.d.ts","sourceRoot":"","sources":["../../src/secToString.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"secToString.d.ts","sourceRoot":"","sources":["../../src/secToString.ts"],"names":[],"mappings":"AAAA,oBAAY,OAAO;IACjB,MAAM,IAAI;IACV,MAAM,KAAc;IACpB,IAAI,OAAc;IAClB,GAAG,QAAY;IACf,IAAI,SAAU;IACd,KAAK,UAAsB;IAC3B,IAAI,WAAa;IACjB,MAAM,YAAY;IAClB,OAAO,aAAc;IACrB,UAAU,cAAe;CAC1B;AAID,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,SAAM,GAAG,MAAM,CAgClE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function uniqueItems<T
|
|
1
|
+
export declare function uniqueItems<T>(data: T[]): T[];
|
|
2
2
|
//# sourceMappingURL=uniqueItems.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniqueItems.d.ts","sourceRoot":"","sources":["../../src/uniqueItems.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"uniqueItems.d.ts","sourceRoot":"","sources":["../../src/uniqueItems.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,CAAC,EAAG,IAAI,EAAE,CAAC,EAAE,GAAK,CAAC,EAAE,CAGhD"}
|
package/dist/types/until.d.ts
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
export interface UntilContext {
|
|
2
2
|
callCount: number;
|
|
3
3
|
lastCall?: number;
|
|
4
|
-
data: Record<
|
|
4
|
+
data: Record<PropertyKey, any>;
|
|
5
|
+
options: UntilOptions;
|
|
5
6
|
}
|
|
6
|
-
declare type DelayFn = (context: Readonly<UntilContext>) => number;
|
|
7
|
-
declare type Delay = DelayFn | number;
|
|
7
|
+
export declare type DelayFn = (context: Readonly<UntilContext>) => number;
|
|
8
|
+
export declare type Delay = DelayFn | number;
|
|
8
9
|
export declare type UntilOptions = {
|
|
9
10
|
delay: Delay;
|
|
10
11
|
timeout?: Delay;
|
|
11
12
|
callLimit?: number;
|
|
12
13
|
};
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
declare type ResolverValue<T> = T | PromiseLike<T>;
|
|
17
|
-
declare type ResolveFn<T> = (value: ResolverValue<T>) => void;
|
|
18
|
-
declare type RejectFn = (error?: Error) => void;
|
|
14
|
+
export declare type ResolverValue<T> = T | PromiseLike<T>;
|
|
15
|
+
export declare type ResolveFn<T> = (value: ResolverValue<T>) => void;
|
|
16
|
+
export declare type RejectFn = (error?: Error) => void;
|
|
19
17
|
export declare type UntilCallback<T> = (resolve: ResolveFn<T>, reject: RejectFn, context: Readonly<UntilContext>) => void;
|
|
20
18
|
/**
|
|
21
19
|
* Return a Promise that delegates resolving/rejecting to the passed in function.
|
|
22
20
|
*/
|
|
23
21
|
export declare function until<T>(fn: UntilCallback<T>, options?: UntilOptions): Promise<T>;
|
|
24
|
-
export {};
|
|
25
22
|
//# sourceMappingURL=until.d.ts.map
|
|
@@ -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":"AAEA,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAC/B,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.11.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
"utilities",
|
|
11
11
|
"asArray",
|
|
12
12
|
"compose",
|
|
13
|
+
"convert",
|
|
13
14
|
"delay",
|
|
14
15
|
"delayAnimationFrame",
|
|
15
16
|
"fcrdns",
|
|
16
17
|
"getOwnKeys",
|
|
18
|
+
"getOwnProperties",
|
|
17
19
|
"getType",
|
|
20
|
+
"isEmpty",
|
|
18
21
|
"joinStrings",
|
|
19
22
|
"normalize",
|
|
20
23
|
"secToString",
|
|
@@ -33,7 +36,7 @@
|
|
|
33
36
|
"main": "./dist/cjs/index.js",
|
|
34
37
|
"types": "./dist/types/index.d.ts",
|
|
35
38
|
"engines": {
|
|
36
|
-
"node": ">=14.
|
|
39
|
+
"node": ">=14.18.0"
|
|
37
40
|
},
|
|
38
41
|
"exports": {
|
|
39
42
|
".": {
|
|
@@ -65,32 +68,37 @@
|
|
|
65
68
|
"postbuild:cjs": "echo '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json",
|
|
66
69
|
"postbuild:mjs": "echo '{\"type\":\"module\"}' > ./dist/mjs/package.json",
|
|
67
70
|
"build": "npm run build:cjs && npm run build:mjs",
|
|
71
|
+
"postbuild": "npm run validate",
|
|
68
72
|
"typecheck": "tsc --noEmit",
|
|
69
73
|
"lint": "eslint ./*.js ./src/ ./test/ --ext .ts --fix",
|
|
70
74
|
"test": "NODE_ENV=test jest",
|
|
75
|
+
"validate": "./bin/validate.cjs",
|
|
76
|
+
"update-keywords": "./bin/update-keywords.mjs",
|
|
71
77
|
"spellcheck": "cspell './{.github,src,test}/**/*.{ts,json}' './*.{md,js}' './package.json'",
|
|
72
78
|
"prepublishOnly": "npm run typecheck && npm run spellcheck && npm run lint && npm test && npm run build"
|
|
73
79
|
},
|
|
74
80
|
"dependencies": {
|
|
75
81
|
"lodash.clonedeep": "^4.5.0",
|
|
76
|
-
"lodash.escaperegexp": "^4.1.2"
|
|
82
|
+
"lodash.escaperegexp": "^4.1.2",
|
|
83
|
+
"ts-essentials": "^9.0.0"
|
|
77
84
|
},
|
|
78
85
|
"devDependencies": {
|
|
79
|
-
"@types/jest": "^27.0
|
|
86
|
+
"@types/jest": "^27.4.0",
|
|
80
87
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
81
88
|
"@types/lodash.escaperegexp": "^4.1.6",
|
|
82
|
-
"@types/node": "^
|
|
83
|
-
"@webdeveric/eslint-config-ts": "^0.4.
|
|
89
|
+
"@types/node": "^17.0.10",
|
|
90
|
+
"@webdeveric/eslint-config-ts": "^0.4.1",
|
|
84
91
|
"core-js": "^3.11.1",
|
|
85
92
|
"cspell": "^5.3.12",
|
|
86
93
|
"eslint": "^8.0.0",
|
|
87
|
-
"eslint-
|
|
94
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
95
|
+
"eslint-plugin-import": "^2.25.4",
|
|
96
|
+
"eslint-plugin-jest": "^26.0.0",
|
|
88
97
|
"jest": "^27.3.0",
|
|
89
98
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
90
99
|
"rimraf": "^3.0.2",
|
|
91
|
-
"ts-essentials": "^9.0.0",
|
|
92
100
|
"ts-jest": "^27.0.7",
|
|
93
101
|
"ts-node": "^10.0.0",
|
|
94
|
-
"typescript": "^4.
|
|
102
|
+
"typescript": "^4.5.4"
|
|
95
103
|
}
|
|
96
104
|
}
|
package/src/asArray.ts
CHANGED
package/src/convert.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getOwnProperties } from './getOwnProperties.js';
|
|
2
|
+
import { getType } from './getType.js';
|
|
3
|
+
|
|
4
|
+
import type { Builtin } from 'ts-essentials';
|
|
5
|
+
|
|
6
|
+
export type ConvertFn<SourceType, ReturnType> = (source: Readonly<SourceType>) => ReturnType;
|
|
7
|
+
|
|
8
|
+
export type ConvertRecord<Input, Output> = {
|
|
9
|
+
[Property in keyof Output]: Output[Property] extends Builtin
|
|
10
|
+
? ConvertFn<Input, Output[Property]>
|
|
11
|
+
: AnyConverter<Input, Output[Property]>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type AnyConverter<Input, Output> = ConvertRecord<Input, Output> | ConvertFn<Input, Output>;
|
|
15
|
+
|
|
16
|
+
export const convert = <Input, Output>(input: Readonly<Input>, converter: AnyConverter<Input, Output>): Output => {
|
|
17
|
+
if (typeof converter === 'function') {
|
|
18
|
+
return converter(input);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (typeof converter === 'object' && converter !== null) {
|
|
22
|
+
return getOwnProperties(converter).reduce<Partial<Output>>((data, key) => {
|
|
23
|
+
data[ key ] = convert(input, converter[ key ]);
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}, {}) as Output;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
throw new TypeError(`${getType(converter)} is not a valid converter`);
|
|
30
|
+
};
|
|
@@ -14,14 +14,14 @@ export function delayAnimationFrames<T>(frames: number, value?: T): Promise<type
|
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const loop = (
|
|
18
|
-
if (
|
|
17
|
+
const loop = (frame: number): void => {
|
|
18
|
+
if (frame === 0) {
|
|
19
19
|
resolve(value);
|
|
20
20
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
window.requestAnimationFrame(() => loop(
|
|
24
|
+
window.requestAnimationFrame(() => loop(frame - 1));
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
loop(frames);
|
package/src/getOwnKeys.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export function getOwnKeys<T>(data: T):
|
|
2
|
-
return [
|
|
3
|
-
...Object.getOwnPropertyNames(data),
|
|
4
|
-
...Object.getOwnPropertySymbols(data),
|
|
5
|
-
] as (keyof T)[];
|
|
1
|
+
export function getOwnKeys<T extends Parameters<typeof Object.keys>[0], K extends keyof T>(data: T): K[] {
|
|
2
|
+
return Object.keys(data) as K[];
|
|
6
3
|
}
|