@webdeveric/utils 0.18.0 → 0.19.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-assertion.js +185 -10
- package/dist/cjs/type-assertion.js.map +1 -1
- package/dist/cjs/type-predicate.js +67 -18
- package/dist/cjs/type-predicate.js.map +1 -1
- package/dist/mjs/type-assertion.js +155 -9
- package/dist/mjs/type-assertion.js.map +1 -1
- package/dist/mjs/type-predicate.js +46 -14
- package/dist/mjs/type-predicate.js.map +1 -1
- package/dist/types/type-assertion.d.ts +35 -4
- package/dist/types/type-assertion.d.ts.map +1 -1
- package/dist/types/type-predicate.d.ts +21 -4
- package/dist/types/type-predicate.d.ts.map +1 -1
- package/dist/types/types.d.ts +2 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/type-assertion.ts +309 -10
- package/src/type-predicate.ts +73 -20
- package/src/types.ts +6 -0
|
@@ -1,23 +1,198 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertIsNumericValueArray = exports.
|
|
3
|
+
exports.assertExhaustive = exports.assertIsUndefined = exports.assertIsSymbol = exports.assertIsStringWithLength = exports.assertIsStringRecord = exports.assertIsStringMatching = exports.assertIsString = exports.assertIsPropertyKey = exports.assertIsPromiseRejectedResult = exports.assertIsPromiseFulfilledResult = exports.assertIsPrimitive = exports.assertIsPositiveInteger = exports.assertIsNumberGTEOne = exports.assertIsPositiveFiniteNumber = exports.assertIsOptionalSymbol = exports.assertIsOptionalString = exports.assertIsOptionalNumber = exports.assertIsOptionalNull = exports.assertIsOptionalBoolean = exports.assertIsOptionalBigInt = exports.assertIsObject = exports.assertIsNumericValueArray = exports.assertIsNumericValue = exports.assertIsNumericString = exports.assertIsNumber = exports.assertIsNull = exports.assertIsLengthAware = exports.assertIsIntString = exports.assertIsInteger = exports.assertIsFiniteNumber = exports.assertIsBoolean = exports.assertIsBigInt = void 0;
|
|
4
4
|
const type_predicate_js_1 = require("./type-predicate.js");
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function getError(error) {
|
|
6
|
+
return error instanceof Error ? error : new TypeError(error);
|
|
7
|
+
}
|
|
8
|
+
function assertIsBigInt(input, error = 'input is not a bigint') {
|
|
9
|
+
if (!(0, type_predicate_js_1.isBigInt)(input)) {
|
|
10
|
+
throw getError(error);
|
|
8
11
|
}
|
|
9
12
|
}
|
|
10
|
-
exports.
|
|
11
|
-
function
|
|
12
|
-
if (!
|
|
13
|
-
throw
|
|
13
|
+
exports.assertIsBigInt = assertIsBigInt;
|
|
14
|
+
function assertIsBoolean(input, error = 'input is not a boolean') {
|
|
15
|
+
if (!(0, type_predicate_js_1.isBoolean)(input)) {
|
|
16
|
+
throw getError(error);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.assertIsBoolean = assertIsBoolean;
|
|
20
|
+
function assertIsFiniteNumber(input, error = 'input is not a finite number') {
|
|
21
|
+
if (!(0, type_predicate_js_1.isFiniteNumber)(input)) {
|
|
22
|
+
throw getError(error);
|
|
14
23
|
}
|
|
15
24
|
}
|
|
16
25
|
exports.assertIsFiniteNumber = assertIsFiniteNumber;
|
|
17
|
-
function
|
|
26
|
+
function assertIsInteger(input, error = 'input is not an integer') {
|
|
27
|
+
if (!(0, type_predicate_js_1.isInteger)(input)) {
|
|
28
|
+
throw getError(error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.assertIsInteger = assertIsInteger;
|
|
32
|
+
function assertIsIntString(input, error = 'input is not an integer string') {
|
|
33
|
+
if (!(0, type_predicate_js_1.isIntString)(input)) {
|
|
34
|
+
throw getError(error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.assertIsIntString = assertIsIntString;
|
|
38
|
+
function assertIsLengthAware(input, error = 'input is not length aware') {
|
|
39
|
+
if (!(0, type_predicate_js_1.isLengthAware)(input)) {
|
|
40
|
+
throw getError(error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.assertIsLengthAware = assertIsLengthAware;
|
|
44
|
+
function assertIsNull(input, error = 'input is not null') {
|
|
45
|
+
if (!(0, type_predicate_js_1.isNull)(input)) {
|
|
46
|
+
throw getError(error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.assertIsNull = assertIsNull;
|
|
50
|
+
function assertIsNumber(input, error = 'input is not a number') {
|
|
51
|
+
if (!(0, type_predicate_js_1.isNumber)(input)) {
|
|
52
|
+
throw getError(error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.assertIsNumber = assertIsNumber;
|
|
56
|
+
function assertIsNumericString(input, error = 'input is not a numeric string') {
|
|
57
|
+
if (!(0, type_predicate_js_1.isNumericString)(input)) {
|
|
58
|
+
throw getError(error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.assertIsNumericString = assertIsNumericString;
|
|
62
|
+
function assertIsNumericValue(input, error = 'input is not a numerical value') {
|
|
63
|
+
if (!(0, type_predicate_js_1.isNumericValue)(input)) {
|
|
64
|
+
throw getError(error);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.assertIsNumericValue = assertIsNumericValue;
|
|
68
|
+
function assertIsNumericValueArray(input, error = 'input is not a numerical value array') {
|
|
18
69
|
if (!(0, type_predicate_js_1.isNumericValueArray)(input)) {
|
|
19
|
-
throw
|
|
70
|
+
throw getError(error);
|
|
20
71
|
}
|
|
21
72
|
}
|
|
22
73
|
exports.assertIsNumericValueArray = assertIsNumericValueArray;
|
|
74
|
+
function assertIsObject(input, error = 'input is not an object') {
|
|
75
|
+
if (!(0, type_predicate_js_1.isObject)(input)) {
|
|
76
|
+
throw getError(error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.assertIsObject = assertIsObject;
|
|
80
|
+
function assertIsOptionalBigInt(input, error = 'input is not an optional bigint') {
|
|
81
|
+
if (!(0, type_predicate_js_1.isOptionalBigInt)(input)) {
|
|
82
|
+
throw getError(error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.assertIsOptionalBigInt = assertIsOptionalBigInt;
|
|
86
|
+
function assertIsOptionalBoolean(input, error = 'input is not an optional boolean') {
|
|
87
|
+
if (!(0, type_predicate_js_1.isOptionalBoolean)(input)) {
|
|
88
|
+
throw getError(error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.assertIsOptionalBoolean = assertIsOptionalBoolean;
|
|
92
|
+
function assertIsOptionalNull(input, error = 'input is not an optional null') {
|
|
93
|
+
if (!(0, type_predicate_js_1.isOptionalNull)(input)) {
|
|
94
|
+
throw getError(error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.assertIsOptionalNull = assertIsOptionalNull;
|
|
98
|
+
function assertIsOptionalNumber(input, error = 'input is not an optional number') {
|
|
99
|
+
if (!(0, type_predicate_js_1.isOptionalNumber)(input)) {
|
|
100
|
+
throw getError(error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.assertIsOptionalNumber = assertIsOptionalNumber;
|
|
104
|
+
function assertIsOptionalString(input, error = 'input is not an optional string') {
|
|
105
|
+
if (!(0, type_predicate_js_1.isOptionalString)(input)) {
|
|
106
|
+
throw getError(error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.assertIsOptionalString = assertIsOptionalString;
|
|
110
|
+
function assertIsOptionalSymbol(input, error = 'input is not an optional symbol') {
|
|
111
|
+
if (!(0, type_predicate_js_1.isOptionalSymbol)(input)) {
|
|
112
|
+
throw getError(error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.assertIsOptionalSymbol = assertIsOptionalSymbol;
|
|
116
|
+
function assertIsPositiveFiniteNumber(input, error = 'input is not a positive finite number') {
|
|
117
|
+
if (!(0, type_predicate_js_1.isPositiveFiniteNumber)(input)) {
|
|
118
|
+
throw getError(error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.assertIsPositiveFiniteNumber = assertIsPositiveFiniteNumber;
|
|
122
|
+
function assertIsNumberGTEOne(input, error = 'input is not a number >= 1') {
|
|
123
|
+
if (!(0, type_predicate_js_1.isPositiveFiniteNumber)(input) || input < 1) {
|
|
124
|
+
throw getError(error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.assertIsNumberGTEOne = assertIsNumberGTEOne;
|
|
128
|
+
function assertIsPositiveInteger(input, error = 'input is not a positive integer') {
|
|
129
|
+
if (!(0, type_predicate_js_1.isPositiveInteger)(input)) {
|
|
130
|
+
throw getError(error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.assertIsPositiveInteger = assertIsPositiveInteger;
|
|
134
|
+
function assertIsPrimitive(input, error = 'input is not primitive') {
|
|
135
|
+
if (!(0, type_predicate_js_1.isPrimitive)(input)) {
|
|
136
|
+
throw getError(error);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.assertIsPrimitive = assertIsPrimitive;
|
|
140
|
+
function assertIsPromiseFulfilledResult(input, error = 'input is not a promise fulfilled result') {
|
|
141
|
+
if (!(0, type_predicate_js_1.isPromiseFulfilledResult)(input)) {
|
|
142
|
+
throw getError(error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.assertIsPromiseFulfilledResult = assertIsPromiseFulfilledResult;
|
|
146
|
+
function assertIsPromiseRejectedResult(input, error = 'input is not a promise rejected result') {
|
|
147
|
+
if (!(0, type_predicate_js_1.isPromiseRejectedResult)(input)) {
|
|
148
|
+
throw getError(error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.assertIsPromiseRejectedResult = assertIsPromiseRejectedResult;
|
|
152
|
+
function assertIsPropertyKey(input, error = 'input is not a property key') {
|
|
153
|
+
if (!(0, type_predicate_js_1.isPropertyKey)(input)) {
|
|
154
|
+
throw getError(error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.assertIsPropertyKey = assertIsPropertyKey;
|
|
158
|
+
function assertIsString(input, error = 'input is not a string') {
|
|
159
|
+
if (!(0, type_predicate_js_1.isString)(input)) {
|
|
160
|
+
throw getError(error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.assertIsString = assertIsString;
|
|
164
|
+
function assertIsStringMatching(input, pattern, error = 'input is not a string that matches the pattern') {
|
|
165
|
+
if (!(0, type_predicate_js_1.isStringMatching)(input, pattern)) {
|
|
166
|
+
throw getError(error);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.assertIsStringMatching = assertIsStringMatching;
|
|
170
|
+
function assertIsStringRecord(input, error = 'input is not a string record') {
|
|
171
|
+
if (!(0, type_predicate_js_1.isStringRecord)(input)) {
|
|
172
|
+
throw getError(error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.assertIsStringRecord = assertIsStringRecord;
|
|
176
|
+
function assertIsStringWithLength(input, error = 'input is not a string with length') {
|
|
177
|
+
if (!(0, type_predicate_js_1.isStringWithLength)(input)) {
|
|
178
|
+
throw getError(error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.assertIsStringWithLength = assertIsStringWithLength;
|
|
182
|
+
function assertIsSymbol(input, error = 'input is not a symbol') {
|
|
183
|
+
if (!(0, type_predicate_js_1.isSymbol)(input)) {
|
|
184
|
+
throw getError(error);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.assertIsSymbol = assertIsSymbol;
|
|
188
|
+
function assertIsUndefined(input, error = 'input is not undefined') {
|
|
189
|
+
if (!(0, type_predicate_js_1.isUndefined)(input)) {
|
|
190
|
+
throw getError(error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.assertIsUndefined = assertIsUndefined;
|
|
194
|
+
function assertExhaustive(_, error = 'Failed exhaustive check') {
|
|
195
|
+
throw getError(error);
|
|
196
|
+
}
|
|
197
|
+
exports.assertExhaustive = assertExhaustive;
|
|
23
198
|
//# sourceMappingURL=type-assertion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-assertion.js","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"type-assertion.js","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":";;;AAAA,2DA+B6B;AAI7B,SAAS,QAAQ,CAAC,KAAqB;IACrC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,SAAgB,cAAc,CAC5B,KAAc,EACd,QAAwB,uBAAuB;IAE/C,IAAI,CAAC,IAAA,4BAAQ,EAAC,KAAK,CAAC,EAAE;QACpB,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAPD,wCAOC;AAED,SAAgB,eAAe,CAC7B,KAAc,EACd,QAAwB,wBAAwB;IAEhD,IAAI,CAAC,IAAA,6BAAS,EAAC,KAAK,CAAC,EAAE;QACrB,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAPD,0CAOC;AAED,SAAgB,oBAAoB,CAClC,KAAc,EACd,QAAwB,8BAA8B;IAEtD,IAAI,CAAC,IAAA,kCAAc,EAAC,KAAK,CAAC,EAAE;QAC1B,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAPD,oDAOC;AAED,SAAgB,eAAe,CAC7B,KAAc,EACd,QAAwB,yBAAyB;IAEjD,IAAI,CAAC,IAAA,6BAAS,EAAC,KAAK,CAAC,EAAE;QACrB,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAPD,0CAOC;AAED,SAAgB,iBAAiB,CAC/B,KAAc,EACd,QAAwB,gCAAgC;IAExD,IAAI,CAAC,IAAA,+BAAW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C;AAED,SAAgB,gBAAgB,CAAC,CAAQ,EAAE,QAAwB,yBAAyB;IAC1F,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC;AAFD,4CAEC"}
|
|
@@ -1,14 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
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 = exports.maybeUndefined = 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 maybeUndefined = (predicate, input) => {
|
|
12
|
+
return typeof input === 'undefined' || predicate(input);
|
|
13
|
+
};
|
|
14
|
+
exports.maybeUndefined = maybeUndefined;
|
|
15
|
+
// Primitives
|
|
16
|
+
const isString = (input) => typeof input === 'string';
|
|
17
|
+
exports.isString = isString;
|
|
18
|
+
const isNumber = (input) => typeof input === 'number' && !Number.isNaN(input);
|
|
19
|
+
exports.isNumber = isNumber;
|
|
20
|
+
const isBigInt = (input) => typeof input === 'bigint';
|
|
21
|
+
exports.isBigInt = isBigInt;
|
|
22
|
+
const isBoolean = (input) => typeof input === 'boolean';
|
|
23
|
+
exports.isBoolean = isBoolean;
|
|
24
|
+
const isUndefined = (input) => typeof input === 'undefined';
|
|
25
|
+
exports.isUndefined = isUndefined;
|
|
26
|
+
const isSymbol = (input) => typeof input === 'symbol';
|
|
27
|
+
exports.isSymbol = isSymbol;
|
|
28
|
+
const isNull = (input) => input === null;
|
|
29
|
+
exports.isNull = isNull;
|
|
30
|
+
const isPrimitive = (input) => (0, exports.isString)(input) ||
|
|
31
|
+
(0, exports.isNumber)(input) ||
|
|
32
|
+
(0, exports.isBigInt)(input) ||
|
|
33
|
+
(0, exports.isBoolean)(input) ||
|
|
34
|
+
(0, exports.isUndefined)(input) ||
|
|
35
|
+
(0, exports.isSymbol)(input) ||
|
|
36
|
+
(0, exports.isNull)(input);
|
|
37
|
+
exports.isPrimitive = isPrimitive;
|
|
38
|
+
// Optional primitives
|
|
39
|
+
const isOptionalString = (input) => (0, exports.maybeUndefined)(exports.isString, input);
|
|
5
40
|
exports.isOptionalString = isOptionalString;
|
|
6
|
-
const isOptionalNumber = (input) => (
|
|
41
|
+
const isOptionalNumber = (input) => (0, exports.maybeUndefined)(exports.isNumber, input);
|
|
7
42
|
exports.isOptionalNumber = isOptionalNumber;
|
|
43
|
+
const isOptionalBigInt = (input) => (0, exports.maybeUndefined)(exports.isBigInt, input);
|
|
44
|
+
exports.isOptionalBigInt = isOptionalBigInt;
|
|
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;
|
|
51
|
+
// Primitives with extra checks
|
|
52
|
+
const isStringWithLength = (input) => typeof input === 'string' && input.length > 0;
|
|
53
|
+
exports.isStringWithLength = isStringWithLength;
|
|
8
54
|
const isStringMatching = (input, pattern) => typeof input === 'string' && pattern.test(input);
|
|
9
55
|
exports.isStringMatching = isStringMatching;
|
|
10
|
-
const isPropertyKey = (input) => typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
|
|
11
|
-
exports.isPropertyKey = isPropertyKey;
|
|
12
56
|
const isNumericString = (input) => (0, exports.isStringMatching)(input, /^[-+]?\d+(\.\d+)?$/);
|
|
13
57
|
exports.isNumericString = isNumericString;
|
|
14
58
|
const isNumericValue = (input) => typeof input === 'number' || typeof input === 'bigint' || (0, exports.isNumericString)(input);
|
|
@@ -17,7 +61,7 @@ const isNumericValueArray = (input) => Array.isArray(input) && input.every(expor
|
|
|
17
61
|
exports.isNumericValueArray = isNumericValueArray;
|
|
18
62
|
const isIntString = (input) => (0, exports.isStringMatching)(input, /^[-+]?\d+$/);
|
|
19
63
|
exports.isIntString = isIntString;
|
|
20
|
-
const isFiniteNumber = (input) =>
|
|
64
|
+
const isFiniteNumber = (input) => Number.isFinite(input);
|
|
21
65
|
exports.isFiniteNumber = isFiniteNumber;
|
|
22
66
|
const isInteger = (input) => Number.isInteger(input);
|
|
23
67
|
exports.isInteger = isInteger;
|
|
@@ -25,18 +69,23 @@ const isPositiveInteger = (input) => (0, exports.isInteger)(input) && input >= 0
|
|
|
25
69
|
exports.isPositiveInteger = isPositiveInteger;
|
|
26
70
|
const isPositiveFiniteNumber = (input) => (0, exports.isFiniteNumber)(input) && input >= 0;
|
|
27
71
|
exports.isPositiveFiniteNumber = isPositiveFiniteNumber;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
exports.isLengthAware = isLengthAware;
|
|
32
|
-
const isPrimitive = (input) => typeof input === 'string' ||
|
|
33
|
-
typeof input === 'number' ||
|
|
34
|
-
typeof input === 'bigint' ||
|
|
35
|
-
typeof input === 'boolean' ||
|
|
36
|
-
typeof input === 'undefined' ||
|
|
37
|
-
typeof input === 'symbol' ||
|
|
38
|
-
input === null;
|
|
39
|
-
exports.isPrimitive = isPrimitive;
|
|
72
|
+
// Common types
|
|
73
|
+
const isPropertyKey = (input) => typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
|
|
74
|
+
exports.isPropertyKey = isPropertyKey;
|
|
40
75
|
const isObject = (input) => input !== null && typeof input === 'object' && !Array.isArray(input);
|
|
41
76
|
exports.isObject = isObject;
|
|
77
|
+
const isLengthAware = (input) => input !== null && typeof input === 'object' && 'length' in input && typeof input.length === 'number';
|
|
78
|
+
exports.isLengthAware = isLengthAware;
|
|
79
|
+
const isStringRecord = (input) => {
|
|
80
|
+
return (0, exports.isObject)(input) && Object.entries(input).every(entry => entry.every(exports.isString));
|
|
81
|
+
};
|
|
82
|
+
exports.isStringRecord = isStringRecord;
|
|
83
|
+
const isPromiseFulfilledResult = (input) => {
|
|
84
|
+
return (0, exports.isObject)(input) && input.status === 'fulfilled';
|
|
85
|
+
};
|
|
86
|
+
exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
|
|
87
|
+
const isPromiseRejectedResult = (input) => {
|
|
88
|
+
return (0, exports.isObject)(input) && input.status === 'rejected' && 'reason' in input;
|
|
89
|
+
};
|
|
90
|
+
exports.isPromiseRejectedResult = isPromiseRejectedResult;
|
|
42
91
|
//# sourceMappingURL=type-predicate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":";;;AAEO,MAAM,
|
|
1
|
+
{"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":";;;AAEO,MAAM,qBAAqB,GAAG,CAA2C,UAAa,EAAsB,EAAE;IACnH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAEzC,OAAO,CAAC,KAAc,EAAc,EAAE;QACpC,OAAO,MAAM,CAAC,QAAQ,CAAC,KA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AAO,IAAA,gBAAQ,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC7E,CAAC,CAAC;AAFW,QAAA,uBAAuB,2BAElC"}
|
|
@@ -1,17 +1,163 @@
|
|
|
1
|
-
import { isNumericValueArray } from './type-predicate.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { isBigInt, isBoolean, isFiniteNumber, isInteger, isIntString, isLengthAware, isNull, isNumber, isNumericString, isNumericValue, isNumericValueArray, isObject, isOptionalBigInt, isOptionalBoolean, isOptionalNull, isOptionalNumber, isOptionalString, isOptionalSymbol, isPositiveFiniteNumber, isPositiveInteger, isPrimitive, isPromiseFulfilledResult, isPromiseRejectedResult, isPropertyKey, isString, isStringMatching, isStringRecord, isStringWithLength, isSymbol, isUndefined, } from './type-predicate.js';
|
|
2
|
+
function getError(error) {
|
|
3
|
+
return error instanceof Error ? error : new TypeError(error);
|
|
4
|
+
}
|
|
5
|
+
export function assertIsBigInt(input, error = 'input is not a bigint') {
|
|
6
|
+
if (!isBigInt(input)) {
|
|
7
|
+
throw getError(error);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function assertIsBoolean(input, error = 'input is not a boolean') {
|
|
11
|
+
if (!isBoolean(input)) {
|
|
12
|
+
throw getError(error);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function assertIsFiniteNumber(input, error = 'input is not a finite number') {
|
|
16
|
+
if (!isFiniteNumber(input)) {
|
|
17
|
+
throw getError(error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function assertIsInteger(input, error = 'input is not an integer') {
|
|
21
|
+
if (!isInteger(input)) {
|
|
22
|
+
throw getError(error);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function assertIsIntString(input, error = 'input is not an integer string') {
|
|
26
|
+
if (!isIntString(input)) {
|
|
27
|
+
throw getError(error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function assertIsLengthAware(input, error = 'input is not length aware') {
|
|
31
|
+
if (!isLengthAware(input)) {
|
|
32
|
+
throw getError(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function assertIsNull(input, error = 'input is not null') {
|
|
36
|
+
if (!isNull(input)) {
|
|
37
|
+
throw getError(error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function assertIsNumber(input, error = 'input is not a number') {
|
|
41
|
+
if (!isNumber(input)) {
|
|
42
|
+
throw getError(error);
|
|
5
43
|
}
|
|
6
44
|
}
|
|
7
|
-
export function
|
|
8
|
-
if (!
|
|
9
|
-
throw
|
|
45
|
+
export function assertIsNumericString(input, error = 'input is not a numeric string') {
|
|
46
|
+
if (!isNumericString(input)) {
|
|
47
|
+
throw getError(error);
|
|
10
48
|
}
|
|
11
49
|
}
|
|
12
|
-
export function
|
|
50
|
+
export function assertIsNumericValue(input, error = 'input is not a numerical value') {
|
|
51
|
+
if (!isNumericValue(input)) {
|
|
52
|
+
throw getError(error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function assertIsNumericValueArray(input, error = 'input is not a numerical value array') {
|
|
13
56
|
if (!isNumericValueArray(input)) {
|
|
14
|
-
throw
|
|
57
|
+
throw getError(error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export function assertIsObject(input, error = 'input is not an object') {
|
|
61
|
+
if (!isObject(input)) {
|
|
62
|
+
throw getError(error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function assertIsOptionalBigInt(input, error = 'input is not an optional bigint') {
|
|
66
|
+
if (!isOptionalBigInt(input)) {
|
|
67
|
+
throw getError(error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function assertIsOptionalBoolean(input, error = 'input is not an optional boolean') {
|
|
71
|
+
if (!isOptionalBoolean(input)) {
|
|
72
|
+
throw getError(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function assertIsOptionalNull(input, error = 'input is not an optional null') {
|
|
76
|
+
if (!isOptionalNull(input)) {
|
|
77
|
+
throw getError(error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export function assertIsOptionalNumber(input, error = 'input is not an optional number') {
|
|
81
|
+
if (!isOptionalNumber(input)) {
|
|
82
|
+
throw getError(error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function assertIsOptionalString(input, error = 'input is not an optional string') {
|
|
86
|
+
if (!isOptionalString(input)) {
|
|
87
|
+
throw getError(error);
|
|
15
88
|
}
|
|
16
89
|
}
|
|
90
|
+
export function assertIsOptionalSymbol(input, error = 'input is not an optional symbol') {
|
|
91
|
+
if (!isOptionalSymbol(input)) {
|
|
92
|
+
throw getError(error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function assertIsPositiveFiniteNumber(input, error = 'input is not a positive finite number') {
|
|
96
|
+
if (!isPositiveFiniteNumber(input)) {
|
|
97
|
+
throw getError(error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export function assertIsNumberGTEOne(input, error = 'input is not a number >= 1') {
|
|
101
|
+
if (!isPositiveFiniteNumber(input) || input < 1) {
|
|
102
|
+
throw getError(error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function assertIsPositiveInteger(input, error = 'input is not a positive integer') {
|
|
106
|
+
if (!isPositiveInteger(input)) {
|
|
107
|
+
throw getError(error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export function assertIsPrimitive(input, error = 'input is not primitive') {
|
|
111
|
+
if (!isPrimitive(input)) {
|
|
112
|
+
throw getError(error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function assertIsPromiseFulfilledResult(input, error = 'input is not a promise fulfilled result') {
|
|
116
|
+
if (!isPromiseFulfilledResult(input)) {
|
|
117
|
+
throw getError(error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function assertIsPromiseRejectedResult(input, error = 'input is not a promise rejected result') {
|
|
121
|
+
if (!isPromiseRejectedResult(input)) {
|
|
122
|
+
throw getError(error);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export function assertIsPropertyKey(input, error = 'input is not a property key') {
|
|
126
|
+
if (!isPropertyKey(input)) {
|
|
127
|
+
throw getError(error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export function assertIsString(input, error = 'input is not a string') {
|
|
131
|
+
if (!isString(input)) {
|
|
132
|
+
throw getError(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export function assertIsStringMatching(input, pattern, error = 'input is not a string that matches the pattern') {
|
|
136
|
+
if (!isStringMatching(input, pattern)) {
|
|
137
|
+
throw getError(error);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function assertIsStringRecord(input, error = 'input is not a string record') {
|
|
141
|
+
if (!isStringRecord(input)) {
|
|
142
|
+
throw getError(error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function assertIsStringWithLength(input, error = 'input is not a string with length') {
|
|
146
|
+
if (!isStringWithLength(input)) {
|
|
147
|
+
throw getError(error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export function assertIsSymbol(input, error = 'input is not a symbol') {
|
|
151
|
+
if (!isSymbol(input)) {
|
|
152
|
+
throw getError(error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export function assertIsUndefined(input, error = 'input is not undefined') {
|
|
156
|
+
if (!isUndefined(input)) {
|
|
157
|
+
throw getError(error);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export function assertExhaustive(_, error = 'Failed exhaustive check') {
|
|
161
|
+
throw getError(error);
|
|
162
|
+
}
|
|
17
163
|
//# sourceMappingURL=type-assertion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-assertion.js","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"type-assertion.js","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,cAAc,EACd,SAAS,EACT,WAAW,EACX,aAAa,EACb,MAAM,EACN,QAAQ,EACR,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,EACX,wBAAwB,EACxB,uBAAuB,EACvB,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAI7B,SAAS,QAAQ,CAAC,KAAqB;IACrC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,KAAc,EACd,QAAwB,uBAAuB;IAE/C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACpB,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,KAAc,EACd,QAAwB,wBAAwB;IAEhD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;QACrB,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,KAAc,EACd,QAAwB,8BAA8B;IAEtD,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;QAC1B,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,KAAc,EACd,QAAwB,yBAAyB;IAEjD,IAAI,CA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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
|
+
};
|
|
10
|
+
// Primitives
|
|
11
|
+
export const isString = (input) => typeof input === 'string';
|
|
12
|
+
export const isNumber = (input) => typeof input === 'number' && !Number.isNaN(input);
|
|
13
|
+
export const isBigInt = (input) => typeof input === 'bigint';
|
|
14
|
+
export const isBoolean = (input) => typeof input === 'boolean';
|
|
15
|
+
export const isUndefined = (input) => typeof input === 'undefined';
|
|
16
|
+
export const isSymbol = (input) => typeof input === 'symbol';
|
|
17
|
+
export const isNull = (input) => input === null;
|
|
18
|
+
export const isPrimitive = (input) => isString(input) ||
|
|
19
|
+
isNumber(input) ||
|
|
20
|
+
isBigInt(input) ||
|
|
21
|
+
isBoolean(input) ||
|
|
22
|
+
isUndefined(input) ||
|
|
23
|
+
isSymbol(input) ||
|
|
24
|
+
isNull(input);
|
|
25
|
+
// Optional primitives
|
|
26
|
+
export const isOptionalString = (input) => maybeUndefined(isString, input);
|
|
27
|
+
export const isOptionalNumber = (input) => maybeUndefined(isNumber, input);
|
|
28
|
+
export const isOptionalBigInt = (input) => maybeUndefined(isBigInt, input);
|
|
29
|
+
export const isOptionalBoolean = (input) => maybeUndefined(isBoolean, input);
|
|
30
|
+
export const isOptionalSymbol = (input) => maybeUndefined(isSymbol, input);
|
|
31
|
+
export const isOptionalNull = (input) => maybeUndefined(isNull, input);
|
|
32
|
+
// Primitives with extra checks
|
|
33
|
+
export const isStringWithLength = (input) => typeof input === 'string' && input.length > 0;
|
|
3
34
|
export const isStringMatching = (input, pattern) => typeof input === 'string' && pattern.test(input);
|
|
4
|
-
export const isPropertyKey = (input) => typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
|
|
5
35
|
export const isNumericString = (input) => isStringMatching(input, /^[-+]?\d+(\.\d+)?$/);
|
|
6
36
|
export const isNumericValue = (input) => typeof input === 'number' || typeof input === 'bigint' || isNumericString(input);
|
|
7
37
|
export const isNumericValueArray = (input) => Array.isArray(input) && input.every(isNumericValue);
|
|
8
38
|
export const isIntString = (input) => isStringMatching(input, /^[-+]?\d+$/);
|
|
9
|
-
export const isFiniteNumber = (input) =>
|
|
39
|
+
export const isFiniteNumber = (input) => Number.isFinite(input);
|
|
10
40
|
export const isInteger = (input) => Number.isInteger(input);
|
|
11
41
|
export const isPositiveInteger = (input) => isInteger(input) && input >= 0;
|
|
12
42
|
export const isPositiveFiniteNumber = (input) => isFiniteNumber(input) && input >= 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
typeof input === 'object' && input !== null && 'length' in input && typeof input.length === 'number';
|
|
16
|
-
export const isPrimitive = (input) => typeof input === 'string' ||
|
|
17
|
-
typeof input === 'number' ||
|
|
18
|
-
typeof input === 'bigint' ||
|
|
19
|
-
typeof input === 'boolean' ||
|
|
20
|
-
typeof input === 'undefined' ||
|
|
21
|
-
typeof input === 'symbol' ||
|
|
22
|
-
input === null;
|
|
43
|
+
// Common types
|
|
44
|
+
export const isPropertyKey = (input) => typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
|
|
23
45
|
export const isObject = (input) => input !== null && typeof input === 'object' && !Array.isArray(input);
|
|
46
|
+
export const isLengthAware = (input) => input !== null && typeof input === 'object' && 'length' in input && typeof input.length === 'number';
|
|
47
|
+
export const isStringRecord = (input) => {
|
|
48
|
+
return isObject(input) && Object.entries(input).every(entry => entry.every(isString));
|
|
49
|
+
};
|
|
50
|
+
export const isPromiseFulfilledResult = (input) => {
|
|
51
|
+
return isObject(input) && input.status === 'fulfilled';
|
|
52
|
+
};
|
|
53
|
+
export const isPromiseRejectedResult = (input) => {
|
|
54
|
+
return isObject(input) && input.status === 'rejected' && 'reason' in input;
|
|
55
|
+
};
|
|
24
56
|
//# sourceMappingURL=type-predicate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAA2C,UAAa,EAAsB,EAAE;IACnH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAEzC,OAAO,CAAC,KAAc,EAAc,EAAE;QACpC,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAI,SAA6B,EAAE,KAAc,EAA0B,EAAE;IACzG,OAAO,OAAO,KAAK,KAAK,WAAW,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF,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,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type { NumericString, NumericValue, Primitive, StringRecord, UnknownRecord } from './types.js';
|
|
2
|
+
export declare function assertIsBigInt(input: unknown, error?: string | Error): asserts input is bigint;
|
|
3
|
+
export declare function assertIsBoolean(input: unknown, error?: string | Error): asserts input is boolean;
|
|
4
|
+
export declare function assertIsFiniteNumber(input: unknown, error?: string | Error): asserts input is number;
|
|
5
|
+
export declare function assertIsInteger(input: unknown, error?: string | Error): asserts input is number;
|
|
6
|
+
export declare function assertIsIntString(input: unknown, error?: string | Error): asserts input is NumericString;
|
|
7
|
+
export declare function assertIsLengthAware(input: unknown, error?: string | Error): asserts input is {
|
|
8
|
+
length: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function assertIsNull(input: unknown, error?: string | Error): asserts input is null;
|
|
11
|
+
export declare function assertIsNumber(input: unknown, error?: string | Error): asserts input is number;
|
|
12
|
+
export declare function assertIsNumericString(input: unknown, error?: string | Error): asserts input is NumericString;
|
|
13
|
+
export declare function assertIsNumericValue(input: unknown, error?: string | Error): asserts input is NumericValue;
|
|
14
|
+
export declare function assertIsNumericValueArray(input: unknown, error?: string | Error): asserts input is NumericValue[];
|
|
15
|
+
export declare function assertIsObject<T extends UnknownRecord = UnknownRecord>(input: unknown, error?: string | Error): asserts input is T;
|
|
16
|
+
export declare function assertIsOptionalBigInt(input: unknown, error?: string | Error): asserts input is bigint | undefined;
|
|
17
|
+
export declare function assertIsOptionalBoolean(input: unknown, error?: string | Error): asserts input is boolean | undefined;
|
|
18
|
+
export declare function assertIsOptionalNull(input: unknown, error?: string | Error): asserts input is null | undefined;
|
|
19
|
+
export declare function assertIsOptionalNumber(input: unknown, error?: string | Error): asserts input is number | undefined;
|
|
20
|
+
export declare function assertIsOptionalString(input: unknown, error?: string | Error): asserts input is string | undefined;
|
|
21
|
+
export declare function assertIsOptionalSymbol(input: unknown, error?: string | Error): asserts input is symbol | undefined;
|
|
22
|
+
export declare function assertIsPositiveFiniteNumber(input: unknown, error?: string | Error): asserts input is number;
|
|
23
|
+
export declare function assertIsNumberGTEOne(input: unknown, error?: string | Error): asserts input is number;
|
|
24
|
+
export declare function assertIsPositiveInteger(input: unknown, error?: string | Error): asserts input is number;
|
|
25
|
+
export declare function assertIsPrimitive(input: unknown, error?: string | Error): asserts input is Primitive;
|
|
26
|
+
export declare function assertIsPromiseFulfilledResult<T>(input: unknown, error?: string | Error): asserts input is PromiseFulfilledResult<T>;
|
|
27
|
+
export declare function assertIsPromiseRejectedResult(input: unknown, error?: string | Error): asserts input is PromiseRejectedResult;
|
|
28
|
+
export declare function assertIsPropertyKey(input: unknown, error?: string | Error): asserts input is PropertyKey;
|
|
29
|
+
export declare function assertIsString(input: unknown, error?: string | Error): asserts input is string;
|
|
30
|
+
export declare function assertIsStringMatching(input: unknown, pattern: RegExp, error?: string | Error): asserts input is string;
|
|
31
|
+
export declare function assertIsStringRecord(input: unknown, error?: string | Error): asserts input is StringRecord;
|
|
32
|
+
export declare function assertIsStringWithLength(input: unknown, error?: string | Error): asserts input is string;
|
|
33
|
+
export declare function assertIsSymbol(input: unknown, error?: string | Error): asserts input is symbol;
|
|
34
|
+
export declare function assertIsUndefined(input: unknown, error?: string | Error): asserts input is undefined;
|
|
35
|
+
export declare function assertExhaustive(_: never, error?: string | Error): never;
|
|
5
36
|
//# sourceMappingURL=type-assertion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-assertion.d.ts","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-assertion.d.ts","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAMtG,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAA+B,GAC9C,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB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AI,MAAM,CAIzB;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAA+B,GAC9C,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAAgC,GAC/C,OAAO,CAAC,KAAK,IAAI,SAAS,CAI5B;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,GAAE,MAAM,GAAG,KAAiC,GAAG,KAAK,CAEnG"}
|
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
import type { NumericValue, Primitive, UnknownRecord } from './types.js';
|
|
1
|
+
import type { NumericValue, Primitive, StringRecord, TypePredicateFn, UnknownRecord } from './types.js';
|
|
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;
|
|
4
|
+
export declare const isString: (input: unknown) => input is string;
|
|
5
|
+
export declare const isNumber: (input: unknown) => input is number;
|
|
6
|
+
export declare const isBigInt: (input: unknown) => input is bigint;
|
|
7
|
+
export declare const isBoolean: (input: unknown) => input is boolean;
|
|
8
|
+
export declare const isUndefined: (input: unknown) => input is undefined;
|
|
9
|
+
export declare const isSymbol: (input: unknown) => input is symbol;
|
|
10
|
+
export declare const isNull: (input: unknown) => input is null;
|
|
11
|
+
export declare const isPrimitive: (input: unknown) => input is Primitive;
|
|
2
12
|
export declare const isOptionalString: (input: unknown) => input is string | undefined;
|
|
3
13
|
export declare const isOptionalNumber: (input: unknown) => input is number | undefined;
|
|
14
|
+
export declare const isOptionalBigInt: (input: unknown) => input is bigint | undefined;
|
|
15
|
+
export declare const isOptionalBoolean: (input: unknown) => input is boolean | undefined;
|
|
16
|
+
export declare const isOptionalSymbol: (input: unknown) => input is symbol | undefined;
|
|
17
|
+
export declare const isOptionalNull: (input: unknown) => input is null | undefined;
|
|
18
|
+
export declare const isStringWithLength: (input: unknown) => input is string;
|
|
4
19
|
export declare const isStringMatching: (input: unknown, pattern: RegExp) => input is string;
|
|
5
|
-
export declare const isPropertyKey: (input: unknown) => input is PropertyKey;
|
|
6
20
|
export declare const isNumericString: (input: unknown) => input is `${number}`;
|
|
7
21
|
export declare const isNumericValue: (input: unknown) => input is NumericValue;
|
|
8
22
|
export declare const isNumericValueArray: (input: unknown) => input is NumericValue[];
|
|
@@ -11,9 +25,12 @@ export declare const isFiniteNumber: (input: unknown) => input is number;
|
|
|
11
25
|
export declare const isInteger: (input: unknown) => input is number;
|
|
12
26
|
export declare const isPositiveInteger: (input: unknown) => input is number;
|
|
13
27
|
export declare const isPositiveFiniteNumber: (input: unknown) => input is number;
|
|
28
|
+
export declare const isPropertyKey: (input: unknown) => input is PropertyKey;
|
|
29
|
+
export declare const isObject: <T extends UnknownRecord = UnknownRecord>(input: unknown) => input is T;
|
|
14
30
|
export declare const isLengthAware: (input: unknown) => input is {
|
|
15
31
|
length: number;
|
|
16
32
|
};
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const
|
|
33
|
+
export declare const isStringRecord: (input: unknown) => input is StringRecord;
|
|
34
|
+
export declare const isPromiseFulfilledResult: <T>(input: unknown) => input is PromiseFulfilledResult<T>;
|
|
35
|
+
export declare const isPromiseRejectedResult: (input: unknown) => input is PromiseRejectedResult;
|
|
19
36
|
//# sourceMappingURL=type-predicate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-predicate.d.ts","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"type-predicate.d.ts","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"AAAA,OAAO,KAA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kE,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/dist/types/types.d.ts
CHANGED
|
@@ -18,4 +18,6 @@ export type RangeTuple<T> = [min: T, max: T];
|
|
|
18
18
|
export type RangeTupleDistributive<T> = T extends any ? [min: T, max: T] : never;
|
|
19
19
|
export type NumberRangeTuple = RangeTuple<number>;
|
|
20
20
|
export type KeyValueTuple<K extends PropertyKey = PropertyKey, V = unknown> = [key: K, value: V];
|
|
21
|
+
export type Predicate<A, T extends A = A> = ((value: T, index: number, array: readonly A[]) => value is T) | ((value: T, index: number, array: readonly A[]) => unknown);
|
|
22
|
+
export type TypePredicateFn<T> = (input: unknown) => input is T;
|
|
21
23
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAGvF,MAAM,MAAM,OAAO,GAAG,IAAI,GAAG,KAAK,GAAG,QAAQ,GAAG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AAG,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAEjG,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,IACpC,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,GAC9D,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC;AAEhE,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,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.19.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"jest": "^29.0.2",
|
|
122
122
|
"jest-environment-jsdom": "^29.0.2",
|
|
123
123
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
124
|
-
"lint-staged": "^13.
|
|
124
|
+
"lint-staged": "^13.1.0",
|
|
125
125
|
"prettier": "^2.6.2",
|
|
126
126
|
"rimraf": "^3.0.2",
|
|
127
127
|
"typescript": "^4.9.3"
|
package/src/type-assertion.ts
CHANGED
|
@@ -1,20 +1,319 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
isBigInt,
|
|
3
|
+
isBoolean,
|
|
4
|
+
isFiniteNumber,
|
|
5
|
+
isInteger,
|
|
6
|
+
isIntString,
|
|
7
|
+
isLengthAware,
|
|
8
|
+
isNull,
|
|
9
|
+
isNumber,
|
|
10
|
+
isNumericString,
|
|
11
|
+
isNumericValue,
|
|
12
|
+
isNumericValueArray,
|
|
13
|
+
isObject,
|
|
14
|
+
isOptionalBigInt,
|
|
15
|
+
isOptionalBoolean,
|
|
16
|
+
isOptionalNull,
|
|
17
|
+
isOptionalNumber,
|
|
18
|
+
isOptionalString,
|
|
19
|
+
isOptionalSymbol,
|
|
20
|
+
isPositiveFiniteNumber,
|
|
21
|
+
isPositiveInteger,
|
|
22
|
+
isPrimitive,
|
|
23
|
+
isPromiseFulfilledResult,
|
|
24
|
+
isPromiseRejectedResult,
|
|
25
|
+
isPropertyKey,
|
|
26
|
+
isString,
|
|
27
|
+
isStringMatching,
|
|
28
|
+
isStringRecord,
|
|
29
|
+
isStringWithLength,
|
|
30
|
+
isSymbol,
|
|
31
|
+
isUndefined,
|
|
32
|
+
} from './type-predicate.js';
|
|
3
33
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
34
|
+
import type { NumericString, NumericValue, Primitive, StringRecord, UnknownRecord } from './types.js';
|
|
35
|
+
|
|
36
|
+
function getError(error: string | Error): Error {
|
|
37
|
+
return error instanceof Error ? error : new TypeError(error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function assertIsBigInt(
|
|
41
|
+
input: unknown,
|
|
42
|
+
error: string | Error = 'input is not a bigint',
|
|
43
|
+
): asserts input is bigint {
|
|
44
|
+
if (!isBigInt(input)) {
|
|
45
|
+
throw getError(error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function assertIsBoolean(
|
|
50
|
+
input: unknown,
|
|
51
|
+
error: string | Error = 'input is not a boolean',
|
|
52
|
+
): asserts input is boolean {
|
|
53
|
+
if (!isBoolean(input)) {
|
|
54
|
+
throw getError(error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function assertIsFiniteNumber(
|
|
59
|
+
input: unknown,
|
|
60
|
+
error: string | Error = 'input is not a finite number',
|
|
61
|
+
): asserts input is number {
|
|
62
|
+
if (!isFiniteNumber(input)) {
|
|
63
|
+
throw getError(error);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function assertIsInteger(
|
|
68
|
+
input: unknown,
|
|
69
|
+
error: string | Error = 'input is not an integer',
|
|
70
|
+
): asserts input is number {
|
|
71
|
+
if (!isInteger(input)) {
|
|
72
|
+
throw getError(error);
|
|
7
73
|
}
|
|
8
74
|
}
|
|
9
75
|
|
|
10
|
-
export function
|
|
11
|
-
|
|
12
|
-
|
|
76
|
+
export function assertIsIntString(
|
|
77
|
+
input: unknown,
|
|
78
|
+
error: string | Error = 'input is not an integer string',
|
|
79
|
+
): asserts input is NumericString {
|
|
80
|
+
if (!isIntString(input)) {
|
|
81
|
+
throw getError(error);
|
|
13
82
|
}
|
|
14
83
|
}
|
|
15
84
|
|
|
16
|
-
export function
|
|
85
|
+
export function assertIsLengthAware(
|
|
86
|
+
input: unknown,
|
|
87
|
+
error: string | Error = 'input is not length aware',
|
|
88
|
+
): asserts input is { length: number } {
|
|
89
|
+
if (!isLengthAware(input)) {
|
|
90
|
+
throw getError(error);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function assertIsNull(input: unknown, error: string | Error = 'input is not null'): asserts input is null {
|
|
95
|
+
if (!isNull(input)) {
|
|
96
|
+
throw getError(error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function assertIsNumber(
|
|
101
|
+
input: unknown,
|
|
102
|
+
error: string | Error = 'input is not a number',
|
|
103
|
+
): asserts input is number {
|
|
104
|
+
if (!isNumber(input)) {
|
|
105
|
+
throw getError(error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function assertIsNumericString(
|
|
110
|
+
input: unknown,
|
|
111
|
+
error: string | Error = 'input is not a numeric string',
|
|
112
|
+
): asserts input is NumericString {
|
|
113
|
+
if (!isNumericString(input)) {
|
|
114
|
+
throw getError(error);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function assertIsNumericValue(
|
|
119
|
+
input: unknown,
|
|
120
|
+
error: string | Error = 'input is not a numerical value',
|
|
121
|
+
): asserts input is NumericValue {
|
|
122
|
+
if (!isNumericValue(input)) {
|
|
123
|
+
throw getError(error);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function assertIsNumericValueArray(
|
|
128
|
+
input: unknown,
|
|
129
|
+
error: string | Error = 'input is not a numerical value array',
|
|
130
|
+
): asserts input is NumericValue[] {
|
|
17
131
|
if (!isNumericValueArray(input)) {
|
|
18
|
-
throw
|
|
132
|
+
throw getError(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function assertIsObject<T extends UnknownRecord = UnknownRecord>(
|
|
137
|
+
input: unknown,
|
|
138
|
+
error: string | Error = 'input is not an object',
|
|
139
|
+
): asserts input is T {
|
|
140
|
+
if (!isObject<T>(input)) {
|
|
141
|
+
throw getError(error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function assertIsOptionalBigInt(
|
|
146
|
+
input: unknown,
|
|
147
|
+
error: string | Error = 'input is not an optional bigint',
|
|
148
|
+
): asserts input is bigint | undefined {
|
|
149
|
+
if (!isOptionalBigInt(input)) {
|
|
150
|
+
throw getError(error);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function assertIsOptionalBoolean(
|
|
155
|
+
input: unknown,
|
|
156
|
+
error: string | Error = 'input is not an optional boolean',
|
|
157
|
+
): asserts input is boolean | undefined {
|
|
158
|
+
if (!isOptionalBoolean(input)) {
|
|
159
|
+
throw getError(error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function assertIsOptionalNull(
|
|
164
|
+
input: unknown,
|
|
165
|
+
error: string | Error = 'input is not an optional null',
|
|
166
|
+
): asserts input is null | undefined {
|
|
167
|
+
if (!isOptionalNull(input)) {
|
|
168
|
+
throw getError(error);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function assertIsOptionalNumber(
|
|
173
|
+
input: unknown,
|
|
174
|
+
error: string | Error = 'input is not an optional number',
|
|
175
|
+
): asserts input is number | undefined {
|
|
176
|
+
if (!isOptionalNumber(input)) {
|
|
177
|
+
throw getError(error);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function assertIsOptionalString(
|
|
182
|
+
input: unknown,
|
|
183
|
+
error: string | Error = 'input is not an optional string',
|
|
184
|
+
): asserts input is string | undefined {
|
|
185
|
+
if (!isOptionalString(input)) {
|
|
186
|
+
throw getError(error);
|
|
19
187
|
}
|
|
20
188
|
}
|
|
189
|
+
|
|
190
|
+
export function assertIsOptionalSymbol(
|
|
191
|
+
input: unknown,
|
|
192
|
+
error: string | Error = 'input is not an optional symbol',
|
|
193
|
+
): asserts input is symbol | undefined {
|
|
194
|
+
if (!isOptionalSymbol(input)) {
|
|
195
|
+
throw getError(error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function assertIsPositiveFiniteNumber(
|
|
200
|
+
input: unknown,
|
|
201
|
+
error: string | Error = 'input is not a positive finite number',
|
|
202
|
+
): asserts input is number {
|
|
203
|
+
if (!isPositiveFiniteNumber(input)) {
|
|
204
|
+
throw getError(error);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function assertIsNumberGTEOne(
|
|
209
|
+
input: unknown,
|
|
210
|
+
error: string | Error = 'input is not a number >= 1',
|
|
211
|
+
): asserts input is number {
|
|
212
|
+
if (!isPositiveFiniteNumber(input) || input < 1) {
|
|
213
|
+
throw getError(error);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function assertIsPositiveInteger(
|
|
218
|
+
input: unknown,
|
|
219
|
+
error: string | Error = 'input is not a positive integer',
|
|
220
|
+
): asserts input is number {
|
|
221
|
+
if (!isPositiveInteger(input)) {
|
|
222
|
+
throw getError(error);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function assertIsPrimitive(
|
|
227
|
+
input: unknown,
|
|
228
|
+
error: string | Error = 'input is not primitive',
|
|
229
|
+
): asserts input is Primitive {
|
|
230
|
+
if (!isPrimitive(input)) {
|
|
231
|
+
throw getError(error);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function assertIsPromiseFulfilledResult<T>(
|
|
236
|
+
input: unknown,
|
|
237
|
+
error: string | Error = 'input is not a promise fulfilled result',
|
|
238
|
+
): asserts input is PromiseFulfilledResult<T> {
|
|
239
|
+
if (!isPromiseFulfilledResult(input)) {
|
|
240
|
+
throw getError(error);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function assertIsPromiseRejectedResult(
|
|
245
|
+
input: unknown,
|
|
246
|
+
error: string | Error = 'input is not a promise rejected result',
|
|
247
|
+
): asserts input is PromiseRejectedResult {
|
|
248
|
+
if (!isPromiseRejectedResult(input)) {
|
|
249
|
+
throw getError(error);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function assertIsPropertyKey(
|
|
254
|
+
input: unknown,
|
|
255
|
+
error: string | Error = 'input is not a property key',
|
|
256
|
+
): asserts input is PropertyKey {
|
|
257
|
+
if (!isPropertyKey(input)) {
|
|
258
|
+
throw getError(error);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function assertIsString(
|
|
263
|
+
input: unknown,
|
|
264
|
+
error: string | Error = 'input is not a string',
|
|
265
|
+
): asserts input is string {
|
|
266
|
+
if (!isString(input)) {
|
|
267
|
+
throw getError(error);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function assertIsStringMatching(
|
|
272
|
+
input: unknown,
|
|
273
|
+
pattern: RegExp,
|
|
274
|
+
error: string | Error = 'input is not a string that matches the pattern',
|
|
275
|
+
): asserts input is string {
|
|
276
|
+
if (!isStringMatching(input, pattern)) {
|
|
277
|
+
throw getError(error);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function assertIsStringRecord(
|
|
282
|
+
input: unknown,
|
|
283
|
+
error: string | Error = 'input is not a string record',
|
|
284
|
+
): asserts input is StringRecord {
|
|
285
|
+
if (!isStringRecord(input)) {
|
|
286
|
+
throw getError(error);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function assertIsStringWithLength(
|
|
291
|
+
input: unknown,
|
|
292
|
+
error: string | Error = 'input is not a string with length',
|
|
293
|
+
): asserts input is string {
|
|
294
|
+
if (!isStringWithLength(input)) {
|
|
295
|
+
throw getError(error);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function assertIsSymbol(
|
|
300
|
+
input: unknown,
|
|
301
|
+
error: string | Error = 'input is not a symbol',
|
|
302
|
+
): asserts input is symbol {
|
|
303
|
+
if (!isSymbol(input)) {
|
|
304
|
+
throw getError(error);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function assertIsUndefined(
|
|
309
|
+
input: unknown,
|
|
310
|
+
error: string | Error = 'input is not undefined',
|
|
311
|
+
): asserts input is undefined {
|
|
312
|
+
if (!isUndefined(input)) {
|
|
313
|
+
throw getError(error);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export function assertExhaustive(_: never, error: string | Error = 'Failed exhaustive check'): never {
|
|
318
|
+
throw getError(error);
|
|
319
|
+
}
|
package/src/type-predicate.ts
CHANGED
|
@@ -1,17 +1,63 @@
|
|
|
1
|
-
import type { NumericString, NumericValue, Primitive, UnknownRecord } from './types.js';
|
|
1
|
+
import type { NumericString, NumericValue, Primitive, StringRecord, TypePredicateFn, UnknownRecord } from './types.js';
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
3
|
+
export const createIsEnumPredicate = <E extends Record<string, unknown>, T = E>(enumObject: E): TypePredicateFn<T> => {
|
|
4
|
+
const values = Object.values(enumObject);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
return (input: unknown): input is T => {
|
|
7
|
+
return values.includes(input);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const maybeUndefined = <T>(predicate: TypePredicateFn<T>, input: unknown): input is T | undefined => {
|
|
12
|
+
return typeof input === 'undefined' || predicate(input);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Primitives
|
|
16
|
+
|
|
17
|
+
export const isString = (input: unknown): input is string => typeof input === 'string';
|
|
18
|
+
|
|
19
|
+
export const isNumber = (input: unknown): input is number => typeof input === 'number' && !Number.isNaN(input);
|
|
20
|
+
|
|
21
|
+
export const isBigInt = (input: unknown): input is bigint => typeof input === 'bigint';
|
|
22
|
+
|
|
23
|
+
export const isBoolean = (input: unknown): input is boolean => typeof input === 'boolean';
|
|
24
|
+
|
|
25
|
+
export const isUndefined = (input: unknown): input is undefined => typeof input === 'undefined';
|
|
26
|
+
|
|
27
|
+
export const isSymbol = (input: unknown): input is symbol => typeof input === 'symbol';
|
|
28
|
+
|
|
29
|
+
export const isNull = (input: unknown): input is null => input === null;
|
|
30
|
+
|
|
31
|
+
export const isPrimitive = (input: unknown): input is Primitive =>
|
|
32
|
+
isString(input) ||
|
|
33
|
+
isNumber(input) ||
|
|
34
|
+
isBigInt(input) ||
|
|
35
|
+
isBoolean(input) ||
|
|
36
|
+
isUndefined(input) ||
|
|
37
|
+
isSymbol(input) ||
|
|
38
|
+
isNull(input);
|
|
39
|
+
|
|
40
|
+
// Optional primitives
|
|
41
|
+
|
|
42
|
+
export const isOptionalString = (input: unknown): input is string | undefined => maybeUndefined(isString, input);
|
|
43
|
+
|
|
44
|
+
export const isOptionalNumber = (input: unknown): input is number | undefined => maybeUndefined(isNumber, input);
|
|
45
|
+
|
|
46
|
+
export const isOptionalBigInt = (input: unknown): input is bigint | undefined => maybeUndefined(isBigInt, input);
|
|
47
|
+
|
|
48
|
+
export const isOptionalBoolean = (input: unknown): input is boolean | undefined => maybeUndefined(isBoolean, input);
|
|
49
|
+
|
|
50
|
+
export const isOptionalSymbol = (input: unknown): input is symbol | undefined => maybeUndefined(isSymbol, input);
|
|
51
|
+
|
|
52
|
+
export const isOptionalNull = (input: unknown): input is null | undefined => maybeUndefined(isNull, input);
|
|
53
|
+
|
|
54
|
+
// Primitives with extra checks
|
|
55
|
+
|
|
56
|
+
export const isStringWithLength = (input: unknown): input is string => typeof input === 'string' && input.length > 0;
|
|
8
57
|
|
|
9
58
|
export const isStringMatching = (input: unknown, pattern: RegExp): input is string =>
|
|
10
59
|
typeof input === 'string' && pattern.test(input);
|
|
11
60
|
|
|
12
|
-
export const isPropertyKey = (input: unknown): input is PropertyKey =>
|
|
13
|
-
typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
|
|
14
|
-
|
|
15
61
|
export const isNumericString = (input: unknown): input is NumericString =>
|
|
16
62
|
isStringMatching(input, /^[-+]?\d+(\.\d+)?$/);
|
|
17
63
|
|
|
@@ -23,7 +69,7 @@ export const isNumericValueArray = (input: unknown): input is NumericValue[] =>
|
|
|
23
69
|
|
|
24
70
|
export const isIntString = (input: unknown): input is NumericString => isStringMatching(input, /^[-+]?\d+$/);
|
|
25
71
|
|
|
26
|
-
export const isFiniteNumber = (input: unknown): input is number =>
|
|
72
|
+
export const isFiniteNumber = (input: unknown): input is number => Number.isFinite(input);
|
|
27
73
|
|
|
28
74
|
export const isInteger = (input: unknown): input is number => Number.isInteger(input);
|
|
29
75
|
|
|
@@ -31,18 +77,25 @@ export const isPositiveInteger = (input: unknown): input is number => isInteger(
|
|
|
31
77
|
|
|
32
78
|
export const isPositiveFiniteNumber = (input: unknown): input is number => isFiniteNumber(input) && input >= 0;
|
|
33
79
|
|
|
34
|
-
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
typeof input === 'object' && input !== null && 'length' in input && typeof (input as any).length === 'number';
|
|
80
|
+
// Common types
|
|
37
81
|
|
|
38
|
-
export const
|
|
39
|
-
typeof input === 'string' ||
|
|
40
|
-
typeof input === 'number' ||
|
|
41
|
-
typeof input === 'bigint' ||
|
|
42
|
-
typeof input === 'boolean' ||
|
|
43
|
-
typeof input === 'undefined' ||
|
|
44
|
-
typeof input === 'symbol' ||
|
|
45
|
-
input === null;
|
|
82
|
+
export const isPropertyKey = (input: unknown): input is PropertyKey =>
|
|
83
|
+
typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
|
|
46
84
|
|
|
47
85
|
export const isObject = <T extends UnknownRecord = UnknownRecord>(input: unknown): input is T =>
|
|
48
86
|
input !== null && typeof input === 'object' && !Array.isArray(input);
|
|
87
|
+
|
|
88
|
+
export const isLengthAware = (input: unknown): input is { length: number } =>
|
|
89
|
+
input !== null && typeof input === 'object' && 'length' in input && typeof input.length === 'number';
|
|
90
|
+
|
|
91
|
+
export const isStringRecord = (input: unknown): input is StringRecord => {
|
|
92
|
+
return isObject(input) && Object.entries(input).every(entry => entry.every(isString));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const isPromiseFulfilledResult = <T>(input: unknown): input is PromiseFulfilledResult<T> => {
|
|
96
|
+
return isObject(input) && input.status === 'fulfilled';
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const isPromiseRejectedResult = (input: unknown): input is PromiseRejectedResult => {
|
|
100
|
+
return isObject(input) && input.status === 'rejected' && 'reason' in input;
|
|
101
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -40,3 +40,9 @@ export type RangeTupleDistributive<T> = T extends any ? [min: T, max: T] : never
|
|
|
40
40
|
export type NumberRangeTuple = RangeTuple<number>;
|
|
41
41
|
|
|
42
42
|
export type KeyValueTuple<K extends PropertyKey = PropertyKey, V = unknown> = [key: K, value: V];
|
|
43
|
+
|
|
44
|
+
export type Predicate<A, T extends A = A> =
|
|
45
|
+
| ((value: T, index: number, array: readonly A[]) => value is T)
|
|
46
|
+
| ((value: T, index: number, array: readonly A[]) => unknown);
|
|
47
|
+
|
|
48
|
+
export type TypePredicateFn<T> = (input: unknown) => input is T;
|