@webdeveric/utils 0.19.0 → 0.20.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/type-predicate-factory.js +19 -0
- package/dist/cjs/type-predicate-factory.js.map +1 -0
- package/dist/cjs/type-predicate.js +8 -24
- package/dist/cjs/type-predicate.js.map +1 -1
- package/dist/mjs/type-predicate-factory.js +11 -0
- package/dist/mjs/type-predicate-factory.js.map +1 -0
- package/dist/mjs/type-predicate.js +7 -15
- package/dist/mjs/type-predicate.js.map +1 -1
- package/dist/types/type-predicate-factory.d.ts +7 -0
- package/dist/types/type-predicate-factory.d.ts.map +1 -0
- package/dist/types/type-predicate.d.ts +7 -9
- package/dist/types/type-predicate.d.ts.map +1 -1
- package/package.json +22 -21
- package/src/asArray.ts +0 -3
- package/src/capitalize.ts +0 -1
- package/src/clamp.ts +0 -7
- package/src/compose.ts +0 -13
- package/src/convert.ts +0 -30
- package/src/delay.ts +0 -23
- package/src/delayAnimationFrame.ts +0 -35
- package/src/getMaxValue.ts +0 -16
- package/src/getMinValue.ts +0 -16
- package/src/getOwnKeys.ts +0 -3
- package/src/getOwnProperties.ts +0 -3
- package/src/getType.ts +0 -3
- package/src/index.ts +0 -24
- package/src/isEmpty.ts +0 -21
- package/src/isObject.ts +0 -3
- package/src/joinStrings.ts +0 -6
- package/src/node/fcrdns.ts +0 -37
- package/src/node/index.ts +0 -1
- package/src/normalize.ts +0 -102
- package/src/secToString.ts +0 -45
- package/src/toPascalCase.ts +0 -29
- package/src/trimEnd.ts +0 -5
- package/src/trimIndentation.ts +0 -18
- package/src/trimStart.ts +0 -5
- package/src/type-assertion.ts +0 -319
- package/src/type-predicate.ts +0 -101
- package/src/types.ts +0 -48
- package/src/uniqueItems.ts +0 -3
- package/src/until.ts +0 -130
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maybeUndefined = exports.maybeNull = exports.maybeArray = exports.everyItem = exports.createIsEnumPredicate = void 0;
|
|
4
|
+
const createIsEnumPredicate = (enumObject) => {
|
|
5
|
+
const values = Object.values(enumObject);
|
|
6
|
+
return (input) => {
|
|
7
|
+
return values.includes(input);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
exports.createIsEnumPredicate = createIsEnumPredicate;
|
|
11
|
+
const everyItem = (predicate) => (input) => Array.isArray(input) && input.every(predicate);
|
|
12
|
+
exports.everyItem = everyItem;
|
|
13
|
+
const maybeArray = (predicate) => (input) => Array.isArray(input) ? input.every(predicate) : predicate(input);
|
|
14
|
+
exports.maybeArray = maybeArray;
|
|
15
|
+
const maybeNull = (predicate) => (input) => input === null || predicate(input);
|
|
16
|
+
exports.maybeNull = maybeNull;
|
|
17
|
+
const maybeUndefined = (predicate) => (input) => typeof input === 'undefined' || predicate(input);
|
|
18
|
+
exports.maybeUndefined = maybeUndefined;
|
|
19
|
+
//# sourceMappingURL=type-predicate-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-predicate-factory.js","sourceRoot":"","sources":["../../src/type-predicate-factory.ts"],"names":[],"mappings":";;;AAEO,MAAM,qBAAqB,GAAG,CAA0B,UAAa,EAA+B,EAAE;IAC3G,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAEzC,OAAO,CAAC,KAAc,EAAuB,EAAE;QAC7C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC,CAAC;AANW,QAAA,qBAAqB,yBAMhC;AAEK,MAAM,SAAS,GACpB,CAAI,SAA6B,EAAwB,EAAE,CAC3D,CAAC,KAAc,EAAgB,EAAE,CAC/B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAHtC,QAAA,SAAS,aAG6B;AAE5C,MAAM,UAAU,GACrB,CAAI,SAA6B,EAA4B,EAAE,CAC/D,CAAC,KAAc,EAAoB,EAAE,CACnC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAHxD,QAAA,UAAU,cAG8C;AAE9D,MAAM,SAAS,GACpB,CAAI,SAA6B,EAA6B,EAAE,CAChE,CAAC,KAAc,EAAqB,EAAE,CACpC,KAAK,KAAK,IAAI,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAH1B,QAAA,SAAS,aAGiB;AAEhC,MAAM,cAAc,GACzB,CAAI,SAA6B,EAAkC,EAAE,CACrE,CAAC,KAAc,EAA0B,EAAE,CACzC,OAAO,KAAK,KAAK,WAAW,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAHxC,QAAA,cAAc,kBAG0B"}
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPromiseRejectedResult = exports.isPromiseFulfilledResult = exports.isStringRecord = exports.isLengthAware = exports.isObject = exports.isPropertyKey = exports.isPositiveFiniteNumber = exports.isPositiveInteger = exports.isInteger = exports.isFiniteNumber = exports.isIntString = exports.isNumericValueArray = exports.isNumericValue = exports.isNumericString = exports.isStringMatching = exports.isStringWithLength = exports.isOptionalNull = exports.isOptionalSymbol = exports.isOptionalBoolean = exports.isOptionalBigInt = exports.isOptionalNumber = exports.isOptionalString = exports.isPrimitive = exports.isNull = exports.isSymbol = exports.isUndefined = exports.isBoolean = exports.isBigInt = exports.isNumber = exports.isString =
|
|
4
|
-
const
|
|
5
|
-
const values = Object.values(enumObject);
|
|
6
|
-
return (input) => {
|
|
7
|
-
return values.includes(input);
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
exports.createIsEnumPredicate = createIsEnumPredicate;
|
|
11
|
-
const maybeUndefined = (predicate, input) => {
|
|
12
|
-
return typeof input === 'undefined' || predicate(input);
|
|
13
|
-
};
|
|
14
|
-
exports.maybeUndefined = maybeUndefined;
|
|
3
|
+
exports.isPromiseRejectedResult = exports.isPromiseFulfilledResult = exports.isStringRecord = exports.isLengthAware = exports.isObject = exports.isPropertyKey = exports.isPositiveFiniteNumber = exports.isPositiveInteger = exports.isInteger = exports.isFiniteNumber = exports.isIntString = exports.isNumericValueArray = exports.isNumericValue = exports.isNumericString = exports.isStringMatching = exports.isStringWithLength = exports.isOptionalNull = exports.isOptionalSymbol = exports.isOptionalBoolean = exports.isOptionalBigInt = exports.isOptionalNumber = exports.isOptionalString = exports.isPrimitive = exports.isNull = exports.isSymbol = exports.isUndefined = exports.isBoolean = exports.isBigInt = exports.isNumber = exports.isString = void 0;
|
|
4
|
+
const type_predicate_factory_js_1 = require("./type-predicate-factory.js");
|
|
15
5
|
// Primitives
|
|
16
6
|
const isString = (input) => typeof input === 'string';
|
|
17
7
|
exports.isString = isString;
|
|
@@ -36,18 +26,12 @@ const isPrimitive = (input) => (0, exports.isString)(input) ||
|
|
|
36
26
|
(0, exports.isNull)(input);
|
|
37
27
|
exports.isPrimitive = isPrimitive;
|
|
38
28
|
// Optional primitives
|
|
39
|
-
|
|
40
|
-
exports.
|
|
41
|
-
|
|
42
|
-
exports.
|
|
43
|
-
|
|
44
|
-
exports.
|
|
45
|
-
const isOptionalBoolean = (input) => (0, exports.maybeUndefined)(exports.isBoolean, input);
|
|
46
|
-
exports.isOptionalBoolean = isOptionalBoolean;
|
|
47
|
-
const isOptionalSymbol = (input) => (0, exports.maybeUndefined)(exports.isSymbol, input);
|
|
48
|
-
exports.isOptionalSymbol = isOptionalSymbol;
|
|
49
|
-
const isOptionalNull = (input) => (0, exports.maybeUndefined)(exports.isNull, input);
|
|
50
|
-
exports.isOptionalNull = isOptionalNull;
|
|
29
|
+
exports.isOptionalString = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isString);
|
|
30
|
+
exports.isOptionalNumber = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isNumber);
|
|
31
|
+
exports.isOptionalBigInt = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isBigInt);
|
|
32
|
+
exports.isOptionalBoolean = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isBoolean);
|
|
33
|
+
exports.isOptionalSymbol = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isSymbol);
|
|
34
|
+
exports.isOptionalNull = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isNull);
|
|
51
35
|
// Primitives with extra checks
|
|
52
36
|
const isStringWithLength = (input) => typeof input === 'string' && input.length > 0;
|
|
53
37
|
exports.isStringWithLength = isStringWithLength;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":";;;AAAA,2EAA6D;AAI7D,aAAa;AAEN,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAA1E,QAAA,QAAQ,YAAkE;AAEhF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAAlG,QAAA,QAAQ,YAA0F;AAExG,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAA1E,QAAA,QAAQ,YAAkE;AAEhF,MAAM,SAAS,GAAG,CAAC,KAAc,EAAoB,EAAE,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC;AAA7E,QAAA,SAAS,aAAoE;AAEnF,MAAM,WAAW,GAAG,CAAC,KAAc,EAA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KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC7E,CAAC,CAAC;AAFW,QAAA,uBAAuB,2BAElC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const createIsEnumPredicate = (enumObject) => {
|
|
2
|
+
const values = Object.values(enumObject);
|
|
3
|
+
return (input) => {
|
|
4
|
+
return values.includes(input);
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export const everyItem = (predicate) => (input) => Array.isArray(input) && input.every(predicate);
|
|
8
|
+
export const maybeArray = (predicate) => (input) => Array.isArray(input) ? input.every(predicate) : predicate(input);
|
|
9
|
+
export const maybeNull = (predicate) => (input) => input === null || predicate(input);
|
|
10
|
+
export const maybeUndefined = (predicate) => (input) => typeof input === 'undefined' || predicate(input);
|
|
11
|
+
//# sourceMappingURL=type-predicate-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-predicate-factory.js","sourceRoot":"","sources":["../../src/type-predicate-factory.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAA0B,UAAa,EAA+B,EAAE;IAC3G,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAEzC,OAAO,CAAC,KAAc,EAAuB,EAAE;QAC7C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GACpB,CAAI,SAA6B,EAAwB,EAAE,CAC3D,CAAC,KAAc,EAAgB,EAAE,CAC/B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAEnD,MAAM,CAAC,MAAM,UAAU,GACrB,CAAI,SAA6B,EAA4B,EAAE,CAC/D,CAAC,KAAc,EAAoB,EAAE,CACnC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,SAAS,GACpB,CAAI,SAA6B,EAA6B,EAAE,CAChE,CAAC,KAAc,EAAqB,EAAE,CACpC,KAAK,KAAK,IAAI,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,cAAc,GACzB,CAAI,SAA6B,EAAkC,EAAE,CACrE,CAAC,KAAc,EAA0B,EAAE,CACzC,OAAO,KAAK,KAAK,WAAW,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const values = Object.values(enumObject);
|
|
3
|
-
return (input) => {
|
|
4
|
-
return values.includes(input);
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
export const maybeUndefined = (predicate, input) => {
|
|
8
|
-
return typeof input === 'undefined' || predicate(input);
|
|
9
|
-
};
|
|
1
|
+
import { maybeUndefined } from './type-predicate-factory.js';
|
|
10
2
|
// Primitives
|
|
11
3
|
export const isString = (input) => typeof input === 'string';
|
|
12
4
|
export const isNumber = (input) => typeof input === 'number' && !Number.isNaN(input);
|
|
@@ -23,12 +15,12 @@ export const isPrimitive = (input) => isString(input) ||
|
|
|
23
15
|
isSymbol(input) ||
|
|
24
16
|
isNull(input);
|
|
25
17
|
// Optional primitives
|
|
26
|
-
export const isOptionalString =
|
|
27
|
-
export const isOptionalNumber =
|
|
28
|
-
export const isOptionalBigInt =
|
|
29
|
-
export const isOptionalBoolean =
|
|
30
|
-
export const isOptionalSymbol =
|
|
31
|
-
export const isOptionalNull =
|
|
18
|
+
export const isOptionalString = maybeUndefined(isString);
|
|
19
|
+
export const isOptionalNumber = maybeUndefined(isNumber);
|
|
20
|
+
export const isOptionalBigInt = maybeUndefined(isBigInt);
|
|
21
|
+
export const isOptionalBoolean = maybeUndefined(isBoolean);
|
|
22
|
+
export const isOptionalSymbol = maybeUndefined(isSymbol);
|
|
23
|
+
export const isOptionalNull = maybeUndefined(isNull);
|
|
32
24
|
// Primitives with extra checks
|
|
33
25
|
export const isStringWithLength = (input) => typeof input === 'string' && input.length > 0;
|
|
34
26
|
export const isStringMatching = (input, pattern) => typeof input === 'string' && pattern.test(input);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAI7D,aAAa;AAEb,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEvF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAE/G,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEvF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAoB,EAAE,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC;AAE1F,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAsB,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC;AAEhG,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEvF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE,CAAC,KAAK,KAAK,IAAI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E,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC;AAEvG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAyB,EAAE;IACtE,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;AACxF,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAI,KAAc,EAAsC,EAAE;IAChG,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAc,EAAkC,EAAE;IACxF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC7E,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TypePredicateFn, UnknownRecord } from './types.js';
|
|
2
|
+
export declare const createIsEnumPredicate: <T extends UnknownRecord>(enumObject: T) => TypePredicateFn<T[keyof T]>;
|
|
3
|
+
export declare const everyItem: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T[]>;
|
|
4
|
+
export declare const maybeArray: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | T[]>;
|
|
5
|
+
export declare const maybeNull: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | null>;
|
|
6
|
+
export declare const maybeUndefined: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | undefined>;
|
|
7
|
+
//# sourceMappingURL=type-predicate-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-predicate-factory.d.ts","sourceRoot":"","sources":["../../src/type-predicate-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEjE,eAAO,MAAM,qBAAqB,yEAMjC,CAAC;AAEF,eAAO,MAAM,SAAS,4DAG4B,CAAC;AAEnD,eAAO,MAAM,UAAU,gEAG6C,CAAC;AAErE,eAAO,MAAM,SAAS,iEAGgB,CAAC;AAEvC,eAAO,MAAM,cAAc,sEAGyB,CAAC"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { NumericValue, Primitive, StringRecord,
|
|
2
|
-
export declare const createIsEnumPredicate: <E extends Record<string, unknown>, T = E>(enumObject: E) => TypePredicateFn<T>;
|
|
3
|
-
export declare const maybeUndefined: <T>(predicate: TypePredicateFn<T>, input: unknown) => input is T | undefined;
|
|
1
|
+
import type { NumericValue, Primitive, StringRecord, UnknownRecord } from './types.js';
|
|
4
2
|
export declare const isString: (input: unknown) => input is string;
|
|
5
3
|
export declare const isNumber: (input: unknown) => input is number;
|
|
6
4
|
export declare const isBigInt: (input: unknown) => input is bigint;
|
|
@@ -9,12 +7,12 @@ export declare const isUndefined: (input: unknown) => input is undefined;
|
|
|
9
7
|
export declare const isSymbol: (input: unknown) => input is symbol;
|
|
10
8
|
export declare const isNull: (input: unknown) => input is null;
|
|
11
9
|
export declare const isPrimitive: (input: unknown) => input is Primitive;
|
|
12
|
-
export declare const isOptionalString: (
|
|
13
|
-
export declare const isOptionalNumber: (
|
|
14
|
-
export declare const isOptionalBigInt: (
|
|
15
|
-
export declare const isOptionalBoolean: (
|
|
16
|
-
export declare const isOptionalSymbol: (
|
|
17
|
-
export declare const isOptionalNull: (
|
|
10
|
+
export declare const isOptionalString: import("./types.js").TypePredicateFn<string | undefined>;
|
|
11
|
+
export declare const isOptionalNumber: import("./types.js").TypePredicateFn<number | undefined>;
|
|
12
|
+
export declare const isOptionalBigInt: import("./types.js").TypePredicateFn<bigint | undefined>;
|
|
13
|
+
export declare const isOptionalBoolean: import("./types.js").TypePredicateFn<boolean | undefined>;
|
|
14
|
+
export declare const isOptionalSymbol: import("./types.js").TypePredicateFn<symbol | undefined>;
|
|
15
|
+
export declare const isOptionalNull: import("./types.js").TypePredicateFn<null | undefined>;
|
|
18
16
|
export declare const isStringWithLength: (input: unknown) => input is string;
|
|
19
17
|
export declare const isStringMatching: (input: unknown, pattern: RegExp) => input is string;
|
|
20
18
|
export declare const isNumericString: (input: unknown) => input is `${number}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-predicate.d.ts","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-predicate.d.ts","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAItG,eAAO,MAAM,QAAQ,UAAW,OAAO,oBAA+C,CAAC;AAEvF,eAAO,MAAM,QAAQ,UAAW,OAAO,oBAAuE,CAAC;AAE/G,eAAO,MAAM,QAAQ,UAAW,OAAO,oBAA+C,CAAC;AAEvF,eAAO,MAAM,SAAS,UAAW,OAAO,qBAAiD,CAAC;AAE1F,eAAO,MAAM,WAAW,UAAW,OAAO,uBAAqD,CAAC;AAEhG,eAAO,MAAM,QAAQ,UAAW,OAAO,oBAA+C,CAAC;AAEvF,eAAO,MAAM,MAAM,UAAW,OAAO,kBAAkC,CAAC;AAExE,eAAO,MAAM,WAAW,UAAW,OAAO,uBAO3B,CAAC;AAIhB,eAAO,MAAM,gBAAgB,0DAA2B,CAAC;AAEzD,eAAO,MAAM,gBAAgB,0DAA2B,CAAC;AAEzD,eAAO,MAAM,gBAAgB,0DAA2B,CAAC;AAEzD,eAAO,MAAM,iBAAiB,2DAA4B,CAAC;AAE3D,eAAO,MAAM,gBAAgB,0DAA2B,CAAC;AAEzD,eAAO,MAAM,cAAc,wDAAyB,CAAC;AAIrD,eAAO,MAAM,kBAAkB,UAAW,OAAO,oBAAmE,CAAC;AAErH,eAAO,MAAM,gBAAgB,UAAW,OAAO,WAAW,MAAM,oBACd,CAAC;AAEnD,eAAO,MAAM,eAAe,UAAW,OAAO,yBACC,CAAC;AAEhD,eAAO,MAAM,cAAc,UAAW,OAAO,0BACqC,CAAC;AAEnF,eAAO,MAAM,mBAAmB,UAAW,OAAO,4BACG,CAAC;AAEtD,eAAO,MAAM,WAAW,UAAW,OAAO,yBAAkE,CAAC;AAE7G,eAAO,MAAM,cAAc,UAAW,OAAO,oBAA4C,CAAC;AAE1F,eAAO,MAAM,SAAS,UAAW,OAAO,oBAA6C,CAAC;AAEtF,eAAO,MAAM,iBAAiB,UAAW,OAAO,oBAAoD,CAAC;AAErG,eAAO,MAAM,sBAAsB,UAAW,OAAO,oBAAyD,CAAC;AAI/G,eAAO,MAAM,aAAa,UAAW,OAAO,yBACyC,CAAC;AAEtF,eAAO,MAAM,QAAQ,mDAAoD,OAAO,eACV,CAAC;AAEvE,eAAO,MAAM,aAAa,UAAW,OAAO;YAAsB,MAAM;CAC8B,CAAC;AAEvG,eAAO,MAAM,cAAc,UAAW,OAAO,0BAE5C,CAAC;AAEF,eAAO,MAAM,wBAAwB,aAAc,OAAO,uCAEzD,CAAC;AAEF,eAAO,MAAM,uBAAuB,UAAW,OAAO,mCAErD,CAAC"}
|
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.20.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"keywords": [
|
|
10
10
|
"utilities",
|
|
11
11
|
"asArray",
|
|
12
|
+
"capitalize",
|
|
12
13
|
"clamp",
|
|
13
14
|
"compose",
|
|
14
15
|
"convert",
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
"secToString",
|
|
28
29
|
"toPascalCase",
|
|
29
30
|
"trimEnd",
|
|
31
|
+
"trimIndentation",
|
|
30
32
|
"trimStart",
|
|
31
33
|
"type-assertion",
|
|
32
34
|
"type-predicate",
|
|
@@ -58,8 +60,7 @@
|
|
|
58
60
|
"./package.json": "./package.json"
|
|
59
61
|
},
|
|
60
62
|
"files": [
|
|
61
|
-
"dist"
|
|
62
|
-
"src"
|
|
63
|
+
"dist"
|
|
63
64
|
],
|
|
64
65
|
"repository": {
|
|
65
66
|
"type": "git",
|
|
@@ -101,29 +102,29 @@
|
|
|
101
102
|
"lodash.escaperegexp": "^4.1.2"
|
|
102
103
|
},
|
|
103
104
|
"devDependencies": {
|
|
104
|
-
"@swc/core": "^1.
|
|
105
|
-
"@swc/jest": "^0.2.
|
|
106
|
-
"@types/jest": "^29.
|
|
107
|
-
"@types/lodash.clonedeep": "^4.5.
|
|
108
|
-
"@types/lodash.escaperegexp": "^4.1.
|
|
109
|
-
"@types/node": "^18.
|
|
105
|
+
"@swc/core": "^1.3.22",
|
|
106
|
+
"@swc/jest": "^0.2.23",
|
|
107
|
+
"@types/jest": "^29.2.4",
|
|
108
|
+
"@types/lodash.clonedeep": "^4.5.7",
|
|
109
|
+
"@types/lodash.escaperegexp": "^4.1.7",
|
|
110
|
+
"@types/node": "^18.11.12",
|
|
110
111
|
"@webdeveric/eslint-config-ts": "^0.5.2",
|
|
111
112
|
"@webdeveric/prettier-config": "^0.2.0",
|
|
112
|
-
"core-js": "^3.
|
|
113
|
-
"cspell": "^6.
|
|
114
|
-
"eslint": "^8.
|
|
113
|
+
"core-js": "^3.26.1",
|
|
114
|
+
"cspell": "^6.17.0",
|
|
115
|
+
"eslint": "^8.29.0",
|
|
115
116
|
"eslint-config-prettier": "^8.5.0",
|
|
116
|
-
"eslint-import-resolver-typescript": "^3.
|
|
117
|
-
"eslint-plugin-import": "^2.
|
|
118
|
-
"eslint-plugin-jest": "^27.
|
|
119
|
-
"eslint-plugin-prettier": "^4.
|
|
120
|
-
"husky": "^8.0.
|
|
121
|
-
"jest": "^29.
|
|
122
|
-
"jest-environment-jsdom": "^29.
|
|
117
|
+
"eslint-import-resolver-typescript": "^3.5.2",
|
|
118
|
+
"eslint-plugin-import": "^2.26.0",
|
|
119
|
+
"eslint-plugin-jest": "^27.1.6",
|
|
120
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
121
|
+
"husky": "^8.0.2",
|
|
122
|
+
"jest": "^29.3.1",
|
|
123
|
+
"jest-environment-jsdom": "^29.3.1",
|
|
123
124
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
124
125
|
"lint-staged": "^13.1.0",
|
|
125
|
-
"prettier": "^2.
|
|
126
|
+
"prettier": "^2.8.1",
|
|
126
127
|
"rimraf": "^3.0.2",
|
|
127
|
-
"typescript": "^4.9.
|
|
128
|
+
"typescript": "^4.9.4"
|
|
128
129
|
}
|
|
129
130
|
}
|
package/src/asArray.ts
DELETED
package/src/capitalize.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const capitalize = (word: string): string => word.substring(0, 1).toUpperCase() + word.substring(1);
|
package/src/clamp.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { getMaxValue } from './getMaxValue.js';
|
|
2
|
-
import { getMinValue } from './getMinValue.js';
|
|
3
|
-
import type { NumericValue } from './types.js';
|
|
4
|
-
|
|
5
|
-
export function clamp(min: NumericValue, value: NumericValue, max: NumericValue): NumericValue {
|
|
6
|
-
return getMaxValue(min, getMinValue(value, max));
|
|
7
|
-
}
|
package/src/compose.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type ComposeFn<T, A extends unknown[], R = T> = ((data: T) => R) | ((data: T, ...args: A) => R);
|
|
2
|
-
|
|
3
|
-
export function compose<T, A extends unknown[]>(...functions: ComposeFn<T, A, T | void>[]): ComposeFn<T, A> {
|
|
4
|
-
return functions.reduce<ComposeFn<T, A>>(
|
|
5
|
-
(prev, next) =>
|
|
6
|
-
(data: T, ...args: A): T => {
|
|
7
|
-
const updatedData = prev(data, ...args);
|
|
8
|
-
|
|
9
|
-
return (next(updatedData, ...args) ?? updatedData) as T;
|
|
10
|
-
},
|
|
11
|
-
(data: T) => data,
|
|
12
|
-
);
|
|
13
|
-
}
|
package/src/convert.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { getOwnProperties } from './getOwnProperties.js';
|
|
2
|
-
import { getType } from './getType.js';
|
|
3
|
-
|
|
4
|
-
import type { Builtin } from './types.js';
|
|
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
|
-
};
|
package/src/delay.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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(milliseconds: number): Promise<undefined>;
|
|
10
|
-
|
|
11
|
-
export function delay<T>(milliseconds: number, value: T): Promise<T>;
|
|
12
|
-
|
|
13
|
-
export function delay<T>(milliseconds: number, value?: T): Promise<typeof value> {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
if (typeof milliseconds !== 'number') {
|
|
16
|
-
reject(new TypeError(`milliseconds must be a number. ${getType(milliseconds)} was provided.`));
|
|
17
|
-
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
setTimeout(resolve, Math.max(0, Math.min(milliseconds, 2_147_483_647)), value);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export function delayAnimationFrame(): Promise<undefined>;
|
|
2
|
-
|
|
3
|
-
export function delayAnimationFrame<T>(value: T): Promise<T>;
|
|
4
|
-
|
|
5
|
-
export function delayAnimationFrame<T>(value?: T): Promise<typeof value> {
|
|
6
|
-
return new Promise(resolve => {
|
|
7
|
-
window.requestAnimationFrame(() => resolve(value));
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function delayAnimationFrames(frames: number): Promise<undefined>;
|
|
12
|
-
|
|
13
|
-
export function delayAnimationFrames<T>(frames: number, value: T): Promise<T>;
|
|
14
|
-
|
|
15
|
-
export function delayAnimationFrames<T>(frames: number, value?: T): Promise<typeof value> {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
if (!Number.isInteger(frames) || frames < 1) {
|
|
18
|
-
reject(new TypeError('frames must be a positive integer'));
|
|
19
|
-
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const loop = (frame: number): void => {
|
|
24
|
-
if (frame === 0) {
|
|
25
|
-
resolve(value);
|
|
26
|
-
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
window.requestAnimationFrame(() => loop(frame - 1));
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
loop(frames);
|
|
34
|
-
});
|
|
35
|
-
}
|
package/src/getMaxValue.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { assertIsNumericValueArray } from './type-assertion.js';
|
|
2
|
-
import type { NumericValue } from './types.js';
|
|
3
|
-
|
|
4
|
-
export function getMaxValue(...values: [NumericValue, ...NumericValue[]]): NumericValue {
|
|
5
|
-
if (values.length === 0) {
|
|
6
|
-
throw new Error('Expected at least one numeric value');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
assertIsNumericValueArray(values);
|
|
10
|
-
|
|
11
|
-
return values.reduce((high, current) => {
|
|
12
|
-
const value = typeof current === 'string' ? Number(current) : current;
|
|
13
|
-
|
|
14
|
-
return value > high ? current : high;
|
|
15
|
-
});
|
|
16
|
-
}
|
package/src/getMinValue.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { assertIsNumericValueArray } from './type-assertion.js';
|
|
2
|
-
import type { NumericValue } from './types.js';
|
|
3
|
-
|
|
4
|
-
export function getMinValue(...values: [NumericValue, ...NumericValue[]]): NumericValue {
|
|
5
|
-
if (values.length === 0) {
|
|
6
|
-
throw new Error('Expected at least one numeric value');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
assertIsNumericValueArray(values);
|
|
10
|
-
|
|
11
|
-
return values.reduce((low, current) => {
|
|
12
|
-
const value = typeof current === 'string' ? Number(current) : current;
|
|
13
|
-
|
|
14
|
-
return value < low ? current : low;
|
|
15
|
-
});
|
|
16
|
-
}
|
package/src/getOwnKeys.ts
DELETED
package/src/getOwnProperties.ts
DELETED
package/src/getType.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export * from './asArray.js';
|
|
2
|
-
export * from './capitalize.js';
|
|
3
|
-
export * from './clamp.js';
|
|
4
|
-
export * from './compose.js';
|
|
5
|
-
export * from './convert.js';
|
|
6
|
-
export * from './delay.js';
|
|
7
|
-
export * from './delayAnimationFrame.js';
|
|
8
|
-
export * from './getMaxValue.js';
|
|
9
|
-
export * from './getMinValue.js';
|
|
10
|
-
export * from './getOwnKeys.js';
|
|
11
|
-
export * from './getOwnProperties.js';
|
|
12
|
-
export * from './getType.js';
|
|
13
|
-
export * from './isEmpty.js';
|
|
14
|
-
export * from './isObject.js';
|
|
15
|
-
export * from './joinStrings.js';
|
|
16
|
-
export * from './normalize.js';
|
|
17
|
-
export * from './secToString.js';
|
|
18
|
-
export * from './toPascalCase.js';
|
|
19
|
-
export * from './trimEnd.js';
|
|
20
|
-
export * from './trimIndentation.js';
|
|
21
|
-
export * from './trimStart.js';
|
|
22
|
-
export * from './types.js';
|
|
23
|
-
export * from './uniqueItems.js';
|
|
24
|
-
export * from './until.js';
|
package/src/isEmpty.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { isLengthAware } from './type-predicate.js';
|
|
2
|
-
|
|
3
|
-
export function isEmpty(input: unknown): boolean {
|
|
4
|
-
if (typeof input === 'undefined' || input === null || (typeof input === 'string' && !input.length)) {
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (Array.isArray(input)) {
|
|
9
|
-
return input.length === 0;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (input instanceof Set || input instanceof Map) {
|
|
13
|
-
return input.size === 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (typeof input === 'object') {
|
|
17
|
-
return isLengthAware(input) ? input.length === 0 : Object.keys(input).length === 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return false;
|
|
21
|
-
}
|
package/src/isObject.ts
DELETED
package/src/joinStrings.ts
DELETED
package/src/node/fcrdns.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { promises as dns } from 'node:dns';
|
|
2
|
-
import { isIP } from 'node:net';
|
|
3
|
-
|
|
4
|
-
export async function hostnameResolvesToIp(hostname: string, ip: string): Promise<boolean> {
|
|
5
|
-
const ipVersion = isIP(ip);
|
|
6
|
-
|
|
7
|
-
if (!ipVersion) {
|
|
8
|
-
throw new Error(`Invalid IP: ${ip}`);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const resolve = ipVersion === 4 ? dns.resolve4 : dns.resolve6;
|
|
12
|
-
|
|
13
|
-
const resolved = await resolve(hostname);
|
|
14
|
-
|
|
15
|
-
return resolved.some(addr => addr === ip);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Forward-confirmed reverse DNS
|
|
20
|
-
*
|
|
21
|
-
* @see https://en.wikipedia.org/wiki/Forward-confirmed_reverse_DNS
|
|
22
|
-
*/
|
|
23
|
-
export async function fcrdns(hostname: string, ip: string): Promise<boolean> {
|
|
24
|
-
const hostnames = await dns.reverse(ip);
|
|
25
|
-
|
|
26
|
-
if (!hostnames.length) {
|
|
27
|
-
throw new Error(`Unable to get hostnames for ${ip}`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!hostnames.every(name => name.endsWith(hostname))) {
|
|
31
|
-
throw new Error(`${ip} does not belong to ${hostname}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const results = await Promise.all(hostnames.map(name => hostnameResolvesToIp(name, ip)));
|
|
35
|
-
|
|
36
|
-
return results.some(val => val);
|
|
37
|
-
}
|
package/src/node/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './fcrdns.js';
|