@webdeveric/utils 0.53.0 → 0.54.1
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/assertion/assertIsStringMatching.js +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/{predicate-factory/createIsEnumPredicate.js → predicate/factory/fromEnum.js} +3 -3
- package/dist/cjs/{predicate-factory → predicate/factory}/index.js +11 -7
- package/dist/cjs/predicate/factory/instanceOf.js +5 -0
- package/dist/cjs/predicate/factory/literal.js +5 -0
- package/dist/cjs/predicate/factory/matching.js +5 -0
- package/dist/cjs/predicate/factory/range.js +15 -0
- package/dist/cjs/predicate/factory/shape.js +20 -0
- package/dist/cjs/predicate/factory/simple.js +5 -0
- package/dist/cjs/predicate/factory/stringLength.js +13 -0
- package/dist/cjs/{predicate-factory/createIsTuplePredicate.js → predicate/factory/tuple.js} +3 -3
- package/dist/cjs/predicate/factory/typeOf.js +5 -0
- package/dist/cjs/predicate/factory/withLength.js +13 -0
- package/dist/cjs/predicate/factory/withSize.js +13 -0
- package/dist/cjs/predicate/isAsyncIterable.js +4 -2
- package/dist/cjs/predicate/isBigIntArray.js +1 -1
- package/dist/cjs/predicate/isBooleanArray.js +1 -1
- package/dist/cjs/predicate/isDigitsString.js +2 -2
- package/dist/cjs/predicate/isISODateString.js +2 -2
- package/dist/cjs/predicate/isIntString.js +2 -2
- package/dist/cjs/predicate/isIterable.js +4 -2
- package/dist/cjs/predicate/isNullArray.js +1 -1
- package/dist/cjs/predicate/isNumberArray.js +1 -1
- package/dist/cjs/predicate/isNumericString.js +2 -2
- package/dist/cjs/predicate/isNumericValueArray.js +1 -1
- package/dist/cjs/predicate/isOptionalBigInt.js +1 -1
- package/dist/cjs/predicate/isOptionalBoolean.js +1 -1
- package/dist/cjs/predicate/isOptionalISODateString.js +1 -1
- package/dist/cjs/predicate/isOptionalNull.js +1 -1
- package/dist/cjs/predicate/isOptionalNumber.js +1 -1
- package/dist/cjs/predicate/isOptionalString.js +1 -1
- package/dist/cjs/predicate/isOptionalSymbol.js +1 -1
- package/dist/cjs/predicate/isPromiseLike.js +6 -5
- package/dist/cjs/predicate/isStringArray.js +1 -1
- package/dist/cjs/predicate/isSymbolArray.js +1 -1
- package/dist/cjs/predicate/isUndefinedArray.js +1 -1
- package/dist/mjs/assertion/assertIsStringMatching.js +2 -2
- package/dist/mjs/index.js +1 -1
- package/dist/mjs/{predicate-factory/createIsEnumPredicate.js → predicate/factory/fromEnum.js} +1 -1
- package/dist/mjs/predicate/factory/index.js +18 -0
- package/dist/mjs/predicate/factory/instanceOf.js +1 -0
- package/dist/mjs/predicate/factory/literal.js +1 -0
- package/dist/mjs/predicate/factory/matching.js +1 -0
- package/dist/mjs/predicate/factory/range.js +12 -0
- package/dist/mjs/predicate/factory/shape.js +16 -0
- package/dist/mjs/predicate/factory/simple.js +1 -0
- package/dist/mjs/predicate/factory/stringLength.js +9 -0
- package/dist/mjs/{predicate-factory/createIsTuplePredicate.js → predicate/factory/tuple.js} +1 -1
- package/dist/mjs/predicate/factory/typeOf.js +1 -0
- package/dist/mjs/predicate/factory/withLength.js +10 -0
- package/dist/mjs/predicate/factory/withSize.js +10 -0
- package/dist/mjs/predicate/isAsyncIterable.js +4 -2
- package/dist/mjs/predicate/isBigIntArray.js +1 -1
- package/dist/mjs/predicate/isBooleanArray.js +1 -1
- package/dist/mjs/predicate/isDigitsString.js +2 -2
- package/dist/mjs/predicate/isISODateString.js +2 -2
- package/dist/mjs/predicate/isIntString.js +2 -2
- package/dist/mjs/predicate/isIterable.js +4 -2
- package/dist/mjs/predicate/isNullArray.js +1 -1
- package/dist/mjs/predicate/isNumberArray.js +1 -1
- package/dist/mjs/predicate/isNumericString.js +2 -2
- package/dist/mjs/predicate/isNumericValueArray.js +1 -1
- package/dist/mjs/predicate/isOptionalBigInt.js +1 -1
- package/dist/mjs/predicate/isOptionalBoolean.js +1 -1
- package/dist/mjs/predicate/isOptionalISODateString.js +1 -1
- package/dist/mjs/predicate/isOptionalNull.js +1 -1
- package/dist/mjs/predicate/isOptionalNumber.js +1 -1
- package/dist/mjs/predicate/isOptionalString.js +1 -1
- package/dist/mjs/predicate/isOptionalSymbol.js +1 -1
- package/dist/mjs/predicate/isPromiseLike.js +5 -4
- package/dist/mjs/predicate/isStringArray.js +1 -1
- package/dist/mjs/predicate/isSymbolArray.js +1 -1
- package/dist/mjs/predicate/isUndefinedArray.js +1 -1
- package/dist/types/assertion/assertIsAsyncIterable.d.ts +1 -1
- package/dist/types/assertion/assertIsFunction.d.ts +1 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/{predicate-factory → predicate/factory}/allOf.d.ts +2 -2
- package/dist/types/{predicate-factory → predicate/factory}/anyOf.d.ts +2 -2
- package/dist/types/predicate/factory/everyItem.d.ts +2 -0
- package/dist/types/predicate/factory/fromEnum.d.ts +3 -0
- package/dist/types/predicate/factory/index.d.ts +18 -0
- package/dist/types/predicate/factory/instanceOf.d.ts +3 -0
- package/dist/types/predicate/factory/is.d.ts +3 -0
- package/dist/types/predicate/factory/literal.d.ts +2 -0
- package/dist/types/predicate/factory/matching.d.ts +2 -0
- package/dist/types/{predicate-factory → predicate/factory}/maybeArray.d.ts +1 -1
- package/dist/types/{predicate-factory → predicate/factory}/maybeNull.d.ts +1 -1
- package/dist/types/{predicate-factory → predicate/factory}/maybeUndefined.d.ts +1 -1
- package/dist/types/predicate/factory/range.d.ts +3 -0
- package/dist/types/{predicate-factory/createObjectShapePredicate.d.ts → predicate/factory/shape.d.ts} +5 -5
- package/dist/types/predicate/factory/simple.d.ts +3 -0
- package/dist/types/predicate/factory/stringLength.d.ts +2 -0
- package/dist/types/predicate/factory/tuple.d.ts +7 -0
- package/dist/types/predicate/factory/typeOf.d.ts +2 -0
- package/dist/types/predicate/factory/withLength.d.ts +17 -0
- package/dist/types/predicate/factory/withSize.d.ts +17 -0
- package/dist/types/predicate/isFunction.d.ts +1 -2
- package/dist/types/predicate/isPromiseLike.d.ts +3 -1
- package/dist/types/types/common.d.ts +10 -0
- package/dist/types/types/numbers.d.ts +1 -0
- package/package.json +14 -9
- package/dist/cjs/predicate-factory/createIsInstanceOfPredicate.js +0 -5
- package/dist/cjs/predicate-factory/createNumberRangePredicate.js +0 -20
- package/dist/cjs/predicate-factory/createObjectShapePredicate.js +0 -19
- package/dist/cjs/predicate-factory/createStringLengthRangePredicate.js +0 -10
- package/dist/cjs/predicate-factory/createStringMatchingPredicate.js +0 -5
- package/dist/mjs/predicate-factory/createIsInstanceOfPredicate.js +0 -1
- package/dist/mjs/predicate-factory/createNumberRangePredicate.js +0 -16
- package/dist/mjs/predicate-factory/createObjectShapePredicate.js +0 -15
- package/dist/mjs/predicate-factory/createStringLengthRangePredicate.js +0 -6
- package/dist/mjs/predicate-factory/createStringMatchingPredicate.js +0 -1
- package/dist/mjs/predicate-factory/index.js +0 -14
- package/dist/types/predicate-factory/createIsEnumPredicate.d.ts +0 -3
- package/dist/types/predicate-factory/createIsInstanceOfPredicate.d.ts +0 -3
- package/dist/types/predicate-factory/createIsTuplePredicate.d.ts +0 -7
- package/dist/types/predicate-factory/createNumberRangePredicate.d.ts +0 -2
- package/dist/types/predicate-factory/createStringLengthRangePredicate.d.ts +0 -2
- package/dist/types/predicate-factory/createStringMatchingPredicate.d.ts +0 -2
- package/dist/types/predicate-factory/everyItem.d.ts +0 -2
- package/dist/types/predicate-factory/index.d.ts +0 -14
- package/dist/types/predicate-factory/is.d.ts +0 -3
- /package/dist/cjs/{predicate-factory → predicate/factory}/allOf.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/anyOf.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/everyItem.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/is.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/maybeArray.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/maybeNull.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/maybeUndefined.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/allOf.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/anyOf.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/everyItem.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/is.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/maybeArray.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/maybeNull.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/maybeUndefined.js +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assertIsStringMatching = assertIsStringMatching;
|
|
4
|
-
const
|
|
4
|
+
const matching_js_1 = require("../predicate/factory/matching.js");
|
|
5
5
|
const getError_js_1 = require("./getError.js");
|
|
6
6
|
function assertIsStringMatching(input, pattern, error = 'input is not a string that matches the pattern') {
|
|
7
|
-
if (!(0,
|
|
7
|
+
if (!(0, matching_js_1.matching)(pattern)(input)) {
|
|
8
8
|
throw (0, getError_js_1.getError)(error);
|
|
9
9
|
}
|
|
10
10
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./assertion/index.js"), exports);
|
|
18
|
-
__exportStar(require("./predicate
|
|
18
|
+
__exportStar(require("./predicate/factory/index.js"), exports);
|
|
19
19
|
__exportStar(require("./predicate/index.js"), exports);
|
|
20
20
|
__exportStar(require("./types/index.js"), exports);
|
|
21
21
|
__exportStar(require("./asArray.js"), exports);
|
package/dist/cjs/{predicate-factory/createIsEnumPredicate.js → predicate/factory/fromEnum.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.fromEnum = void 0;
|
|
4
4
|
const getEnumValues = (enumObject) => {
|
|
5
5
|
const entries = Object.entries(enumObject);
|
|
6
6
|
const ignoreKeys = entries.reduce((keys, [, value]) => {
|
|
@@ -16,8 +16,8 @@ const getEnumValues = (enumObject) => {
|
|
|
16
16
|
return values;
|
|
17
17
|
}, new Set());
|
|
18
18
|
};
|
|
19
|
-
const
|
|
19
|
+
const fromEnum = (enumObject) => {
|
|
20
20
|
const values = getEnumValues(enumObject);
|
|
21
21
|
return (input) => values.has(input);
|
|
22
22
|
};
|
|
23
|
-
exports.
|
|
23
|
+
exports.fromEnum = fromEnum;
|
|
@@ -16,15 +16,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./allOf.js"), exports);
|
|
18
18
|
__exportStar(require("./anyOf.js"), exports);
|
|
19
|
-
__exportStar(require("./createIsEnumPredicate.js"), exports);
|
|
20
|
-
__exportStar(require("./createIsInstanceOfPredicate.js"), exports);
|
|
21
|
-
__exportStar(require("./createIsTuplePredicate.js"), exports);
|
|
22
|
-
__exportStar(require("./createNumberRangePredicate.js"), exports);
|
|
23
|
-
__exportStar(require("./createObjectShapePredicate.js"), exports);
|
|
24
|
-
__exportStar(require("./createStringLengthRangePredicate.js"), exports);
|
|
25
|
-
__exportStar(require("./createStringMatchingPredicate.js"), exports);
|
|
26
19
|
__exportStar(require("./everyItem.js"), exports);
|
|
20
|
+
__exportStar(require("./fromEnum.js"), exports);
|
|
21
|
+
__exportStar(require("./instanceOf.js"), exports);
|
|
27
22
|
__exportStar(require("./is.js"), exports);
|
|
23
|
+
__exportStar(require("./literal.js"), exports);
|
|
24
|
+
__exportStar(require("./matching.js"), exports);
|
|
28
25
|
__exportStar(require("./maybeArray.js"), exports);
|
|
29
26
|
__exportStar(require("./maybeNull.js"), exports);
|
|
30
27
|
__exportStar(require("./maybeUndefined.js"), exports);
|
|
28
|
+
__exportStar(require("./range.js"), exports);
|
|
29
|
+
__exportStar(require("./shape.js"), exports);
|
|
30
|
+
__exportStar(require("./stringLength.js"), exports);
|
|
31
|
+
__exportStar(require("./tuple.js"), exports);
|
|
32
|
+
__exportStar(require("./typeOf.js"), exports);
|
|
33
|
+
__exportStar(require("./withLength.js"), exports);
|
|
34
|
+
__exportStar(require("./withSize.js"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.range = range;
|
|
4
|
+
function range(min, max) {
|
|
5
|
+
if (min === Number.NEGATIVE_INFINITY && max === Number.POSITIVE_INFINITY) {
|
|
6
|
+
throw new RangeError('min and max cannot be -Infinity and Infinity');
|
|
7
|
+
}
|
|
8
|
+
if (Number.isNaN(min) || Number.isNaN(max)) {
|
|
9
|
+
throw new RangeError('min and max must not be NaN');
|
|
10
|
+
}
|
|
11
|
+
if (min >= max) {
|
|
12
|
+
throw new RangeError('min must be less than max');
|
|
13
|
+
}
|
|
14
|
+
return (input) => (typeof input === 'number' || typeof input === 'bigint') && input >= min && input <= max;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shape = void 0;
|
|
4
|
+
const isAnyObject_js_1 = require("../isAnyObject.js");
|
|
5
|
+
const literal_js_1 = require("./literal.js");
|
|
6
|
+
const matching_js_1 = require("./matching.js");
|
|
7
|
+
const shape = (objectShape) => {
|
|
8
|
+
const entries = Object.entries(objectShape).map(([key, value]) => {
|
|
9
|
+
const predicate = typeof value === 'function'
|
|
10
|
+
? value
|
|
11
|
+
: value instanceof RegExp
|
|
12
|
+
? (0, matching_js_1.matching)(value)
|
|
13
|
+
: (0, isAnyObject_js_1.isAnyObject)(value)
|
|
14
|
+
? (0, exports.shape)(value)
|
|
15
|
+
: (0, literal_js_1.literal)(value);
|
|
16
|
+
return [key, predicate];
|
|
17
|
+
});
|
|
18
|
+
return (input) => (0, isAnyObject_js_1.isAnyObject)(input) && entries.every(([key, predicate]) => predicate(input[key]));
|
|
19
|
+
};
|
|
20
|
+
exports.shape = shape;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringLength = void 0;
|
|
4
|
+
const stringLength = (min, max = Number.POSITIVE_INFINITY) => {
|
|
5
|
+
if (min < 0) {
|
|
6
|
+
throw new RangeError('min must be greater than or equal to 0');
|
|
7
|
+
}
|
|
8
|
+
if (min > max) {
|
|
9
|
+
throw new RangeError('min cannot be greater than max');
|
|
10
|
+
}
|
|
11
|
+
return (input) => typeof input === 'string' && input.length >= min && input.length <= max;
|
|
12
|
+
};
|
|
13
|
+
exports.stringLength = stringLength;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.tuple = void 0;
|
|
4
|
+
const tuple = (tupleShape) => {
|
|
5
5
|
return (input) => Array.isArray(input) && input.length === tupleShape.length
|
|
6
6
|
? input.every((value, index) => {
|
|
7
7
|
const item = tupleShape[index];
|
|
@@ -9,4 +9,4 @@ const createIsTuplePredicate = (tupleShape) => {
|
|
|
9
9
|
})
|
|
10
10
|
: false;
|
|
11
11
|
};
|
|
12
|
-
exports.
|
|
12
|
+
exports.tuple = tuple;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withLength = withLength;
|
|
4
|
+
function withLength(fn, lengthRange) {
|
|
5
|
+
if (Array.isArray(lengthRange)) {
|
|
6
|
+
const [min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY] = lengthRange;
|
|
7
|
+
if (min > max) {
|
|
8
|
+
throw new RangeError('min cannot be greater than max');
|
|
9
|
+
}
|
|
10
|
+
return (input) => fn(input) && input.length >= min && input.length <= max;
|
|
11
|
+
}
|
|
12
|
+
return (input) => fn(input) && input.length === lengthRange;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withSize = withSize;
|
|
4
|
+
function withSize(fn, sizeRange) {
|
|
5
|
+
if (Array.isArray(sizeRange)) {
|
|
6
|
+
const [min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY] = sizeRange;
|
|
7
|
+
if (min > max) {
|
|
8
|
+
throw new RangeError('min cannot be greater than max');
|
|
9
|
+
}
|
|
10
|
+
return (input) => fn(input) && input.size >= min && input.size <= max;
|
|
11
|
+
}
|
|
12
|
+
return (input) => fn(input) && input.size === sizeRange;
|
|
13
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isAsyncIterable = void 0;
|
|
4
|
-
const isObjectWith_js_1 = require("./isObjectWith.js");
|
|
5
4
|
const isAsyncIterable = (input) => {
|
|
6
|
-
return (
|
|
5
|
+
return (input !== null &&
|
|
6
|
+
typeof input === 'object' &&
|
|
7
|
+
Symbol.asyncIterator in input &&
|
|
8
|
+
typeof input[Symbol.asyncIterator] === 'function');
|
|
7
9
|
};
|
|
8
10
|
exports.isAsyncIterable = isAsyncIterable;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isBigIntArray = void 0;
|
|
4
|
-
const everyItem_js_1 = require("
|
|
4
|
+
const everyItem_js_1 = require("./factory/everyItem.js");
|
|
5
5
|
const isBigInt_js_1 = require("./isBigInt.js");
|
|
6
6
|
exports.isBigIntArray = (0, everyItem_js_1.everyItem)(isBigInt_js_1.isBigInt);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isBooleanArray = void 0;
|
|
4
|
-
const everyItem_js_1 = require("
|
|
4
|
+
const everyItem_js_1 = require("./factory/everyItem.js");
|
|
5
5
|
const isBoolean_js_1 = require("./isBoolean.js");
|
|
6
6
|
exports.isBooleanArray = (0, everyItem_js_1.everyItem)(isBoolean_js_1.isBoolean);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isDigitsString = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.isDigitsString = (0,
|
|
4
|
+
const matching_js_1 = require("./factory/matching.js");
|
|
5
|
+
exports.isDigitsString = (0, matching_js_1.matching)(/^\d+$/);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isISODateString = exports.ISO_DATE_PATTERN = void 0;
|
|
4
|
-
const
|
|
4
|
+
const matching_js_1 = require("./factory/matching.js");
|
|
5
5
|
exports.ISO_DATE_PATTERN = /^(?<year>[+-]?\d{4,})-(?<month>[01]\d)-(?<day>0[1-9]|[12]\d|3[01])T(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(\.(?<timezone>\d{3}Z))?$/;
|
|
6
|
-
exports.isISODateString = (0,
|
|
6
|
+
exports.isISODateString = (0, matching_js_1.matching)(exports.ISO_DATE_PATTERN);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isIntString = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.isIntString = (0,
|
|
4
|
+
const matching_js_1 = require("./factory/matching.js");
|
|
5
|
+
exports.isIntString = (0, matching_js_1.matching)(/^[-+]?\d+$/);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isIterable = void 0;
|
|
4
|
-
const isObject_js_1 = require("./isObject.js");
|
|
5
4
|
const isIterable = (input) => {
|
|
6
|
-
return (
|
|
5
|
+
return (input !== null &&
|
|
6
|
+
typeof input === 'object' &&
|
|
7
|
+
Symbol.iterator in input &&
|
|
8
|
+
typeof input[Symbol.iterator] === 'function');
|
|
7
9
|
};
|
|
8
10
|
exports.isIterable = isIterable;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isNullArray = void 0;
|
|
4
|
-
const everyItem_js_1 = require("
|
|
4
|
+
const everyItem_js_1 = require("./factory/everyItem.js");
|
|
5
5
|
const isNull_js_1 = require("./isNull.js");
|
|
6
6
|
exports.isNullArray = (0, everyItem_js_1.everyItem)(isNull_js_1.isNull);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isNumberArray = void 0;
|
|
4
|
-
const everyItem_js_1 = require("
|
|
4
|
+
const everyItem_js_1 = require("./factory/everyItem.js");
|
|
5
5
|
const isNumber_js_1 = require("./isNumber.js");
|
|
6
6
|
exports.isNumberArray = (0, everyItem_js_1.everyItem)(isNumber_js_1.isNumber);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isNumericString = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.isNumericString = (0,
|
|
4
|
+
const matching_js_1 = require("./factory/matching.js");
|
|
5
|
+
exports.isNumericString = (0, matching_js_1.matching)(/^[-+]?\d+(\.\d+)?$/);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isNumericValueArray = void 0;
|
|
4
|
-
const everyItem_js_1 = require("
|
|
4
|
+
const everyItem_js_1 = require("./factory/everyItem.js");
|
|
5
5
|
const isNumericValue_js_1 = require("./isNumericValue.js");
|
|
6
6
|
exports.isNumericValueArray = (0, everyItem_js_1.everyItem)(isNumericValue_js_1.isNumericValue);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptionalBigInt = void 0;
|
|
4
|
-
const maybeUndefined_js_1 = require("
|
|
4
|
+
const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
|
|
5
5
|
const isBigInt_js_1 = require("./isBigInt.js");
|
|
6
6
|
exports.isOptionalBigInt = (0, maybeUndefined_js_1.maybeUndefined)(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 maybeUndefined_js_1 = require("
|
|
4
|
+
const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
|
|
5
5
|
const isBoolean_js_1 = require("./isBoolean.js");
|
|
6
6
|
exports.isOptionalBoolean = (0, maybeUndefined_js_1.maybeUndefined)(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 maybeUndefined_js_1 = require("
|
|
4
|
+
const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
|
|
5
5
|
const isISODateString_js_1 = require("./isISODateString.js");
|
|
6
6
|
exports.isOptionalISODateString = (0, maybeUndefined_js_1.maybeUndefined)(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 maybeUndefined_js_1 = require("
|
|
4
|
+
const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
|
|
5
5
|
const isNull_js_1 = require("./isNull.js");
|
|
6
6
|
exports.isOptionalNull = (0, maybeUndefined_js_1.maybeUndefined)(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 maybeUndefined_js_1 = require("
|
|
4
|
+
const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
|
|
5
5
|
const isNumber_js_1 = require("./isNumber.js");
|
|
6
6
|
exports.isOptionalNumber = (0, maybeUndefined_js_1.maybeUndefined)(isNumber_js_1.isNumber);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptionalString = void 0;
|
|
4
|
-
const maybeUndefined_js_1 = require("
|
|
4
|
+
const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
|
|
5
5
|
const isString_js_1 = require("./isString.js");
|
|
6
6
|
exports.isOptionalString = (0, maybeUndefined_js_1.maybeUndefined)(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 maybeUndefined_js_1 = require("
|
|
4
|
+
const maybeUndefined_js_1 = require("./factory/maybeUndefined.js");
|
|
5
5
|
const isSymbol_js_1 = require("./isSymbol.js");
|
|
6
6
|
exports.isOptionalSymbol = (0, maybeUndefined_js_1.maybeUndefined)(isSymbol_js_1.isSymbol);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPromiseLike =
|
|
3
|
+
exports.isPromiseLike = void 0;
|
|
4
|
+
const shape_js_1 = require("./factory/shape.js");
|
|
5
|
+
const withLength_js_1 = require("./factory/withLength.js");
|
|
4
6
|
const isFunction_js_1 = require("./isFunction.js");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
7
|
+
exports.isPromiseLike = (0, shape_js_1.shape)({
|
|
8
|
+
then: (0, withLength_js_1.withLength)(isFunction_js_1.isFunction, 2),
|
|
9
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isStringArray = void 0;
|
|
4
|
-
const everyItem_js_1 = require("
|
|
4
|
+
const everyItem_js_1 = require("./factory/everyItem.js");
|
|
5
5
|
const isString_js_1 = require("./isString.js");
|
|
6
6
|
exports.isStringArray = (0, everyItem_js_1.everyItem)(isString_js_1.isString);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isSymbolArray = void 0;
|
|
4
|
-
const everyItem_js_1 = require("
|
|
4
|
+
const everyItem_js_1 = require("./factory/everyItem.js");
|
|
5
5
|
const isSymbol_js_1 = require("./isSymbol.js");
|
|
6
6
|
exports.isSymbolArray = (0, everyItem_js_1.everyItem)(isSymbol_js_1.isSymbol);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isUndefinedArray = void 0;
|
|
4
|
-
const everyItem_js_1 = require("
|
|
4
|
+
const everyItem_js_1 = require("./factory/everyItem.js");
|
|
5
5
|
const isUndefined_js_1 = require("./isUndefined.js");
|
|
6
6
|
exports.isUndefinedArray = (0, everyItem_js_1.everyItem)(isUndefined_js_1.isUndefined);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { matching } from '../predicate/factory/matching.js';
|
|
2
2
|
import { getError } from './getError.js';
|
|
3
3
|
export function assertIsStringMatching(input, pattern, error = 'input is not a string that matches the pattern') {
|
|
4
|
-
if (!
|
|
4
|
+
if (!matching(pattern)(input)) {
|
|
5
5
|
throw getError(error);
|
|
6
6
|
}
|
|
7
7
|
}
|
package/dist/mjs/index.js
CHANGED
package/dist/mjs/{predicate-factory/createIsEnumPredicate.js → predicate/factory/fromEnum.js}
RENAMED
|
@@ -13,7 +13,7 @@ const getEnumValues = (enumObject) => {
|
|
|
13
13
|
return values;
|
|
14
14
|
}, new Set());
|
|
15
15
|
};
|
|
16
|
-
export const
|
|
16
|
+
export const fromEnum = (enumObject) => {
|
|
17
17
|
const values = getEnumValues(enumObject);
|
|
18
18
|
return (input) => values.has(input);
|
|
19
19
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './allOf.js';
|
|
2
|
+
export * from './anyOf.js';
|
|
3
|
+
export * from './everyItem.js';
|
|
4
|
+
export * from './fromEnum.js';
|
|
5
|
+
export * from './instanceOf.js';
|
|
6
|
+
export * from './is.js';
|
|
7
|
+
export * from './literal.js';
|
|
8
|
+
export * from './matching.js';
|
|
9
|
+
export * from './maybeArray.js';
|
|
10
|
+
export * from './maybeNull.js';
|
|
11
|
+
export * from './maybeUndefined.js';
|
|
12
|
+
export * from './range.js';
|
|
13
|
+
export * from './shape.js';
|
|
14
|
+
export * from './stringLength.js';
|
|
15
|
+
export * from './tuple.js';
|
|
16
|
+
export * from './typeOf.js';
|
|
17
|
+
export * from './withLength.js';
|
|
18
|
+
export * from './withSize.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const instanceOf = (constructor) => (input) => input instanceof constructor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const literal = (value) => (input) => input === value;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const matching = (pattern) => (input) => typeof input === 'string' && pattern.test(input);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function range(min, max) {
|
|
2
|
+
if (min === Number.NEGATIVE_INFINITY && max === Number.POSITIVE_INFINITY) {
|
|
3
|
+
throw new RangeError('min and max cannot be -Infinity and Infinity');
|
|
4
|
+
}
|
|
5
|
+
if (Number.isNaN(min) || Number.isNaN(max)) {
|
|
6
|
+
throw new RangeError('min and max must not be NaN');
|
|
7
|
+
}
|
|
8
|
+
if (min >= max) {
|
|
9
|
+
throw new RangeError('min must be less than max');
|
|
10
|
+
}
|
|
11
|
+
return (input) => (typeof input === 'number' || typeof input === 'bigint') && input >= min && input <= max;
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isAnyObject } from '../isAnyObject.js';
|
|
2
|
+
import { literal } from './literal.js';
|
|
3
|
+
import { matching } from './matching.js';
|
|
4
|
+
export const shape = (objectShape) => {
|
|
5
|
+
const entries = Object.entries(objectShape).map(([key, value]) => {
|
|
6
|
+
const predicate = typeof value === 'function'
|
|
7
|
+
? value
|
|
8
|
+
: value instanceof RegExp
|
|
9
|
+
? matching(value)
|
|
10
|
+
: isAnyObject(value)
|
|
11
|
+
? shape(value)
|
|
12
|
+
: literal(value);
|
|
13
|
+
return [key, predicate];
|
|
14
|
+
});
|
|
15
|
+
return (input) => isAnyObject(input) && entries.every(([key, predicate]) => predicate(input[key]));
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const simple = (fn) => (input) => fn(input);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const stringLength = (min, max = Number.POSITIVE_INFINITY) => {
|
|
2
|
+
if (min < 0) {
|
|
3
|
+
throw new RangeError('min must be greater than or equal to 0');
|
|
4
|
+
}
|
|
5
|
+
if (min > max) {
|
|
6
|
+
throw new RangeError('min cannot be greater than max');
|
|
7
|
+
}
|
|
8
|
+
return (input) => typeof input === 'string' && input.length >= min && input.length <= max;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const typeOf = (...types) => (input) => types.some((type) => typeof input === type);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function withLength(fn, lengthRange) {
|
|
2
|
+
if (Array.isArray(lengthRange)) {
|
|
3
|
+
const [min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY] = lengthRange;
|
|
4
|
+
if (min > max) {
|
|
5
|
+
throw new RangeError('min cannot be greater than max');
|
|
6
|
+
}
|
|
7
|
+
return (input) => fn(input) && input.length >= min && input.length <= max;
|
|
8
|
+
}
|
|
9
|
+
return (input) => fn(input) && input.length === lengthRange;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function withSize(fn, sizeRange) {
|
|
2
|
+
if (Array.isArray(sizeRange)) {
|
|
3
|
+
const [min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY] = sizeRange;
|
|
4
|
+
if (min > max) {
|
|
5
|
+
throw new RangeError('min cannot be greater than max');
|
|
6
|
+
}
|
|
7
|
+
return (input) => fn(input) && input.size >= min && input.size <= max;
|
|
8
|
+
}
|
|
9
|
+
return (input) => fn(input) && input.size === sizeRange;
|
|
10
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { isObjectWith } from './isObjectWith.js';
|
|
2
1
|
export const isAsyncIterable = (input) => {
|
|
3
|
-
return
|
|
2
|
+
return (input !== null &&
|
|
3
|
+
typeof input === 'object' &&
|
|
4
|
+
Symbol.asyncIterator in input &&
|
|
5
|
+
typeof input[Symbol.asyncIterator] === 'function');
|
|
4
6
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const isDigitsString =
|
|
1
|
+
import { matching } from './factory/matching.js';
|
|
2
|
+
export const isDigitsString = matching(/^\d+$/);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { matching } from './factory/matching.js';
|
|
2
2
|
export const ISO_DATE_PATTERN = /^(?<year>[+-]?\d{4,})-(?<month>[01]\d)-(?<day>0[1-9]|[12]\d|3[01])T(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(\.(?<timezone>\d{3}Z))?$/;
|
|
3
|
-
export const isISODateString =
|
|
3
|
+
export const isISODateString = matching(ISO_DATE_PATTERN);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const isIntString =
|
|
1
|
+
import { matching } from './factory/matching.js';
|
|
2
|
+
export const isIntString = matching(/^[-+]?\d+$/);
|