@webdeveric/utils 0.54.1 → 0.56.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/predicate/factory/index.js +3 -2
- package/dist/cjs/predicate/factory/nonNullable.js +5 -0
- package/dist/cjs/predicate/factory/nullable.js +5 -0
- package/dist/cjs/predicate/factory/optional.js +5 -0
- package/dist/cjs/predicate/factory/shape.js +3 -2
- package/dist/cjs/predicate/factory/withLength.js +4 -1
- package/dist/cjs/predicate/factory/withSize.js +4 -1
- package/dist/cjs/predicate/index.js +8 -0
- package/dist/cjs/predicate/isAny.js +5 -0
- package/dist/cjs/predicate/isArray.js +5 -0
- package/dist/cjs/predicate/isBinaryNumberString.js +5 -0
- package/dist/cjs/predicate/isHexNumberString.js +5 -0
- package/dist/cjs/predicate/isNumericValue.js +1 -1
- package/dist/cjs/predicate/isOctalNumberString.js +5 -0
- package/dist/cjs/predicate/isOptionalArray.js +6 -0
- package/dist/cjs/predicate/isOptionalBigInt.js +2 -2
- package/dist/cjs/predicate/isOptionalBoolean.js +2 -2
- package/dist/cjs/predicate/isOptionalISODateString.js +2 -2
- package/dist/cjs/predicate/isOptionalNull.js +2 -2
- package/dist/cjs/predicate/isOptionalNumber.js +2 -2
- package/dist/cjs/predicate/isOptionalObject.js +6 -0
- package/dist/cjs/predicate/isOptionalString.js +2 -2
- package/dist/cjs/predicate/isOptionalSymbol.js +2 -2
- package/dist/cjs/predicate/isUnknown.js +5 -0
- package/dist/mjs/predicate/factory/index.js +3 -2
- package/dist/mjs/predicate/factory/nonNullable.js +1 -0
- package/dist/mjs/predicate/factory/nullable.js +1 -0
- package/dist/mjs/predicate/factory/optional.js +1 -0
- package/dist/mjs/predicate/factory/shape.js +3 -2
- package/dist/mjs/predicate/factory/withLength.js +4 -1
- package/dist/mjs/predicate/factory/withSize.js +4 -1
- package/dist/mjs/predicate/index.js +8 -0
- package/dist/mjs/predicate/isAny.js +1 -0
- package/dist/mjs/predicate/isArray.js +1 -0
- package/dist/mjs/predicate/isBinaryNumberString.js +2 -0
- package/dist/mjs/predicate/isHexNumberString.js +2 -0
- package/dist/mjs/predicate/isNumericValue.js +1 -1
- package/dist/mjs/predicate/isOctalNumberString.js +2 -0
- package/dist/mjs/predicate/isOptionalArray.js +3 -0
- package/dist/mjs/predicate/isOptionalBigInt.js +2 -2
- package/dist/mjs/predicate/isOptionalBoolean.js +2 -2
- package/dist/mjs/predicate/isOptionalISODateString.js +2 -2
- package/dist/mjs/predicate/isOptionalNull.js +2 -2
- package/dist/mjs/predicate/isOptionalNumber.js +2 -2
- package/dist/mjs/predicate/isOptionalObject.js +3 -0
- package/dist/mjs/predicate/isOptionalString.js +2 -2
- package/dist/mjs/predicate/isOptionalSymbol.js +2 -2
- package/dist/mjs/predicate/isUnknown.js +1 -0
- package/dist/types/predicate/factory/fromEnum.d.ts +2 -2
- package/dist/types/predicate/factory/index.d.ts +3 -2
- package/dist/types/predicate/factory/nonNullable.d.ts +2 -0
- package/dist/types/predicate/factory/nullable.d.ts +2 -0
- package/dist/types/predicate/factory/optional.d.ts +2 -0
- package/dist/types/predicate/index.d.ts +8 -0
- package/dist/types/predicate/isAny.d.ts +1 -0
- package/dist/types/predicate/isAnyObject.d.ts +1 -2
- package/dist/types/predicate/isArray.d.ts +1 -0
- package/dist/types/predicate/isAsyncIterable.d.ts +1 -1
- package/dist/types/predicate/isBinaryNumberString.d.ts +1 -0
- package/dist/types/predicate/isDigitsString.d.ts +1 -1
- package/dist/types/predicate/isHexNumberString.d.ts +1 -0
- package/dist/types/predicate/isIntString.d.ts +1 -1
- package/dist/types/predicate/isNumericString.d.ts +1 -1
- package/dist/types/predicate/isObject.d.ts +1 -2
- package/dist/types/predicate/isOctalNumberString.d.ts +1 -0
- package/dist/types/predicate/isOptionalArray.d.ts +1 -0
- package/dist/types/predicate/isOptionalObject.d.ts +1 -0
- package/dist/types/predicate/isUnknown.d.ts +1 -0
- package/dist/types/types/common.d.ts +1 -1
- package/dist/types/types/numbers.d.ts +6 -0
- package/dist/types/types/records.d.ts +1 -0
- package/dist/types/types/strings.d.ts +2 -1
- package/package.json +5 -5
- package/dist/cjs/predicate/factory/maybeNull.js +0 -5
- package/dist/cjs/predicate/factory/maybeUndefined.js +0 -5
- package/dist/mjs/predicate/factory/maybeNull.js +0 -1
- package/dist/mjs/predicate/factory/maybeUndefined.js +0 -1
- package/dist/types/predicate/factory/maybeNull.d.ts +0 -2
- package/dist/types/predicate/factory/maybeUndefined.d.ts +0 -2
|
@@ -23,8 +23,9 @@ __exportStar(require("./is.js"), exports);
|
|
|
23
23
|
__exportStar(require("./literal.js"), exports);
|
|
24
24
|
__exportStar(require("./matching.js"), exports);
|
|
25
25
|
__exportStar(require("./maybeArray.js"), exports);
|
|
26
|
-
__exportStar(require("./
|
|
27
|
-
__exportStar(require("./
|
|
26
|
+
__exportStar(require("./nonNullable.js"), exports);
|
|
27
|
+
__exportStar(require("./nullable.js"), exports);
|
|
28
|
+
__exportStar(require("./optional.js"), exports);
|
|
28
29
|
__exportStar(require("./range.js"), exports);
|
|
29
30
|
__exportStar(require("./shape.js"), exports);
|
|
30
31
|
__exportStar(require("./stringLength.js"), exports);
|
|
@@ -5,7 +5,8 @@ const isAnyObject_js_1 = require("../isAnyObject.js");
|
|
|
5
5
|
const literal_js_1 = require("./literal.js");
|
|
6
6
|
const matching_js_1 = require("./matching.js");
|
|
7
7
|
const shape = (objectShape) => {
|
|
8
|
-
const entries =
|
|
8
|
+
const entries = Reflect.ownKeys(objectShape).map((key) => {
|
|
9
|
+
const value = Reflect.get(objectShape, key);
|
|
9
10
|
const predicate = typeof value === 'function'
|
|
10
11
|
? value
|
|
11
12
|
: value instanceof RegExp
|
|
@@ -15,6 +16,6 @@ const shape = (objectShape) => {
|
|
|
15
16
|
: (0, literal_js_1.literal)(value);
|
|
16
17
|
return [key, predicate];
|
|
17
18
|
});
|
|
18
|
-
return (input) => (0, isAnyObject_js_1.isAnyObject)(input) && entries.every(([key, predicate]) => predicate(input
|
|
19
|
+
return (input) => (0, isAnyObject_js_1.isAnyObject)(input) && entries.every(([key, predicate]) => predicate(Reflect.get(input, key)));
|
|
19
20
|
};
|
|
20
21
|
exports.shape = shape;
|
|
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.withLength = withLength;
|
|
4
4
|
function withLength(fn, lengthRange) {
|
|
5
5
|
if (Array.isArray(lengthRange)) {
|
|
6
|
-
const [min =
|
|
6
|
+
const [min = 0, max = Number.POSITIVE_INFINITY] = lengthRange;
|
|
7
|
+
if (min < 0) {
|
|
8
|
+
throw new RangeError('min must be greater than or equal to 0');
|
|
9
|
+
}
|
|
7
10
|
if (min > max) {
|
|
8
11
|
throw new RangeError('min cannot be greater than max');
|
|
9
12
|
}
|
|
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.withSize = withSize;
|
|
4
4
|
function withSize(fn, sizeRange) {
|
|
5
5
|
if (Array.isArray(sizeRange)) {
|
|
6
|
-
const [min =
|
|
6
|
+
const [min = 0, max = Number.POSITIVE_INFINITY] = sizeRange;
|
|
7
|
+
if (min < 0) {
|
|
8
|
+
throw new RangeError('min must be greater than or equal to 0');
|
|
9
|
+
}
|
|
7
10
|
if (min > max) {
|
|
8
11
|
throw new RangeError('min cannot be greater than max');
|
|
9
12
|
}
|
|
@@ -14,17 +14,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./isAny.js"), exports);
|
|
17
18
|
__exportStar(require("./isAnyObject.js"), exports);
|
|
18
19
|
__exportStar(require("./isAnyObjectWith.js"), exports);
|
|
19
20
|
__exportStar(require("./isAnyObjectWithOwn.js"), exports);
|
|
21
|
+
__exportStar(require("./isArray.js"), exports);
|
|
20
22
|
__exportStar(require("./isAsyncIterable.js"), exports);
|
|
21
23
|
__exportStar(require("./isBigInt.js"), exports);
|
|
22
24
|
__exportStar(require("./isBigIntArray.js"), exports);
|
|
25
|
+
__exportStar(require("./isBinaryNumberString.js"), exports);
|
|
23
26
|
__exportStar(require("./isBoolean.js"), exports);
|
|
24
27
|
__exportStar(require("./isBooleanArray.js"), exports);
|
|
25
28
|
__exportStar(require("./isDigitsString.js"), exports);
|
|
26
29
|
__exportStar(require("./isFiniteNumber.js"), exports);
|
|
27
30
|
__exportStar(require("./isFunction.js"), exports);
|
|
31
|
+
__exportStar(require("./isHexNumberString.js"), exports);
|
|
28
32
|
__exportStar(require("./isInt32.js"), exports);
|
|
29
33
|
__exportStar(require("./isInteger.js"), exports);
|
|
30
34
|
__exportStar(require("./isIntString.js"), exports);
|
|
@@ -41,11 +45,14 @@ __exportStar(require("./isNumericValue.js"), exports);
|
|
|
41
45
|
__exportStar(require("./isNumericValueArray.js"), exports);
|
|
42
46
|
__exportStar(require("./isObject.js"), exports);
|
|
43
47
|
__exportStar(require("./isObjectWith.js"), exports);
|
|
48
|
+
__exportStar(require("./isOctalNumberString.js"), exports);
|
|
49
|
+
__exportStar(require("./isOptionalArray.js"), exports);
|
|
44
50
|
__exportStar(require("./isOptionalBigInt.js"), exports);
|
|
45
51
|
__exportStar(require("./isOptionalBoolean.js"), exports);
|
|
46
52
|
__exportStar(require("./isOptionalISODateString.js"), exports);
|
|
47
53
|
__exportStar(require("./isOptionalNull.js"), exports);
|
|
48
54
|
__exportStar(require("./isOptionalNumber.js"), exports);
|
|
55
|
+
__exportStar(require("./isOptionalObject.js"), exports);
|
|
49
56
|
__exportStar(require("./isOptionalString.js"), exports);
|
|
50
57
|
__exportStar(require("./isOptionalSymbol.js"), exports);
|
|
51
58
|
__exportStar(require("./isPositiveFiniteNumber.js"), exports);
|
|
@@ -64,3 +71,4 @@ __exportStar(require("./isSymbol.js"), exports);
|
|
|
64
71
|
__exportStar(require("./isSymbolArray.js"), exports);
|
|
65
72
|
__exportStar(require("./isUndefined.js"), exports);
|
|
66
73
|
__exportStar(require("./isUndefinedArray.js"), exports);
|
|
74
|
+
__exportStar(require("./isUnknown.js"), exports);
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isNumericValue = void 0;
|
|
4
4
|
const isNumericString_js_1 = require("./isNumericString.js");
|
|
5
|
-
const isNumericValue = (input) => typeof input === 'number' || typeof input === 'bigint' || (0, isNumericString_js_1.isNumericString)(input);
|
|
5
|
+
const isNumericValue = (input) => (typeof input === 'number' && !Number.isNaN(input)) || typeof input === 'bigint' || (0, isNumericString_js_1.isNumericString)(input);
|
|
6
6
|
exports.isNumericValue = isNumericValue;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOptionalArray = void 0;
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
|
+
const isArray_js_1 = require("./isArray.js");
|
|
6
|
+
exports.isOptionalArray = (0, optional_js_1.optional)(isArray_js_1.isArray);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptionalBigInt = void 0;
|
|
4
|
-
const
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isBigInt_js_1 = require("./isBigInt.js");
|
|
6
|
-
exports.isOptionalBigInt = (0,
|
|
6
|
+
exports.isOptionalBigInt = (0, optional_js_1.optional)(isBigInt_js_1.isBigInt);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptionalBoolean = void 0;
|
|
4
|
-
const
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isBoolean_js_1 = require("./isBoolean.js");
|
|
6
|
-
exports.isOptionalBoolean = (0,
|
|
6
|
+
exports.isOptionalBoolean = (0, optional_js_1.optional)(isBoolean_js_1.isBoolean);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptionalISODateString = void 0;
|
|
4
|
-
const
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isISODateString_js_1 = require("./isISODateString.js");
|
|
6
|
-
exports.isOptionalISODateString = (0,
|
|
6
|
+
exports.isOptionalISODateString = (0, optional_js_1.optional)(isISODateString_js_1.isISODateString);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptionalNull = void 0;
|
|
4
|
-
const
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isNull_js_1 = require("./isNull.js");
|
|
6
|
-
exports.isOptionalNull = (0,
|
|
6
|
+
exports.isOptionalNull = (0, optional_js_1.optional)(isNull_js_1.isNull);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptionalNumber = void 0;
|
|
4
|
-
const
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isNumber_js_1 = require("./isNumber.js");
|
|
6
|
-
exports.isOptionalNumber = (0,
|
|
6
|
+
exports.isOptionalNumber = (0, optional_js_1.optional)(isNumber_js_1.isNumber);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOptionalObject = void 0;
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
|
+
const isObject_js_1 = require("./isObject.js");
|
|
6
|
+
exports.isOptionalObject = (0, optional_js_1.optional)(isObject_js_1.isObject);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptionalString = void 0;
|
|
4
|
-
const
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isString_js_1 = require("./isString.js");
|
|
6
|
-
exports.isOptionalString = (0,
|
|
6
|
+
exports.isOptionalString = (0, optional_js_1.optional)(isString_js_1.isString);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptionalSymbol = void 0;
|
|
4
|
-
const
|
|
4
|
+
const optional_js_1 = require("./factory/optional.js");
|
|
5
5
|
const isSymbol_js_1 = require("./isSymbol.js");
|
|
6
|
-
exports.isOptionalSymbol = (0,
|
|
6
|
+
exports.isOptionalSymbol = (0, optional_js_1.optional)(isSymbol_js_1.isSymbol);
|
|
@@ -7,8 +7,9 @@ export * from './is.js';
|
|
|
7
7
|
export * from './literal.js';
|
|
8
8
|
export * from './matching.js';
|
|
9
9
|
export * from './maybeArray.js';
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
10
|
+
export * from './nonNullable.js';
|
|
11
|
+
export * from './nullable.js';
|
|
12
|
+
export * from './optional.js';
|
|
12
13
|
export * from './range.js';
|
|
13
14
|
export * from './shape.js';
|
|
14
15
|
export * from './stringLength.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const nonNullable = (predicate) => (input) => input != null && predicate(input);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const nullable = (predicate) => (input) => input === null || predicate(input);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const optional = (predicate) => (input) => typeof input === 'undefined' || predicate(input);
|
|
@@ -2,7 +2,8 @@ import { isAnyObject } from '../isAnyObject.js';
|
|
|
2
2
|
import { literal } from './literal.js';
|
|
3
3
|
import { matching } from './matching.js';
|
|
4
4
|
export const shape = (objectShape) => {
|
|
5
|
-
const entries =
|
|
5
|
+
const entries = Reflect.ownKeys(objectShape).map((key) => {
|
|
6
|
+
const value = Reflect.get(objectShape, key);
|
|
6
7
|
const predicate = typeof value === 'function'
|
|
7
8
|
? value
|
|
8
9
|
: value instanceof RegExp
|
|
@@ -12,5 +13,5 @@ export const shape = (objectShape) => {
|
|
|
12
13
|
: literal(value);
|
|
13
14
|
return [key, predicate];
|
|
14
15
|
});
|
|
15
|
-
return (input) => isAnyObject(input) && entries.every(([key, predicate]) => predicate(input
|
|
16
|
+
return (input) => isAnyObject(input) && entries.every(([key, predicate]) => predicate(Reflect.get(input, key)));
|
|
16
17
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export function withLength(fn, lengthRange) {
|
|
2
2
|
if (Array.isArray(lengthRange)) {
|
|
3
|
-
const [min =
|
|
3
|
+
const [min = 0, max = Number.POSITIVE_INFINITY] = lengthRange;
|
|
4
|
+
if (min < 0) {
|
|
5
|
+
throw new RangeError('min must be greater than or equal to 0');
|
|
6
|
+
}
|
|
4
7
|
if (min > max) {
|
|
5
8
|
throw new RangeError('min cannot be greater than max');
|
|
6
9
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export function withSize(fn, sizeRange) {
|
|
2
2
|
if (Array.isArray(sizeRange)) {
|
|
3
|
-
const [min =
|
|
3
|
+
const [min = 0, max = Number.POSITIVE_INFINITY] = sizeRange;
|
|
4
|
+
if (min < 0) {
|
|
5
|
+
throw new RangeError('min must be greater than or equal to 0');
|
|
6
|
+
}
|
|
4
7
|
if (min > max) {
|
|
5
8
|
throw new RangeError('min cannot be greater than max');
|
|
6
9
|
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
export * from './isAny.js';
|
|
1
2
|
export * from './isAnyObject.js';
|
|
2
3
|
export * from './isAnyObjectWith.js';
|
|
3
4
|
export * from './isAnyObjectWithOwn.js';
|
|
5
|
+
export * from './isArray.js';
|
|
4
6
|
export * from './isAsyncIterable.js';
|
|
5
7
|
export * from './isBigInt.js';
|
|
6
8
|
export * from './isBigIntArray.js';
|
|
9
|
+
export * from './isBinaryNumberString.js';
|
|
7
10
|
export * from './isBoolean.js';
|
|
8
11
|
export * from './isBooleanArray.js';
|
|
9
12
|
export * from './isDigitsString.js';
|
|
10
13
|
export * from './isFiniteNumber.js';
|
|
11
14
|
export * from './isFunction.js';
|
|
15
|
+
export * from './isHexNumberString.js';
|
|
12
16
|
export * from './isInt32.js';
|
|
13
17
|
export * from './isInteger.js';
|
|
14
18
|
export * from './isIntString.js';
|
|
@@ -25,11 +29,14 @@ export * from './isNumericValue.js';
|
|
|
25
29
|
export * from './isNumericValueArray.js';
|
|
26
30
|
export * from './isObject.js';
|
|
27
31
|
export * from './isObjectWith.js';
|
|
32
|
+
export * from './isOctalNumberString.js';
|
|
33
|
+
export * from './isOptionalArray.js';
|
|
28
34
|
export * from './isOptionalBigInt.js';
|
|
29
35
|
export * from './isOptionalBoolean.js';
|
|
30
36
|
export * from './isOptionalISODateString.js';
|
|
31
37
|
export * from './isOptionalNull.js';
|
|
32
38
|
export * from './isOptionalNumber.js';
|
|
39
|
+
export * from './isOptionalObject.js';
|
|
33
40
|
export * from './isOptionalString.js';
|
|
34
41
|
export * from './isOptionalSymbol.js';
|
|
35
42
|
export * from './isPositiveFiniteNumber.js';
|
|
@@ -48,3 +55,4 @@ export * from './isSymbol.js';
|
|
|
48
55
|
export * from './isSymbolArray.js';
|
|
49
56
|
export * from './isUndefined.js';
|
|
50
57
|
export * from './isUndefinedArray.js';
|
|
58
|
+
export * from './isUnknown.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isAny = (_input) => true;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isArray = (input) => Array.isArray(input);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { isNumericString } from './isNumericString.js';
|
|
2
|
-
export const isNumericValue = (input) => typeof input === 'number' || typeof input === 'bigint' || isNumericString(input);
|
|
2
|
+
export const isNumericValue = (input) => (typeof input === 'number' && !Number.isNaN(input)) || typeof input === 'bigint' || isNumericString(input);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isBigInt } from './isBigInt.js';
|
|
3
|
-
export const isOptionalBigInt =
|
|
3
|
+
export const isOptionalBigInt = optional(isBigInt);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isBoolean } from './isBoolean.js';
|
|
3
|
-
export const isOptionalBoolean =
|
|
3
|
+
export const isOptionalBoolean = optional(isBoolean);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isISODateString } from './isISODateString.js';
|
|
3
|
-
export const isOptionalISODateString =
|
|
3
|
+
export const isOptionalISODateString = optional(isISODateString);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isNull } from './isNull.js';
|
|
3
|
-
export const isOptionalNull =
|
|
3
|
+
export const isOptionalNull = optional(isNull);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isNumber } from './isNumber.js';
|
|
3
|
-
export const isOptionalNumber =
|
|
3
|
+
export const isOptionalNumber = optional(isNumber);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isString } from './isString.js';
|
|
3
|
-
export const isOptionalString =
|
|
3
|
+
export const isOptionalString = optional(isString);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optional } from './factory/optional.js';
|
|
2
2
|
import { isSymbol } from './isSymbol.js';
|
|
3
|
-
export const isOptionalSymbol =
|
|
3
|
+
export const isOptionalSymbol = optional(isSymbol);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isUnknown = (_input) => true;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TypePredicateFn } from '../../types/functions.js';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const fromEnum: <T extends
|
|
2
|
+
import type { EnumRecord } from '../../types/records.js';
|
|
3
|
+
export declare const fromEnum: <T extends EnumRecord>(enumObject: T) => TypePredicateFn<T[keyof T]>;
|
|
@@ -7,8 +7,9 @@ export * from './is.js';
|
|
|
7
7
|
export * from './literal.js';
|
|
8
8
|
export * from './matching.js';
|
|
9
9
|
export * from './maybeArray.js';
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
10
|
+
export * from './nonNullable.js';
|
|
11
|
+
export * from './nullable.js';
|
|
12
|
+
export * from './optional.js';
|
|
12
13
|
export * from './range.js';
|
|
13
14
|
export * from './shape.js';
|
|
14
15
|
export * from './stringLength.js';
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
export * from './isAny.js';
|
|
1
2
|
export * from './isAnyObject.js';
|
|
2
3
|
export * from './isAnyObjectWith.js';
|
|
3
4
|
export * from './isAnyObjectWithOwn.js';
|
|
5
|
+
export * from './isArray.js';
|
|
4
6
|
export * from './isAsyncIterable.js';
|
|
5
7
|
export * from './isBigInt.js';
|
|
6
8
|
export * from './isBigIntArray.js';
|
|
9
|
+
export * from './isBinaryNumberString.js';
|
|
7
10
|
export * from './isBoolean.js';
|
|
8
11
|
export * from './isBooleanArray.js';
|
|
9
12
|
export * from './isDigitsString.js';
|
|
10
13
|
export * from './isFiniteNumber.js';
|
|
11
14
|
export * from './isFunction.js';
|
|
15
|
+
export * from './isHexNumberString.js';
|
|
12
16
|
export * from './isInt32.js';
|
|
13
17
|
export * from './isInteger.js';
|
|
14
18
|
export * from './isIntString.js';
|
|
@@ -25,11 +29,14 @@ export * from './isNumericValue.js';
|
|
|
25
29
|
export * from './isNumericValueArray.js';
|
|
26
30
|
export * from './isObject.js';
|
|
27
31
|
export * from './isObjectWith.js';
|
|
32
|
+
export * from './isOctalNumberString.js';
|
|
33
|
+
export * from './isOptionalArray.js';
|
|
28
34
|
export * from './isOptionalBigInt.js';
|
|
29
35
|
export * from './isOptionalBoolean.js';
|
|
30
36
|
export * from './isOptionalISODateString.js';
|
|
31
37
|
export * from './isOptionalNull.js';
|
|
32
38
|
export * from './isOptionalNumber.js';
|
|
39
|
+
export * from './isOptionalObject.js';
|
|
33
40
|
export * from './isOptionalString.js';
|
|
34
41
|
export * from './isOptionalSymbol.js';
|
|
35
42
|
export * from './isPositiveFiniteNumber.js';
|
|
@@ -48,3 +55,4 @@ export * from './isSymbol.js';
|
|
|
48
55
|
export * from './isSymbolArray.js';
|
|
49
56
|
export * from './isUndefined.js';
|
|
50
57
|
export * from './isUndefinedArray.js';
|
|
58
|
+
export * from './isUnknown.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isAny: (_input: unknown) => _input is any;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const isAnyObject: <T>(input: T) => input is T & UnknownRecord;
|
|
1
|
+
export declare const isAnyObject: (input: unknown) => input is object;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isArray: (input: unknown) => input is unknown[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isAsyncIterable:
|
|
1
|
+
export declare const isAsyncIterable: (input: unknown) => input is AsyncIterable<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isBinaryNumberString: import("../index.js").TypePredicateFn<`0b${number}` | `0B${number}`>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isDigitsString: import("../index.js").TypePredicateFn<`${number}`>;
|
|
1
|
+
export declare const isDigitsString: import("../index.js").TypePredicateFn<`${number}` | `${bigint}`>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isHexNumberString: import("../index.js").TypePredicateFn<`0x${string}` | `0X${string}`>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isIntString: import("../index.js").TypePredicateFn<`${number}`>;
|
|
1
|
+
export declare const isIntString: import("../index.js").TypePredicateFn<`${number}` | `${bigint}`>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isNumericString: import("../index.js").TypePredicateFn<`${number}`>;
|
|
1
|
+
export declare const isNumericString: import("../index.js").TypePredicateFn<`${number}` | `${bigint}`>;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const isObject: <T>(input: T) => input is T & UnknownRecord;
|
|
1
|
+
export declare const isObject: (input: unknown) => input is object;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isOctalNumberString: import("../index.js").TypePredicateFn<`0o${number}` | `0O${number}`>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isOptionalArray: import("../index.js").TypePredicateFn<unknown[] | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isOptionalObject: import("../index.js").TypePredicateFn<object | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isUnknown: (_input: unknown) => _input is unknown;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NotPromise } from './utils.js';
|
|
2
2
|
export type Primitive = string | number | boolean | bigint | symbol | undefined | null;
|
|
3
|
-
export type NumericString<T extends string | number = number> = `${T}` extends `${number}` ? `${T}` : never;
|
|
3
|
+
export type NumericString<T extends string | number | bigint = number | bigint> = `${T}` extends `${number | bigint}` ? `${T}` : never;
|
|
4
4
|
export type NumericValue = number | bigint | NumericString;
|
|
5
5
|
export type JsonObject = {
|
|
6
6
|
[key: string]: JsonValue;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { Branded } from './branded.js';
|
|
2
|
+
export type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
3
|
+
export type DecimalNumberString = `${'-' | '+' | ''}${Digit}${number}`;
|
|
4
|
+
export type HexNumberString = `0${'x' | 'X'}${string}`;
|
|
5
|
+
export type OctalNumberString = `0${'o' | 'O'}${number}`;
|
|
6
|
+
export type BinaryNumberString = `0${'b' | 'B'}${number}`;
|
|
7
|
+
export type ExponentiationString = `${number}${'e' | 'E'}${number}`;
|
|
2
8
|
export type Int32 = Branded<number, 'Int32'>;
|
|
3
9
|
export type NumberRange = [min: number] | [min: number, max: undefined] | [min: number, max: number] | [min: undefined, max: number];
|
|
@@ -2,6 +2,7 @@ export type AnyRecord = Record<PropertyKey, any>;
|
|
|
2
2
|
export type UnknownRecord = Record<PropertyKey, unknown>;
|
|
3
3
|
export type NeverRecord = Record<PropertyKey, never>;
|
|
4
4
|
export type StringRecord = Record<string, string>;
|
|
5
|
+
export type EnumRecord = Record<string, string | number>;
|
|
5
6
|
export type RemoveIndex<Type> = {
|
|
6
7
|
[Key in keyof Type as symbol extends Key ? never : string extends Key ? never : number extends Key ? never : Key]: Type[Key];
|
|
7
8
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { Digit } from './numbers.js';
|
|
1
2
|
export type EmptyString = '';
|
|
2
3
|
export type Space = ' ';
|
|
3
4
|
export type AlphaCharacter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
|
|
4
|
-
export type NumericCharacter =
|
|
5
|
+
export type NumericCharacter = `${Digit}`;
|
|
5
6
|
export type AlphanumericCharacter = AlphaCharacter | Capitalize<AlphaCharacter> | NumericCharacter;
|
|
6
7
|
export type MaybePlural<T extends string> = T | `${T}s`;
|
|
7
8
|
export type StripWhitespace<Type extends string> = string extends Type ? Type : Type extends `${infer First}${infer Rest}` ? First extends Space ? StripWhitespace<Rest> : `${First}${StripWhitespace<Rest>}` : EmptyString;
|
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.56.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"url": "https://github.com/webdeveric/utils/issues"
|
|
67
67
|
},
|
|
68
68
|
"homepage": "https://github.com/webdeveric/utils/#readme",
|
|
69
|
-
"packageManager": "pnpm@10.6.
|
|
69
|
+
"packageManager": "pnpm@10.6.5+sha512.cdf928fca20832cd59ec53826492b7dc25dc524d4370b6b4adbf65803d32efaa6c1c88147c0ae4e8d579a6c9eec715757b50d4fa35eea179d868eada4ed043af",
|
|
70
70
|
"scripts": {
|
|
71
71
|
"clean": "rimraf ./dist/",
|
|
72
72
|
"prebuild": "pnpm clean",
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@commitlint/config-conventional": "^19.8.0",
|
|
89
89
|
"@commitlint/types": "^19.8.0",
|
|
90
|
-
"@types/node": "^22.13.
|
|
91
|
-
"@vitest/coverage-v8": "^3.0.
|
|
90
|
+
"@types/node": "^22.13.11",
|
|
91
|
+
"@vitest/coverage-v8": "^3.0.9",
|
|
92
92
|
"@webdeveric/eslint-config-ts": "^0.11.0",
|
|
93
93
|
"@webdeveric/prettier-config": "^0.3.0",
|
|
94
94
|
"commitlint": "^19.8.0",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"semantic-release": "^24.2.3",
|
|
108
108
|
"typescript": "^5.8.2",
|
|
109
109
|
"validate-package-exports": "^0.8.0",
|
|
110
|
-
"vitest": "^3.0.
|
|
110
|
+
"vitest": "^3.0.9"
|
|
111
111
|
},
|
|
112
112
|
"pnpm": {
|
|
113
113
|
"onlyBuiltDependencies": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const maybeNull = (predicate) => (input) => input === null || predicate(input);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const maybeUndefined = (predicate) => (input) => typeof input === 'undefined' || predicate(input);
|