is-kit 1.10.0 → 1.11.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/README.md +12 -1
- package/dist/index.d.mts +32 -6
- package/dist/index.d.ts +32 -6
- package/dist/index.js +43 -36
- package/dist/index.mjs +41 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -270,6 +270,17 @@ const isDefinedString = required(optional(isString));
|
|
|
270
270
|
const isNonNullString = nonNull(nullable(isString));
|
|
271
271
|
```
|
|
272
272
|
|
|
273
|
+
For a plain "is it `null` or `undefined`?" check, reach for `isNil` instead of
|
|
274
|
+
hand-rolling `isNull(x) || isUndefined(x)`:
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
import { isNil } from 'is-kit';
|
|
278
|
+
|
|
279
|
+
isNil(null); // true
|
|
280
|
+
isNil(undefined); // true
|
|
281
|
+
isNil(0); // false
|
|
282
|
+
```
|
|
283
|
+
|
|
273
284
|
### 8. Parse or assert unknown input
|
|
274
285
|
|
|
275
286
|
Use `safeParse` when you want a result object, and `assert` when invalid data should stop execution.
|
|
@@ -434,7 +445,7 @@ The library is organized around a few small building blocks:
|
|
|
434
445
|
- **Object shapes**: `struct`, `optionalKey`, `hasKey`, `hasKeys`, `narrowKeyTo`
|
|
435
446
|
- **Collections**: `arrayOf`, `nonEmptyArrayOf`, `tupleOf`, `setOf`, `mapOf`, `recordOf`
|
|
436
447
|
- **Literals**: `oneOfValues`, `equals`, `equalsBy`, `equalsKey`
|
|
437
|
-
- **Nullish handling**: `nullable`, `nonNull`, `nullish`, `optional`, `required`
|
|
448
|
+
- **Nullish handling**: `isNil`, `nullable`, `nonNull`, `nullish`, `optional`, `required`
|
|
438
449
|
- **Result helpers**: `safeParse`, `safeParseWith`, `safeJsonParse`, `assert`
|
|
439
450
|
|
|
440
451
|
For the full API list and dedicated pages, use the docs site below.
|
package/dist/index.d.mts
CHANGED
|
@@ -351,15 +351,34 @@ declare const isSymbol: Predicate<symbol>;
|
|
|
351
351
|
/**
|
|
352
352
|
* Checks whether a value is exactly `undefined`.
|
|
353
353
|
*
|
|
354
|
+
* To accept `null` as well, use {@link isNil}.
|
|
355
|
+
*
|
|
354
356
|
* @returns Predicate narrowing to `undefined`.
|
|
355
357
|
*/
|
|
356
358
|
declare const isUndefined: Predicate<undefined>;
|
|
357
359
|
/**
|
|
358
360
|
* Checks whether a value is exactly `null`.
|
|
359
361
|
*
|
|
362
|
+
* To accept `undefined` as well, use {@link isNil}.
|
|
363
|
+
*
|
|
360
364
|
* @returns Predicate narrowing to `null`.
|
|
361
365
|
*/
|
|
362
366
|
declare const isNull: Predicate<null>;
|
|
367
|
+
/**
|
|
368
|
+
* Checks whether a value is `null` or `undefined` (nullish).
|
|
369
|
+
*
|
|
370
|
+
* Prefer this over hand-rolling `isNull(x) || isUndefined(x)`: it is the same
|
|
371
|
+
* check expressed once. To widen an existing guard so it also accepts nullish
|
|
372
|
+
* values, use {@link nullish} instead.
|
|
373
|
+
*
|
|
374
|
+
* @returns Predicate narrowing to `null | undefined`.
|
|
375
|
+
* @example
|
|
376
|
+
* isNil(null); // true
|
|
377
|
+
* isNil(undefined); // true
|
|
378
|
+
* isNil(0); // false
|
|
379
|
+
* @see or
|
|
380
|
+
*/
|
|
381
|
+
declare const isNil: Guard<null | undefined>;
|
|
363
382
|
/**
|
|
364
383
|
* Checks whether a value is a JavaScript primitive.
|
|
365
384
|
*
|
|
@@ -485,6 +504,12 @@ declare const isURL: Guard<URL>;
|
|
|
485
504
|
* @returns Predicate narrowing to `Blob` when supported; otherwise always false.
|
|
486
505
|
*/
|
|
487
506
|
declare const isBlob: Guard<Blob>;
|
|
507
|
+
/**
|
|
508
|
+
* Checks whether a value is a `File` (in environments with File available).
|
|
509
|
+
*
|
|
510
|
+
* @returns Predicate narrowing to `File` when supported; otherwise always false.
|
|
511
|
+
*/
|
|
512
|
+
declare const isFile: Guard<File>;
|
|
488
513
|
/**
|
|
489
514
|
* Creates a guard that checks whether a value is an instance of `constructor`.
|
|
490
515
|
*
|
|
@@ -613,6 +638,7 @@ declare function tupleOf<const Fs extends readonly Predicate<unknown>[]>(...guar
|
|
|
613
638
|
readonly [K in keyof Fs]: GuardedOf<Fs[K]>;
|
|
614
639
|
}>;
|
|
615
640
|
|
|
641
|
+
type BooleanPredicate<T> = (value: T) => boolean;
|
|
616
642
|
/**
|
|
617
643
|
* Checks whether every array element satisfies the provided predicate.
|
|
618
644
|
*
|
|
@@ -620,7 +646,7 @@ declare function tupleOf<const Fs extends readonly Predicate<unknown>[]>(...guar
|
|
|
620
646
|
* @param predicate Predicate applied to each element.
|
|
621
647
|
* @returns Whether all elements satisfy `predicate`.
|
|
622
648
|
*/
|
|
623
|
-
declare const everyArrayValue: (values: readonly unknown[], predicate:
|
|
649
|
+
declare const everyArrayValue: (values: readonly unknown[], predicate: BooleanPredicate<unknown>) => boolean;
|
|
624
650
|
/**
|
|
625
651
|
* Checks whether a tuple matches the provided element predicates in order.
|
|
626
652
|
*
|
|
@@ -628,7 +654,7 @@ declare const everyArrayValue: (values: readonly unknown[], predicate: (value: u
|
|
|
628
654
|
* @param predicates Predicates aligned to each tuple index.
|
|
629
655
|
* @returns Whether lengths match and each index passes.
|
|
630
656
|
*/
|
|
631
|
-
declare const everyTupleValue: (values: readonly unknown[], predicates: readonly
|
|
657
|
+
declare const everyTupleValue: (values: readonly unknown[], predicates: readonly BooleanPredicate<unknown>[]) => boolean;
|
|
632
658
|
/**
|
|
633
659
|
* Checks whether every set value satisfies the provided predicate.
|
|
634
660
|
*
|
|
@@ -636,7 +662,7 @@ declare const everyTupleValue: (values: readonly unknown[], predicates: readonly
|
|
|
636
662
|
* @param predicate Predicate applied to each value.
|
|
637
663
|
* @returns Whether all set values satisfy `predicate`.
|
|
638
664
|
*/
|
|
639
|
-
declare const everySetValue: (values: ReadonlySet<unknown>, predicate:
|
|
665
|
+
declare const everySetValue: (values: ReadonlySet<unknown>, predicate: BooleanPredicate<unknown>) => boolean;
|
|
640
666
|
/**
|
|
641
667
|
* Checks whether every map entry satisfies the provided key and value predicates.
|
|
642
668
|
*
|
|
@@ -645,7 +671,7 @@ declare const everySetValue: (values: ReadonlySet<unknown>, predicate: (value: u
|
|
|
645
671
|
* @param valuePredicate Predicate applied to each value.
|
|
646
672
|
* @returns Whether all keys and values satisfy their predicates.
|
|
647
673
|
*/
|
|
648
|
-
declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicate:
|
|
674
|
+
declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicate: BooleanPredicate<unknown>, valuePredicate: BooleanPredicate<unknown>) => boolean;
|
|
649
675
|
/**
|
|
650
676
|
* Checks whether every own enumerable string key/value pair satisfies the provided predicates.
|
|
651
677
|
*
|
|
@@ -654,7 +680,7 @@ declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicat
|
|
|
654
680
|
* @param valuePredicate Predicate applied to each corresponding value.
|
|
655
681
|
* @returns Whether all enumerable entries satisfy their predicates.
|
|
656
682
|
*/
|
|
657
|
-
declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPredicate:
|
|
683
|
+
declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPredicate: BooleanPredicate<string>, valuePredicate: BooleanPredicate<unknown>) => boolean;
|
|
658
684
|
|
|
659
685
|
/**
|
|
660
686
|
* Converts predicates to plain boolean predicates for iteration helpers.
|
|
@@ -664,4 +690,4 @@ declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPred
|
|
|
664
690
|
*/
|
|
665
691
|
declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
|
|
666
692
|
|
|
667
|
-
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OptionalSchemaField, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, type SchemaField, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, everyArrayValue, everyMapEntry, everyOwnEnumerableEntry, everySetValue, everyTupleValue, guardIn, hasKey, hasKeys, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInstanceOf, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, lazy, mapOf, narrowKeyTo, nonEmptyArrayOf, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, optionalKey, or, predicateToRefine, recordOf, required, safeJsonParse, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf, typedStruct };
|
|
693
|
+
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OptionalSchemaField, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, type SchemaField, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, everyArrayValue, everyMapEntry, everyOwnEnumerableEntry, everySetValue, everyTupleValue, guardIn, hasKey, hasKeys, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFile, isFiniteNumber, isFunction, isInfiniteNumber, isInstanceOf, isInteger, isIterable, isMap, isNaN, isNegative, isNil, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, lazy, mapOf, narrowKeyTo, nonEmptyArrayOf, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, optionalKey, or, predicateToRefine, recordOf, required, safeJsonParse, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf, typedStruct };
|
package/dist/index.d.ts
CHANGED
|
@@ -351,15 +351,34 @@ declare const isSymbol: Predicate<symbol>;
|
|
|
351
351
|
/**
|
|
352
352
|
* Checks whether a value is exactly `undefined`.
|
|
353
353
|
*
|
|
354
|
+
* To accept `null` as well, use {@link isNil}.
|
|
355
|
+
*
|
|
354
356
|
* @returns Predicate narrowing to `undefined`.
|
|
355
357
|
*/
|
|
356
358
|
declare const isUndefined: Predicate<undefined>;
|
|
357
359
|
/**
|
|
358
360
|
* Checks whether a value is exactly `null`.
|
|
359
361
|
*
|
|
362
|
+
* To accept `undefined` as well, use {@link isNil}.
|
|
363
|
+
*
|
|
360
364
|
* @returns Predicate narrowing to `null`.
|
|
361
365
|
*/
|
|
362
366
|
declare const isNull: Predicate<null>;
|
|
367
|
+
/**
|
|
368
|
+
* Checks whether a value is `null` or `undefined` (nullish).
|
|
369
|
+
*
|
|
370
|
+
* Prefer this over hand-rolling `isNull(x) || isUndefined(x)`: it is the same
|
|
371
|
+
* check expressed once. To widen an existing guard so it also accepts nullish
|
|
372
|
+
* values, use {@link nullish} instead.
|
|
373
|
+
*
|
|
374
|
+
* @returns Predicate narrowing to `null | undefined`.
|
|
375
|
+
* @example
|
|
376
|
+
* isNil(null); // true
|
|
377
|
+
* isNil(undefined); // true
|
|
378
|
+
* isNil(0); // false
|
|
379
|
+
* @see or
|
|
380
|
+
*/
|
|
381
|
+
declare const isNil: Guard<null | undefined>;
|
|
363
382
|
/**
|
|
364
383
|
* Checks whether a value is a JavaScript primitive.
|
|
365
384
|
*
|
|
@@ -485,6 +504,12 @@ declare const isURL: Guard<URL>;
|
|
|
485
504
|
* @returns Predicate narrowing to `Blob` when supported; otherwise always false.
|
|
486
505
|
*/
|
|
487
506
|
declare const isBlob: Guard<Blob>;
|
|
507
|
+
/**
|
|
508
|
+
* Checks whether a value is a `File` (in environments with File available).
|
|
509
|
+
*
|
|
510
|
+
* @returns Predicate narrowing to `File` when supported; otherwise always false.
|
|
511
|
+
*/
|
|
512
|
+
declare const isFile: Guard<File>;
|
|
488
513
|
/**
|
|
489
514
|
* Creates a guard that checks whether a value is an instance of `constructor`.
|
|
490
515
|
*
|
|
@@ -613,6 +638,7 @@ declare function tupleOf<const Fs extends readonly Predicate<unknown>[]>(...guar
|
|
|
613
638
|
readonly [K in keyof Fs]: GuardedOf<Fs[K]>;
|
|
614
639
|
}>;
|
|
615
640
|
|
|
641
|
+
type BooleanPredicate<T> = (value: T) => boolean;
|
|
616
642
|
/**
|
|
617
643
|
* Checks whether every array element satisfies the provided predicate.
|
|
618
644
|
*
|
|
@@ -620,7 +646,7 @@ declare function tupleOf<const Fs extends readonly Predicate<unknown>[]>(...guar
|
|
|
620
646
|
* @param predicate Predicate applied to each element.
|
|
621
647
|
* @returns Whether all elements satisfy `predicate`.
|
|
622
648
|
*/
|
|
623
|
-
declare const everyArrayValue: (values: readonly unknown[], predicate:
|
|
649
|
+
declare const everyArrayValue: (values: readonly unknown[], predicate: BooleanPredicate<unknown>) => boolean;
|
|
624
650
|
/**
|
|
625
651
|
* Checks whether a tuple matches the provided element predicates in order.
|
|
626
652
|
*
|
|
@@ -628,7 +654,7 @@ declare const everyArrayValue: (values: readonly unknown[], predicate: (value: u
|
|
|
628
654
|
* @param predicates Predicates aligned to each tuple index.
|
|
629
655
|
* @returns Whether lengths match and each index passes.
|
|
630
656
|
*/
|
|
631
|
-
declare const everyTupleValue: (values: readonly unknown[], predicates: readonly
|
|
657
|
+
declare const everyTupleValue: (values: readonly unknown[], predicates: readonly BooleanPredicate<unknown>[]) => boolean;
|
|
632
658
|
/**
|
|
633
659
|
* Checks whether every set value satisfies the provided predicate.
|
|
634
660
|
*
|
|
@@ -636,7 +662,7 @@ declare const everyTupleValue: (values: readonly unknown[], predicates: readonly
|
|
|
636
662
|
* @param predicate Predicate applied to each value.
|
|
637
663
|
* @returns Whether all set values satisfy `predicate`.
|
|
638
664
|
*/
|
|
639
|
-
declare const everySetValue: (values: ReadonlySet<unknown>, predicate:
|
|
665
|
+
declare const everySetValue: (values: ReadonlySet<unknown>, predicate: BooleanPredicate<unknown>) => boolean;
|
|
640
666
|
/**
|
|
641
667
|
* Checks whether every map entry satisfies the provided key and value predicates.
|
|
642
668
|
*
|
|
@@ -645,7 +671,7 @@ declare const everySetValue: (values: ReadonlySet<unknown>, predicate: (value: u
|
|
|
645
671
|
* @param valuePredicate Predicate applied to each value.
|
|
646
672
|
* @returns Whether all keys and values satisfy their predicates.
|
|
647
673
|
*/
|
|
648
|
-
declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicate:
|
|
674
|
+
declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicate: BooleanPredicate<unknown>, valuePredicate: BooleanPredicate<unknown>) => boolean;
|
|
649
675
|
/**
|
|
650
676
|
* Checks whether every own enumerable string key/value pair satisfies the provided predicates.
|
|
651
677
|
*
|
|
@@ -654,7 +680,7 @@ declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicat
|
|
|
654
680
|
* @param valuePredicate Predicate applied to each corresponding value.
|
|
655
681
|
* @returns Whether all enumerable entries satisfy their predicates.
|
|
656
682
|
*/
|
|
657
|
-
declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPredicate:
|
|
683
|
+
declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPredicate: BooleanPredicate<string>, valuePredicate: BooleanPredicate<unknown>) => boolean;
|
|
658
684
|
|
|
659
685
|
/**
|
|
660
686
|
* Converts predicates to plain boolean predicates for iteration helpers.
|
|
@@ -664,4 +690,4 @@ declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPred
|
|
|
664
690
|
*/
|
|
665
691
|
declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
|
|
666
692
|
|
|
667
|
-
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OptionalSchemaField, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, type SchemaField, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, everyArrayValue, everyMapEntry, everyOwnEnumerableEntry, everySetValue, everyTupleValue, guardIn, hasKey, hasKeys, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInstanceOf, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, lazy, mapOf, narrowKeyTo, nonEmptyArrayOf, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, optionalKey, or, predicateToRefine, recordOf, required, safeJsonParse, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf, typedStruct };
|
|
693
|
+
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OptionalSchemaField, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, type SchemaField, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, everyArrayValue, everyMapEntry, everyOwnEnumerableEntry, everySetValue, everyTupleValue, guardIn, hasKey, hasKeys, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFile, isFiniteNumber, isFunction, isInfiniteNumber, isInstanceOf, isInteger, isIterable, isMap, isNaN, isNegative, isNil, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, lazy, mapOf, narrowKeyTo, nonEmptyArrayOf, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, optionalKey, or, predicateToRefine, recordOf, required, safeJsonParse, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf, typedStruct };
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,7 @@ __export(index_exports, {
|
|
|
45
45
|
isDataView: () => isDataView,
|
|
46
46
|
isDate: () => isDate,
|
|
47
47
|
isError: () => isError,
|
|
48
|
+
isFile: () => isFile,
|
|
48
49
|
isFiniteNumber: () => isFiniteNumber,
|
|
49
50
|
isFunction: () => isFunction,
|
|
50
51
|
isInfiniteNumber: () => isInfiniteNumber,
|
|
@@ -54,6 +55,7 @@ __export(index_exports, {
|
|
|
54
55
|
isMap: () => isMap,
|
|
55
56
|
isNaN: () => isNaN,
|
|
56
57
|
isNegative: () => isNegative,
|
|
58
|
+
isNil: () => isNil,
|
|
57
59
|
isNull: () => isNull,
|
|
58
60
|
isNumber: () => isNumber,
|
|
59
61
|
isNumberPrimitive: () => isNumberPrimitive,
|
|
@@ -112,6 +114,38 @@ function define(fn) {
|
|
|
112
114
|
return (value) => !!fn(value);
|
|
113
115
|
}
|
|
114
116
|
|
|
117
|
+
// src/utils/guard-collections.ts
|
|
118
|
+
var everyIterableValue = (values, predicate) => {
|
|
119
|
+
for (const value of values) {
|
|
120
|
+
if (!predicate(value)) return false;
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
};
|
|
124
|
+
var everyKeyValueEntry = (entries, predicate) => {
|
|
125
|
+
for (const [key, value] of entries) {
|
|
126
|
+
if (!predicate(key, value)) return false;
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
};
|
|
130
|
+
var everyArrayValue = (values, predicate) => everyIterableValue(values, predicate);
|
|
131
|
+
var everyTupleValue = (values, predicates) => {
|
|
132
|
+
if (values.length !== predicates.length) return false;
|
|
133
|
+
for (let index = 0; index < predicates.length; index += 1) {
|
|
134
|
+
const predicate = predicates[index];
|
|
135
|
+
if (!predicate(values[index])) return false;
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
};
|
|
139
|
+
var everySetValue = (values, predicate) => everyIterableValue(values, predicate);
|
|
140
|
+
var everyMapEntry = (values, keyPredicate, valuePredicate) => everyKeyValueEntry(
|
|
141
|
+
values,
|
|
142
|
+
(key, value) => keyPredicate(key) && valuePredicate(value)
|
|
143
|
+
);
|
|
144
|
+
var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => everyIterableValue(
|
|
145
|
+
Object.keys(values),
|
|
146
|
+
(key) => keyPredicate(key) && valuePredicate(values[key])
|
|
147
|
+
);
|
|
148
|
+
|
|
115
149
|
// src/utils/object-tags.ts
|
|
116
150
|
var objectToString = Object.prototype.toString;
|
|
117
151
|
var OBJECT_TAG_DATE = "[object Date]";
|
|
@@ -125,6 +159,9 @@ var OBJECT_TAG_DATA_VIEW = "[object DataView]";
|
|
|
125
159
|
var OBJECT_TAG_ERROR = "[object Error]";
|
|
126
160
|
var getTag = (value) => objectToString.call(value);
|
|
127
161
|
|
|
162
|
+
// src/utils/to-boolean-predicates.ts
|
|
163
|
+
var toBooleanPredicates = (predicates) => predicates;
|
|
164
|
+
|
|
128
165
|
// src/core/object.ts
|
|
129
166
|
var defineTagGuard = (tag) => define((value) => getTag(value) === tag);
|
|
130
167
|
var defineOptionalInstanceGuard = (constructor) => constructor === void 0 ? define(() => false) : define(
|
|
@@ -177,6 +214,9 @@ var isURL = defineOptionalInstanceGuard(
|
|
|
177
214
|
var isBlob = defineOptionalInstanceGuard(
|
|
178
215
|
typeof Blob === "undefined" ? void 0 : Blob
|
|
179
216
|
);
|
|
217
|
+
var isFile = defineOptionalInstanceGuard(
|
|
218
|
+
typeof File === "undefined" ? void 0 : File
|
|
219
|
+
);
|
|
180
220
|
var isInstanceOf = (constructor) => define((value) => value instanceof constructor);
|
|
181
221
|
|
|
182
222
|
// src/core/equals.ts
|
|
@@ -230,42 +270,6 @@ function lazy(factory) {
|
|
|
230
270
|
};
|
|
231
271
|
}
|
|
232
272
|
|
|
233
|
-
// src/utils/guard-collections.ts
|
|
234
|
-
var everyArrayValue = (values, predicate) => {
|
|
235
|
-
for (const value of values) {
|
|
236
|
-
if (!predicate(value)) return false;
|
|
237
|
-
}
|
|
238
|
-
return true;
|
|
239
|
-
};
|
|
240
|
-
var everyTupleValue = (values, predicates) => {
|
|
241
|
-
if (values.length !== predicates.length) return false;
|
|
242
|
-
for (const [index, predicate] of predicates.entries()) {
|
|
243
|
-
if (!predicate(values[index])) return false;
|
|
244
|
-
}
|
|
245
|
-
return true;
|
|
246
|
-
};
|
|
247
|
-
var everySetValue = (values, predicate) => {
|
|
248
|
-
for (const value of values) {
|
|
249
|
-
if (!predicate(value)) return false;
|
|
250
|
-
}
|
|
251
|
-
return true;
|
|
252
|
-
};
|
|
253
|
-
var everyMapEntry = (values, keyPredicate, valuePredicate) => {
|
|
254
|
-
for (const [key, value] of values) {
|
|
255
|
-
if (!keyPredicate(key) || !valuePredicate(value)) return false;
|
|
256
|
-
}
|
|
257
|
-
return true;
|
|
258
|
-
};
|
|
259
|
-
var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => {
|
|
260
|
-
for (const key of Object.keys(values)) {
|
|
261
|
-
if (!keyPredicate(key) || !valuePredicate(values[key])) return false;
|
|
262
|
-
}
|
|
263
|
-
return true;
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
// src/utils/to-boolean-predicates.ts
|
|
267
|
-
var toBooleanPredicates = (predicates) => predicates;
|
|
268
|
-
|
|
269
273
|
// src/core/logic.ts
|
|
270
274
|
function and(precondition, condition) {
|
|
271
275
|
return define((input) => {
|
|
@@ -372,6 +376,7 @@ var isBigInt = define((value) => typeof value === "bigint");
|
|
|
372
376
|
var isSymbol = define((value) => typeof value === "symbol");
|
|
373
377
|
var isUndefined = define((value) => value === void 0);
|
|
374
378
|
var isNull = define((value) => value === null);
|
|
379
|
+
var isNil = or(isNull, isUndefined);
|
|
375
380
|
var isPrimitive = or(
|
|
376
381
|
isString,
|
|
377
382
|
isNumberPrimitive,
|
|
@@ -542,6 +547,7 @@ function tupleOf(...guards) {
|
|
|
542
547
|
isDataView,
|
|
543
548
|
isDate,
|
|
544
549
|
isError,
|
|
550
|
+
isFile,
|
|
545
551
|
isFiniteNumber,
|
|
546
552
|
isFunction,
|
|
547
553
|
isInfiniteNumber,
|
|
@@ -551,6 +557,7 @@ function tupleOf(...guards) {
|
|
|
551
557
|
isMap,
|
|
552
558
|
isNaN,
|
|
553
559
|
isNegative,
|
|
560
|
+
isNil,
|
|
554
561
|
isNull,
|
|
555
562
|
isNumber,
|
|
556
563
|
isNumberPrimitive,
|
package/dist/index.mjs
CHANGED
|
@@ -10,6 +10,38 @@ function define(fn) {
|
|
|
10
10
|
return (value) => !!fn(value);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
// src/utils/guard-collections.ts
|
|
14
|
+
var everyIterableValue = (values, predicate) => {
|
|
15
|
+
for (const value of values) {
|
|
16
|
+
if (!predicate(value)) return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
var everyKeyValueEntry = (entries, predicate) => {
|
|
21
|
+
for (const [key, value] of entries) {
|
|
22
|
+
if (!predicate(key, value)) return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
var everyArrayValue = (values, predicate) => everyIterableValue(values, predicate);
|
|
27
|
+
var everyTupleValue = (values, predicates) => {
|
|
28
|
+
if (values.length !== predicates.length) return false;
|
|
29
|
+
for (let index = 0; index < predicates.length; index += 1) {
|
|
30
|
+
const predicate = predicates[index];
|
|
31
|
+
if (!predicate(values[index])) return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
var everySetValue = (values, predicate) => everyIterableValue(values, predicate);
|
|
36
|
+
var everyMapEntry = (values, keyPredicate, valuePredicate) => everyKeyValueEntry(
|
|
37
|
+
values,
|
|
38
|
+
(key, value) => keyPredicate(key) && valuePredicate(value)
|
|
39
|
+
);
|
|
40
|
+
var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => everyIterableValue(
|
|
41
|
+
Object.keys(values),
|
|
42
|
+
(key) => keyPredicate(key) && valuePredicate(values[key])
|
|
43
|
+
);
|
|
44
|
+
|
|
13
45
|
// src/utils/object-tags.ts
|
|
14
46
|
var objectToString = Object.prototype.toString;
|
|
15
47
|
var OBJECT_TAG_DATE = "[object Date]";
|
|
@@ -23,6 +55,9 @@ var OBJECT_TAG_DATA_VIEW = "[object DataView]";
|
|
|
23
55
|
var OBJECT_TAG_ERROR = "[object Error]";
|
|
24
56
|
var getTag = (value) => objectToString.call(value);
|
|
25
57
|
|
|
58
|
+
// src/utils/to-boolean-predicates.ts
|
|
59
|
+
var toBooleanPredicates = (predicates) => predicates;
|
|
60
|
+
|
|
26
61
|
// src/core/object.ts
|
|
27
62
|
var defineTagGuard = (tag) => define((value) => getTag(value) === tag);
|
|
28
63
|
var defineOptionalInstanceGuard = (constructor) => constructor === void 0 ? define(() => false) : define(
|
|
@@ -75,6 +110,9 @@ var isURL = defineOptionalInstanceGuard(
|
|
|
75
110
|
var isBlob = defineOptionalInstanceGuard(
|
|
76
111
|
typeof Blob === "undefined" ? void 0 : Blob
|
|
77
112
|
);
|
|
113
|
+
var isFile = defineOptionalInstanceGuard(
|
|
114
|
+
typeof File === "undefined" ? void 0 : File
|
|
115
|
+
);
|
|
78
116
|
var isInstanceOf = (constructor) => define((value) => value instanceof constructor);
|
|
79
117
|
|
|
80
118
|
// src/core/equals.ts
|
|
@@ -128,42 +166,6 @@ function lazy(factory) {
|
|
|
128
166
|
};
|
|
129
167
|
}
|
|
130
168
|
|
|
131
|
-
// src/utils/guard-collections.ts
|
|
132
|
-
var everyArrayValue = (values, predicate) => {
|
|
133
|
-
for (const value of values) {
|
|
134
|
-
if (!predicate(value)) return false;
|
|
135
|
-
}
|
|
136
|
-
return true;
|
|
137
|
-
};
|
|
138
|
-
var everyTupleValue = (values, predicates) => {
|
|
139
|
-
if (values.length !== predicates.length) return false;
|
|
140
|
-
for (const [index, predicate] of predicates.entries()) {
|
|
141
|
-
if (!predicate(values[index])) return false;
|
|
142
|
-
}
|
|
143
|
-
return true;
|
|
144
|
-
};
|
|
145
|
-
var everySetValue = (values, predicate) => {
|
|
146
|
-
for (const value of values) {
|
|
147
|
-
if (!predicate(value)) return false;
|
|
148
|
-
}
|
|
149
|
-
return true;
|
|
150
|
-
};
|
|
151
|
-
var everyMapEntry = (values, keyPredicate, valuePredicate) => {
|
|
152
|
-
for (const [key, value] of values) {
|
|
153
|
-
if (!keyPredicate(key) || !valuePredicate(value)) return false;
|
|
154
|
-
}
|
|
155
|
-
return true;
|
|
156
|
-
};
|
|
157
|
-
var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => {
|
|
158
|
-
for (const key of Object.keys(values)) {
|
|
159
|
-
if (!keyPredicate(key) || !valuePredicate(values[key])) return false;
|
|
160
|
-
}
|
|
161
|
-
return true;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// src/utils/to-boolean-predicates.ts
|
|
165
|
-
var toBooleanPredicates = (predicates) => predicates;
|
|
166
|
-
|
|
167
169
|
// src/core/logic.ts
|
|
168
170
|
function and(precondition, condition) {
|
|
169
171
|
return define((input) => {
|
|
@@ -270,6 +272,7 @@ var isBigInt = define((value) => typeof value === "bigint");
|
|
|
270
272
|
var isSymbol = define((value) => typeof value === "symbol");
|
|
271
273
|
var isUndefined = define((value) => value === void 0);
|
|
272
274
|
var isNull = define((value) => value === null);
|
|
275
|
+
var isNil = or(isNull, isUndefined);
|
|
273
276
|
var isPrimitive = or(
|
|
274
277
|
isString,
|
|
275
278
|
isNumberPrimitive,
|
|
@@ -439,6 +442,7 @@ export {
|
|
|
439
442
|
isDataView,
|
|
440
443
|
isDate,
|
|
441
444
|
isError,
|
|
445
|
+
isFile,
|
|
442
446
|
isFiniteNumber,
|
|
443
447
|
isFunction,
|
|
444
448
|
isInfiniteNumber,
|
|
@@ -448,6 +452,7 @@ export {
|
|
|
448
452
|
isMap,
|
|
449
453
|
isNaN,
|
|
450
454
|
isNegative,
|
|
455
|
+
isNil,
|
|
451
456
|
isNull,
|
|
452
457
|
isNumber,
|
|
453
458
|
isNumberPrimitive,
|