is-kit 1.7.3 → 1.8.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
@@ -309,22 +309,33 @@ if (isAdmin(value)) {
309
309
 
310
310
  Here are the kinds of problems `is-kit` is especially good at solving:
311
311
 
312
- ### API response checks
312
+ ### Typed object guard checks
313
313
 
314
314
  ```ts
315
- import { isNumber, isString, safeParse, struct } from 'is-kit';
315
+ import { isNumber, isString, optionalKey, safeParse, typedStruct } from 'is-kit';
316
316
 
317
- const isPost = struct({
317
+ type PostResponse = ApiResponse<'/posts/{id}', 'get'>;
318
+
319
+ const isPost = typedStruct<PostResponse>()({
318
320
  id: isNumber,
319
- title: isString
321
+ title: isString,
322
+ summary: optionalKey(isString)
320
323
  });
321
324
 
325
+ const payload: unknown = await fetchPost();
322
326
  const parsed = safeParse(isPost, payload);
327
+
323
328
  if (parsed.valid) {
324
329
  renderPost(parsed.value);
325
330
  }
326
331
  ```
327
332
 
333
+ `typedStruct<T>()` is a small helper for keeping hand-written `struct` guards in
334
+ sync with an existing object type. Optional keys in `T` must still be declared
335
+ with `optionalKey(...)`; this makes drift visible when the target type changes.
336
+ OpenAPI-generated response types are one useful case, but the helper is not an
337
+ OpenAPI validator or schema generator.
338
+
328
339
  ### Safe array filtering
329
340
 
330
341
  ```ts
@@ -371,7 +382,7 @@ https://is-kit-docs.vercel.app/
371
382
 
372
383
  ## 👨‍💻 Development
373
384
 
374
- Requires Node 22 and pnpm 10.33.4.
385
+ Requires Node 22.22.0 and pnpm 11.2.2.
375
386
 
376
387
  - `pnpm lint`
377
388
  - `pnpm build`
package/dist/index.d.mts CHANGED
@@ -11,7 +11,7 @@ type ParseResult<T> = {
11
11
  } | {
12
12
  valid: false;
13
13
  };
14
- type GuardedOf<F> = F extends (value: unknown) => value is infer G ? G : never;
14
+ type GuardedOf<F> = F extends ((value: unknown) => value is infer G) ? G : never;
15
15
  type GuardedWithin<Fs, A> = Extract<Fs extends readonly unknown[] ? GuardedOf<Fs[number]> : never, A>;
16
16
 
17
17
  type Primitive = string | number | boolean | bigint | symbol | null | undefined;
@@ -31,7 +31,7 @@ type SchemaField = Predicate<unknown> | OptionalSchemaField<Predicate<unknown>>;
31
31
  * Object schema consumed by `struct`.
32
32
  */
33
33
  type Schema = Readonly<Record<string, SchemaField>>;
34
- type Simplify<T> = {
34
+ type Simplify$1<T> = {
35
35
  [K in keyof T]: T[K];
36
36
  };
37
37
  type InferSchemaField<F> = F extends Predicate<unknown> ? GuardedOf<F> : F extends OptionalSchemaField<infer G> ? GuardedOf<G> : never;
@@ -44,7 +44,7 @@ type OptionalSchemaKeys<S extends Schema> = {
44
44
  /**
45
45
  * Infers the readonly object type produced by a `struct` schema.
46
46
  */
47
- type InferSchema<S extends Schema> = Simplify<{
47
+ type InferSchema<S extends Schema> = Simplify$1<{
48
48
  readonly [K in RequiredSchemaKeys<S>]: InferSchemaField<S[K]>;
49
49
  } & {
50
50
  readonly [K in OptionalSchemaKeys<S>]?: InferSchemaField<S[K]>;
@@ -381,31 +381,31 @@ declare const isDate: Predicate<Date>;
381
381
  *
382
382
  * @returns Predicate narrowing to `RegExp`.
383
383
  */
384
- declare const isRegExp: Predicate<RegExp>;
384
+ declare const isRegExp: Guard<RegExp>;
385
385
  /**
386
386
  * Checks whether a value is a `Map`.
387
387
  *
388
388
  * @returns Predicate narrowing to `Map<unknown, unknown>`.
389
389
  */
390
- declare const isMap: Predicate<Map<unknown, unknown>>;
390
+ declare const isMap: Guard<Map<unknown, unknown>>;
391
391
  /**
392
392
  * Checks whether a value is a `Set`.
393
393
  *
394
394
  * @returns Predicate narrowing to `Set<unknown>`.
395
395
  */
396
- declare const isSet: Predicate<Set<unknown>>;
396
+ declare const isSet: Guard<Set<unknown>>;
397
397
  /**
398
398
  * Checks whether a value is a `WeakMap`.
399
399
  *
400
400
  * @returns Predicate narrowing to `WeakMap<object, unknown>`.
401
401
  */
402
- declare const isWeakMap: Predicate<WeakMap<object, unknown>>;
402
+ declare const isWeakMap: Guard<WeakMap<object, unknown>>;
403
403
  /**
404
404
  * Checks whether a value is a `WeakSet`.
405
405
  *
406
406
  * @returns Predicate narrowing to `WeakSet<object>`.
407
407
  */
408
- declare const isWeakSet: Predicate<WeakSet<object>>;
408
+ declare const isWeakSet: Guard<WeakSet<object>>;
409
409
  /**
410
410
  * Checks whether a value is promise-like (has a `then` function).
411
411
  *
@@ -429,13 +429,13 @@ declare const isAsyncIterable: Predicate<AsyncIterable<unknown>>;
429
429
  *
430
430
  * @returns Predicate narrowing to `ArrayBuffer`.
431
431
  */
432
- declare const isArrayBuffer: Predicate<ArrayBuffer>;
432
+ declare const isArrayBuffer: Guard<ArrayBuffer>;
433
433
  /**
434
434
  * Checks whether a value is a `DataView`.
435
435
  *
436
436
  * @returns Predicate narrowing to `DataView`.
437
437
  */
438
- declare const isDataView: Predicate<DataView<ArrayBufferLike>>;
438
+ declare const isDataView: Guard<DataView<ArrayBufferLike>>;
439
439
  /**
440
440
  * Checks whether a value is a typed array view (any `ArrayBufferView` except DataView).
441
441
  *
@@ -553,6 +553,34 @@ declare function struct<S extends Schema>(schema: S, options?: {
553
553
  exact?: boolean;
554
554
  }): Predicate<InferSchema<S>>;
555
555
 
556
+ type Simplify<T> = {
557
+ [K in keyof T]: T[K];
558
+ };
559
+ type StringKeyOf<T> = Extract<keyof T, string>;
560
+ type OptionalKeys<T> = {
561
+ [K in keyof T]-?: {} extends Pick<T, K> ? K : never;
562
+ }[keyof T];
563
+ type RequiredKeys<T> = Exclude<keyof T, OptionalKeys<T>>;
564
+ type TypedStructShape<T extends object> = {
565
+ readonly [K in Extract<RequiredKeys<T>, string>]-?: Predicate<T[K]>;
566
+ } & {
567
+ readonly [K in Extract<OptionalKeys<T>, string>]-?: OptionalSchemaField<Predicate<T[K]>>;
568
+ };
569
+ type NoExtraKeys<S, Shape> = S & {
570
+ readonly [K in Exclude<keyof S, keyof Shape>]: never;
571
+ };
572
+ type TypedStructTarget<T extends object> = Simplify<Readonly<Pick<T, StringKeyOf<T>>>>;
573
+ /**
574
+ * Creates a `struct` builder checked against an existing object type.
575
+ * Optional target keys must also be declared with `optionalKey` so type drift
576
+ * stays visible when the target type changes.
577
+ *
578
+ * @returns Builder that rejects missing, extra, or incompatible struct fields.
579
+ */
580
+ declare function typedStruct<T extends object>(): <const S extends TypedStructShape<T>>(fields: NoExtraKeys<S, TypedStructShape<T>>, options?: {
581
+ exact?: boolean;
582
+ }) => Predicate<TypedStructTarget<T>>;
583
+
556
584
  /**
557
585
  * Validates a fixed-length tuple by applying element-wise guards.
558
586
  *
@@ -614,4 +642,4 @@ declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPred
614
642
  */
615
643
  declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
616
644
 
617
- 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, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf };
645
+ 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, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf, typedStruct };
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ type ParseResult<T> = {
11
11
  } | {
12
12
  valid: false;
13
13
  };
14
- type GuardedOf<F> = F extends (value: unknown) => value is infer G ? G : never;
14
+ type GuardedOf<F> = F extends ((value: unknown) => value is infer G) ? G : never;
15
15
  type GuardedWithin<Fs, A> = Extract<Fs extends readonly unknown[] ? GuardedOf<Fs[number]> : never, A>;
16
16
 
17
17
  type Primitive = string | number | boolean | bigint | symbol | null | undefined;
@@ -31,7 +31,7 @@ type SchemaField = Predicate<unknown> | OptionalSchemaField<Predicate<unknown>>;
31
31
  * Object schema consumed by `struct`.
32
32
  */
33
33
  type Schema = Readonly<Record<string, SchemaField>>;
34
- type Simplify<T> = {
34
+ type Simplify$1<T> = {
35
35
  [K in keyof T]: T[K];
36
36
  };
37
37
  type InferSchemaField<F> = F extends Predicate<unknown> ? GuardedOf<F> : F extends OptionalSchemaField<infer G> ? GuardedOf<G> : never;
@@ -44,7 +44,7 @@ type OptionalSchemaKeys<S extends Schema> = {
44
44
  /**
45
45
  * Infers the readonly object type produced by a `struct` schema.
46
46
  */
47
- type InferSchema<S extends Schema> = Simplify<{
47
+ type InferSchema<S extends Schema> = Simplify$1<{
48
48
  readonly [K in RequiredSchemaKeys<S>]: InferSchemaField<S[K]>;
49
49
  } & {
50
50
  readonly [K in OptionalSchemaKeys<S>]?: InferSchemaField<S[K]>;
@@ -381,31 +381,31 @@ declare const isDate: Predicate<Date>;
381
381
  *
382
382
  * @returns Predicate narrowing to `RegExp`.
383
383
  */
384
- declare const isRegExp: Predicate<RegExp>;
384
+ declare const isRegExp: Guard<RegExp>;
385
385
  /**
386
386
  * Checks whether a value is a `Map`.
387
387
  *
388
388
  * @returns Predicate narrowing to `Map<unknown, unknown>`.
389
389
  */
390
- declare const isMap: Predicate<Map<unknown, unknown>>;
390
+ declare const isMap: Guard<Map<unknown, unknown>>;
391
391
  /**
392
392
  * Checks whether a value is a `Set`.
393
393
  *
394
394
  * @returns Predicate narrowing to `Set<unknown>`.
395
395
  */
396
- declare const isSet: Predicate<Set<unknown>>;
396
+ declare const isSet: Guard<Set<unknown>>;
397
397
  /**
398
398
  * Checks whether a value is a `WeakMap`.
399
399
  *
400
400
  * @returns Predicate narrowing to `WeakMap<object, unknown>`.
401
401
  */
402
- declare const isWeakMap: Predicate<WeakMap<object, unknown>>;
402
+ declare const isWeakMap: Guard<WeakMap<object, unknown>>;
403
403
  /**
404
404
  * Checks whether a value is a `WeakSet`.
405
405
  *
406
406
  * @returns Predicate narrowing to `WeakSet<object>`.
407
407
  */
408
- declare const isWeakSet: Predicate<WeakSet<object>>;
408
+ declare const isWeakSet: Guard<WeakSet<object>>;
409
409
  /**
410
410
  * Checks whether a value is promise-like (has a `then` function).
411
411
  *
@@ -429,13 +429,13 @@ declare const isAsyncIterable: Predicate<AsyncIterable<unknown>>;
429
429
  *
430
430
  * @returns Predicate narrowing to `ArrayBuffer`.
431
431
  */
432
- declare const isArrayBuffer: Predicate<ArrayBuffer>;
432
+ declare const isArrayBuffer: Guard<ArrayBuffer>;
433
433
  /**
434
434
  * Checks whether a value is a `DataView`.
435
435
  *
436
436
  * @returns Predicate narrowing to `DataView`.
437
437
  */
438
- declare const isDataView: Predicate<DataView<ArrayBufferLike>>;
438
+ declare const isDataView: Guard<DataView<ArrayBufferLike>>;
439
439
  /**
440
440
  * Checks whether a value is a typed array view (any `ArrayBufferView` except DataView).
441
441
  *
@@ -553,6 +553,34 @@ declare function struct<S extends Schema>(schema: S, options?: {
553
553
  exact?: boolean;
554
554
  }): Predicate<InferSchema<S>>;
555
555
 
556
+ type Simplify<T> = {
557
+ [K in keyof T]: T[K];
558
+ };
559
+ type StringKeyOf<T> = Extract<keyof T, string>;
560
+ type OptionalKeys<T> = {
561
+ [K in keyof T]-?: {} extends Pick<T, K> ? K : never;
562
+ }[keyof T];
563
+ type RequiredKeys<T> = Exclude<keyof T, OptionalKeys<T>>;
564
+ type TypedStructShape<T extends object> = {
565
+ readonly [K in Extract<RequiredKeys<T>, string>]-?: Predicate<T[K]>;
566
+ } & {
567
+ readonly [K in Extract<OptionalKeys<T>, string>]-?: OptionalSchemaField<Predicate<T[K]>>;
568
+ };
569
+ type NoExtraKeys<S, Shape> = S & {
570
+ readonly [K in Exclude<keyof S, keyof Shape>]: never;
571
+ };
572
+ type TypedStructTarget<T extends object> = Simplify<Readonly<Pick<T, StringKeyOf<T>>>>;
573
+ /**
574
+ * Creates a `struct` builder checked against an existing object type.
575
+ * Optional target keys must also be declared with `optionalKey` so type drift
576
+ * stays visible when the target type changes.
577
+ *
578
+ * @returns Builder that rejects missing, extra, or incompatible struct fields.
579
+ */
580
+ declare function typedStruct<T extends object>(): <const S extends TypedStructShape<T>>(fields: NoExtraKeys<S, TypedStructShape<T>>, options?: {
581
+ exact?: boolean;
582
+ }) => Predicate<TypedStructTarget<T>>;
583
+
556
584
  /**
557
585
  * Validates a fixed-length tuple by applying element-wise guards.
558
586
  *
@@ -614,4 +642,4 @@ declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPred
614
642
  */
615
643
  declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
616
644
 
617
- 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, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf };
645
+ 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, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf, typedStruct };
package/dist/index.js CHANGED
@@ -93,7 +93,8 @@ __export(index_exports, {
93
93
  setOf: () => setOf,
94
94
  struct: () => struct,
95
95
  toBooleanPredicates: () => toBooleanPredicates,
96
- tupleOf: () => tupleOf
96
+ tupleOf: () => tupleOf,
97
+ typedStruct: () => typedStruct
97
98
  });
98
99
  module.exports = __toCommonJS(index_exports);
99
100
 
@@ -123,6 +124,7 @@ var OBJECT_TAG_ERROR = "[object Error]";
123
124
  var getTag = (value) => objectToString.call(value);
124
125
 
125
126
  // src/core/object.ts
127
+ var defineTagGuard = (tag) => define((value) => getTag(value) === tag);
126
128
  var defineOptionalInstanceGuard = (constructor) => constructor === void 0 ? define(() => false) : define(
127
129
  (value) => typeof constructor === "function" && value instanceof constructor
128
130
  );
@@ -145,21 +147,11 @@ var isArray = define(Array.isArray);
145
147
  var isDate = define(
146
148
  (value) => getTag(value) === OBJECT_TAG_DATE && !Number.isNaN(value.getTime())
147
149
  );
148
- var isRegExp = define(
149
- (value) => getTag(value) === OBJECT_TAG_REGEXP
150
- );
151
- var isMap = define(
152
- (value) => getTag(value) === OBJECT_TAG_MAP
153
- );
154
- var isSet = define(
155
- (value) => getTag(value) === OBJECT_TAG_SET
156
- );
157
- var isWeakMap = define(
158
- (value) => getTag(value) === OBJECT_TAG_WEAK_MAP
159
- );
160
- var isWeakSet = define(
161
- (value) => getTag(value) === OBJECT_TAG_WEAK_SET
162
- );
150
+ var isRegExp = defineTagGuard(OBJECT_TAG_REGEXP);
151
+ var isMap = defineTagGuard(OBJECT_TAG_MAP);
152
+ var isSet = defineTagGuard(OBJECT_TAG_SET);
153
+ var isWeakMap = defineTagGuard(OBJECT_TAG_WEAK_MAP);
154
+ var isWeakSet = defineTagGuard(OBJECT_TAG_WEAK_SET);
163
155
  var isPromiseLike = define(
164
156
  (value) => isFunction(readObjectProperty(value, "then"))
165
157
  );
@@ -169,12 +161,8 @@ var isIterable = define(
169
161
  var isAsyncIterable = define(
170
162
  (value) => isFunction(readObjectProperty(value, Symbol.asyncIterator))
171
163
  );
172
- var isArrayBuffer = define(
173
- (value) => getTag(value) === OBJECT_TAG_ARRAY_BUFFER
174
- );
175
- var isDataView = define(
176
- (value) => getTag(value) === OBJECT_TAG_DATA_VIEW
177
- );
164
+ var isArrayBuffer = defineTagGuard(OBJECT_TAG_ARRAY_BUFFER);
165
+ var isDataView = defineTagGuard(OBJECT_TAG_DATA_VIEW);
178
166
  var isTypedArray = define(
179
167
  (value) => ArrayBuffer.isView(value) && getTag(value) !== OBJECT_TAG_DATA_VIEW
180
168
  );
@@ -213,9 +201,7 @@ function equalsKey(key, target) {
213
201
  }
214
202
 
215
203
  // src/core/key.ts
216
- var hasKey = (key) => define(
217
- (input) => isObject(input) && Object.hasOwn(input, key)
218
- );
204
+ var hasKey = (key) => define((input) => isObject(input) && Object.hasOwn(input, key));
219
205
  var hasKeys = (...keys) => {
220
206
  if (keys.length === 0) {
221
207
  return define(() => false);
@@ -492,6 +478,15 @@ function struct(schema, options) {
492
478
  });
493
479
  }
494
480
 
481
+ // src/core/combinators/typed-struct.ts
482
+ function typedStruct() {
483
+ return (fields, options) => (
484
+ // WHY: `typedStruct` keeps `struct` runtime behavior while using the target
485
+ // type only to check that hand-written guard fields stay in sync.
486
+ struct(fields, options)
487
+ );
488
+ }
489
+
495
490
  // src/core/combinators/tuple.ts
496
491
  function tupleOf(...guards) {
497
492
  return define(
@@ -573,5 +568,6 @@ function tupleOf(...guards) {
573
568
  setOf,
574
569
  struct,
575
570
  toBooleanPredicates,
576
- tupleOf
571
+ tupleOf,
572
+ typedStruct
577
573
  });
package/dist/index.mjs CHANGED
@@ -24,6 +24,7 @@ var OBJECT_TAG_ERROR = "[object Error]";
24
24
  var getTag = (value) => objectToString.call(value);
25
25
 
26
26
  // src/core/object.ts
27
+ var defineTagGuard = (tag) => define((value) => getTag(value) === tag);
27
28
  var defineOptionalInstanceGuard = (constructor) => constructor === void 0 ? define(() => false) : define(
28
29
  (value) => typeof constructor === "function" && value instanceof constructor
29
30
  );
@@ -46,21 +47,11 @@ var isArray = define(Array.isArray);
46
47
  var isDate = define(
47
48
  (value) => getTag(value) === OBJECT_TAG_DATE && !Number.isNaN(value.getTime())
48
49
  );
49
- var isRegExp = define(
50
- (value) => getTag(value) === OBJECT_TAG_REGEXP
51
- );
52
- var isMap = define(
53
- (value) => getTag(value) === OBJECT_TAG_MAP
54
- );
55
- var isSet = define(
56
- (value) => getTag(value) === OBJECT_TAG_SET
57
- );
58
- var isWeakMap = define(
59
- (value) => getTag(value) === OBJECT_TAG_WEAK_MAP
60
- );
61
- var isWeakSet = define(
62
- (value) => getTag(value) === OBJECT_TAG_WEAK_SET
63
- );
50
+ var isRegExp = defineTagGuard(OBJECT_TAG_REGEXP);
51
+ var isMap = defineTagGuard(OBJECT_TAG_MAP);
52
+ var isSet = defineTagGuard(OBJECT_TAG_SET);
53
+ var isWeakMap = defineTagGuard(OBJECT_TAG_WEAK_MAP);
54
+ var isWeakSet = defineTagGuard(OBJECT_TAG_WEAK_SET);
64
55
  var isPromiseLike = define(
65
56
  (value) => isFunction(readObjectProperty(value, "then"))
66
57
  );
@@ -70,12 +61,8 @@ var isIterable = define(
70
61
  var isAsyncIterable = define(
71
62
  (value) => isFunction(readObjectProperty(value, Symbol.asyncIterator))
72
63
  );
73
- var isArrayBuffer = define(
74
- (value) => getTag(value) === OBJECT_TAG_ARRAY_BUFFER
75
- );
76
- var isDataView = define(
77
- (value) => getTag(value) === OBJECT_TAG_DATA_VIEW
78
- );
64
+ var isArrayBuffer = defineTagGuard(OBJECT_TAG_ARRAY_BUFFER);
65
+ var isDataView = defineTagGuard(OBJECT_TAG_DATA_VIEW);
79
66
  var isTypedArray = define(
80
67
  (value) => ArrayBuffer.isView(value) && getTag(value) !== OBJECT_TAG_DATA_VIEW
81
68
  );
@@ -114,9 +101,7 @@ function equalsKey(key, target) {
114
101
  }
115
102
 
116
103
  // src/core/key.ts
117
- var hasKey = (key) => define(
118
- (input) => isObject(input) && Object.hasOwn(input, key)
119
- );
104
+ var hasKey = (key) => define((input) => isObject(input) && Object.hasOwn(input, key));
120
105
  var hasKeys = (...keys) => {
121
106
  if (keys.length === 0) {
122
107
  return define(() => false);
@@ -393,6 +378,15 @@ function struct(schema, options) {
393
378
  });
394
379
  }
395
380
 
381
+ // src/core/combinators/typed-struct.ts
382
+ function typedStruct() {
383
+ return (fields, options) => (
384
+ // WHY: `typedStruct` keeps `struct` runtime behavior while using the target
385
+ // type only to check that hand-written guard fields stay in sync.
386
+ struct(fields, options)
387
+ );
388
+ }
389
+
396
390
  // src/core/combinators/tuple.ts
397
391
  function tupleOf(...guards) {
398
392
  return define(
@@ -473,5 +467,6 @@ export {
473
467
  setOf,
474
468
  struct,
475
469
  toBooleanPredicates,
476
- tupleOf
470
+ tupleOf,
471
+ typedStruct
477
472
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-kit",
3
- "version": "1.7.3",
3
+ "version": "1.8.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",
@@ -37,16 +37,11 @@
37
37
  "author": "nyaomaru",
38
38
  "license": "MIT",
39
39
  "devDependencies": {
40
- "@eslint/js": "^9.33.0",
41
40
  "@types/jest": "^30.0.0",
42
- "@typescript-eslint/eslint-plugin": "^8.12.0",
43
- "@typescript-eslint/parser": "^8.12.0",
44
- "eslint": "^9.33.0",
45
- "eslint-config-prettier": "^10.1.8",
46
- "eslint-plugin-prettier": "^5.5.4",
47
41
  "jest": "^30.0.5",
48
42
  "lefthook": "^2.0.13",
49
- "prettier": "^3.6.2",
43
+ "oxfmt": "^0.52.0",
44
+ "oxlint": "^1.67.0",
50
45
  "ts-jest": "^29.4.1",
51
46
  "tsd": "^0.33.0",
52
47
  "tsup": "^8.5.0",
@@ -62,7 +57,9 @@
62
57
  "scripts": {
63
58
  "test": "jest",
64
59
  "test:types": "tsd",
65
- "lint": "eslint .",
60
+ "lint": "oxlint .",
61
+ "format": "oxfmt .",
62
+ "format:check": "oxfmt --check .",
66
63
  "build": "tsup",
67
64
  "typedoc": "typedoc --out docs/public/api"
68
65
  }