lay-sing 0.1.2 → 0.2.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/README.md +78 -66
- package/esm/main/async.d.ts +9 -1
- package/esm/main/async.d.ts.map +1 -1
- package/esm/main/async.js.map +1 -1
- package/esm/main/boolean.d.ts +43 -20
- package/esm/main/boolean.d.ts.map +1 -1
- package/esm/main/boolean.js.map +1 -1
- package/esm/main/control.d.ts +70 -46
- package/esm/main/control.d.ts.map +1 -1
- package/esm/main/control.js.map +1 -1
- package/esm/main/doc.d.ts +33 -7
- package/esm/main/doc.d.ts.map +1 -1
- package/esm/main/doc.js.map +1 -1
- package/esm/main/function.d.ts +11 -5
- package/esm/main/function.d.ts.map +1 -1
- package/esm/main/function.js +0 -1
- package/esm/main/function.js.map +1 -1
- package/esm/main/index.d.ts +6 -1
- package/esm/main/index.d.ts.map +1 -1
- package/esm/main/index.js +8 -1
- package/esm/main/index.js.map +1 -1
- package/esm/main/key.d.ts +51 -13
- package/esm/main/key.d.ts.map +1 -1
- package/esm/main/key.js.map +1 -1
- package/esm/main/object.d.ts +74 -35
- package/esm/main/object.d.ts.map +1 -1
- package/esm/main/object.js.map +1 -1
- package/esm/main/tuple.d.ts +64 -0
- package/esm/main/tuple.d.ts.map +1 -0
- package/esm/main/tuple.js +2 -0
- package/esm/main/tuple.js.map +1 -0
- package/esm/main/type/compare.d.ts +118 -28
- package/esm/main/type/compare.d.ts.map +1 -1
- package/esm/main/type/compare.js.map +1 -1
- package/esm/main/type/index.d.ts.map +1 -1
- package/esm/main/type/index.js +2 -0
- package/esm/main/type/index.js.map +1 -1
- package/esm/main/type/set.d.ts +17 -12
- package/esm/main/type/set.d.ts.map +1 -1
- package/esm/main/type/set.js.map +1 -1
- package/esm/test-utils/compare.d.ts +81 -0
- package/esm/test-utils/compare.d.ts.map +1 -0
- package/esm/test-utils/compare.js +2 -0
- package/esm/test-utils/compare.js.map +1 -0
- package/esm/test-utils/expect.d.ts +278 -0
- package/esm/test-utils/expect.d.ts.map +1 -0
- package/esm/test-utils/expect.js +2 -0
- package/esm/test-utils/expect.js.map +1 -0
- package/esm/test-utils/index.d.ts +77 -0
- package/esm/test-utils/index.d.ts.map +1 -0
- package/esm/{test-utils.js → test-utils/index.js} +9 -5
- package/esm/test-utils/index.js.map +1 -0
- package/package.json +3 -3
- package/script/main/async.d.ts +9 -1
- package/script/main/async.d.ts.map +1 -1
- package/script/main/async.js.map +1 -1
- package/script/main/boolean.d.ts +43 -20
- package/script/main/boolean.d.ts.map +1 -1
- package/script/main/boolean.js.map +1 -1
- package/script/main/control.d.ts +70 -46
- package/script/main/control.d.ts.map +1 -1
- package/script/main/control.js.map +1 -1
- package/script/main/doc.d.ts +33 -7
- package/script/main/doc.d.ts.map +1 -1
- package/script/main/doc.js.map +1 -1
- package/script/main/function.d.ts +11 -5
- package/script/main/function.d.ts.map +1 -1
- package/script/main/function.js +0 -1
- package/script/main/function.js.map +1 -1
- package/script/main/index.d.ts +6 -1
- package/script/main/index.d.ts.map +1 -1
- package/script/main/index.js +8 -1
- package/script/main/index.js.map +1 -1
- package/script/main/key.d.ts +51 -13
- package/script/main/key.d.ts.map +1 -1
- package/script/main/key.js.map +1 -1
- package/script/main/object.d.ts +74 -35
- package/script/main/object.d.ts.map +1 -1
- package/script/main/object.js.map +1 -1
- package/script/main/tuple.d.ts +64 -0
- package/script/main/tuple.d.ts.map +1 -0
- package/script/main/{array.js → tuple.js} +1 -1
- package/script/main/tuple.js.map +1 -0
- package/script/main/type/compare.d.ts +118 -28
- package/script/main/type/compare.d.ts.map +1 -1
- package/script/main/type/compare.js.map +1 -1
- package/script/main/type/index.d.ts.map +1 -1
- package/script/main/type/index.js +2 -0
- package/script/main/type/index.js.map +1 -1
- package/script/main/type/set.d.ts +17 -12
- package/script/main/type/set.d.ts.map +1 -1
- package/script/main/type/set.js.map +1 -1
- package/script/test-utils/compare.d.ts +81 -0
- package/script/test-utils/compare.d.ts.map +1 -0
- package/script/test-utils/compare.js +3 -0
- package/script/test-utils/compare.js.map +1 -0
- package/script/test-utils/expect.d.ts +278 -0
- package/script/test-utils/expect.d.ts.map +1 -0
- package/script/test-utils/expect.js +3 -0
- package/script/test-utils/expect.js.map +1 -0
- package/script/test-utils/index.d.ts +77 -0
- package/script/test-utils/index.d.ts.map +1 -0
- package/script/{test-utils.js → test-utils/index.js} +10 -6
- package/script/test-utils/index.js.map +1 -0
- package/esm/main/array.d.ts +0 -48
- package/esm/main/array.d.ts.map +0 -1
- package/esm/main/array.js +0 -2
- package/esm/main/array.js.map +0 -1
- package/esm/test-utils.d.ts +0 -348
- package/esm/test-utils.d.ts.map +0 -1
- package/esm/test-utils.js.map +0 -1
- package/script/main/array.d.ts +0 -48
- package/script/main/array.d.ts.map +0 -1
- package/script/main/array.js.map +0 -1
- package/script/test-utils.d.ts +0 -348
- package/script/test-utils.d.ts.map +0 -1
- package/script/test-utils.js.map +0 -1
package/esm/main/doc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc.js","sourceRoot":"","sources":["../../src/main/doc.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Append documentation or auxiliary metadata to type `
|
|
1
|
+
{"version":3,"file":"doc.js","sourceRoot":"","sources":["../../src/main/doc.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Append documentation or auxiliary metadata to type `T`\n * without changing its shape.\n *\n * This type intersects `Doc` onto `T`, but only keeps the keys\n * originally defined in `T`. As a result:\n *\n * - `Doc` cannot introduce new properties\n * - Existing properties in `T` are preserved\n * - `Doc` may further constrain or annotate existing properties\n *\n * This is typically used to attach JSDoc comments, branding,\n * or editor-only metadata to an existing type while keeping\n * its public structure intact.\n *\n * @template T - The target type to append documentation to\n * @template Doc - The documentation or metadata type to append\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * type User = { name: string; age: number }\n * type UserWithDoc = AppendDoc<User, { name: string }>\n *\n * expect<UserWithDoc>().toBe<User>().success\n * ```\n */\nexport type AppendDoc<T, Doc> = Pick<T & Doc, keyof T>\n\n/**\n * Prepend documentation or auxiliary metadata to type `T`\n * without changing its shape.\n *\n * This is similar to {@link AppendDoc}, but the intersection order\n * is reversed (`Doc & T`), which can affect how property types,\n * documentation, and hover information are presented by tooling.\n *\n * In practice, this allows `Doc` to act as a non-invasive,\n * descriptive layer while ensuring `T` remains the authoritative\n * source of truth for property types.\n *\n * @template T - The target type to prepend documentation to\n * @template Doc - The documentation or metadata type to prepend\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * type User = { name: string; age: number }\n * type UserWithDoc = PrependDoc<User, { age: number }>\n *\n * expect<UserWithDoc>().toBe<User>().success\n * ```\n */\nexport type PrependDoc<T, Doc> = Pick<Doc & T, keyof T>\n"]}
|
package/esm/main/function.d.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Represents a function with any parameters and a specific return type
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* @template Return - The return type of the function
|
|
5
|
+
* @template Params - The parameters of the function as a tuple type
|
|
5
6
|
*
|
|
7
|
+
* @example
|
|
6
8
|
* ```ts
|
|
7
|
-
* type
|
|
9
|
+
* type NumberToStringFn = AnyFunction<string, [number]>
|
|
10
|
+
* // Equivalent to: (arg: number) => string
|
|
8
11
|
* ```
|
|
9
12
|
*/
|
|
10
13
|
export type AnyFunction<Return = any, Params extends any[] = any[]> = (...args: Params) => Return;
|
|
11
14
|
/**
|
|
12
|
-
* Represents a constructor with any parameters and a specific return type
|
|
15
|
+
* Represents a constructor function with any parameters and a specific return type
|
|
13
16
|
*
|
|
14
|
-
*
|
|
17
|
+
* @template Return - The type returned by the constructor function
|
|
18
|
+
* @template Params - The parameters of the constructor function as a tuple type
|
|
15
19
|
*
|
|
20
|
+
* @example
|
|
16
21
|
* ```ts
|
|
17
|
-
* type
|
|
22
|
+
* type StringConstructor = Constructor<string, [number]>
|
|
23
|
+
* // Equivalent to: new (arg: number) => string
|
|
18
24
|
* ```
|
|
19
25
|
*/
|
|
20
26
|
export type Constructor<Return = any, Params extends any[] = any[]> = new (...args: Params) => Return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/main/function.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/main/function.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,CACrB,MAAM,GAAG,GAAG,EACZ,MAAM,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE,IAC1B,CAAC,GAAG,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;AAE/B;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,CACrB,MAAM,GAAG,GAAG,EACZ,MAAM,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE,IAC1B,KAAK,GAAG,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA"}
|
package/esm/main/function.js
CHANGED
package/esm/main/function.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/main/function.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/main/function.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a function with any parameters and a specific return type\n *\n * @template Return - The return type of the function\n * @template Params - The parameters of the function as a tuple type\n *\n * @example\n * ```ts\n * type NumberToStringFn = AnyFunction<string, [number]>\n * // Equivalent to: (arg: number) => string\n * ```\n */\nexport type AnyFunction<\n Return = any,\n Params extends any[] = any[],\n> = (...args: Params) => Return\n\n/**\n * Represents a constructor function with any parameters and a specific return type\n *\n * @template Return - The type returned by the constructor function\n * @template Params - The parameters of the constructor function as a tuple type\n *\n * @example\n * ```ts\n * type StringConstructor = Constructor<string, [number]>\n * // Equivalent to: new (arg: number) => string\n * ```\n */\nexport type Constructor<\n Return = any,\n Params extends any[] = any[],\n> = new (...args: Params) => Return\n"]}
|
package/esm/main/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* [Full API documentation is available on JSR](https://jsr.io/@leawind/lay-sing/doc)
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
2
6
|
export * from './async.js';
|
|
3
7
|
export * from './boolean.js';
|
|
4
8
|
export * from './control.js';
|
|
@@ -7,6 +11,7 @@ export * from './function.js';
|
|
|
7
11
|
export * from './json.js';
|
|
8
12
|
export * from './key.js';
|
|
9
13
|
export * from './object.js';
|
|
14
|
+
export * from './tuple.js';
|
|
10
15
|
export * from './type/index.js';
|
|
11
16
|
export * from './typed-array.js';
|
|
12
17
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/main/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
|
package/esm/main/index.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* [Full API documentation is available on JSR](https://jsr.io/@leawind/lay-sing/doc)
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
// Index start >>>>>>>>>>>>>>>>
|
|
2
7
|
export * from './async.js';
|
|
3
8
|
export * from './boolean.js';
|
|
4
9
|
export * from './control.js';
|
|
@@ -7,6 +12,8 @@ export * from './function.js';
|
|
|
7
12
|
export * from './json.js';
|
|
8
13
|
export * from './key.js';
|
|
9
14
|
export * from './object.js';
|
|
15
|
+
export * from './tuple.js';
|
|
10
16
|
export * from './type/index.js';
|
|
11
17
|
export * from './typed-array.js';
|
|
18
|
+
// <<<<<<<<<<<<<<<< Index end
|
|
12
19
|
//# sourceMappingURL=index.js.map
|
package/esm/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+BAA+B;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,+BAA+B","sourcesContent":["/**\n * [Full API documentation is available on JSR](https://jsr.io/@leawind/lay-sing/doc)\n *\n * @module\n */\n\n// Index start >>>>>>>>>>>>>>>>\nexport * from './async.js'\nexport * from './boolean.js'\nexport * from './control.js'\nexport * from './doc.js'\nexport * from './function.js'\nexport * from './json.js'\nexport * from './key.js'\nexport * from './object.js'\nexport * from './tuple.js'\nexport * from './type/index.js'\nexport * from './typed-array.js'\n// <<<<<<<<<<<<<<<< Index end\n"]}
|
package/esm/main/key.d.ts
CHANGED
|
@@ -1,26 +1,64 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Exact } from './type/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Extracts the keys of type
|
|
3
|
+
* Extracts the keys of an object whose **base value type** matches the specified `ValueType` (ignoring undefined from optional properties).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* This utility matches the underlying/base type of each property (stripping `undefined` added by optional modifiers `?`).
|
|
6
|
+
* For optional properties (e.g., `a?: string`), the type is treated as `string` – no need to include `undefined` in `ValueType` to match.
|
|
6
7
|
*
|
|
8
|
+
* @template Obj - The target object type to extract keys from.
|
|
9
|
+
* @template ValueType - The base type to match against property values (ignoring undefined from optional properties).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
7
12
|
* ```ts
|
|
8
|
-
*
|
|
9
|
-
*
|
|
13
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
14
|
+
*
|
|
15
|
+
* // Basic usage: match base type (non-optional property)
|
|
16
|
+
* type A = { a: 1; b: 2; c: 1 };
|
|
17
|
+
* expect<KeysOfBaseType<A, 1>>().toBe<'a' | 'c'>().success
|
|
18
|
+
*
|
|
19
|
+
* // Key difference: optional property matching (ignores undefined)
|
|
20
|
+
* type B = { a?: string; b: string };
|
|
21
|
+
* expect<KeysOfBaseType<B, string>>().toBe<'a' | 'b'>().success // matches base type of both
|
|
22
|
+
* expect<KeysOfBaseType<B, string | undefined>>().toBe<never>().success // base type does not include undefined
|
|
23
|
+
*
|
|
24
|
+
* type C = { a: never; b: any; c: unknown };
|
|
25
|
+
* expect<KeysOfBaseType<C, never>>().toBe<'a'>().success
|
|
26
|
+
* expect<KeysOfBaseType<C, any>>().toBe<'b'>().success
|
|
27
|
+
* expect<KeysOfBaseType<C, unknown>>().toBe<'c'>().success
|
|
10
28
|
* ```
|
|
11
29
|
*/
|
|
12
|
-
export type
|
|
13
|
-
[K in keyof
|
|
14
|
-
}[keyof
|
|
30
|
+
export type KeysOfBaseType<Obj, ValueType> = Exclude<{
|
|
31
|
+
[K in keyof Obj]: Exact<Required<Obj>[K], ValueType> extends true ? K : never;
|
|
32
|
+
}[keyof Obj], undefined>;
|
|
15
33
|
/**
|
|
16
|
-
* Extracts the keys of type
|
|
34
|
+
* Extracts the keys of an object whose **complete value type** exactly matches the specified `ValueType` (including undefined for optional properties).
|
|
17
35
|
*
|
|
18
|
-
*
|
|
36
|
+
* This utility strictly matches the full type of each property (including `undefined` added by optional modifiers `?`).
|
|
37
|
+
* For optional properties (e.g., `a?: string`), the type is treated as `string | undefined` – to match, `ValueType` must include `undefined`.
|
|
19
38
|
*
|
|
39
|
+
* @template Obj - The target object type to extract keys from.
|
|
40
|
+
* @template ValueType - The exact type to match against property values (including undefined for optional properties).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
20
43
|
* ```ts
|
|
21
|
-
*
|
|
22
|
-
*
|
|
44
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
45
|
+
*
|
|
46
|
+
* // Basic usage: match exact type (non-optional property)
|
|
47
|
+
* type A = { a: 1; b: 2; c: 1 };
|
|
48
|
+
* expect<KeysOfExactType<A, 1>>().toBe<'a' | 'c'>().success
|
|
49
|
+
*
|
|
50
|
+
* // Key difference: optional property matching (requires undefined in `ValueType`)
|
|
51
|
+
* type B = { a?: string };
|
|
52
|
+
* expect<KeysOfExactType<B, string | undefined>>().toBe<'a'>().success // matches complete type
|
|
53
|
+
* expect<KeysOfExactType<B, string>>().toBe<never>().success // does not match complete type
|
|
54
|
+
*
|
|
55
|
+
* type C = { a: never; b: any; c: unknown };
|
|
56
|
+
* expect<KeysOfExactType<C, never>>().toBe<'a'>().success
|
|
57
|
+
* expect<KeysOfExactType<C, any>>().toBe<'b'>().success
|
|
58
|
+
* expect<KeysOfExactType<C, unknown>>().toBe<'c'>().success
|
|
23
59
|
* ```
|
|
24
60
|
*/
|
|
25
|
-
export type
|
|
61
|
+
export type KeysOfExactType<Obj, ValueType> = Exclude<{
|
|
62
|
+
[K in keyof Obj]: Exact<Obj[K], ValueType> extends true ? K : never;
|
|
63
|
+
}[keyof Obj], undefined>;
|
|
26
64
|
//# sourceMappingURL=key.d.ts.map
|
package/esm/main/key.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../../src/main/key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../../src/main/key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,MAAM,cAAc,CAAC,GAAG,EAAE,SAAS,IAAI,OAAO,CAClD;KACG,CAAC,IAAI,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,KAAK;CAC9E,CAAC,MAAM,GAAG,CAAC,EACZ,SAAS,CACV,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,MAAM,eAAe,CAAC,GAAG,EAAE,SAAS,IAAI,OAAO,CACnD;KAAG,CAAC,IAAI,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,KAAK;CAAE,CAAC,MAAM,GAAG,CAAC,EAClF,SAAS,CACV,CAAA"}
|
package/esm/main/key.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../src/main/key.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../src/main/key.ts"],"names":[],"mappings":"","sourcesContent":["import type { Exact } from './type/index.js'\n\n/**\n * Extracts the keys of an object whose **base value type** matches the specified `ValueType` (ignoring undefined from optional properties).\n *\n * This utility matches the underlying/base type of each property (stripping `undefined` added by optional modifiers `?`).\n * For optional properties (e.g., `a?: string`), the type is treated as `string` – no need to include `undefined` in `ValueType` to match.\n *\n * @template Obj - The target object type to extract keys from.\n * @template ValueType - The base type to match against property values (ignoring undefined from optional properties).\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * // Basic usage: match base type (non-optional property)\n * type A = { a: 1; b: 2; c: 1 };\n * expect<KeysOfBaseType<A, 1>>().toBe<'a' | 'c'>().success\n *\n * // Key difference: optional property matching (ignores undefined)\n * type B = { a?: string; b: string };\n * expect<KeysOfBaseType<B, string>>().toBe<'a' | 'b'>().success // matches base type of both\n * expect<KeysOfBaseType<B, string | undefined>>().toBe<never>().success // base type does not include undefined\n *\n * type C = { a: never; b: any; c: unknown };\n * expect<KeysOfBaseType<C, never>>().toBe<'a'>().success\n * expect<KeysOfBaseType<C, any>>().toBe<'b'>().success\n * expect<KeysOfBaseType<C, unknown>>().toBe<'c'>().success\n * ```\n */\nexport type KeysOfBaseType<Obj, ValueType> = Exclude<\n {\n [K in keyof Obj]: Exact<Required<Obj>[K], ValueType> extends true ? K : never\n }[keyof Obj],\n undefined\n>\n\n/**\n * Extracts the keys of an object whose **complete value type** exactly matches the specified `ValueType` (including undefined for optional properties).\n *\n * This utility strictly matches the full type of each property (including `undefined` added by optional modifiers `?`).\n * For optional properties (e.g., `a?: string`), the type is treated as `string | undefined` – to match, `ValueType` must include `undefined`.\n *\n * @template Obj - The target object type to extract keys from.\n * @template ValueType - The exact type to match against property values (including undefined for optional properties).\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * // Basic usage: match exact type (non-optional property)\n * type A = { a: 1; b: 2; c: 1 };\n * expect<KeysOfExactType<A, 1>>().toBe<'a' | 'c'>().success\n *\n * // Key difference: optional property matching (requires undefined in `ValueType`)\n * type B = { a?: string };\n * expect<KeysOfExactType<B, string | undefined>>().toBe<'a'>().success // matches complete type\n * expect<KeysOfExactType<B, string>>().toBe<never>().success // does not match complete type\n *\n * type C = { a: never; b: any; c: unknown };\n * expect<KeysOfExactType<C, never>>().toBe<'a'>().success\n * expect<KeysOfExactType<C, any>>().toBe<'b'>().success\n * expect<KeysOfExactType<C, unknown>>().toBe<'c'>().success\n * ```\n */\nexport type KeysOfExactType<Obj, ValueType> = Exclude<\n { [K in keyof Obj]: Exact<Obj[K], ValueType> extends true ? K : never }[keyof Obj],\n undefined\n>\n"]}
|
package/esm/main/object.d.ts
CHANGED
|
@@ -1,22 +1,55 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { KeysOfExactType } from './key.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Get property type from object, with fallback for missing keys.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* @template Obj - The object type to access
|
|
6
|
+
* @template K - The key to access in the object
|
|
7
|
+
* @template E - The fallback type if the key doesn't exist (defaults to `never`)
|
|
6
8
|
*
|
|
9
|
+
* @returns `Obj[K]` if key exists, otherwise `E`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
14
|
+
*
|
|
15
|
+
* type User = { name: string; age?: number };
|
|
16
|
+
*
|
|
17
|
+
* expect<Access<User, 'name'>>().toBe<string>().success
|
|
18
|
+
* expect<Access<User, 'age'>>().toBe<number | undefined>().success
|
|
19
|
+
* expect<Access<User, 'email', 'none'>>().toBe<'none'>().success
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export type Access<Obj, K extends PropertyKey, E = never> = K extends keyof Obj ? Obj[K] : E;
|
|
23
|
+
/**
|
|
24
|
+
* Inverse of `Access` - gets keys from an object that have values of a specific type
|
|
25
|
+
*
|
|
26
|
+
* @template T - The object type to inspect
|
|
27
|
+
* @template V - The value type to match against
|
|
28
|
+
* @template E - The fallback type if no keys match (defaults to `never`)
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
7
31
|
* ```ts
|
|
8
|
-
*
|
|
9
|
-
*
|
|
32
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
33
|
+
*
|
|
34
|
+
* expect<InverseAccess<{ a: string }, string>>().toBe<'a'>().success
|
|
35
|
+
* expect<InverseAccess<{ a: string; b: string }, string>>().toBe<'a' | 'b'>().success
|
|
36
|
+
* expect<InverseAccess<{ a: string }, number>>().toBe<never>().success
|
|
10
37
|
* ```
|
|
11
38
|
*/
|
|
12
|
-
export type
|
|
39
|
+
export type InverseAccess<T, V, E = never> = {
|
|
40
|
+
[K in keyof T]: T[K] extends V ? K : E;
|
|
41
|
+
}[keyof T];
|
|
13
42
|
/**
|
|
14
43
|
* Recursively makes all properties of `T` optional
|
|
15
44
|
*
|
|
16
|
-
*
|
|
45
|
+
* @template T - The object type to make deep partial
|
|
17
46
|
*
|
|
47
|
+
* @example
|
|
18
48
|
* ```ts
|
|
19
|
-
*
|
|
49
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
50
|
+
*
|
|
51
|
+
* type Result = DeepPartial<{ a: string; nested: { b: number } }>
|
|
52
|
+
* expect<Result>().toBe<{ a?: string; nested?: { b?: number } }>().success
|
|
20
53
|
* ```
|
|
21
54
|
*/
|
|
22
55
|
export type DeepPartial<T> = {
|
|
@@ -25,57 +58,63 @@ export type DeepPartial<T> = {
|
|
|
25
58
|
/**
|
|
26
59
|
* Recursively makes all properties of `T` required
|
|
27
60
|
*
|
|
28
|
-
*
|
|
61
|
+
* @template T - The object type to make deep required
|
|
29
62
|
*
|
|
63
|
+
* @example
|
|
30
64
|
* ```ts
|
|
31
|
-
*
|
|
32
|
-
*
|
|
65
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
66
|
+
*
|
|
67
|
+
* expect<DeepRequire<{ _?: { _?: 1 } }>>().toBe<{ _: { _: 1 } }>().success
|
|
33
68
|
* ```
|
|
34
69
|
*/
|
|
35
70
|
export type DeepRequire<T> = {
|
|
36
|
-
[
|
|
71
|
+
[K in keyof T]-?: T[K] extends object | undefined ? DeepRequire<NonNullable<T[K]>> : T[K];
|
|
37
72
|
};
|
|
38
73
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* ### Examples
|
|
74
|
+
* **⚠️Important:** parameter `T` and `U` are not distributive. When they are union type, it treats them as a single entity.
|
|
42
75
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* type _2 = AssertExtends<string, number> // never
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export type AssertExtends<T, A> = T extends A ? T : never;
|
|
49
|
-
/**
|
|
50
|
-
* Safely picks keys `K` from type T, excluding non-existent keys
|
|
76
|
+
* @template T - The type to test (not distributed over unions)
|
|
77
|
+
* @template U - The constraint type to test against
|
|
51
78
|
*
|
|
52
|
-
*
|
|
79
|
+
* @example
|
|
53
80
|
*
|
|
54
81
|
* ```ts
|
|
55
|
-
*
|
|
82
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
83
|
+
*
|
|
84
|
+
* expect<AssertExtends<string, number>>().toBeNever
|
|
85
|
+
* expect<AssertExtends<1 | 2, 1>>().toBeNever
|
|
86
|
+
* expect<AssertExtends<1, 1 | 2>>().toBe<1>().success
|
|
56
87
|
* ```
|
|
57
88
|
*/
|
|
58
|
-
export type
|
|
89
|
+
export type AssertExtends<T, U> = [T] extends [U] ? T : never;
|
|
59
90
|
/**
|
|
60
|
-
*
|
|
91
|
+
* Safely picks keys `Key` from type `Obj`, excluding non-existent keys
|
|
61
92
|
*
|
|
62
|
-
*
|
|
93
|
+
* @template Obj - The object type to pick keys from
|
|
94
|
+
* @template Key - The keys to pick from the object
|
|
63
95
|
*
|
|
96
|
+
* @example
|
|
64
97
|
* ```ts
|
|
65
|
-
*
|
|
66
|
-
*
|
|
98
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
99
|
+
*
|
|
100
|
+
* type Result = SafePick<{ a: string; b: number }, 'a' | 'c'>
|
|
101
|
+
* expect<Result>().toBe<{ a: string }>().success
|
|
67
102
|
* ```
|
|
68
103
|
*/
|
|
69
|
-
export type
|
|
104
|
+
export type SafePick<Obj, Key> = Pick<Obj, Key & keyof Obj>;
|
|
70
105
|
/**
|
|
71
|
-
* Picks properties from `T` that
|
|
106
|
+
* Picks properties from `T` that have values of type `U`
|
|
72
107
|
*
|
|
73
|
-
*
|
|
108
|
+
* @template T - The object type to pick properties from
|
|
109
|
+
* @template U - The value type to match against
|
|
74
110
|
*
|
|
111
|
+
* @example
|
|
75
112
|
* ```ts
|
|
113
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
76
114
|
* type A = { a: string; b: number; c: string }
|
|
77
|
-
* type
|
|
115
|
+
* type Strings = PropsOfBaseType<A, string> // { a: string; c: string }
|
|
116
|
+
* expect<PropsOfBaseType<A, string>>().toBe<{ a: string; c: string }>()
|
|
78
117
|
* ```
|
|
79
118
|
*/
|
|
80
|
-
export type
|
|
119
|
+
export type PropsOfBaseType<T, U> = Pick<T, KeysOfExactType<Required<T>, U>>;
|
|
81
120
|
//# sourceMappingURL=object.d.ts.map
|
package/esm/main/object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/main/object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/main/object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,WAAW,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAE5F;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;CAAE,CAAC,MAAM,CAAC,CAAC,CAAA;AAEhG;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAA;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC1F,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAE7D;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,CAAC,CAAA;AAE3D;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
package/esm/main/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/main/object.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/main/object.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeysOfExactType } from './key.js'\n\n/**\n * Get property type from object, with fallback for missing keys.\n *\n * @template Obj - The object type to access\n * @template K - The key to access in the object\n * @template E - The fallback type if the key doesn't exist (defaults to `never`)\n *\n * @returns `Obj[K]` if key exists, otherwise `E`.\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * type User = { name: string; age?: number };\n *\n * expect<Access<User, 'name'>>().toBe<string>().success\n * expect<Access<User, 'age'>>().toBe<number | undefined>().success\n * expect<Access<User, 'email', 'none'>>().toBe<'none'>().success\n * ```\n */\nexport type Access<Obj, K extends PropertyKey, E = never> = K extends keyof Obj ? Obj[K] : E\n\n/**\n * Inverse of `Access` - gets keys from an object that have values of a specific type\n *\n * @template T - The object type to inspect\n * @template V - The value type to match against\n * @template E - The fallback type if no keys match (defaults to `never`)\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<InverseAccess<{ a: string }, string>>().toBe<'a'>().success\n * expect<InverseAccess<{ a: string; b: string }, string>>().toBe<'a' | 'b'>().success\n * expect<InverseAccess<{ a: string }, number>>().toBe<never>().success\n * ```\n */\nexport type InverseAccess<T, V, E = never> = { [K in keyof T]: T[K] extends V ? K : E }[keyof T]\n\n/**\n * Recursively makes all properties of `T` optional\n *\n * @template T - The object type to make deep partial\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * type Result = DeepPartial<{ a: string; nested: { b: number } }>\n * expect<Result>().toBe<{ a?: string; nested?: { b?: number } }>().success\n * ```\n */\nexport type DeepPartial<T> = {\n [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]\n}\n\n/**\n * Recursively makes all properties of `T` required\n *\n * @template T - The object type to make deep required\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<DeepRequire<{ _?: { _?: 1 } }>>().toBe<{ _: { _: 1 } }>().success\n * ```\n */\nexport type DeepRequire<T> = {\n [K in keyof T]-?: T[K] extends object | undefined ? DeepRequire<NonNullable<T[K]>> : T[K]\n}\n\n/**\n * **⚠️Important:** parameter `T` and `U` are not distributive. When they are union type, it treats them as a single entity.\n *\n * @template T - The type to test (not distributed over unions)\n * @template U - The constraint type to test against\n *\n * @example\n *\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<AssertExtends<string, number>>().toBeNever\n * expect<AssertExtends<1 | 2, 1>>().toBeNever\n * expect<AssertExtends<1, 1 | 2>>().toBe<1>().success\n * ```\n */\nexport type AssertExtends<T, U> = [T] extends [U] ? T : never\n\n/**\n * Safely picks keys `Key` from type `Obj`, excluding non-existent keys\n *\n * @template Obj - The object type to pick keys from\n * @template Key - The keys to pick from the object\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * type Result = SafePick<{ a: string; b: number }, 'a' | 'c'>\n * expect<Result>().toBe<{ a: string }>().success\n * ```\n */\nexport type SafePick<Obj, Key> = Pick<Obj, Key & keyof Obj>\n\n/**\n * Picks properties from `T` that have values of type `U`\n *\n * @template T - The object type to pick properties from\n * @template U - The value type to match against\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n * type A = { a: string; b: number; c: string }\n * type Strings = PropsOfBaseType<A, string> // { a: string; c: string }\n * expect<PropsOfBaseType<A, string>>().toBe<{ a: string; c: string }>()\n * ```\n */\nexport type PropsOfBaseType<T, U> = Pick<T, KeysOfExactType<Required<T>, U>>\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Exact } from './type/compare.js';
|
|
2
|
+
/**
|
|
3
|
+
* Concatenates two tuples into a single tuple type
|
|
4
|
+
*
|
|
5
|
+
* @template Left - The first tuple type to concatenate
|
|
6
|
+
* @template Right - The second tuple type to concatenate
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
11
|
+
*
|
|
12
|
+
* expect<ConcatTuple<[1, 2], [3, 4]>>().toBe<[1, 2, 3, 4]>().success
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type ConcatTuple<Left extends readonly unknown[], Right extends readonly unknown[]> = Left extends readonly unknown[] ? (Right extends readonly unknown[] ? [...Left, ...Right] : never) : never;
|
|
16
|
+
/**
|
|
17
|
+
* Checks whether a tuple includes a specific element type
|
|
18
|
+
*
|
|
19
|
+
* @template Tuple - The tuple type to check
|
|
20
|
+
* @template Element - The element type to look for
|
|
21
|
+
* @template Yes - The result if the element is found (defaults to `true`)
|
|
22
|
+
* @template No - The result if the element is not found (defaults to `false`)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
27
|
+
*
|
|
28
|
+
* expect<IfTupleIncludes<[1, 2, 3], 2>>().toBeTrue
|
|
29
|
+
* expect<IfTupleIncludes<[1, 2, 3], 4>>().toBeFalse
|
|
30
|
+
* expect<IfTupleIncludes<[1, 2, 1], 1>>().toBeTrue
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type IfTupleIncludes<Tuple extends readonly unknown[], Element, Yes = true, No = false> = Exact<Tuple, any> extends true ? never : Tuple extends readonly [infer First, ...infer Rest] ? (Exact<Element, First> extends true ? Yes : IfTupleIncludes<Rest, Element, Yes, No>) : No;
|
|
34
|
+
/**
|
|
35
|
+
* Appends an element to a tuple only if it doesn't already exist in the tuple
|
|
36
|
+
*
|
|
37
|
+
* @template Tuple - The tuple type to append to
|
|
38
|
+
* @template Element - The element type to append
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
43
|
+
*
|
|
44
|
+
* expect<AppendUnique<[1, 2, 3], 4>>().toBe<[1, 2, 3, 4]>().success
|
|
45
|
+
* expect<AppendUnique<[1, 2, 3], 2>>().toBe<[1, 2, 3]>().success
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export type AppendUnique<Tuple extends readonly unknown[], Element> = IfTupleIncludes<Tuple, Element> extends true ? Tuple : [...Tuple, Element];
|
|
49
|
+
/**
|
|
50
|
+
* Concatenates two tuples while ensuring uniqueness of elements
|
|
51
|
+
*
|
|
52
|
+
* @template Left - The first tuple type to concatenate
|
|
53
|
+
* @template Right - The second tuple type to concatenate
|
|
54
|
+
* @template R - The intermediate result tuple type (defaults to `Left`)
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { expect } from '@leawind/lay-sing/test-utils'
|
|
59
|
+
*
|
|
60
|
+
* expect<ConcatUniqueTuple<[1, 2, 3], [2, 3, 4]>>().toBe<[1, 2, 3, 4]>().success
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export type ConcatUniqueTuple<Left extends readonly unknown[], Right extends readonly unknown[], R extends readonly unknown[] = Left> = Right extends readonly [infer First, ...infer Rest] ? ConcatUniqueTuple<Left, Rest, AppendUnique<R, First>> : R;
|
|
64
|
+
//# sourceMappingURL=tuple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../../src/main/tuple.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAE9C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,CACrB,IAAI,SAAS,SAAS,OAAO,EAAE,EAC/B,KAAK,SAAS,SAAS,OAAO,EAAE,IAC9B,IAAI,SAAS,SAAS,OAAO,EAAE,GAAG,CAAC,KAAK,SAAS,SAAS,OAAO,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAA;AAE9G;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,eAAe,CACzB,KAAK,SAAS,SAAS,OAAO,EAAE,EAChC,OAAO,EACP,GAAG,GAAG,IAAI,EACV,EAAE,GAAG,KAAK,IACR,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,SAAS,IAAI,GAAG,KAAK,GACtC,KAAK,SAAS,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GACjD,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,IAAI,GAAG,GAAG,GAAG,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,GACtF,EAAE,CAAA;AAEN;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,YAAY,CACtB,KAAK,SAAS,SAAS,OAAO,EAAE,EAChC,OAAO,IACL,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,CAAA;AAE9E;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,iBAAiB,CAC3B,IAAI,SAAS,SAAS,OAAO,EAAE,EAC/B,KAAK,SAAS,SAAS,OAAO,EAAE,EAChC,CAAC,SAAS,SAAS,OAAO,EAAE,GAAG,IAAI,IACjC,KAAK,SAAS,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../src/main/tuple.ts"],"names":[],"mappings":"","sourcesContent":["import type { Exact } from './type/compare.js'\n\n/**\n * Concatenates two tuples into a single tuple type\n *\n * @template Left - The first tuple type to concatenate\n * @template Right - The second tuple type to concatenate\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<ConcatTuple<[1, 2], [3, 4]>>().toBe<[1, 2, 3, 4]>().success\n * ```\n */\nexport type ConcatTuple<\n Left extends readonly unknown[],\n Right extends readonly unknown[],\n> = Left extends readonly unknown[] ? (Right extends readonly unknown[] ? [...Left, ...Right] : never) : never\n\n/**\n * Checks whether a tuple includes a specific element type\n *\n * @template Tuple - The tuple type to check\n * @template Element - The element type to look for\n * @template Yes - The result if the element is found (defaults to `true`)\n * @template No - The result if the element is not found (defaults to `false`)\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<IfTupleIncludes<[1, 2, 3], 2>>().toBeTrue\n * expect<IfTupleIncludes<[1, 2, 3], 4>>().toBeFalse\n * expect<IfTupleIncludes<[1, 2, 1], 1>>().toBeTrue\n * ```\n */\nexport type IfTupleIncludes<\n Tuple extends readonly unknown[],\n Element,\n Yes = true,\n No = false,\n> = Exact<Tuple, any> extends true ? never\n : Tuple extends readonly [infer First, ...infer Rest]\n ? (Exact<Element, First> extends true ? Yes : IfTupleIncludes<Rest, Element, Yes, No>)\n : No\n\n/**\n * Appends an element to a tuple only if it doesn't already exist in the tuple\n *\n * @template Tuple - The tuple type to append to\n * @template Element - The element type to append\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<AppendUnique<[1, 2, 3], 4>>().toBe<[1, 2, 3, 4]>().success\n * expect<AppendUnique<[1, 2, 3], 2>>().toBe<[1, 2, 3]>().success\n * ```\n */\nexport type AppendUnique<\n Tuple extends readonly unknown[],\n Element,\n> = IfTupleIncludes<Tuple, Element> extends true ? Tuple : [...Tuple, Element]\n\n/**\n * Concatenates two tuples while ensuring uniqueness of elements\n *\n * @template Left - The first tuple type to concatenate\n * @template Right - The second tuple type to concatenate\n * @template R - The intermediate result tuple type (defaults to `Left`)\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<ConcatUniqueTuple<[1, 2, 3], [2, 3, 4]>>().toBe<[1, 2, 3, 4]>().success\n * ```\n */\nexport type ConcatUniqueTuple<\n Left extends readonly unknown[],\n Right extends readonly unknown[],\n R extends readonly unknown[] = Left,\n> = Right extends readonly [infer First, ...infer Rest] ? ConcatUniqueTuple<Left, Rest, AppendUnique<R, First>> : R\n"]}
|