@webdeveric/utils 0.7.1 → 0.9.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/delay.js +15 -5
- package/dist/cjs/delay.js.map +1 -1
- package/dist/cjs/delayAnimationFrame.js +7 -5
- package/dist/cjs/delayAnimationFrame.js.map +1 -1
- package/dist/cjs/getOwnKeys.js +11 -0
- package/dist/cjs/getOwnKeys.js.map +1 -0
- package/dist/cjs/getType.js +8 -0
- package/dist/cjs/getType.js.map +1 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/joinStrings.js +1 -1
- package/dist/cjs/joinStrings.js.map +1 -1
- package/dist/cjs/node/fcrdns.js +7 -8
- package/dist/cjs/node/fcrdns.js.map +1 -1
- package/dist/cjs/normalize.js +55 -0
- package/dist/cjs/normalize.js.map +1 -0
- package/dist/cjs/secToString.js +37 -23
- package/dist/cjs/secToString.js.map +1 -1
- package/dist/cjs/toPascalCase.js +4 -3
- package/dist/cjs/toPascalCase.js.map +1 -1
- package/dist/cjs/trimEnd.js +1 -1
- package/dist/cjs/trimEnd.js.map +1 -1
- package/dist/cjs/trimStart.js +1 -1
- package/dist/cjs/trimStart.js.map +1 -1
- package/dist/cjs/uniqueItems.js.map +1 -1
- package/dist/cjs/until.js +1 -1
- package/dist/cjs/until.js.map +1 -1
- package/dist/mjs/asArray.js.map +1 -1
- package/dist/mjs/delay.js +15 -5
- package/dist/mjs/delay.js.map +1 -1
- package/dist/mjs/delayAnimationFrame.js +7 -5
- package/dist/mjs/delayAnimationFrame.js.map +1 -1
- package/dist/mjs/getOwnKeys.js +7 -0
- package/dist/mjs/getOwnKeys.js.map +1 -0
- package/dist/mjs/getType.js +4 -0
- package/dist/mjs/getType.js.map +1 -0
- package/dist/mjs/index.js +3 -0
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/node/fcrdns.js +4 -5
- package/dist/mjs/node/fcrdns.js.map +1 -1
- package/dist/mjs/normalize.js +48 -0
- package/dist/mjs/normalize.js.map +1 -0
- package/dist/mjs/secToString.js +36 -22
- package/dist/mjs/secToString.js.map +1 -1
- package/dist/mjs/toPascalCase.js +4 -3
- package/dist/mjs/toPascalCase.js.map +1 -1
- package/dist/mjs/uniqueItems.js.map +1 -1
- package/dist/mjs/until.js +1 -1
- 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/delay.d.ts +7 -1
- package/dist/types/delay.d.ts.map +1 -1
- package/dist/types/delayAnimationFrame.d.ts.map +1 -1
- package/dist/types/getOwnKeys.d.ts +2 -0
- package/dist/types/getOwnKeys.d.ts.map +1 -0
- package/dist/types/getType.d.ts +2 -0
- package/dist/types/getType.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/node/fcrdns.d.ts.map +1 -1
- package/dist/types/normalize.d.ts +27 -0
- package/dist/types/normalize.d.ts.map +1 -0
- package/dist/types/secToString.d.ts +13 -1
- package/dist/types/secToString.d.ts.map +1 -1
- package/dist/types/toPascalCase.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 +4 -4
- package/dist/types/until.d.ts.map +1 -1
- package/package.json +30 -21
- package/src/asArray.ts +1 -1
- package/src/delay.ts +17 -5
- package/src/delayAnimationFrame.ts +7 -5
- package/src/getOwnKeys.ts +6 -0
- package/src/getType.ts +3 -0
- package/src/index.ts +3 -0
- package/src/node/fcrdns.ts +7 -8
- package/src/normalize.ts +80 -0
- package/src/secToString.ts +40 -24
- package/src/toPascalCase.ts +5 -3
- package/src/uniqueItems.ts +1 -1
- package/src/until.ts +6 -6
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import cloneDeep from 'lodash.clonedeep';
|
|
2
|
+
import { getOwnKeys } from './getOwnKeys';
|
|
3
|
+
import { getType } from './getType';
|
|
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,
|
|
24
|
+
data: {},
|
|
25
|
+
});
|
|
26
|
+
const walk = (currentRecord, currentNormalizers) => {
|
|
27
|
+
if (typeof currentNormalizers === 'undefined') {
|
|
28
|
+
return currentRecord;
|
|
29
|
+
}
|
|
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 getOwnKeys(currentNormalizers).reduce((data, key) => {
|
|
36
|
+
data[key] = walk(data[key], currentNormalizers[key]);
|
|
37
|
+
return data;
|
|
38
|
+
}, currentRecord);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new TypeError(`normalizers must be function or object. ${getType(currentNormalizers)} was received.`);
|
|
43
|
+
}
|
|
44
|
+
return currentRecord;
|
|
45
|
+
};
|
|
46
|
+
return walk(normalized, normalizers);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../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,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/mjs/secToString.js
CHANGED
|
@@ -1,25 +1,39 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
return str.replace('centurys', 'centuries').trim();
|
|
34
|
+
return output;
|
|
35
|
+
}, []);
|
|
36
|
+
// cSpell:ignore centurys
|
|
37
|
+
return parts.join(joinString).replace('centurys', 'centuries');
|
|
24
38
|
}
|
|
25
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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getType } from './getType.js';
|
|
1
2
|
export function toPascalCase(text, customWords) {
|
|
2
3
|
let words = String(text).match(/[A-Z][a-z']+|\d+|[a-z']+/g);
|
|
3
4
|
if (!words) {
|
|
@@ -5,10 +6,10 @@ export function toPascalCase(text, customWords) {
|
|
|
5
6
|
}
|
|
6
7
|
// Remove apostrophes then uppercase the first letter of each word.
|
|
7
8
|
words = words.map(word => {
|
|
8
|
-
const
|
|
9
|
-
return
|
|
9
|
+
const fixedWord = word.replace(/'/g, '');
|
|
10
|
+
return fixedWord[0].toUpperCase() + fixedWord.substring(1);
|
|
10
11
|
});
|
|
11
|
-
if (customWords &&
|
|
12
|
+
if (customWords && getType(customWords) === 'Object') {
|
|
12
13
|
const replacements = Object.entries(customWords).map(([key, value]) => [
|
|
13
14
|
key.toLowerCase(),
|
|
14
15
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toPascalCase.js","sourceRoot":"","sources":["../../src/toPascalCase.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,WAAoC;IAE7E,IAAI,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAE,2BAA2B,CAAE,CAAC;IAE9D,IAAK,CAAE,KAAK,EAAG;QACb,OAAO,EAAE,CAAC;KACX;IAED,mEAAmE;IACnE,KAAK,GAAG,KAAK,CAAC,GAAG,CAAE,IAAI,CAAC,EAAE;QACxB,MAAM,
|
|
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,CAAE,KAAK,EAAG;QACb,OAAO,EAAE,CAAC;KACX;IAED,mEAAmE;IACnE,KAAK,GAAG,KAAK,CAAC,GAAG,CAAE,IAAI,CAAC,EAAE;QACxB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAEzC,OAAO,SAAS,CAAE,CAAC,CAAE,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,IAAK,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,KAAK,QAAQ,EAAG;QACtD,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAE,WAAW,CAAE,CAAC,GAAG,CAAC,CAAC,CAAE,GAAG,EAAE,KAAK,CAAE,EAAE,EAAE,CAAC;YACzE,GAAG,CAAC,WAAW,EAAE;YACjB,KAAK;SACN,CAAC,CAAC;QAEH,IAAK,YAAY,CAAC,MAAM,EAAG;YACzB,+EAA+E;YAC/E,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAW,EAAE;gBACnD,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;gBAErC,KAAK,MAAM,CAAE,GAAG,EAAE,KAAK,CAAE,IAAI,YAAY,EAAE;oBACzC,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
package/dist/mjs/until.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"until.js","sourceRoot":"","sources":["../../src/until.ts"],"names":[],"mappings":"AA6BA,SAAS,cAAc,CAAE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
|
|
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"}
|
package/dist/types/delay.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Delay a specified number of milliseconds before resolving.
|
|
3
|
+
* The `ms` value can be between zero and the max delay value for `setTimeout`.
|
|
4
|
+
*
|
|
5
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value}
|
|
6
|
+
*/
|
|
7
|
+
export declare function delay<T>(milliseconds: number, value?: T): Promise<T>;
|
|
2
8
|
//# sourceMappingURL=delay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../src/delay.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../src/delay.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,GAAI,OAAO,CAAC,CAAC,CAAC,CAWrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delayAnimationFrame.d.ts","sourceRoot":"","sources":["../../src/delayAnimationFrame.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,GAAI,OAAO,CAAC,OAAO,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"delayAnimationFrame.d.ts","sourceRoot":"","sources":["../../src/delayAnimationFrame.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,GAAI,OAAO,CAAC,OAAO,KAAK,CAAC,CAKxE;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,KAAK,CAAC,CAqBxF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOwnKeys.d.ts","sourceRoot":"","sources":["../../src/getOwnKeys.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAK7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getType.d.ts","sourceRoot":"","sources":["../../src/getType.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE9C"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ export * from './asArray.js';
|
|
|
2
2
|
export * from './compose.js';
|
|
3
3
|
export * from './delay.js';
|
|
4
4
|
export * from './delayAnimationFrame.js';
|
|
5
|
+
export * from './getOwnKeys.js';
|
|
6
|
+
export * from './getType.js';
|
|
5
7
|
export * from './joinStrings.js';
|
|
8
|
+
export * from './normalize.js';
|
|
6
9
|
export * from './secToString.js';
|
|
7
10
|
export * from './toPascalCase.js';
|
|
8
11
|
export * from './trimEnd.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,kBAAkB,CAAC;AACjC,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,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 +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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Builtin } from 'ts-essentials';
|
|
2
|
+
export declare type NormalizeContext<OwnerRecordType> = {
|
|
3
|
+
original: Readonly<OwnerRecordType>;
|
|
4
|
+
current: OwnerRecordType;
|
|
5
|
+
data: Record<PropertyKey, unknown>;
|
|
6
|
+
};
|
|
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>;
|
|
10
|
+
};
|
|
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;
|
|
27
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +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;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toPascalCase.d.ts","sourceRoot":"","sources":["../../src/toPascalCase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"toPascalCase.d.ts","sourceRoot":"","sources":["../../src/toPascalCase.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAI,MAAM,CAwCxF"}
|
|
@@ -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
|
@@ -5,21 +5,21 @@ export interface UntilContext {
|
|
|
5
5
|
}
|
|
6
6
|
declare type DelayFn = (context: Readonly<UntilContext>) => number;
|
|
7
7
|
declare type Delay = DelayFn | number;
|
|
8
|
-
declare type
|
|
8
|
+
export declare type UntilOptions = {
|
|
9
9
|
delay: Delay;
|
|
10
10
|
timeout?: Delay;
|
|
11
11
|
callLimit?: number;
|
|
12
12
|
};
|
|
13
13
|
export interface UntilContext {
|
|
14
|
-
options:
|
|
14
|
+
options: UntilOptions;
|
|
15
15
|
}
|
|
16
16
|
declare type ResolverValue<T> = T | PromiseLike<T>;
|
|
17
17
|
declare type ResolveFn<T> = (value: ResolverValue<T>) => void;
|
|
18
18
|
declare type RejectFn = (error?: Error) => void;
|
|
19
|
-
declare type UntilCallback<T> = (resolve: ResolveFn<T>, reject: RejectFn, context: Readonly<UntilContext>) => void;
|
|
19
|
+
export declare type UntilCallback<T> = (resolve: ResolveFn<T>, reject: RejectFn, context: Readonly<UntilContext>) => void;
|
|
20
20
|
/**
|
|
21
21
|
* Return a Promise that delegates resolving/rejecting to the passed in function.
|
|
22
22
|
*/
|
|
23
|
-
export declare function until<T>(fn: UntilCallback<T>, options?:
|
|
23
|
+
export declare function until<T>(fn: UntilCallback<T>, options?: UntilOptions): Promise<T>;
|
|
24
24
|
export {};
|
|
25
25
|
//# sourceMappingURL=until.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../src/until.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B;AAED,aAAK,OAAO,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,KAAK,MAAM,CAAC;AAE3D,aAAK,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAE9B,
|
|
1
|
+
{"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../src/until.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B;AAED,aAAK,OAAO,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,KAAK,MAAM,CAAC;AAE3D,aAAK,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAE9B,oBAAY,YAAY,GAAG;IACzB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,aAAK,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAE3C,aAAK,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEtD,aAAK,QAAQ,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;AAExC,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;AAgBlH;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAG,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,YAA6B,GAAK,OAAO,CAAC,CAAC,CAAC,CA6FpG"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdeveric/utils",
|
|
3
3
|
"description": "Just another collection of utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"utilities",
|
|
11
|
+
"asArray",
|
|
12
|
+
"compose",
|
|
11
13
|
"delay",
|
|
14
|
+
"delayAnimationFrame",
|
|
12
15
|
"fcrdns",
|
|
13
|
-
"
|
|
16
|
+
"getOwnKeys",
|
|
17
|
+
"getType",
|
|
18
|
+
"joinStrings",
|
|
19
|
+
"normalize",
|
|
20
|
+
"secToString",
|
|
21
|
+
"toPascalCase",
|
|
22
|
+
"trimEnd",
|
|
23
|
+
"trimStart",
|
|
24
|
+
"uniqueItems",
|
|
25
|
+
"until"
|
|
14
26
|
],
|
|
15
27
|
"author": {
|
|
16
28
|
"email": "eric@webdeveric.com",
|
|
@@ -21,7 +33,7 @@
|
|
|
21
33
|
"main": "./dist/cjs/index.js",
|
|
22
34
|
"types": "./dist/types/index.d.ts",
|
|
23
35
|
"engines": {
|
|
24
|
-
"node": ">=14.
|
|
36
|
+
"node": ">=14.18.0"
|
|
25
37
|
},
|
|
26
38
|
"exports": {
|
|
27
39
|
".": {
|
|
@@ -48,40 +60,37 @@
|
|
|
48
60
|
"scripts": {
|
|
49
61
|
"clean": "rimraf ./dist/",
|
|
50
62
|
"prebuild": "npm run clean",
|
|
51
|
-
"build:cjs": "tsc -p ./tsconfig.json",
|
|
63
|
+
"build:cjs": "tsc -p ./tsconfig.cjs.json",
|
|
52
64
|
"build:mjs": "tsc -p ./tsconfig.mjs.json",
|
|
53
65
|
"postbuild:cjs": "echo '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json",
|
|
54
66
|
"postbuild:mjs": "echo '{\"type\":\"module\"}' > ./dist/mjs/package.json",
|
|
55
|
-
"build:babel": "babel --extensions '.ts' ./src --out-dir ./dist-babel",
|
|
56
67
|
"build": "npm run build:cjs && npm run build:mjs",
|
|
57
68
|
"typecheck": "tsc --noEmit",
|
|
58
|
-
"lint": "eslint ./*.js ./src/ --ext .ts --fix",
|
|
69
|
+
"lint": "eslint ./*.js ./src/ ./test/ --ext .ts --fix",
|
|
59
70
|
"test": "NODE_ENV=test jest",
|
|
60
|
-
"spellcheck": "cspell
|
|
61
|
-
"prepublishOnly": "npm run spellcheck && npm run lint && npm test && npm run build"
|
|
71
|
+
"spellcheck": "cspell './{.github,src,test}/**/*.{ts,json}' './*.{md,js}' './package.json'",
|
|
72
|
+
"prepublishOnly": "npm run typecheck && npm run spellcheck && npm run lint && npm test && npm run build"
|
|
62
73
|
},
|
|
63
74
|
"dependencies": {
|
|
75
|
+
"lodash.clonedeep": "^4.5.0",
|
|
64
76
|
"lodash.escaperegexp": "^4.1.2"
|
|
65
77
|
},
|
|
66
78
|
"devDependencies": {
|
|
67
|
-
"@
|
|
68
|
-
"@
|
|
69
|
-
"@babel/plugin-proposal-class-properties": "^7.13.0",
|
|
70
|
-
"@babel/plugin-proposal-private-methods": "^7.13.0",
|
|
71
|
-
"@babel/preset-env": "^7.14.0",
|
|
72
|
-
"@babel/preset-typescript": "^7.13.0",
|
|
79
|
+
"@types/jest": "^27.0.2",
|
|
80
|
+
"@types/lodash.clonedeep": "^4.5.6",
|
|
73
81
|
"@types/lodash.escaperegexp": "^4.1.6",
|
|
74
|
-
"@types/node": "^
|
|
75
|
-
"@webdeveric/eslint-config-ts": "^0.
|
|
82
|
+
"@types/node": "^17.0.9",
|
|
83
|
+
"@webdeveric/eslint-config-ts": "^0.4.0",
|
|
76
84
|
"core-js": "^3.11.1",
|
|
77
85
|
"cspell": "^5.3.12",
|
|
78
|
-
"eslint": "^
|
|
79
|
-
"eslint-plugin-jest": "^
|
|
80
|
-
"jest": "^27.0
|
|
86
|
+
"eslint": "^8.0.0",
|
|
87
|
+
"eslint-plugin-jest": "^25.2.1",
|
|
88
|
+
"jest": "^27.3.0",
|
|
81
89
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
82
|
-
"regenerator-runtime": "^0.13.7",
|
|
83
90
|
"rimraf": "^3.0.2",
|
|
91
|
+
"ts-essentials": "^9.0.0",
|
|
92
|
+
"ts-jest": "^27.0.7",
|
|
84
93
|
"ts-node": "^10.0.0",
|
|
85
|
-
"typescript": "^4.
|
|
94
|
+
"typescript": "^4.5.4"
|
|
86
95
|
}
|
|
87
96
|
}
|
package/src/asArray.ts
CHANGED
package/src/delay.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { getType } from './getType.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Delay a specified number of milliseconds before resolving.
|
|
5
|
+
* The `ms` value can be between zero and the max delay value for `setTimeout`.
|
|
6
|
+
*
|
|
7
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value}
|
|
8
|
+
*/
|
|
9
|
+
export function delay<T>(milliseconds: number, value?: T) : Promise<T>
|
|
2
10
|
{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
11
|
+
return new Promise( (resolve, reject) => {
|
|
12
|
+
if ( typeof milliseconds !== 'number' ) {
|
|
13
|
+
reject( new TypeError(`milliseconds must be a number. ${getType(milliseconds)} was provided.`) );
|
|
14
|
+
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
6
17
|
|
|
7
|
-
|
|
18
|
+
setTimeout( resolve, Math.max(0, Math.min(milliseconds, 2_147_483_647)), value );
|
|
19
|
+
} );
|
|
8
20
|
}
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
export function delayAnimationFrame<T>(value?: T) : Promise<typeof value>
|
|
2
2
|
{
|
|
3
|
-
return new Promise(resolve =>
|
|
3
|
+
return new Promise(resolve => {
|
|
4
|
+
window.requestAnimationFrame( () => resolve(value) );
|
|
5
|
+
});
|
|
4
6
|
}
|
|
5
7
|
|
|
6
8
|
export function delayAnimationFrames<T>(frames: number, value?: T): Promise<typeof value>
|
|
7
9
|
{
|
|
8
10
|
return new Promise( (resolve, reject) => {
|
|
9
11
|
if ( ! Number.isInteger(frames) || frames < 1 ) {
|
|
10
|
-
reject( new
|
|
12
|
+
reject( new TypeError('frames must be a positive integer') );
|
|
11
13
|
|
|
12
14
|
return;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
const loop = (
|
|
16
|
-
if (
|
|
17
|
+
const loop = (frame: number): void => {
|
|
18
|
+
if (frame === 0) {
|
|
17
19
|
resolve(value);
|
|
18
20
|
|
|
19
21
|
return;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
window.requestAnimationFrame(() => loop(
|
|
24
|
+
window.requestAnimationFrame(() => loop(frame - 1));
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
loop(frames);
|
package/src/getType.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -2,7 +2,10 @@ export * from './asArray.js';
|
|
|
2
2
|
export * from './compose.js';
|
|
3
3
|
export * from './delay.js';
|
|
4
4
|
export * from './delayAnimationFrame.js';
|
|
5
|
+
export * from './getOwnKeys.js';
|
|
6
|
+
export * from './getType.js';
|
|
5
7
|
export * from './joinStrings.js';
|
|
8
|
+
export * from './normalize.js';
|
|
6
9
|
export * from './secToString.js';
|
|
7
10
|
export * from './toPascalCase.js';
|
|
8
11
|
export * from './trimEnd.js';
|
package/src/node/fcrdns.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { promises as dns } from 'dns';
|
|
2
|
-
import { isIP } from 'net';
|
|
1
|
+
import { promises as dns } from 'node:dns';
|
|
2
|
+
import { isIP } from 'node:net';
|
|
3
3
|
|
|
4
4
|
export async function hostnameResolvesToIp( hostname: string, ip: string ) : Promise<boolean>
|
|
5
5
|
{
|
|
@@ -11,9 +11,9 @@ export async function hostnameResolvesToIp( hostname: string, ip: string ) : Pro
|
|
|
11
11
|
|
|
12
12
|
const resolve = ipVersion === 4 ? dns.resolve4 : dns.resolve6;
|
|
13
13
|
|
|
14
|
-
const resolved
|
|
14
|
+
const resolved = await resolve( hostname );
|
|
15
15
|
|
|
16
|
-
return resolved.some(
|
|
16
|
+
return resolved.some( addr => addr === ip );
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -23,18 +23,17 @@ export async function hostnameResolvesToIp( hostname: string, ip: string ) : Pro
|
|
|
23
23
|
*/
|
|
24
24
|
export async function fcrdns( hostname: string, ip: string ) : Promise<boolean>
|
|
25
25
|
{
|
|
26
|
-
const hostnames
|
|
26
|
+
const hostnames = await dns.reverse(ip);
|
|
27
27
|
|
|
28
28
|
if ( ! hostnames.length ) {
|
|
29
29
|
throw new Error(`Unable to get hostnames for ${ip}`);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
if ( ! hostnames.every(
|
|
32
|
+
if ( ! hostnames.every( name => name.endsWith( hostname ) ) ) {
|
|
33
33
|
throw new Error(`${ip} does not belong to ${hostname}`);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
const results: boolean[] = await Promise.all(
|
|
36
|
+
const results = await Promise.all(
|
|
38
37
|
hostnames.map(
|
|
39
38
|
name => hostnameResolvesToIp( name, ip ),
|
|
40
39
|
),
|