@tolki/types 1.1.4 → 1.1.5
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 +2 -0
- package/package.json +1 -1
- package/src/arrays.d.ts +52 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/abetwothree/tolki/refs/heads/master/docs/vitepress/public/tolki-logo-short.svg" width="50%" alt="Laravel Tolki JS Logo"></p>
|
|
2
|
+
|
|
1
3
|
# Tolki JS Types Package
|
|
2
4
|
|
|
3
5
|
Utility TypeScript types for @tolki packages and Laravel HTTP responses.
|
package/package.json
CHANGED
package/src/arrays.d.ts
CHANGED
|
@@ -11,7 +11,58 @@ export interface ArrayAccess<TValue> {
|
|
|
11
11
|
|
|
12
12
|
export type ArrayInnerValue<X> = X extends ReadonlyArray<infer U> ? U : never;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Recursively extracts the deepest non-array value type.
|
|
16
|
+
* Useful for inferring the leaf value type after fully flattening nested arrays.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* FlatArrayValue<number> // number
|
|
20
|
+
* FlatArrayValue<number[]> // number
|
|
21
|
+
* FlatArrayValue<number[][]> // number
|
|
22
|
+
* FlatArrayValue<string | number[]> // string | number
|
|
23
|
+
*/
|
|
24
|
+
export type FlatArrayValue<T> = T extends readonly (infer U)[]
|
|
25
|
+
? FlatArrayValue<U>
|
|
26
|
+
: T;
|
|
27
|
+
|
|
28
|
+
export type ArrayItems<T> = readonly T[];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Represents a value that may be nested within arrays to any depth.
|
|
32
|
+
* Used by functions like `undot` that produce nested array structures
|
|
33
|
+
* from flat dot-notated keys.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* UndotValue<string> // string | UndotValue<string>[]
|
|
37
|
+
* UndotValue<number> // number | UndotValue<number>[]
|
|
38
|
+
*/
|
|
39
|
+
export type UndotValue<T> = T | UndotValue<T>[];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a string type contains a dot (.) separator.
|
|
43
|
+
*/
|
|
44
|
+
type ContainsDot<S> = S extends `${string}.${string}` ? true : false;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Determines the return type for array undot operations.
|
|
48
|
+
*
|
|
49
|
+
* - When keys are generic strings (could contain dots): returns `UndotValue<TValue>[]`
|
|
50
|
+
* - When keys are literal strings with dots: returns `UndotValue<TValue>[]`
|
|
51
|
+
* - When keys are literal strings without dots: returns `TValue[]`
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* UndotResult<"0" | "1", string> // string[]
|
|
55
|
+
* UndotResult<"0" | "1.0", string> // UndotValue<string>[]
|
|
56
|
+
* UndotResult<string, number> // UndotValue<number>[]
|
|
57
|
+
*/
|
|
58
|
+
export type UndotResult<
|
|
59
|
+
TKey extends PropertyKey,
|
|
60
|
+
TValue,
|
|
61
|
+
> = string extends TKey & string
|
|
62
|
+
? UndotValue<TValue>[]
|
|
63
|
+
: [true] extends [ContainsDot<TKey & string>]
|
|
64
|
+
? UndotValue<TValue>[]
|
|
65
|
+
: TValue[];
|
|
15
66
|
|
|
16
67
|
/**
|
|
17
68
|
* Helper type to check if an array is mutable (not readonly)
|