is-kit 1.6.0 → 1.6.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/index.js +17 -17
- package/dist/index.mjs +17 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -111,24 +111,24 @@ var toBooleanPredicates = (predicates) => predicates;
|
|
|
111
111
|
|
|
112
112
|
// src/core/logic.ts
|
|
113
113
|
function and(precondition, condition) {
|
|
114
|
-
return (input) => {
|
|
114
|
+
return define((input) => {
|
|
115
115
|
if (precondition(input)) {
|
|
116
116
|
return condition(input);
|
|
117
117
|
}
|
|
118
118
|
return false;
|
|
119
|
-
};
|
|
119
|
+
});
|
|
120
120
|
}
|
|
121
121
|
function andAll(precondition, ...steps) {
|
|
122
|
-
return (input) => {
|
|
122
|
+
return define((input) => {
|
|
123
123
|
if (!precondition(input)) return false;
|
|
124
124
|
return applyRefinements(input, steps);
|
|
125
|
-
};
|
|
125
|
+
});
|
|
126
126
|
}
|
|
127
127
|
function or(...guards) {
|
|
128
128
|
const predicates = toBooleanPredicates(guards);
|
|
129
|
-
return (
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
return define(
|
|
130
|
+
(input) => predicates.some((guard) => guard(input))
|
|
131
|
+
);
|
|
132
132
|
}
|
|
133
133
|
function guardIn() {
|
|
134
134
|
return (guard) => (input) => guard(input);
|
|
@@ -296,13 +296,13 @@ var isPrimitive = or(
|
|
|
296
296
|
|
|
297
297
|
// src/core/combinators/array.ts
|
|
298
298
|
function arrayOf(elementGuard) {
|
|
299
|
-
return (input) => {
|
|
299
|
+
return define((input) => {
|
|
300
300
|
if (!Array.isArray(input)) return false;
|
|
301
301
|
for (const element of input) {
|
|
302
302
|
if (!elementGuard(element)) return false;
|
|
303
303
|
}
|
|
304
304
|
return true;
|
|
305
|
-
};
|
|
305
|
+
});
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
// src/core/combinators/set.ts
|
|
@@ -330,11 +330,11 @@ function mapOf(keyGuard, valueGuard) {
|
|
|
330
330
|
|
|
331
331
|
// src/core/combinators/tuple.ts
|
|
332
332
|
function tupleOf(...guards) {
|
|
333
|
-
return (input) => {
|
|
333
|
+
return define((input) => {
|
|
334
334
|
return Array.isArray(input) && input.length === guards.length && guards.every(
|
|
335
335
|
(guard, index) => guard(input[index])
|
|
336
336
|
);
|
|
337
|
-
};
|
|
337
|
+
});
|
|
338
338
|
}
|
|
339
339
|
|
|
340
340
|
// src/core/combinators/one-of.ts
|
|
@@ -391,14 +391,14 @@ function struct(schema, options) {
|
|
|
391
391
|
requiredEntries.push([key, field]);
|
|
392
392
|
}
|
|
393
393
|
const allowed = options?.exact ? new Set(schemaKeys) : null;
|
|
394
|
-
return (input) => {
|
|
394
|
+
return define((input) => {
|
|
395
395
|
if (!isPlainObject(input)) return false;
|
|
396
396
|
const obj = input;
|
|
397
397
|
if (!hasRequiredKeys(obj, requiredEntries)) return false;
|
|
398
398
|
if (!hasValidOptionalKeys(obj, optionalEntries)) return false;
|
|
399
399
|
if (!allowed) return true;
|
|
400
400
|
return hasOnlyAllowedKeys(obj, allowed);
|
|
401
|
-
};
|
|
401
|
+
});
|
|
402
402
|
}
|
|
403
403
|
|
|
404
404
|
// src/core/combinators/one-of-values.ts
|
|
@@ -412,9 +412,9 @@ var isZeroNumber = and(
|
|
|
412
412
|
);
|
|
413
413
|
var normalizeValues = (args) => isSingleArrayArg(args) ? args[0] : args;
|
|
414
414
|
var createLinearPredicate = (items) => {
|
|
415
|
-
return (input) => {
|
|
415
|
+
return define((input) => {
|
|
416
416
|
return items.some((value) => Object.is(value, input));
|
|
417
|
-
};
|
|
417
|
+
});
|
|
418
418
|
};
|
|
419
419
|
var createSetPredicate = (items) => {
|
|
420
420
|
let hasPositiveZero = false;
|
|
@@ -428,12 +428,12 @@ var createSetPredicate = (items) => {
|
|
|
428
428
|
valueSet.add(literalValue);
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
|
-
return (input) => {
|
|
431
|
+
return define((input) => {
|
|
432
432
|
if (isZeroNumber(input)) {
|
|
433
433
|
return Object.is(input, -0) ? hasNegativeZero : hasPositiveZero;
|
|
434
434
|
}
|
|
435
435
|
return valueSet.has(input);
|
|
436
|
-
};
|
|
436
|
+
});
|
|
437
437
|
};
|
|
438
438
|
function oneOfValues(...args) {
|
|
439
439
|
const items = normalizeValues(args);
|
package/dist/index.mjs
CHANGED
|
@@ -18,24 +18,24 @@ var toBooleanPredicates = (predicates) => predicates;
|
|
|
18
18
|
|
|
19
19
|
// src/core/logic.ts
|
|
20
20
|
function and(precondition, condition) {
|
|
21
|
-
return (input) => {
|
|
21
|
+
return define((input) => {
|
|
22
22
|
if (precondition(input)) {
|
|
23
23
|
return condition(input);
|
|
24
24
|
}
|
|
25
25
|
return false;
|
|
26
|
-
};
|
|
26
|
+
});
|
|
27
27
|
}
|
|
28
28
|
function andAll(precondition, ...steps) {
|
|
29
|
-
return (input) => {
|
|
29
|
+
return define((input) => {
|
|
30
30
|
if (!precondition(input)) return false;
|
|
31
31
|
return applyRefinements(input, steps);
|
|
32
|
-
};
|
|
32
|
+
});
|
|
33
33
|
}
|
|
34
34
|
function or(...guards) {
|
|
35
35
|
const predicates = toBooleanPredicates(guards);
|
|
36
|
-
return (
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
return define(
|
|
37
|
+
(input) => predicates.some((guard) => guard(input))
|
|
38
|
+
);
|
|
39
39
|
}
|
|
40
40
|
function guardIn() {
|
|
41
41
|
return (guard) => (input) => guard(input);
|
|
@@ -203,13 +203,13 @@ var isPrimitive = or(
|
|
|
203
203
|
|
|
204
204
|
// src/core/combinators/array.ts
|
|
205
205
|
function arrayOf(elementGuard) {
|
|
206
|
-
return (input) => {
|
|
206
|
+
return define((input) => {
|
|
207
207
|
if (!Array.isArray(input)) return false;
|
|
208
208
|
for (const element of input) {
|
|
209
209
|
if (!elementGuard(element)) return false;
|
|
210
210
|
}
|
|
211
211
|
return true;
|
|
212
|
-
};
|
|
212
|
+
});
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
// src/core/combinators/set.ts
|
|
@@ -237,11 +237,11 @@ function mapOf(keyGuard, valueGuard) {
|
|
|
237
237
|
|
|
238
238
|
// src/core/combinators/tuple.ts
|
|
239
239
|
function tupleOf(...guards) {
|
|
240
|
-
return (input) => {
|
|
240
|
+
return define((input) => {
|
|
241
241
|
return Array.isArray(input) && input.length === guards.length && guards.every(
|
|
242
242
|
(guard, index) => guard(input[index])
|
|
243
243
|
);
|
|
244
|
-
};
|
|
244
|
+
});
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
// src/core/combinators/one-of.ts
|
|
@@ -298,14 +298,14 @@ function struct(schema, options) {
|
|
|
298
298
|
requiredEntries.push([key, field]);
|
|
299
299
|
}
|
|
300
300
|
const allowed = options?.exact ? new Set(schemaKeys) : null;
|
|
301
|
-
return (input) => {
|
|
301
|
+
return define((input) => {
|
|
302
302
|
if (!isPlainObject(input)) return false;
|
|
303
303
|
const obj = input;
|
|
304
304
|
if (!hasRequiredKeys(obj, requiredEntries)) return false;
|
|
305
305
|
if (!hasValidOptionalKeys(obj, optionalEntries)) return false;
|
|
306
306
|
if (!allowed) return true;
|
|
307
307
|
return hasOnlyAllowedKeys(obj, allowed);
|
|
308
|
-
};
|
|
308
|
+
});
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
// src/core/combinators/one-of-values.ts
|
|
@@ -319,9 +319,9 @@ var isZeroNumber = and(
|
|
|
319
319
|
);
|
|
320
320
|
var normalizeValues = (args) => isSingleArrayArg(args) ? args[0] : args;
|
|
321
321
|
var createLinearPredicate = (items) => {
|
|
322
|
-
return (input) => {
|
|
322
|
+
return define((input) => {
|
|
323
323
|
return items.some((value) => Object.is(value, input));
|
|
324
|
-
};
|
|
324
|
+
});
|
|
325
325
|
};
|
|
326
326
|
var createSetPredicate = (items) => {
|
|
327
327
|
let hasPositiveZero = false;
|
|
@@ -335,12 +335,12 @@ var createSetPredicate = (items) => {
|
|
|
335
335
|
valueSet.add(literalValue);
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
|
-
return (input) => {
|
|
338
|
+
return define((input) => {
|
|
339
339
|
if (isZeroNumber(input)) {
|
|
340
340
|
return Object.is(input, -0) ? hasNegativeZero : hasPositiveZero;
|
|
341
341
|
}
|
|
342
342
|
return valueSet.has(input);
|
|
343
|
-
};
|
|
343
|
+
});
|
|
344
344
|
};
|
|
345
345
|
function oneOfValues(...args) {
|
|
346
346
|
const items = normalizeValues(args);
|