is-kit 1.9.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 CHANGED
@@ -116,6 +116,7 @@ This is the core idea of `is-kit`:
116
116
  If you are new to the library, these are the pieces to remember:
117
117
 
118
118
  - `define<T>(fn)` turns a boolean check into a typed guard.
119
+ - `lazy(factory)` defers a guard definition so recursive structures can refer to themselves.
119
120
  - `predicateToRefine(fn)` upgrades an existing predicate so it can participate in narrowing chains.
120
121
  - `struct({...})` builds an object-shape guard.
121
122
  - `safeParse(guard, value)` gives you a small tagged result object.
@@ -224,7 +225,31 @@ import { oneOfValues } from 'is-kit';
224
225
  const isStatus = oneOfValues('draft', 'published', 'archived');
225
226
  ```
226
227
 
227
- ### 6. Handle null and undefined explicitly
228
+ ### 6. Validate recursive structures
229
+
230
+ Use `lazy` when a guard needs to refer to itself. The factory runs on first use,
231
+ and the resulting guard is cached.
232
+
233
+ ```ts
234
+ import { arrayOf, isString, lazy, typedStruct } from 'is-kit';
235
+ import type { Predicate } from 'is-kit';
236
+
237
+ type Tree = {
238
+ readonly value: string;
239
+ readonly children: readonly Tree[];
240
+ };
241
+
242
+ const isTree: Predicate<Tree> = lazy(() =>
243
+ typedStruct<Tree>()({
244
+ value: isString,
245
+ children: arrayOf(isTree)
246
+ })
247
+ );
248
+ ```
249
+
250
+ `lazy` does not detect circular references in the input value.
251
+
252
+ ### 7. Handle null and undefined explicitly
228
253
 
229
254
  Use the nullish helpers to say exactly what is allowed.
230
255
 
@@ -245,7 +270,18 @@ const isDefinedString = required(optional(isString));
245
270
  const isNonNullString = nonNull(nullable(isString));
246
271
  ```
247
272
 
248
- ### 7. Parse or assert unknown input
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
+
284
+ ### 8. Parse or assert unknown input
249
285
 
250
286
  Use `safeParse` when you want a result object, and `assert` when invalid data should stop execution.
251
287
 
@@ -264,7 +300,7 @@ assert(isString, input, 'Expected a string');
264
300
  input.toUpperCase();
