is-kit 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -31,20 +31,26 @@ 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$1<T> = {
34
+ /**
35
+ * Object schema shape preserving concrete keys.
36
+ */
37
+ type SchemaShape<S extends object> = Readonly<{
38
+ [K in keyof S]: SchemaField;
39
+ }>;
40
+ type Simplify<T> = {
35
41
  [K in keyof T]: T[K];
36
42
  };
37
43
  type InferSchemaField<F> = F extends Predicate<unknown> ? GuardedOf<F> : F extends OptionalSchemaField<infer G> ? GuardedOf<G> : never;
38
- type RequiredSchemaKeys<S extends Schema> = {
44
+ type RequiredSchemaKeys<S extends SchemaShape<S>> = {
39
45
  [K in keyof S]-?: S[K] extends OptionalSchemaField<Predicate<unknown>> ? never : K;
40
46
  }[keyof S];
41
- type OptionalSchemaKeys<S extends Schema> = {
47
+ type OptionalSchemaKeys<S extends SchemaShape<S>> = {
42
48
  [K in keyof S]-?: S[K] extends OptionalSchemaField<Predicate<unknown>> ? K : never;
43
49
  }[keyof S];
44
50
  /**
45
51
  * Infers the readonly object type produced by a `struct` schema.
46
52
  */
47
- type InferSchema<S extends Schema> = Simplify$1<{
53
+ type InferSchema<S extends SchemaShape<S>> = Simplify<{
48
54
  readonly [K in RequiredSchemaKeys<S>]: InferSchemaField<S[K]>;
49
55
  } & {
50
56
  readonly [K in OptionalSchemaKeys<S>]?: InferSchemaField<S[K]>;
@@ -549,14 +555,10 @@ declare function optionalKey<G extends Predicate<unknown>>(guard: G): OptionalSc
549
555
  * @param options When `{ exact: true }`, disallows properties not in `schema`.
550
556
  * @returns Predicate that narrows to the inferred struct type.
551
557
  */
552
- declare function struct<S extends Schema>(schema: S, options?: {
558
+ declare function struct<const S extends SchemaShape<S>>(schema: S, options?: {
553
559
  exact?: boolean;
554
560
  }): Predicate<InferSchema<S>>;
555
561
 
556
- type Simplify<T> = {
557
- [K in keyof T]: T[K];
558
- };
559
- type StringKeyOf<T> = Extract<keyof T, string>;
560
562
  type OptionalKeys<T> = {
561
563
  [K in keyof T]-?: {} extends Pick<T, K> ? K : never;
562
564
  }[keyof T];
@@ -569,7 +571,7 @@ type TypedStructShape<T extends object> = {
569
571
  type NoExtraKeys<S, Shape> = S & {
570
572
  readonly [K in Exclude<keyof S, keyof Shape>]: never;
571
573
  };
572
- type TypedStructTarget<T extends object> = Simplify<Readonly<Pick<T, StringKeyOf<T>>>>;
574
+ type TypedStructFields<T extends object, S extends TypedStructShape<T>> = NoExtraKeys<S, TypedStructShape<T>>;
573
575
  /**
574
576
  * Creates a `struct` builder checked against an existing object type.
575
577
  * Optional target keys must also be declared with `optionalKey` so type drift
@@ -577,9 +579,9 @@ type TypedStructTarget<T extends object> = Simplify<Readonly<Pick<T, StringKeyOf
577
579
  *
578
580
  * @returns Builder that rejects missing, extra, or incompatible struct fields.
579
581
  */
580
- declare function typedStruct<T extends object>(): <const S extends TypedStructShape<T>>(fields: NoExtraKeys<S, TypedStructShape<T>>, options?: {
582
+ declare function typedStruct<T extends object>(): <const S extends TypedStructShape<T>>(fields: TypedStructFields<T, S>, options?: {
581
583
  exact?: boolean;
582
- }) => Predicate<TypedStructTarget<T>>;
584
+ }) => Predicate<InferSchema<TypedStructFields<T, S>>>;
583
585
 
584
586
  /**
585
587
  * Validates a fixed-length tuple by applying element-wise guards.
package/dist/index.d.ts CHANGED
@@ -31,20 +31,26 @@ 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$1<T> = {
34
+ /**
35
+ * Object schema shape preserving concrete keys.
36
+ */
37
+ type SchemaShape<S extends object> = Readonly<{
38
+ [K in keyof S]: SchemaField;
39
+ }>;
40
+ type Simplify<T> = {
35
41
  [K in keyof T]: T[K];
36
42
  };
37
43
  type InferSchemaField<F> = F extends Predicate<unknown> ? GuardedOf<F> : F extends OptionalSchemaField<infer G> ? GuardedOf<G> : never;
38
- type RequiredSchemaKeys<S extends Schema> = {
44
+ type RequiredSchemaKeys<S extends SchemaShape<S>> = {
39
45
  [K in keyof S]-?: S[K] extends OptionalSchemaField<Predicate<unknown>> ? never : K;
40
46
  }[keyof S];
41
- type OptionalSchemaKeys<S extends Schema> = {
47
+ type OptionalSchemaKeys<S extends SchemaShape<S>> = {
42
48
  [K in keyof S]-?: S[K] extends OptionalSchemaField<Predicate<unknown>> ? K : never;
43
49
  }[keyof S];
44
50
  /**
45
51
  * Infers the readonly object type produced by a `struct` schema.
46
52
  */
47
- type InferSchema<S extends Schema> = Simplify$1<{
53
+ type InferSchema<S extends SchemaShape<S>> = Simplify<{
48
54
  readonly [K in RequiredSchemaKeys<S>]: InferSchemaField<S[K]>;
49
55
  } & {
50
56
  readonly [K in OptionalSchemaKeys<S>]?: InferSchemaField<S[K]>;
@@ -549,14 +555,10 @@ declare function optionalKey<G extends Predicate<unknown>>(guard: G): OptionalSc
549
555
  * @param options When `{ exact: true }`, disallows properties not in `schema`.
550
556
  * @returns Predicate that narrows to the inferred struct type.
551
557
  */
552
- declare function struct<S extends Schema>(schema: S, options?: {
558
+ declare function struct<const S extends SchemaShape<S>>(schema: S, options?: {
553
559
  exact?: boolean;
554
560
  }): Predicate<InferSchema<S>>;
555
561
 
556
- type Simplify<T> = {
557
- [K in keyof T]: T[K];
558
- };
559
- type StringKeyOf<T> = Extract<keyof T, string>;
560
562
  type OptionalKeys<T> = {
561
563
  [K in keyof T]-?: {} extends Pick<T, K> ? K : never;
562
564
  }[keyof T];
@@ -569,7 +571,7 @@ type TypedStructShape<T extends object> = {
569
571
  type NoExtraKeys<S, Shape> = S & {
570
572
  readonly [K in Exclude<keyof S, keyof Shape>]: never;
571
573
  };
572
- type TypedStructTarget<T extends object> = Simplify<Readonly<Pick<T, StringKeyOf<T>>>>;
574
+ type TypedStructFields<T extends object, S extends TypedStructShape<T>> = NoExtraKeys<S, TypedStructShape<T>>;
573
575
  /**
574
576
  * Creates a `struct` builder checked against an existing object type.
575
577
  * Optional target keys must also be declared with `optionalKey` so type drift
@@ -577,9 +579,9 @@ type TypedStructTarget<T extends object> = Simplify<Readonly<Pick<T, StringKeyOf
577
579
  *
578
580
  * @returns Builder that rejects missing, extra, or incompatible struct fields.
579
581
  */
580
- declare function typedStruct<T extends object>(): <const S extends TypedStructShape<T>>(fields: NoExtraKeys<S, TypedStructShape<T>>, options?: {
582
+ declare function typedStruct<T extends object>(): <const S extends TypedStructShape<T>>(fields: TypedStructFields<T, S>, options?: {
581
583
  exact?: boolean;
582
- }) => Predicate<TypedStructTarget<T>>;
584
+ }) => Predicate<InferSchema<TypedStructFields<T, S>>>;
583
585
 
584
586
  /**
585
587
  * Validates a fixed-length tuple by applying element-wise guards.
package/dist/index.js CHANGED
@@ -459,7 +459,9 @@ function struct(schema, options) {
459
459
  const requiredEntries = [];
460
460
  const optionalEntries = [];
461
461
  const schemaKeys = [];
462
- for (const [key, field] of Object.entries(schema)) {
462
+ for (const key in schema) {
463
+ if (!Object.hasOwn(schema, key)) continue;
464
+ const field = schema[key];
463
465
  schemaKeys.push(key);
464
466
  if (isOptionalSchemaField(field)) {
465
467
  optionalEntries.push([key, field.guard]);
package/dist/index.mjs CHANGED
@@ -359,7 +359,9 @@ function struct(schema, options) {
359
359
  const requiredEntries = [];
360
360
  const optionalEntries = [];
361
361
  const schemaKeys = [];
362
- for (const [key, field] of Object.entries(schema)) {
362
+ for (const key in schema) {
363
+ if (!Object.hasOwn(schema, key)) continue;
364
+ const field = schema[key];
363
365
  schemaKeys.push(key);
364
366
  if (isOptionalSchemaField(field)) {
365
367
  optionalEntries.push([key, field.guard]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-kit",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
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",