is-kit 1.7.0 → 1.7.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.d.mts +149 -149
- package/dist/index.d.ts +149 -149
- package/dist/index.js +162 -162
- package/dist/index.mjs +162 -162
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -97,14 +97,6 @@ __export(index_exports, {
|
|
|
97
97
|
});
|
|
98
98
|
module.exports = __toCommonJS(index_exports);
|
|
99
99
|
|
|
100
|
-
// src/core/define.ts
|
|
101
|
-
function define(fn) {
|
|
102
|
-
return (value) => !!fn(value);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// src/core/predicate.ts
|
|
106
|
-
var predicateToRefine = (fn) => (value) => fn(value);
|
|
107
|
-
|
|
108
100
|
// src/core/assert.ts
|
|
109
101
|
var DEFAULT_ASSERT_MESSAGE = "Assertion failed";
|
|
110
102
|
function assert(fn, value, message) {
|
|
@@ -112,94 +104,9 @@ function assert(fn, value, message) {
|
|
|
112
104
|
throw new Error(message ?? DEFAULT_ASSERT_MESSAGE);
|
|
113
105
|
}
|
|
114
106
|
|
|
115
|
-
// src/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (!predicate(value)) return false;
|
|
119
|
-
}
|
|
120
|
-
return true;
|
|
121
|
-
};
|
|
122
|
-
var everyTupleValue = (values, predicates) => {
|
|
123
|
-
if (values.length !== predicates.length) return false;
|
|
124
|
-
for (const [index, predicate] of predicates.entries()) {
|
|
125
|
-
if (!predicate(values[index])) return false;
|
|
126
|
-
}
|
|
127
|
-
return true;
|
|
128
|
-
};
|
|
129
|
-
var everySetValue = (values, predicate) => {
|
|
130
|
-
for (const value of values) {
|
|
131
|
-
if (!predicate(value)) return false;
|
|
132
|
-
}
|
|
133
|
-
return true;
|
|
134
|
-
};
|
|
135
|
-
var everyMapEntry = (values, keyPredicate, valuePredicate) => {
|
|
136
|
-
for (const [key, value] of values) {
|
|
137
|
-
if (!keyPredicate(key) || !valuePredicate(value)) return false;
|
|
138
|
-
}
|
|
139
|
-
return true;
|
|
140
|
-
};
|
|
141
|
-
var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => {
|
|
142
|
-
for (const key of Object.keys(values)) {
|
|
143
|
-
if (!keyPredicate(key) || !valuePredicate(values[key])) return false;
|
|
144
|
-
}
|
|
145
|
-
return true;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// src/utils/to-boolean-predicates.ts
|
|
149
|
-
var toBooleanPredicates = (predicates) => predicates;
|
|
150
|
-
|
|
151
|
-
// src/core/logic.ts
|
|
152
|
-
function and(precondition, condition) {
|
|
153
|
-
return define((input) => {
|
|
154
|
-
if (precondition(input)) {
|
|
155
|
-
return condition(input);
|
|
156
|
-
}
|
|
157
|
-
return false;
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
function andAll(precondition, ...steps) {
|
|
161
|
-
return define((input) => {
|
|
162
|
-
if (!precondition(input)) return false;
|
|
163
|
-
return applyRefinements(input, steps);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
function or(...guards) {
|
|
167
|
-
const predicates = toBooleanPredicates(guards);
|
|
168
|
-
return define(
|
|
169
|
-
(input) => predicates.some((guard) => guard(input))
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
function guardIn() {
|
|
173
|
-
return (guard) => (input) => guard(input);
|
|
174
|
-
}
|
|
175
|
-
function not(fn) {
|
|
176
|
-
return (input) => !fn(input);
|
|
177
|
-
}
|
|
178
|
-
function applyRefinements(value, steps) {
|
|
179
|
-
if (!steps || steps.length === 0) return true;
|
|
180
|
-
for (const step of steps) {
|
|
181
|
-
if (!step(value)) return false;
|
|
182
|
-
}
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// src/core/nullish.ts
|
|
187
|
-
var allowWhen = (acceptedValue, predicate) => (value) => acceptedValue(value) || predicate(value);
|
|
188
|
-
var requireWhen = (rejectedValue, predicate) => (value) => !rejectedValue(value) && predicate(value);
|
|
189
|
-
function nullable(fn) {
|
|
190
|
-
return allowWhen((value) => value === null, fn);
|
|
191
|
-
}
|
|
192
|
-
function nonNull(fn) {
|
|
193
|
-
return requireWhen((value) => value === null, fn);
|
|
194
|
-
}
|
|
195
|
-
function nullish(fn) {
|
|
196
|
-
return allowWhen((value) => value == null, fn);
|
|
197
|
-
}
|
|
198
|
-
function optional(fn) {
|
|
199
|
-
return allowWhen((value) => value === void 0, fn);
|
|
200
|
-
}
|
|
201
|
-
function required(fn) {
|
|
202
|
-
return requireWhen((value) => value === void 0, fn);
|
|
107
|
+
// src/core/define.ts
|
|
108
|
+
function define(fn) {
|
|
109
|
+
return (value) => !!fn(value);
|
|
203
110
|
}
|
|
204
111
|
|
|
205
112
|
// src/utils/object-tags.ts
|
|
@@ -297,6 +204,117 @@ function equalsKey(key, target) {
|
|
|
297
204
|
return (input) => hasMatchingKey(input);
|
|
298
205
|
}
|
|
299
206
|
|
|
207
|
+
// src/core/key.ts
|
|
208
|
+
var hasKey = (key) => define(
|
|
209
|
+
(input) => isObject(input) && Object.hasOwn(input, key)
|
|
210
|
+
);
|
|
211
|
+
var hasKeys = (...keys) => {
|
|
212
|
+
if (keys.length === 0) {
|
|
213
|
+
return define(() => false);
|
|
214
|
+
}
|
|
215
|
+
return define(
|
|
216
|
+
(input) => isObject(input) && keys.every((key) => Object.hasOwn(input, key))
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
function narrowKeyTo(guard, key) {
|
|
220
|
+
return (target) => {
|
|
221
|
+
const keyEquals = equalsKey(key, target);
|
|
222
|
+
return define(
|
|
223
|
+
(input) => guard(input) && keyEquals(input)
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/utils/guard-collections.ts
|
|
229
|
+
var everyArrayValue = (values, predicate) => {
|
|
230
|
+
for (const value of values) {
|
|
231
|
+
if (!predicate(value)) return false;
|
|
232
|
+
}
|
|
233
|
+
return true;
|
|
234
|
+
};
|
|
235
|
+
var everyTupleValue = (values, predicates) => {
|
|
236
|
+
if (values.length !== predicates.length) return false;
|
|
237
|
+
for (const [index, predicate] of predicates.entries()) {
|
|
238
|
+
if (!predicate(values[index])) return false;
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
};
|
|
242
|
+
var everySetValue = (values, predicate) => {
|
|
243
|
+
for (const value of values) {
|
|
244
|
+
if (!predicate(value)) return false;
|
|
245
|
+
}
|
|
246
|
+
return true;
|
|
247
|
+
};
|
|
248
|
+
var everyMapEntry = (values, keyPredicate, valuePredicate) => {
|
|
249
|
+
for (const [key, value] of values) {
|
|
250
|
+
if (!keyPredicate(key) || !valuePredicate(value)) return false;
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
};
|
|
254
|
+
var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => {
|
|
255
|
+
for (const key of Object.keys(values)) {
|
|
256
|
+
if (!keyPredicate(key) || !valuePredicate(values[key])) return false;
|
|
257
|
+
}
|
|
258
|
+
return true;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// src/utils/to-boolean-predicates.ts
|
|
262
|
+
var toBooleanPredicates = (predicates) => predicates;
|
|
263
|
+
|
|
264
|
+
// src/core/logic.ts
|
|
265
|
+
function and(precondition, condition) {
|
|
266
|
+
return define((input) => {
|
|
267
|
+
if (precondition(input)) {
|
|
268
|
+
return condition(input);
|
|
269
|
+
}
|
|
270
|
+
return false;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function andAll(precondition, ...steps) {
|
|
274
|
+
return define((input) => {
|
|
275
|
+
if (!precondition(input)) return false;
|
|
276
|
+
return applyRefinements(input, steps);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function or(...guards) {
|
|
280
|
+
const predicates = toBooleanPredicates(guards);
|
|
281
|
+
return define(
|
|
282
|
+
(input) => predicates.some((guard) => guard(input))
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
function guardIn() {
|
|
286
|
+
return (guard) => (input) => guard(input);
|
|
287
|
+
}
|
|
288
|
+
function not(fn) {
|
|
289
|
+
return (input) => !fn(input);
|
|
290
|
+
}
|
|
291
|
+
function applyRefinements(value, steps) {
|
|
292
|
+
if (!steps || steps.length === 0) return true;
|
|
293
|
+
for (const step of steps) {
|
|
294
|
+
if (!step(value)) return false;
|
|
295
|
+
}
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/core/nullish.ts
|
|
300
|
+
var allowWhen = (acceptedValue, predicate) => (value) => acceptedValue(value) || predicate(value);
|
|
301
|
+
var requireWhen = (rejectedValue, predicate) => (value) => !rejectedValue(value) && predicate(value);
|
|
302
|
+
function nullable(fn) {
|
|
303
|
+
return allowWhen((value) => value === null, fn);
|
|
304
|
+
}
|
|
305
|
+
function nonNull(fn) {
|
|
306
|
+
return requireWhen((value) => value === null, fn);
|
|
307
|
+
}
|
|
308
|
+
function nullish(fn) {
|
|
309
|
+
return allowWhen((value) => value == null, fn);
|
|
310
|
+
}
|
|
311
|
+
function optional(fn) {
|
|
312
|
+
return allowWhen((value) => value === void 0, fn);
|
|
313
|
+
}
|
|
314
|
+
function required(fn) {
|
|
315
|
+
return requireWhen((value) => value === void 0, fn);
|
|
316
|
+
}
|
|
317
|
+
|
|
300
318
|
// src/core/parse.ts
|
|
301
319
|
function safeParse(fn, value) {
|
|
302
320
|
const valid = fn(value);
|
|
@@ -306,6 +324,9 @@ function safeParseWith(fn) {
|
|
|
306
324
|
return (value) => safeParse(fn, value);
|
|
307
325
|
}
|
|
308
326
|
|
|
327
|
+
// src/core/predicate.ts
|
|
328
|
+
var predicateToRefine = (fn) => (value) => fn(value);
|
|
329
|
+
|
|
309
330
|
// src/core/primitive.ts
|
|
310
331
|
var isString = define((value) => typeof value === "string");
|
|
311
332
|
var isNumberPrimitive = define(
|
|
@@ -359,13 +380,6 @@ function nonEmptyArrayOf(elementGuard) {
|
|
|
359
380
|
);
|
|
360
381
|
}
|
|
361
382
|
|
|
362
|
-
// src/core/combinators/set.ts
|
|
363
|
-
function setOf(valueGuard) {
|
|
364
|
-
return define(
|
|
365
|
-
(input) => isSet(input) && everySetValue(input, valueGuard)
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
383
|
// src/core/combinators/map.ts
|
|
370
384
|
function mapOf(keyGuard, valueGuard) {
|
|
371
385
|
return define(
|
|
@@ -373,18 +387,46 @@ function mapOf(keyGuard, valueGuard) {
|
|
|
373
387
|
);
|
|
374
388
|
}
|
|
375
389
|
|
|
376
|
-
// src/core/combinators/tuple.ts
|
|
377
|
-
function tupleOf(...guards) {
|
|
378
|
-
return define(
|
|
379
|
-
(input) => Array.isArray(input) && everyTupleValue(input, guards)
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
390
|
// src/core/combinators/one-of.ts
|
|
384
391
|
function oneOf(...guards) {
|
|
385
392
|
return or(...guards);
|
|
386
393
|
}
|
|
387
394
|
|
|
395
|
+
// src/core/combinators/one-of-values.ts
|
|
396
|
+
var ONE_OF_VALUES_LINEAR_SCAN_MAX = 8;
|
|
397
|
+
var isSingleArrayArg = define(
|
|
398
|
+
(value) => Array.isArray(value) && value.length === 1 && Array.isArray(value[0])
|
|
399
|
+
);
|
|
400
|
+
var normalizeValues = (args) => isSingleArrayArg(args) ? args[0] : args;
|
|
401
|
+
var createLinearPredicate = (items) => {
|
|
402
|
+
return define((input) => {
|
|
403
|
+
return items.some((value) => Object.is(value, input));
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
var createSetPredicate = (items) => {
|
|
407
|
+
let hasPositiveZero = false;
|
|
408
|
+
let hasNegativeZero = false;
|
|
409
|
+
const valueSet = /* @__PURE__ */ new Set();
|
|
410
|
+
for (const literalValue of items) {
|
|
411
|
+
if (isZero(literalValue)) {
|
|
412
|
+
if (Object.is(literalValue, -0)) hasNegativeZero = true;
|
|
413
|
+
else hasPositiveZero = true;
|
|
414
|
+
} else {
|
|
415
|
+
valueSet.add(literalValue);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return define((input) => {
|
|
419
|
+
if (isZero(input)) {
|
|
420
|
+
return Object.is(input, -0) ? hasNegativeZero : hasPositiveZero;
|
|
421
|
+
}
|
|
422
|
+
return valueSet.has(input);
|
|
423
|
+
});
|
|
424
|
+
};
|
|
425
|
+
function oneOfValues(...args) {
|
|
426
|
+
const items = normalizeValues(args);
|
|
427
|
+
return items.length <= ONE_OF_VALUES_LINEAR_SCAN_MAX ? createLinearPredicate(items) : createSetPredicate(items);
|
|
428
|
+
}
|
|
429
|
+
|
|
388
430
|
// src/core/combinators/record.ts
|
|
389
431
|
function recordOf(keyFunction, valueFunction) {
|
|
390
432
|
return define(
|
|
@@ -392,6 +434,13 @@ function recordOf(keyFunction, valueFunction) {
|
|
|
392
434
|
);
|
|
393
435
|
}
|
|
394
436
|
|
|
437
|
+
// src/core/combinators/set.ts
|
|
438
|
+
function setOf(valueGuard) {
|
|
439
|
+
return define(
|
|
440
|
+
(input) => isSet(input) && everySetValue(input, valueGuard)
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
|
|
395
444
|
// src/core/combinators/struct.ts
|
|
396
445
|
var isOptionalSchemaField = define(
|
|
397
446
|
// WHY: Optional fields are represented as a small tagged object so `struct`
|
|
@@ -435,60 +484,11 @@ function struct(schema, options) {
|
|
|
435
484
|
});
|
|
436
485
|
}
|
|
437
486
|
|
|
438
|
-
// src/core/combinators/
|
|
439
|
-
|
|
440
|
-
var isSingleArrayArg = define(
|
|
441
|
-
(value) => Array.isArray(value) && value.length === 1 && Array.isArray(value[0])
|
|
442
|
-
);
|
|
443
|
-
var normalizeValues = (args) => isSingleArrayArg(args) ? args[0] : args;
|
|
444
|
-
var createLinearPredicate = (items) => {
|
|
445
|
-
return define((input) => {
|
|
446
|
-
return items.some((value) => Object.is(value, input));
|
|
447
|
-
});
|
|
448
|
-
};
|
|
449
|
-
var createSetPredicate = (items) => {
|
|
450
|
-
let hasPositiveZero = false;
|
|
451
|
-
let hasNegativeZero = false;
|
|
452
|
-
const valueSet = /* @__PURE__ */ new Set();
|
|
453
|
-
for (const literalValue of items) {
|
|
454
|
-
if (isZero(literalValue)) {
|
|
455
|
-
if (Object.is(literalValue, -0)) hasNegativeZero = true;
|
|
456
|
-
else hasPositiveZero = true;
|
|
457
|
-
} else {
|
|
458
|
-
valueSet.add(literalValue);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
return define((input) => {
|
|
462
|
-
if (isZero(input)) {
|
|
463
|
-
return Object.is(input, -0) ? hasNegativeZero : hasPositiveZero;
|
|
464
|
-
}
|
|
465
|
-
return valueSet.has(input);
|
|
466
|
-
});
|
|
467
|
-
};
|
|
468
|
-
function oneOfValues(...args) {
|
|
469
|
-
const items = normalizeValues(args);
|
|
470
|
-
return items.length <= ONE_OF_VALUES_LINEAR_SCAN_MAX ? createLinearPredicate(items) : createSetPredicate(items);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// src/core/key.ts
|
|
474
|
-
var hasKey = (key) => define(
|
|
475
|
-
(input) => isObject(input) && Object.hasOwn(input, key)
|
|
476
|
-
);
|
|
477
|
-
var hasKeys = (...keys) => {
|
|
478
|
-
if (keys.length === 0) {
|
|
479
|
-
return define(() => false);
|
|
480
|
-
}
|
|
487
|
+
// src/core/combinators/tuple.ts
|
|
488
|
+
function tupleOf(...guards) {
|
|
481
489
|
return define(
|
|
482
|
-
(input) =>
|
|
490
|
+
(input) => Array.isArray(input) && everyTupleValue(input, guards)
|
|
483
491
|
);
|
|
484
|
-
};
|
|
485
|
-
function narrowKeyTo(guard, key) {
|
|
486
|
-
return (target) => {
|
|
487
|
-
const keyEquals = equalsKey(key, target);
|
|
488
|
-
return define(
|
|
489
|
-
(input) => guard(input) && keyEquals(input)
|
|
490
|
-
);
|
|
491
|
-
};
|
|
492
492
|
}
|
|
493
493
|
// Annotate the CommonJS export names for ESM import in node:
|
|
494
494
|
0 && (module.exports = {
|