265
301
  ```
266
302
 
267
- ### 8. Decode and validate JSON input
303
+ ### 9. Decode and validate JSON input
268
304
 
269
305
  Use `safeJsonParse` at a JSON text boundary. It decodes the text, treats the
270
306
  result as `unknown`, and only returns the value after the guard accepts it.
@@ -296,7 +332,7 @@ if (result.valid) {
296
332
  coercion and does not depend on a transport or schema format such as HTTP or
297
333
  OpenAPI.
298
334
 
299
- ### 9. Narrow object keys
335
+ ### 10. Narrow object keys
300
336
 
301
337
  Use key helpers when the important part of a value is one property.
302
338
 
@@ -409,7 +445,7 @@ The library is organized around a few small building blocks:
409
445
  - **Object shapes**: `struct`, `optionalKey`, `hasKey`, `hasKeys`, `narrowKeyTo`
410
446
  - **Collections**: `arrayOf`, `nonEmptyArrayOf`, `tupleOf`, `setOf`, `mapOf`, `recordOf`
411
447
  - **Literals**: `oneOfValues`, `equals`, `equalsBy`, `equalsKey`
412
- - **Nullish handling**: `nullable`, `nonNull`, `nullish`, `optional`, `required`
448
+ - **Nullish handling**: `isNil`, `nullable`, `nonNull`, `nullish`, `optional`, `required`
413
449
  - **Result helpers**: `safeParse`, `safeParseWith`, `safeJsonParse`, `assert`
414
450
 
415
451
  For the full API list and dedicated pages, use the docs site below.
package/dist/index.d.mts CHANGED
@@ -133,6 +133,17 @@ declare const hasKeys: <const KS extends readonly [PropertyKey, ...PropertyKey[]
133
133
  */
134
134
  declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <const T extends A[K]>(target: T) => Predicate<A & Record<K, T>>;
135
135
 
136
+ /**
137
+ * Creates a predicate whose implementation is initialized on first use.
138
+ *
139
+ * The initialized predicate is cached after the factory returns successfully.
140
+ * Circular references in the input value are not detected.
141
+ *
142
+ * @param factory Function that creates the predicate when it is first evaluated.
143
+ * @returns Predicate that delegates to the lazily initialized implementation.
144
+ */
145
+ declare function lazy<T>(factory: () => Predicate<T>): Predicate<T>;
146
+
136
147
  /**
137
148
  * Combines a precondition guard with an additional refinement to narrow the type.
138
149
  *
@@ -340,15 +351,34 @@ declare const isSymbol: Predicate<symbol>;
340
351
  /**
341
352
  * Checks whether a value is exactly `undefined`.
342
353
  *
354
+ * To accept `null` as well, use {@link isNil}.
355
+ *
343
356
  * @returns Predicate narrowing to `undefined`.
344
357
  */
345
358
  declare const isUndefined: Predicate<undefined>;
346
359
  /**
347
360
  * Checks whether a value is exactly `null`.
348
361
  *
362
+ * To accept `undefined` as well, use {@link isNil}.
363
+ *
349
364
  * @returns Predicate narrowing to `null`.
350
365
  */
351
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>;
352
382
  /**
353
383
  * Checks whether a value is a JavaScript primitive.
354
384
  *
@@ -474,6 +504,12 @@ declare const isURL: Guard<URL>;
474
504
  * @returns Predicate narrowing to `Blob` when supported; otherwise always false.
475
505
  */
476
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>;
477
513
  /**
478
514
  * Creates a guard that checks whether a value is an instance of `constructor`.
479
515
  *
@@ -602,6 +638,7 @@ declare function tupleOf<const Fs extends readonly Predicate<unknown>[]>(...guar
602
638
  readonly [K in keyof Fs]: GuardedOf<Fs[K]>;
603
639
  }>;
604
640
 
641
+ type BooleanPredicate<T> = (value: T) => boolean;
605
642
  /**
606
643
  * Checks whether every array element satisfies the provided predicate.
607
644
  *
@@ -609,7 +646,7 @@ declare function tupleOf<const Fs extends readonly Predicate<unknown>[]>(...guar
609
646
  * @param predicate Predicate applied to each element.
610
647
  * @returns Whether all elements satisfy `predicate`.
611
648
  */
612
- declare const everyArrayValue: (values: readonly unknown[], predicate: (value: unknown) => boolean) => boolean;
649
+ declare const everyArrayValue: (values: readonly unknown[], predicate: BooleanPredicate<unknown>) => boolean;
613
650
  /**
614
651
  * Checks whether a tuple matches the provided element predicates in order.
615
652
  *
@@ -617,7 +654,7 @@ declare const everyArrayValue: (values: readonly unknown[], predicate: (value: u
617
654
  * @param predicates Predicates aligned to each tuple index.
618
655
  * @returns Whether lengths match and each index passes.
619
656
  */
620
- declare const everyTupleValue: (values: readonly unknown[], predicates: readonly ((value: unknown) => boolean)[]) => boolean;
657
+ declare const everyTupleValue: (values: readonly unknown[], predicates: readonly BooleanPredicate<unknown>[]) => boolean;
621
658
  /**
622
659
  * Checks whether every set value satisfies the provided predicate.
623
660
  *
@@ -625,7 +662,7 @@ declare const everyTupleValue: (values: readonly unknown[], predicates: readonly
625
662
  * @param predicate Predicate applied to each value.
626
663
  * @returns Whether all set values satisfy `predicate`.
627
664
  */
628
- declare const everySetValue: (values: ReadonlySet<unknown>, predicate: (value: unknown) => boolean) => boolean;
665
+ declare const everySetValue: (values: ReadonlySet<unknown>, predicate: BooleanPredicate<unknown>) => boolean;
629
666
  /**
630
667
  * Checks whether every map entry satisfies the provided key and value predicates.
631
668
  *
@@ -634,7 +671,7 @@ declare const everySetValue: (values: ReadonlySet<unknown>, predicate: (value: u
634
671
  * @param valuePredicate Predicate applied to each value.
635
672
  * @returns Whether all keys and values satisfy their predicates.
636
673
  */
637
- declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicate: (key: unknown) => boolean, valuePredicate: (value: unknown) => boolean) => boolean;
674
+ declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicate: BooleanPredicate<unknown>, valuePredicate: BooleanPredicate<unknown>) => boolean;
638
675
  /**
639
676
  * Checks whether every own enumerable string key/value pair satisfies the provided predicates.
640
677
  *
@@ -643,7 +680,7 @@ declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicat
643
680
  * @param valuePredicate Predicate applied to each corresponding value.
644
681
  * @returns Whether all enumerable entries satisfy their predicates.
645
682
  */
646
- declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPredicate: (key: string) => boolean, valuePredicate: (value: unknown) => boolean) => boolean;
683
+ declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPredicate: BooleanPredicate<string>, valuePredicate: BooleanPredicate<unknown>) => boolean;
647
684
 
648
685
  /**
649
686
  * Converts predicates to plain boolean predicates for iteration helpers.
@@ -653,4 +690,4 @@ declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPred
653
690
  */
654
691
  declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
655
692
 
656
- 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, 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
@@ -133,6 +133,17 @@ declare const hasKeys: <const KS extends readonly [PropertyKey, ...PropertyKey[]
133
133
  */
134
134
  declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <const T extends A[K]>(target: T) => Predicate<A & Record<K, T>>;
135
135
 
136
+ /**
137
+ * Creates a predicate whose implementation is initialized on first use.
138
+ *
139
+ * The initialized predicate is cached after the factory returns successfully.
140
+ * Circular references in the input value are not detected.
141
+ *
142
+ * @param factory Function that creates the predicate when it is first evaluated.
143
+ * @returns Predicate that delegates to the lazily initialized implementation.
144
+ */
145
+ declare function lazy<T>(factory: () => Predicate<T>): Predicate<T>;
146
+
136
147
  /**
137
148
  * Combines a precondition guard with an additional refinement to narrow the type.
138
149
  *
@@ -340,15 +351,34 @@ declare const isSymbol: Predicate<symbol>;
340
351
  /**
341
352
  * Checks whether a value is exactly `undefined`.
342
353
  *
354
+ * To accept `null` as well, use {@link isNil}.
355
+ *
343
356
  * @returns Predicate narrowing to `undefined`.
344
357
  */
345
358
  declare const isUndefined: Predicate<undefined>;
346
359
  /**
347
360
  * Checks whether a value is exactly `null`.
348
361
  *
362
+ * To accept `undefined` as well, use {@link isNil}.
363
+ *
349
364
  * @returns Predicate narrowing to `null`.
350
365
  */
351
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>;
352
382
  /**
353
383
  * Checks whether a value is a JavaScript primitive.
354
384
  *
@@ -474,6 +504,12 @@ declare const isURL: Guard<URL>;
474
504
  * @returns Predicate narrowing to `Blob` when supported; otherwise always false.
475
505
  */
476
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>;
477
513
  /**
478
514
  * Creates a guard that checks whether a value is an instance of `constructor`.
479
515
  *
@@ -602,6 +638,7 @@ declare function tupleOf<const Fs extends readonly Predicate<unknown>[]>(...guar
602
638
  readonly [K in keyof Fs]: GuardedOf<Fs[K]>;
603
639
  }>;
604
640
 
641
+ type BooleanPredicate<T> = (value: T) => boolean;
605
642
  /**
606
643
  * Checks whether every array element satisfies the provided predicate.
607
644
  *
@@ -609,7 +646,7 @@ declare function tupleOf<const Fs extends readonly Predicate<unknown>[]>(...guar
609
646
  * @param predicate Predicate applied to each element.
610
647
  * @returns Whether all elements satisfy `predicate`.
611
648
  */
612
- declare const everyArrayValue: (values: readonly unknown[], predicate: (value: unknown) => boolean) => boolean;
649
+ declare const everyArrayValue: (values: readonly unknown[], predicate: BooleanPredicate<unknown>) => boolean;
613
650
  /**
614
651
  * Checks whether a tuple matches the provided element predicates in order.
615
652
  *
@@ -617,7 +654,7 @@ declare const everyArrayValue: (values: readonly unknown[], predicate: (value: u
617
654
  * @param predicates Predicates aligned to each tuple index.
618
655
  * @returns Whether lengths match and each index passes.
619
656
  */
620
- declare const everyTupleValue: (values: readonly unknown[], predicates: readonly ((value: unknown) => boolean)[]) => boolean;
657
+ declare const everyTupleValue: (values: readonly unknown[], predicates: readonly BooleanPredicate<unknown>[]) => boolean;
621
658
  /**
622
659
  * Checks whether every set value satisfies the provided predicate.
623
660
  *
@@ -625,7 +662,7 @@ declare const everyTupleValue: (values: readonly unknown[], predicates: readonly
625
662
  * @param predicate Predicate applied to each value.
626
663
  * @returns Whether all set values satisfy `predicate`.
627
664
  */
628
- declare const everySetValue: (values: ReadonlySet<unknown>, predicate: (value: unknown) => boolean) => boolean;
665
+ declare const everySetValue: (values: ReadonlySet<unknown>, predicate: BooleanPredicate<unknown>) => boolean;
629
666
  /**
630
667
  * Checks whether every map entry satisfies the provided key and value predicates.
631
668
  *
@@ -634,7 +671,7 @@ declare const everySetValue: (values: ReadonlySet<unknown>, predicate: (value: u
634
671
  * @param valuePredicate Predicate applied to each value.
635
672
  * @returns Whether all keys and values satisfy their predicates.
636
673
  */
637
- declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicate: (key: unknown) => boolean, valuePredicate: (value: unknown) => boolean) => boolean;
674
+ declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicate: BooleanPredicate<unknown>, valuePredicate: BooleanPredicate<unknown>) => boolean;
638
675
  /**
639
676
  * Checks whether every own enumerable string key/value pair satisfies the provided predicates.
640
677
  *
@@ -643,7 +680,7 @@ declare const everyMapEntry: (values: ReadonlyMap<unknown, unknown>, keyPredicat
643
680
  * @param valuePredicate Predicate applied to each corresponding value.
644
681
  * @returns Whether all enumerable entries satisfy their predicates.
645
682
  */
646
- declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPredicate: (key: string) => boolean, valuePredicate: (value: unknown) => boolean) => boolean;
683
+ declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPredicate: BooleanPredicate<string>, valuePredicate: BooleanPredicate<unknown>) => boolean;
647
684
 
648
685
  /**
649
686
  * Converts predicates to plain boolean predicates for iteration helpers.
@@ -653,4 +690,4 @@ declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPred
653
690
  */
654
691
  declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
655
692
 
656
- 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, 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,
@@ -73,6 +75,7 @@ __export(index_exports, {
73
75
  isWeakMap: () => isWeakMap,
74
76
  isWeakSet: () => isWeakSet,
75
77
  isZero: () => isZero,
78
+ lazy: () => lazy,
76
79
  mapOf: () => mapOf,
77
80
  narrowKeyTo: () => narrowKeyTo,
78
81
  nonEmptyArrayOf: () => nonEmptyArrayOf,
@@ -111,6 +114,38 @@ function define(fn) {
111
114
  return (value) => !!fn(value);
112
115
  }
113
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
+
114
149
  // src/utils/object-tags.ts
115
150
  var objectToString = Object.prototype.toString;
116
151
  var OBJECT_TAG_DATE = "[object Date]";
@@ -124,6 +159,9 @@ var OBJECT_TAG_DATA_VIEW = "[object DataView]";
124
159
  var OBJECT_TAG_ERROR = "[object Error]";
125
160
  var getTag = (value) => objectToString.call(value);
126
161
 
162
+ // src/utils/to-boolean-predicates.ts
163
+ var toBooleanPredicates = (predicates) => predicates;
164
+
127
165
  // src/core/object.ts
128
166
  var defineTagGuard = (tag) => define((value) => getTag(value) === tag);
129
167
  var defineOptionalInstanceGuard = (constructor) => constructor === void 0 ? define(() => false) : define(
@@ -176,6 +214,9 @@ var isURL = defineOptionalInstanceGuard(
176
214
  var isBlob = defineOptionalInstanceGuard(
177
215
  typeof Blob === "undefined" ? void 0 : Blob
178
216
  );
217
+ var isFile = defineOptionalInstanceGuard(
218
+ typeof File === "undefined" ? void 0 : File
219
+ );
179
220
  var isInstanceOf = (constructor) => define((value) => value instanceof constructor);
180
221
 
181
222
  // src/core/equals.ts
@@ -220,41 +261,14 @@ function narrowKeyTo(guard, key) {
220
261
  };
221
262
  }
222
263
 
223
- // src/utils/guard-collections.ts
224
- var everyArrayValue = (values, predicate) => {
225
- for (const value of values) {
226
- if (!predicate(value)) return false;
227
- }
228
- return true;
229
- };
230
- var everyTupleValue = (values, predicates) => {
231
- if (values.length !== predicates.length) return false;
232
- for (const [index, predicate] of predicates.entries()) {
233
- if (!predicate(values[index])) return false;
234
- }
235
- return true;
236
- };
237
- var everySetValue = (values, predicate) => {
238
- for (const value of values) {
239
- if (!predicate(value)) return false;
240
- }
241
- return true;
242
- };
243
- var everyMapEntry = (values, keyPredicate, valuePredicate) => {
244
- for (const [key, value] of values) {
245
- if (!keyPredicate(key) || !valuePredicate(value)) return false;
246
- }
247
- return true;
248
- };
249
- var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => {
250
- for (const key of Object.keys(values)) {
251
- if (!keyPredicate(key) || !valuePredicate(values[key])) return false;
252
- }
253
- return true;
254
- };
255
-
256
- // src/utils/to-boolean-predicates.ts
257
- var toBooleanPredicates = (predicates) => predicates;
264
+ // src/core/lazy.ts
265
+ function lazy(factory) {
266
+ let predicate;
267
+ return (value) => {
268
+ predicate ??= factory();
269
+ return predicate(value);
270
+ };
271
+ }
258
272
 
259
273
  // src/core/logic.ts
260
274
  function and(precondition, condition) {
@@ -362,6 +376,7 @@ var isBigInt = define((value) => typeof value === "bigint");
362
376
  var isSymbol = define((value) => typeof value === "symbol");
363
377
  var isUndefined = define((value) => value === void 0);
364
378
  var isNull = define((value) => value === null);
379
+ var isNil = or(isNull, isUndefined);
365
380
  var isPrimitive = or(
366
381
  isString,
367
382
  isNumberPrimitive,
@@ -532,6 +547,7 @@ function tupleOf(...guards) {
532
547
  isDataView,
533
548
  isDate,
534
549
  isError,
550
+ isFile,
535
551
  isFiniteNumber,
536
552
  isFunction,
537
553
  isInfiniteNumber,
@@ -541,6 +557,7 @@ function tupleOf(...guards) {
541
557
  isMap,
542
558
  isNaN,
543
559
  isNegative,
560
+ isNil,
544
561
  isNull,
545
562
  isNumber,
546
563
  isNumberPrimitive,
@@ -560,6 +577,7 @@ function tupleOf(...guards) {
560
577
  isWeakMap,
561
578
  isWeakSet,
562
579
  isZero,
580
+ lazy,
563
581
  mapOf,
564
582
  narrowKeyTo,
565
583
  nonEmptyArrayOf,
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
@@ -119,41 +157,14 @@ function narrowKeyTo(guard, key) {
119
157
  };
120
158
  }
121
159
 
122
- // src/utils/guard-collections.ts
123
- var everyArrayValue = (values, predicate) => {
124
- for (const value of values) {
125
- if (!predicate(value)) return false;
126
- }
127
- return true;
128
- };
129
- var everyTupleValue = (values, predicates) => {
130
- if (values.length !== predicates.length) return false;
131
- for (const [index, predicate] of predicates.entries()) {
132
- if (!predicate(values[index])) return false;
133
- }
134
- return true;
135
- };
136
- var everySetValue = (values, predicate) => {
137
- for (const value of values) {
138
- if (!predicate(value)) return false;
139
- }
140
- return true;
141
- };
142
- var everyMapEntry = (values, keyPredicate, valuePredicate) => {
143
- for (const [key, value] of values) {
144
- if (!keyPredicate(key) || !valuePredicate(value)) return false;
145
- }
146
- return true;
147
- };
148
- var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => {
149
- for (const key of Object.keys(values)) {
150
- if (!keyPredicate(key) || !valuePredicate(values[key])) return false;
151
- }
152
- return true;
153
- };
154
-
155
- // src/utils/to-boolean-predicates.ts
156
- var toBooleanPredicates = (predicates) => predicates;
160
+ // src/core/lazy.ts
161
+ function lazy(factory) {
162
+ let predicate;
163
+ return (value) => {
164
+ predicate ??= factory();
165
+ return predicate(value);
166
+ };
167
+ }
157
168
 
158
169
  // src/core/logic.ts
159
170
  function and(precondition, condition) {
@@ -261,6 +272,7 @@ var isBigInt = define((value) => typeof value === "bigint");
261
272
  var isSymbol = define((value) => typeof value === "symbol");
262
273
  var isUndefined = define((value) => value === void 0);
263
274
  var isNull = define((value) => value === null);
275
+ var isNil = or(isNull, isUndefined);
264
276
  var isPrimitive = or(
265
277
  isString,
266
278
  isNumberPrimitive,
@@ -430,6 +442,7 @@ export {
430
442
  isDataView,
431
443
  isDate,
432
444
  isError,
445
+ isFile,
433
446
  isFiniteNumber,
434
447
  isFunction,
435
448
  isInfiniteNumber,
@@ -439,6 +452,7 @@ export {
439
452
  isMap,
440
453
  isNaN,
441
454
  isNegative,
455
+ isNil,
442
456
  isNull,
443
457
  isNumber,
444
458
  isNumberPrimitive,
@@ -458,6 +472,7 @@ export {
458
472
  isWeakMap,
459
473
  isWeakSet,
460
474
  isZero,
475
+ lazy,
461
476
  mapOf,
462
477
  narrowKeyTo,
463
478
  nonEmptyArrayOf,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-kit",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "Make 'isXXX' easier. Let's make your code type safe and more readable!",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",