is-kit 1.2.0 → 1.3.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
@@ -157,6 +157,25 @@ isInfiniteNumber(Infinity); // true
157
157
  isInfiniteNumber(1); // false
158
158
  ```
159
159
 
160
+ ### Object guards
161
+
162
+ Object/built-in guards cover arrays, dates, maps/sets, and more. Use
163
+ `isInstanceOf` when you want a reusable guard from a class constructor.
164
+
165
+ ```ts
166
+ import { isArray, isDate, isInstanceOf } from 'is-kit';
167
+
168
+ class Animal {}
169
+ class Dog extends Animal {}
170
+
171
+ const isAnimal = isInstanceOf(Animal);
172
+
173
+ isArray([]); // true
174
+ isDate(new Date()); // true
175
+ isAnimal(new Dog()); // true
176
+ isAnimal({}); // false
177
+ ```
178
+
160
179
  ## Core Ideas
161
180
 
162
181
  - **Define once**: `define<T>(fn)` turns a plain function into a type guard.
package/dist/index.d.mts CHANGED
@@ -461,6 +461,13 @@ declare const isURL: Predicate<URL>;
461
461
  * @returns Predicate narrowing to `Blob` when supported; otherwise always false.
462
462
  */
463
463
  declare const isBlob: Predicate<Blob>;
464
+ /**
465
+ * Creates a guard that checks whether a value is an instance of `constructor`.
466
+ *
467
+ * @param constructor Constructor used as the right-hand side of `instanceof`.
468
+ * @returns Predicate narrowing to `InstanceType<C>`.
469
+ */
470
+ declare const isInstanceOf: <C extends abstract new (...args: unknown[]) => unknown>(constructor: C) => Guard<InstanceType<C>>;
464
471
 
465
472
  /**
466
473
  * Checks whether a value has the specified own key.
@@ -491,4 +498,4 @@ declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <co
491
498
  */
492
499
  declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
493
500
 
494
- export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, guardIn, hasKey, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
501
+ export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, guardIn, hasKey, 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, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
package/dist/index.d.ts CHANGED
@@ -461,6 +461,13 @@ declare const isURL: Predicate<URL>;
461
461
  * @returns Predicate narrowing to `Blob` when supported; otherwise always false.
462
462
  */
463
463
  declare const isBlob: Predicate<Blob>;
464
+ /**
465
+ * Creates a guard that checks whether a value is an instance of `constructor`.
466
+ *
467
+ * @param constructor Constructor used as the right-hand side of `instanceof`.
468
+ * @returns Predicate narrowing to `InstanceType<C>`.
469
+ */
470
+ declare const isInstanceOf: <C extends abstract new (...args: unknown[]) => unknown>(constructor: C) => Guard<InstanceType<C>>;
464
471
 
465
472
  /**
466
473
  * Checks whether a value has the specified own key.
@@ -491,4 +498,4 @@ declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <co
491
498
  */
492
499
  declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
493
500
 
494
- export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, guardIn, hasKey, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
501
+ export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, guardIn, hasKey, 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, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
package/dist/index.js CHANGED
@@ -42,6 +42,7 @@ __export(index_exports, {
42
42
  isFiniteNumber: () => isFiniteNumber,
43
43
  isFunction: () => isFunction,
44
44
  isInfiniteNumber: () => isInfiniteNumber,
45
+ isInstanceOf: () => isInstanceOf,
45
46
  isInteger: () => isInteger,
46
47
  isIterable: () => isIterable,
47
48
  isMap: () => isMap,
@@ -218,6 +219,7 @@ var isError = define(
218
219
  );
219
220
  var isURL = typeof URL !== "undefined" ? define((value) => value instanceof URL) : define(() => false);
220
221
  var isBlob = typeof Blob !== "undefined" ? define((value) => value instanceof Blob) : define(() => false);
222
+ var isInstanceOf = (constructor) => define((value) => value instanceof constructor);
221
223
 
222
224
  // src/core/equals.ts
223
225
  function equals(target) {
@@ -421,6 +423,7 @@ function narrowKeyTo(guard, key) {
421
423
  isFiniteNumber,
422
424
  isFunction,
423
425
  isInfiniteNumber,
426
+ isInstanceOf,
424
427
  isInteger,
425
428
  isIterable,
426
429
  isMap,
package/dist/index.mjs CHANGED
@@ -130,6 +130,7 @@ var isError = define(
130
130
  );
131
131
  var isURL = typeof URL !== "undefined" ? define((value) => value instanceof URL) : define(() => false);
132
132
  var isBlob = typeof Blob !== "undefined" ? define((value) => value instanceof Blob) : define(() => false);
133
+ var isInstanceOf = (constructor) => define((value) => value instanceof constructor);
133
134
 
134
135
  // src/core/equals.ts
135
136
  function equals(target) {
@@ -332,6 +333,7 @@ export {
332
333
  isFiniteNumber,
333
334
  isFunction,
334
335
  isInfiniteNumber,
336
+ isInstanceOf,
335
337
  isInteger,
336
338
  isIterable,
337
339
  isMap,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-kit",
3
- "version": "1.2.0",
3
+ "version": "1.3.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",