@kakasoo/deep-strict-types 2.0.4 → 2.0.6
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 +141 -267
- package/bin/src/functions/DeepStrictAssert.d.ts +19 -0
- package/bin/src/functions/DeepStrictAssert.d.ts.map +1 -1
- package/bin/src/functions/DeepStrictAssert.js +19 -0
- package/bin/src/functions/DeepStrictAssert.js.map +1 -1
- package/bin/src/functions/DeepStrictObjectKeys.d.ts +27 -0
- package/bin/src/functions/DeepStrictObjectKeys.d.ts.map +1 -1
- package/bin/src/functions/DeepStrictObjectKeys.js +20 -0
- package/bin/src/functions/DeepStrictObjectKeys.js.map +1 -1
- package/bin/src/types/DeepDateToString.d.ts +22 -4
- package/bin/src/types/DeepDateToString.d.ts.map +1 -1
- package/bin/src/types/DeepStrictMerge.d.ts +11 -0
- package/bin/src/types/DeepStrictMerge.d.ts.map +1 -1
- package/bin/src/types/DeepStrictObjectKeys.d.ts +4 -3
- package/bin/src/types/DeepStrictObjectKeys.d.ts.map +1 -1
- package/bin/src/types/DeepStrictObjectLastKeys.d.ts +18 -3
- package/bin/src/types/DeepStrictObjectLastKeys.d.ts.map +1 -1
- package/bin/src/types/DeepStrictOmit.d.ts +13 -0
- package/bin/src/types/DeepStrictOmit.d.ts.map +1 -1
- package/bin/src/types/DeepStrictUnbrand.d.ts +13 -0
- package/bin/src/types/DeepStrictUnbrand.d.ts.map +1 -1
- package/bin/src/types/ElementOf.d.ts +28 -1
- package/bin/src/types/ElementOf.d.ts.map +1 -1
- package/bin/src/types/Equal.d.ts +31 -2
- package/bin/src/types/Equal.d.ts.map +1 -1
- package/bin/src/types/GetType.d.ts +35 -13
- package/bin/src/types/GetType.d.ts.map +1 -1
- package/bin/src/types/IsAny.d.ts +11 -6
- package/bin/src/types/IsAny.d.ts.map +1 -1
- package/bin/src/types/IsUnion.d.ts +26 -6
- package/bin/src/types/IsUnion.d.ts.map +1 -1
- package/bin/src/types/RemoveAfterDot.d.ts +22 -0
- package/bin/src/types/RemoveAfterDot.d.ts.map +1 -1
- package/bin/src/types/RemoveArraySymbol.d.ts +16 -4
- package/bin/src/types/RemoveArraySymbol.d.ts.map +1 -1
- package/bin/src/types/RemoveLastProperty.d.ts +21 -0
- package/bin/src/types/RemoveLastProperty.d.ts.map +1 -1
- package/bin/src/types/StringToDeepObject.d.ts +25 -0
- package/bin/src/types/StringToDeepObject.d.ts.map +1 -1
- package/bin/src/types/ValueType.d.ts +17 -0
- package/bin/src/types/ValueType.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import { DeepStrictUnbrand } from './DeepStrictUnbrand';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* @title Type for Recursively Converting All Date Types to String.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* A utility type that recursively traverses a nested object or array type and converts
|
|
6
|
+
* every `Date` type to `string`. This is useful for representing serialized forms of objects
|
|
7
|
+
* where dates are transmitted as ISO strings (e.g., JSON responses from APIs).
|
|
8
|
+
*
|
|
9
|
+
* Conversion rules:
|
|
10
|
+
* - If `T` is an array of objects, each element is processed recursively.
|
|
11
|
+
* - If `T` is a `Date`, it becomes `string`.
|
|
12
|
+
* - If `T` is an object, each property is checked: `Date` properties become `string`,
|
|
13
|
+
* nested objects are recursed into, and primitives are preserved as-is.
|
|
14
|
+
* - Union types containing `Date` (e.g., `Date | null`) have only the `Date` portion converted.
|
|
15
|
+
* - Branded types are unbranded via {@link DeepStrictUnbrand} before recursion.
|
|
16
|
+
*
|
|
17
|
+
* @template T - The object type to convert
|
|
18
|
+
* @returns A new type with all `Date` occurrences replaced by `string`
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* type Ex1 = DeepDateToString<{ created: Date; name: string }>; // { created: string; name: string }
|
|
23
|
+
* type Ex2 = DeepDateToString<{ items: { date: Date }[] }>; // { items: { date: string }[] }
|
|
24
|
+
* type Ex3 = DeepDateToString<{ prop: Date | null }>; // { prop: string | null }
|
|
25
|
+
* ```
|
|
8
26
|
*/
|
|
9
27
|
export type DeepDateToString<T extends object> = DeepStrictUnbrand<T> extends Array<infer I extends object> ? Array<DeepDateToString<I>> : T extends Date ? string : {
|
|
10
28
|
[K in keyof T]: T[K] extends infer I ? I extends Date ? string : DeepStrictUnbrand<I> extends object ? DeepDateToString<DeepStrictUnbrand<I>> : I : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeepDateToString.d.ts","sourceRoot":"","sources":["../../../src/types/DeepDateToString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD
|
|
1
|
+
{"version":3,"file":"DeepDateToString.d.ts","sourceRoot":"","sources":["../../../src/types/DeepDateToString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,IAC3C,iBAAiB,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,SAAS,MAAM,CAAC,GACtD,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAC1B,CAAC,SAAS,IAAI,GACZ,MAAM,GACN;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,GAChC,CAAC,SAAS,IAAI,GACZ,MAAM,GACN,iBAAiB,CAAC,CAAC,CAAC,SAAS,MAAM,GACjC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GACtC,CAAC,GACL,KAAK;CACV,CAAC"}
|
|
@@ -25,6 +25,17 @@ declare namespace DeepStrictMerge {
|
|
|
25
25
|
* 2. For array types, if both `Target` and `Source` are arrays and their elements are objects, those elements are merged.
|
|
26
26
|
* - If the elements of the arrays are not objects, merging is not possible.
|
|
27
27
|
* 3. If only one of the types is an array, merging is not possible.
|
|
28
|
+
*
|
|
29
|
+
* @template Target - The primary object type. Its values take precedence on overlapping keys.
|
|
30
|
+
* @template Source - The secondary object type whose unique keys are added to the result.
|
|
31
|
+
* @returns A deeply merged object type combining `Target` and `Source`
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* type Ex1 = DeepStrictMerge<{ a: 1 }, { b: 2 }>; // { a: 1; b: 2 }
|
|
36
|
+
* type Ex2 = DeepStrictMerge<{ a: { b: 1 } }, { a: { c: 2 } }>; // { a: { b: 1; c: 2 } }
|
|
37
|
+
* type Ex3 = DeepStrictMerge<{ a: 1 }, { a: 2 }>; // { a: 1 } (Target wins)
|
|
38
|
+
* ```
|
|
28
39
|
*/
|
|
29
40
|
export type DeepStrictMerge<Target extends object, Source extends object> = Target extends Array<infer TE extends object> ? Source extends Array<infer PE extends object> ? DeepStrictMerge.Infer<TE, PE>[] : never : DeepStrictMerge.Infer<Target, Source>;
|
|
30
41
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeepStrictMerge.d.ts","sourceRoot":"","sources":["../../../src/types/DeepStrictMerge.ts"],"names":[],"mappings":"AAAA,kBAAU,eAAe,CAAC;IACxB;;;;;;;;;;OAUG;IACH,KAAY,KAAK,CAAC,MAAM,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,IAAI;SAE/D,GAAG,IAAI,MAAM,MAAM,GAAG,MAAM,MAAM,GAAG,GAAG,SAAS,MAAM,MAAM,GAC1D,GAAG,SAAS,MAAM,MAAM,GACtB,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,GACxB,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,GACxB,MAAM,CAAC,GAAG,CAAC,SAAS,KAAK,CAAC,MAAM,EAAE,SAAS,MAAM,CAAC,GAChD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MAAM,CAAC,GAC3C,eAAe,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAC/B,KAAK,GACP,eAAe,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -30,9 +30,10 @@ declare namespace DeepStrictObjectKeys {
|
|
|
30
30
|
* type Example1 = DeepStrictObjectKeys<{ a: { b: 1; c: 2 } }>; // "a" | "a.b" | "a.c"
|
|
31
31
|
* type Example2 = DeepStrictObjectKeys<{ a: { b: 1; c: { d: number }[] } }>; // "a" | "a.b" | "a.c" | "a.c[*].d"
|
|
32
32
|
* ```
|
|
33
|
-
* @template Target
|
|
34
|
-
* @template Joiner
|
|
35
|
-
* @template IsSafe When
|
|
33
|
+
* @template Target - The object type to extract nested keys from
|
|
34
|
+
* @template Joiner - Defines the separator symbols for joining nested paths. `array` is used for array access (default `'[*]'`), `object` is used for object access (default `'.'`).
|
|
35
|
+
* @template IsSafe - When `true`, stops at union types that mix primitives and objects without recursing into them. When `false`, recursively explores all branches of such union types.
|
|
36
|
+
* @returns A union of all dot-notation key paths in `Target`
|
|
36
37
|
*/
|
|
37
38
|
export type DeepStrictObjectKeys<Target extends object, Joiner extends {
|
|
38
39
|
array: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeepStrictObjectKeys.d.ts","sourceRoot":"","sources":["../../../src/types/DeepStrictObjectKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,kBAAU,oBAAoB,CAAC;IAC7B;;;;;;OAMG;IACH,KAAY,KAAK,CACf,MAAM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C,IAAI,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GACvF,MAAM,CAAC,OAAO,CAAC,GAEnB,oBAAoB,CAAC,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -3,6 +3,16 @@ import type { IsAny } from './IsAny';
|
|
|
3
3
|
import type { IsUnion } from './IsUnion';
|
|
4
4
|
import type { ValueType } from './ValueType';
|
|
5
5
|
declare namespace DeepStrictObjectLastKeys {
|
|
6
|
+
/**
|
|
7
|
+
* @internal Recursively extracts only the leaf-level (last) keys from a nested object type.
|
|
8
|
+
*
|
|
9
|
+
* Unlike {@link DeepStrictObjectKeys.Infer}, this type skips intermediate keys and only
|
|
10
|
+
* returns the deepest reachable paths. Union-typed properties are treated as leaf keys.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The object type to extract leaf keys from
|
|
13
|
+
* @template Joiner - Separator symbols for array and object paths
|
|
14
|
+
* @template P - The current property keys being processed
|
|
15
|
+
*/
|
|
6
16
|
type Infer<T extends object, Joiner extends {
|
|
7
17
|
array: string;
|
|
8
18
|
object: string;
|
|
@@ -20,10 +30,15 @@ declare namespace DeepStrictObjectLastKeys {
|
|
|
20
30
|
* - For arrays, it appends array indices (`[*]`) followed by the key of the element.
|
|
21
31
|
* - For objects, it recursively traverses the nested structure and appends the last level keys.
|
|
22
32
|
*
|
|
23
|
-
*
|
|
33
|
+
* @template T - The object type to extract leaf keys from
|
|
34
|
+
* @template Joiner - Defines the separator symbols for joining nested paths. `array` is used for array access (default `'[*]'`), `object` is used for object access (default `'.'`).
|
|
35
|
+
* @template P - The property keys of `T` to iterate over (defaults to `keyof T`)
|
|
36
|
+
* @returns A union of dot-notation strings representing only the deepest (leaf) keys in `T`
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
24
39
|
* ```ts
|
|
25
|
-
* type
|
|
26
|
-
* type
|
|
40
|
+
* type Ex1 = DeepStrictObjectLastKeys<{ a: { b: { c: number[] } } }>; // "a.b.c"
|
|
41
|
+
* type Ex2 = DeepStrictObjectLastKeys<{ a: { b: number[]; c: { d: string }[] } }>; // "a.b" | "a.c[*].d"
|
|
27
42
|
* ```
|
|
28
43
|
*/
|
|
29
44
|
export type DeepStrictObjectLastKeys<T extends object, Joiner extends {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeepStrictObjectLastKeys.d.ts","sourceRoot":"","sources":["../../../src/types/DeepStrictObjectLastKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,kBAAU,wBAAwB,CAAC;IACjC,KAAY,KAAK,CACf,CAAC,SAAS,MAAM,EAChB,MAAM,SAAS;QACb,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG;QACF,KAAK,EAAE,KAAK,CAAC;QACb,MAAM,EAAE,GAAG,CAAC;KACb,EACD,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,IACzB,CAAC,SAAS,MAAM,GAChB,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GACxB,CAAC,GACD,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,OAAO,SAAS,MAAM,CAAC,GAC9C,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,GACpE,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,GACpB,CAAC,GACD,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SA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|
1
1
|
import type { DeepStrictObjectKeys } from './DeepStrictObjectKeys';
|
|
2
2
|
import type { GetElementMember } from './GetMember';
|
|
3
3
|
declare namespace DeepStrictOmit {
|
|
4
|
+
/**
|
|
5
|
+
* @internal Recursively omits keys from a non-array object type.
|
|
6
|
+
*
|
|
7
|
+
* Handles three cases for each property:
|
|
8
|
+
* - Array of objects: recurses into array elements using {@link GetElementMember} to extract sub-keys
|
|
9
|
+
* - Object (non-Date): recurses into the nested object
|
|
10
|
+
* - Primitive / Date / array of primitives: preserves as-is
|
|
11
|
+
*
|
|
12
|
+
* Top-level keys that exactly match `K` are removed via the `as` clause.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The object type to omit keys from
|
|
15
|
+
* @template K - The dot-notation key paths to omit (must be valid keys of `T`)
|
|
16
|
+
*/
|
|
4
17
|
type Infer<T extends object, K extends DeepStrictObjectKeys<T>> = [K] extends [never] ? T : {
|
|
5
18
|
[key in keyof T as key extends K ? never : key]: T[key] extends Array<infer Element extends object> ? key extends string ? Element extends Date ? Array<Element> : GetElementMember<K, key> extends DeepStrictObjectKeys<Element> ? Array<Infer<Element, GetElementMember<K, key>>> : Array<Element> : never : T[key] extends Array<infer Element> ? Array<Element> : T[key] extends object ? key extends string ? T[key] extends Date ? T[key] : GetElementMember<K, key> extends DeepStrictObjectKeys<T[key]> ? Infer<T[key], GetElementMember<K, key>> : T[key] : never : T[key];
|
|
6
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeepStrictOmit.d.ts","sourceRoot":"","sources":["../../../src/types/DeepStrictOmit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,kBAAU,cAAc,CAAC;IACvB,KAAY,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,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ChB,CAAC,CAAC,GAAG,CAAC,SAAS,IAAI,GACjB,CAAC,CAAC,GAAG,CAAC,GACN,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAC3D,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GACvC,CAAC,CAAC,GAAG,CAAC,GACV,KAAK,GACP,CAAC,CAAC,GAAG,CAAC;KACf,CAAC;CACP;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,IAC5E,CAAC,SAAS,KAAK,CAAC,MAAM,OAAO,SAAS,MAAM,CAAC,GACzC,KAAK,CACH,cAAc,CACZ,OAAO,EACP,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,oBAAoB,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,CAChG,CACF,GACD,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
declare namespace DeepStrictUnbrand {
|
|
2
|
+
/**
|
|
3
|
+
* @internal Union of all JavaScript primitive types.
|
|
4
|
+
* Used to detect branded primitives (primitives intersected with `Record<any, any>`).
|
|
5
|
+
*/
|
|
2
6
|
type Primitive = string | number | boolean | symbol | null | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* @internal Strips branding from a single branded primitive type.
|
|
9
|
+
*
|
|
10
|
+
* A "branded primitive" is a type like `string & { __brand: 'email' }`.
|
|
11
|
+
* This type pattern-matches the base primitive and returns it without the brand.
|
|
12
|
+
*
|
|
13
|
+
* @template T - A branded primitive type (must extend both `Primitive` and `Record<any, any>`)
|
|
14
|
+
* @returns The underlying primitive type with branding removed
|
|
15
|
+
*/
|
|
3
16
|
type Infer<T extends Primitive & Record<any, any>> = T extends string & Record<any, any> ? string : T extends number & Record<any, any> ? number : T extends boolean & Record<any, any> ? boolean : T extends symbol & Record<any, any> ? symbol : T extends null & Record<any, any> ? null : T extends undefined & Record<any, any> ? undefined : T;
|
|
4
17
|
}
|
|
5
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeepStrictUnbrand.d.ts","sourceRoot":"","sources":["../../../src/types/DeepStrictUnbrand.ts"],"names":[],"mappings":"AAAA,kBAAU,iBAAiB,CAAC;IAC1B,KAAY,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"DeepStrictUnbrand.d.ts","sourceRoot":"","sources":["../../../src/types/DeepStrictUnbrand.ts"],"names":[],"mappings":"AAAA,kBAAU,iBAAiB,CAAC;IAC1B;;;OAGG;IACH,KAAY,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAE9E;;;;;;;;OAQG;IACH,KAAY,KAAK,CAAC,CAAC,SAAS,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAC3F,MAAM,GACN,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GACjC,MAAM,GACN,CAAC,SAAS,OAAO,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAClC,OAAO,GACP,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GACjC,MAAM,GACN,CAAC,SAAS,IAAI,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAC/B,IAAI,GACJ,CAAC,SAAS,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GACpC,SAAS,GACT,CAAC,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,GAC3C,EAAE,GACF,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,SAAS,MAAM,CAAC,GACrC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAC3B,CAAC,SAAS,iBAAiB,CAAC,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,GAC1D,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,GAC1B,CAAC,SAAS,IAAI,GACZ,CAAC,GACD;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAC/B,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACvB,CAAC,CAAC,CAAC,CAAC;CACT,CAAC"}
|
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @title Type for Inferring the Element Type of an Array.
|
|
3
|
+
*
|
|
4
|
+
* Extracts the element type from an array type. This utility type uses conditional types
|
|
5
|
+
* with the `infer` keyword to extract the type of elements contained within an array.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The array type from which to extract the element type
|
|
8
|
+
* @returns The type of elements in the array, or `never` if T is not an array
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* type StringArray = string[];
|
|
13
|
+
* type StringElement = ElementOf<StringArray>; // string
|
|
14
|
+
*
|
|
15
|
+
* type NumberArray = number[];
|
|
16
|
+
* type NumberElement = ElementOf<NumberArray>; // number
|
|
17
|
+
*
|
|
18
|
+
* type MixedArray = (string | number)[];
|
|
19
|
+
* type MixedElement = ElementOf<MixedArray>; // string | number
|
|
20
|
+
*
|
|
21
|
+
* type ObjectArray = { id: number; name: string }[];
|
|
22
|
+
* type ObjectElement = ElementOf<ObjectArray>; // { id: number; name: string }
|
|
23
|
+
*
|
|
24
|
+
* type ReadonlyArray = readonly string[];
|
|
25
|
+
* type ReadonlyElement = ElementOf<ReadonlyArray>; // string
|
|
26
|
+
*
|
|
27
|
+
* type TupleArray = [string, number, boolean];
|
|
28
|
+
* type TupleElement = ElementOf<TupleArray>; // string | number | boolean
|
|
29
|
+
* ```
|
|
3
30
|
*/
|
|
4
|
-
export type ElementOf<T extends
|
|
31
|
+
export type ElementOf<T extends any[] | readonly any[]> = T extends (infer E)[] ? E : T extends readonly (infer E)[] ? E : never;
|
|
5
32
|
//# sourceMappingURL=ElementOf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElementOf.d.ts","sourceRoot":"","sources":["../../../src/types/ElementOf.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ElementOf.d.ts","sourceRoot":"","sources":["../../../src/types/ElementOf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,GAAG,EAAE,GAAG,SAAS,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC3E,CAAC,GACD,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC5B,CAAC,GACD,KAAK,CAAC"}
|
package/bin/src/types/Equal.d.ts
CHANGED
|
@@ -1,13 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Helper type that creates a generic function signature for type comparison.
|
|
3
|
+
* This technique leverages TypeScript's strict function type checking to determine type equality.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
3
6
|
*/
|
|
4
7
|
type Expression<X> = <T>() => T extends X ? 1 : 2;
|
|
5
8
|
/**
|
|
6
9
|
* @title Type for Checking if Two Types are Equal.
|
|
7
10
|
*
|
|
8
11
|
* The `Equal<X, Y>` type uses conditional types and a helper type `Expression<X>`
|
|
9
|
-
* to determine if two types `X` and `Y` are the same. It returns `true` if they are
|
|
12
|
+
* to determine if two types `X` and `Y` are exactly the same. It returns `true` if they are
|
|
10
13
|
* equal, and `false` otherwise.
|
|
14
|
+
*
|
|
15
|
+
* This type performs a strict equality check that distinguishes between:
|
|
16
|
+
* - Union types with different members
|
|
17
|
+
* - Branded types vs their base types
|
|
18
|
+
* - Optional vs required properties
|
|
19
|
+
*
|
|
20
|
+
* **Known limitation:** Due to how TypeScript resolves `any` in generic function signatures,
|
|
21
|
+
* `Equal<any, T>` returns `true` for any `T`. This means `any` cannot be distinguished
|
|
22
|
+
* from specific types using this approach.
|
|
23
|
+
*
|
|
24
|
+
* @template X - The first type to compare
|
|
25
|
+
* @template Y - The second type to compare
|
|
26
|
+
* @returns `true` if X and Y are exactly the same type, `false` otherwise
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* type Test1 = Equal<string, string>; // true
|
|
31
|
+
* type Test2 = Equal<string, number>; // false
|
|
32
|
+
* type Test3 = Equal<string | number, string | number>; // true
|
|
33
|
+
* type Test4 = Equal<string | number, number | string>; // true (order doesn't matter)
|
|
34
|
+
* type Test5 = Equal<{ a: string }, { a: string }>; // true
|
|
35
|
+
* type Test6 = Equal<{ a: string }, { a: string; b?: string }>; // false
|
|
36
|
+
* type Test7 = Equal<any, string>; // true (known limitation)
|
|
37
|
+
* type Test8 = Equal<unknown, any>; // true (known limitation)
|
|
38
|
+
* type Test9 = Equal<string & { __brand: 'ID' }, string>; // false (branded types)
|
|
39
|
+
* ```
|
|
11
40
|
*/
|
|
12
41
|
export type Equal<X, Y> = Expression<X> extends Expression<Y> ? true : false;
|
|
13
42
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Equal.d.ts","sourceRoot":"","sources":["../../../src/types/Equal.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Equal.d.ts","sourceRoot":"","sources":["../../../src/types/Equal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC"}
|
|
@@ -3,27 +3,49 @@ import type { DeepStrictObjectKeys } from './DeepStrictObjectKeys';
|
|
|
3
3
|
import type { ElementOf } from './ElementOf';
|
|
4
4
|
import type { RemoveArraySymbol } from './RemoveArraySymbol';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Helper type that extracts all value types from an object type.
|
|
7
|
+
* Similar to `T[keyof T]`, it returns a union of all property value types.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
* @template T - The object type to extract values from
|
|
7
11
|
*/
|
|
8
12
|
type ValueOf<T> = T[keyof T];
|
|
9
13
|
/**
|
|
10
|
-
* @title
|
|
14
|
+
* @title Type for extracting the type at a specific nested path in an object.
|
|
11
15
|
*
|
|
12
|
-
* This type extracts the type of a specific key from a nested object,
|
|
16
|
+
* This type extracts the type of a specific key from a nested object structure,
|
|
13
17
|
* supporting arrays and deeply nested keys. It uses `DeepStrictObjectKeys`
|
|
14
|
-
* to
|
|
18
|
+
* to validate the key path and correctly resolves the type for the given key.
|
|
19
|
+
*
|
|
20
|
+
* Key features:
|
|
21
|
+
* - Supports dot notation for nested object access (e.g., "a.b.c")
|
|
22
|
+
* - Handles array access with `[*]` notation (e.g., "items[*].name")
|
|
23
|
+
* - Type-safe: only accepts valid key paths as defined by `DeepStrictObjectKeys`
|
|
24
|
+
* - Recursively resolves nested types through objects and arrays
|
|
15
25
|
*
|
|
16
|
-
*
|
|
17
|
-
* -
|
|
18
|
-
*
|
|
26
|
+
* @template T - The object type to extract from
|
|
27
|
+
* @template K - The key path string (must be a valid key from DeepStrictObjectKeys<T>)
|
|
28
|
+
* @returns The type at the specified path, or `never` if the path is invalid
|
|
19
29
|
*
|
|
20
|
-
* @
|
|
21
|
-
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* type Data = {
|
|
33
|
+
* user: {
|
|
34
|
+
* name: string;
|
|
35
|
+
* posts: {
|
|
36
|
+
* title: string;
|
|
37
|
+
* tags: string[];
|
|
38
|
+
* }[];
|
|
39
|
+
* };
|
|
40
|
+
* };
|
|
22
41
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* type
|
|
26
|
-
* type
|
|
42
|
+
* type UserType = GetType<Data, "user">; // { name: string; posts: {...}[] }
|
|
43
|
+
* type NameType = GetType<Data, "user.name">; // string
|
|
44
|
+
* type PostsType = GetType<Data, "user.posts">; // { title: string; tags: string[] }[]
|
|
45
|
+
* type PostType = GetType<Data, "user.posts[*]">; // { title: string; tags: string[] }
|
|
46
|
+
* type TitleType = GetType<Data, "user.posts[*].title">; // string
|
|
47
|
+
* type TagsType = GetType<Data, "user.posts[*].tags">; // string[]
|
|
48
|
+
* type TagType = GetType<Data, "user.posts[*].tags[*]">; // string
|
|
27
49
|
* ```
|
|
28
50
|
*/
|
|
29
51
|
export type GetType<T extends object, K extends DeepStrictObjectKeys<T>> = StringType.Split<K, '.'> extends [infer First extends keyof T] ? ValueOf<Pick<T, First>> : StringType.Split<K, '.'> extends [infer First extends string, ...infer Rest extends string[]] ? RemoveArraySymbol<First> extends keyof T ? ValueOf<Pick<T, RemoveArraySymbol<First>>> extends object ? ValueOf<Pick<T, RemoveArraySymbol<First>>> extends Array<infer E> ? E extends object ? GetType<E, Extract<ArrayType.Join<Rest, '.'>, DeepStrictObjectKeys<E>>> : E : GetType<ValueOf<Pick<T, RemoveArraySymbol<First>>>, Extract<ArrayType.Join<Rest, '.'>, DeepStrictObjectKeys<ValueOf<Pick<T, RemoveArraySymbol<First>>>>>> : never : T extends any[] ? RemoveArraySymbol<First> extends '' ? GetType<ElementOf<T>, Extract<ArrayType.Join<Rest, '.'>, DeepStrictObjectKeys<ElementOf<T>>>> : never : never : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GetType.d.ts","sourceRoot":"","sources":["../../../src/types/GetType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D
|
|
1
|
+
{"version":3,"file":"GetType.d.ts","sourceRoot":"","sources":["../../../src/types/GetType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;;;;;GAMG;AACH,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,IACrE,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,MAAM,KAAK,SAAS,MAAM,CAAC,CAAC,GAC1D,OAAO,CAAC,IA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|
|
|
1
1
|
/**
|
|
2
|
-
* @title Type for
|
|
2
|
+
* @title Type for Checking if a Type is `any`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Determines whether the provided type `T` is `any`. It leverages the fact that `any`
|
|
5
|
+
* is the only type where `0 extends 1 & T` evaluates to `true`, because `1 & any` collapses
|
|
6
|
+
* to `any`, and `0 extends any` is always true.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* @template T - The type to check
|
|
9
|
+
* @returns `true` if `T` is `any`, `false` otherwise
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
10
13
|
* type Test1 = IsAny<any>; // true
|
|
11
14
|
* type Test2 = IsAny<string>; // false
|
|
15
|
+
* type Test3 = IsAny<unknown>; // false
|
|
16
|
+
* type Test4 = IsAny<never>; // false
|
|
12
17
|
* ```
|
|
13
18
|
*/
|
|
14
19
|
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IsAny.d.ts","sourceRoot":"","sources":["../../../src/types/IsAny.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"IsAny.d.ts","sourceRoot":"","sources":["../../../src/types/IsAny.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC"}
|
|
@@ -1,19 +1,39 @@
|
|
|
1
1
|
import type { Equal } from './Equal';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Helper type that checks if a partition of type T is the same as the entire type T.
|
|
4
|
+
* This works by distributing T through conditional types and checking if each partition
|
|
5
|
+
* equals the whole. For union types, this produces `false | true`, while for single types
|
|
6
|
+
* it produces just `false`.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
* @template T - The type to check
|
|
10
|
+
* @template P - The preserved original type (defaults to T)
|
|
4
11
|
*/
|
|
5
12
|
type IsPartitionSameEntire<T, P = T> = T extends any ? P extends T ? false : true : never;
|
|
6
13
|
/**
|
|
7
14
|
* @title Type for checking if a type is a union type.
|
|
8
15
|
*
|
|
9
|
-
* This type uses the `IsPartitionSameEntire` type to check whether the provided type `T` is a union type.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
16
|
+
* This type uses the `IsPartitionSameEntire` helper type to check whether the provided type `T` is a union type.
|
|
17
|
+
* It works by partitioning the type `T` and checking if the type consists of multiple distinct elements.
|
|
18
|
+
*
|
|
19
|
+
* The detection mechanism:
|
|
20
|
+
* - For union types: produces `boolean` (which is `false | true`)
|
|
21
|
+
* - For single types: produces `false`
|
|
22
|
+
* - Then checks if the result equals `boolean` to determine if it's a union
|
|
23
|
+
*
|
|
24
|
+
* @template T - The type to check
|
|
25
|
+
* @returns `true` if T is a union type, `false` otherwise
|
|
12
26
|
*
|
|
13
|
-
*
|
|
14
|
-
* ```
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
15
29
|
* type Test1 = IsUnion<string | number>; // true
|
|
16
30
|
* type Test2 = IsUnion<string>; // false
|
|
31
|
+
* type Test3 = IsUnion<'a' | 'b' | 'c'>; // true
|
|
32
|
+
* type Test4 = IsUnion<{ a: string } | { b: number }>; // true
|
|
33
|
+
* type Test5 = IsUnion<never>; // false
|
|
34
|
+
* type Test6 = IsUnion<unknown>; // false
|
|
35
|
+
* type Test7 = IsUnion<any>; // false
|
|
36
|
+
* type Test8 = IsUnion<boolean>; // true (boolean is true | false)
|
|
17
37
|
* ```
|
|
18
38
|
*/
|
|
19
39
|
export type IsUnion<T> = Equal<IsPartitionSameEntire<T>, boolean> extends true ? true : false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IsUnion.d.ts","sourceRoot":"","sources":["../../../src/types/IsUnion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"IsUnion.d.ts","sourceRoot":"","sources":["../../../src/types/IsUnion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC;;;;;;;;;GASG;AACH,KAAK,qBAAqB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,GAChD,CAAC,SAAS,CAAC,GACT,KAAK,GACL,IAAI,GACN,KAAK,CAAC;AAEV;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC"}
|
|
@@ -1,3 +1,25 @@
|
|
|
1
1
|
import { ElementOf } from './ElementOf';
|
|
2
|
+
/**
|
|
3
|
+
* @title Type for Generating Wildcard Patterns for Descendant Keys.
|
|
4
|
+
*
|
|
5
|
+
* A helper type used by {@link DeepStrictPick} to generate string patterns that match
|
|
6
|
+
* all keys below a given path in a nested object. This allows `DeepStrictPick` to preserve
|
|
7
|
+
* child properties when selecting a parent key.
|
|
8
|
+
*
|
|
9
|
+
* For object properties, it produces `"key.${string}"` patterns.
|
|
10
|
+
* For array properties, it produces `"key[*].${string}"` patterns.
|
|
11
|
+
* The type recurses through the object structure following the key path `K`.
|
|
12
|
+
*
|
|
13
|
+
* @template T - The object type to traverse
|
|
14
|
+
* @template K - The key path to generate descendant patterns for
|
|
15
|
+
* @returns A template literal type matching all descendant keys, or `never` if the path is invalid
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* type Ex1 = RemoveAfterDot<{ a: { b: number } }, "a">; // `a.${string}`
|
|
20
|
+
* type Ex2 = RemoveAfterDot<{ items: { name: string }[] }, "items">; // `items[*].${string}`
|
|
21
|
+
* type Ex3 = RemoveAfterDot<{ a: { b: { c: number } } }, "a.b">; // `a.b.${string}`
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
2
24
|
export type RemoveAfterDot<T extends object, K extends string> = K extends `${infer First}.${infer Last}` ? First extends keyof T ? T[First] extends Array<any> ? `${First}[*].${string}` : T[First] extends object ? `${First}.${RemoveAfterDot<T[First], Last>}` : never : First extends '[*]' ? T extends Array<any> ? RemoveAfterDot<ElementOf<T>, Last> : never : First extends `${infer Second extends string}[*]` ? Second extends keyof T ? T[Second] extends object ? `${First}.${RemoveAfterDot<T[Second], Last>}` : never : never : never : K extends keyof T ? T[K] extends Array<any> ? `${K}[*].${string}` : `${K}.${string}` : T extends Array<any> ? RemoveAfterDot<ElementOf<T>, K> : never;
|
|
3
25
|
//# sourceMappingURL=RemoveAfterDot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoveAfterDot.d.ts","sourceRoot":"","sources":["../../../src/types/RemoveAfterDot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,GACrG,KAAK,SAAS,MAAM,CAAC,GACnB,CAAC,CAAC,KAAK,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,GACzB,GAAG,KAAK,OAAO,MAAM,EAAE,GACvB,CAAC,CAAC,KAAK,CAAC,SAAS,MAAM,GACrB,GAAG,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,GAC5C,KAAK,GACT,KAAK,SAAS,KAAK,GACjB,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,GAClB,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE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C,CAAC,EAAE,IAAI,CAAC,GAClC,KAAK,GACP,KAAK,SAAS,GAAG,MAAM,MAAM,SAAS,MAAM,KAAK,GAC/C,MAAM,SAAS,MAAM,CAAC,GACpB,CAAC,CAAC,MAAM,CAAC,SAAS,MAAM,GACtB,GAAG,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,GAC7C,KAAK,GACP,KAAK,GACP,KAAK,GACX,CAAC,SAAS,MAAM,CAAC,GACf,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,GACrB,GAAG,CAAC,OAAO,MAAM,EAAE,GACnB,GAAG,CAAC,IAAI,MAAM,EAAE,GAClB,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,GAClB,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAC/B,KAAK,CAAC"}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @title
|
|
2
|
+
* @title Type for Stripping the Array Symbol Suffix from a Key String.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* A helper type that removes the trailing array symbol (default `[*]`) from a key string.
|
|
5
|
+
* Used internally by {@link GetType} and other types to extract the base property name
|
|
6
|
+
* from keys that include array notation.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
+
* If the string does not end with the array symbol, it is returned unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The key string to process
|
|
11
|
+
* @template ArraySymbol - The array symbol to strip (defaults to `[*]`)
|
|
12
|
+
* @returns The key string with the trailing array symbol removed, or the original string if no match
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* type Ex1 = RemoveArraySymbol<"items[*]">; // "items"
|
|
17
|
+
* type Ex2 = RemoveArraySymbol<"items">; // "items"
|
|
18
|
+
* type Ex3 = RemoveArraySymbol<"[*]">; // ""
|
|
19
|
+
* type Ex4 = RemoveArraySymbol<"data[]", "[]">; // "data"
|
|
8
20
|
* ```
|
|
9
21
|
*/
|
|
10
22
|
export type RemoveArraySymbol<T extends string, ArraySymbol extends string = '[*]'> = T extends `${infer P}${ArraySymbol}` ? P : T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoveArraySymbol.d.ts","sourceRoot":"","sources":["../../../src/types/RemoveArraySymbol.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"RemoveArraySymbol.d.ts","sourceRoot":"","sources":["../../../src/types/RemoveArraySymbol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,iBAAiB,CAC3B,CAAC,SAAS,MAAM,EAChB,WAAW,SAAS,MAAM,GAAG,KAAK,IAChC,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,WAAW,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -1,2 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Type for Extracting All Parent Path Segments from a Dot-Notation Key.
|
|
3
|
+
*
|
|
4
|
+
* A helper type used by {@link DeepStrictPick} to extract all intermediate (parent) paths
|
|
5
|
+
* from a dot-notation key string. When picking a nested key like `"a.b.c"`, the parent
|
|
6
|
+
* paths `"a"` and `"a.b"` must be preserved in the result. This type generates those paths.
|
|
7
|
+
*
|
|
8
|
+
* For paths containing array notation (`[*]`), both the array path and the base key
|
|
9
|
+
* without `[*]` are included.
|
|
10
|
+
*
|
|
11
|
+
* @template S - The dot-notation key string to extract parent paths from
|
|
12
|
+
* @returns A union of all parent path segments, or `never` if the key has no dots
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* type Ex1 = RemoveLastProperty<"a.b">; // "a"
|
|
17
|
+
* type Ex2 = RemoveLastProperty<"a.b.c">; // "a" | "a.b"
|
|
18
|
+
* type Ex3 = RemoveLastProperty<"a[*].b">; // "a[*]" | "a"
|
|
19
|
+
* type Ex4 = RemoveLastProperty<"a">; // never
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
1
22
|
export type RemoveLastProperty<S extends string> = S extends `${infer First}.${infer Last}` ? First extends `${infer ObjectPart}[*]` ? First | ObjectPart | `${First}.${RemoveLastProperty<Last>}` : `${First}` | `${First}.${RemoveLastProperty<Last>}` : never;
|
|
2
23
|
//# sourceMappingURL=RemoveLastProperty.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoveLastProperty.d.ts","sourceRoot":"","sources":["../../../src/types/RemoveLastProperty.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,GACvF,KAAK,SAAS,GAAG,MAAM,UAAU,KAAK,GACpC,KAAK,GAAG,UAAU,GAAG,GAAG,KAAK,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,GAC3D,GAAG,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,GACrD,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"RemoveLastProperty.d.ts","sourceRoot":"","sources":["../../../src/types/RemoveLastProperty.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,GACvF,KAAK,SAAS,GAAG,MAAM,UAAU,KAAK,GACpC,KAAK,GAAG,UAAU,GAAG,GAAG,KAAK,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,GAC3D,GAAG,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,GACrD,KAAK,CAAC"}
|
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
import { StringType } from '@kakasoo/proto-typescript';
|
|
2
|
+
/** @internal Converts a union type to an intersection type. */
|
|
2
3
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
4
|
+
/** @internal Extracts the portion before the first dot in a string. */
|
|
3
5
|
type BeforeDot<T extends string> = T extends `${infer Before}.${infer _}` ? Before : never;
|
|
6
|
+
/** @internal Extracts the portion after the first dot in a string. */
|
|
4
7
|
type AfterDot<T extends string> = T extends `${infer _}.${infer After}` ? After : never;
|
|
8
|
+
/** @internal Extracts a union of all property value types from an object. */
|
|
5
9
|
type ValueOf<T> = T[keyof T];
|
|
10
|
+
/** @internal Converts a string or number type to its string literal representation. */
|
|
6
11
|
type ToString<T> = T extends string ? T : T extends number ? `${T}` : never;
|
|
12
|
+
/**
|
|
13
|
+
* @title Type for Converting a Comma-Separated Dot-Notation String to a Nested Object Type.
|
|
14
|
+
*
|
|
15
|
+
* Converts a string like `"a.b,c"` into a nested object type `{ a: { b: any }; c: any }`.
|
|
16
|
+
* Comma-separated segments produce an intersection of records, and dot-separated segments
|
|
17
|
+
* produce nested `Record` types. Leaf values are typed as `any`.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The comma-separated dot-notation string to convert
|
|
20
|
+
* @template P - The split string segments (defaults to splitting T by comma)
|
|
21
|
+
* @returns A nested object type representing the string structure
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* type Ex1 = StringToDeepObject<"a">; // { a: any }
|
|
26
|
+
* type Ex2 = StringToDeepObject<"a.b">; // { a: { b: any } }
|
|
27
|
+
* type Ex3 = StringToDeepObject<"a,b">; // { a: any; b: any }
|
|
28
|
+
* type Ex4 = StringToDeepObject<"a.b,c">; // { a: { b: any }; c: any }
|
|
29
|
+
* type Ex5 = StringToDeepObject<"a.b.c">; // { a: { b: { c: any } } }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
7
32
|
export type StringToDeepObject<T extends string, P extends string[] = StringType.Split<T, ','>> = UnionToIntersection<ValueOf<{
|
|
8
33
|
[key in P[number]]: StringType.Includes<key, '.'> extends true ? Record<BeforeDot<key>, StringToDeepObject<ToString<AfterDot<key>>>> : Record<key, any>;
|
|
9
34
|
}>>;
|