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.
Files changed (117) hide show
  1. package/README.md +78 -66
  2. package/esm/main/async.d.ts +9 -1
  3. package/esm/main/async.d.ts.map +1 -1
  4. package/esm/main/async.js.map +1 -1
  5. package/esm/main/boolean.d.ts +43 -20
  6. package/esm/main/boolean.d.ts.map +1 -1
  7. package/esm/main/boolean.js.map +1 -1
  8. package/esm/main/control.d.ts +70 -46
  9. package/esm/main/control.d.ts.map +1 -1
  10. package/esm/main/control.js.map +1 -1
  11. package/esm/main/doc.d.ts +33 -7
  12. package/esm/main/doc.d.ts.map +1 -1
  13. package/esm/main/doc.js.map +1 -1
  14. package/esm/main/function.d.ts +11 -5
  15. package/esm/main/function.d.ts.map +1 -1
  16. package/esm/main/function.js +0 -1
  17. package/esm/main/function.js.map +1 -1
  18. package/esm/main/index.d.ts +6 -1
  19. package/esm/main/index.d.ts.map +1 -1
  20. package/esm/main/index.js +8 -1
  21. package/esm/main/index.js.map +1 -1
  22. package/esm/main/key.d.ts +51 -13
  23. package/esm/main/key.d.ts.map +1 -1
  24. package/esm/main/key.js.map +1 -1
  25. package/esm/main/object.d.ts +74 -35
  26. package/esm/main/object.d.ts.map +1 -1
  27. package/esm/main/object.js.map +1 -1
  28. package/esm/main/tuple.d.ts +64 -0
  29. package/esm/main/tuple.d.ts.map +1 -0
  30. package/esm/main/tuple.js +2 -0
  31. package/esm/main/tuple.js.map +1 -0
  32. package/esm/main/type/compare.d.ts +118 -28
  33. package/esm/main/type/compare.d.ts.map +1 -1
  34. package/esm/main/type/compare.js.map +1 -1
  35. package/esm/main/type/index.d.ts.map +1 -1
  36. package/esm/main/type/index.js +2 -0
  37. package/esm/main/type/index.js.map +1 -1
  38. package/esm/main/type/set.d.ts +17 -12
  39. package/esm/main/type/set.d.ts.map +1 -1
  40. package/esm/main/type/set.js.map +1 -1
  41. package/esm/test-utils/compare.d.ts +81 -0
  42. package/esm/test-utils/compare.d.ts.map +1 -0
  43. package/esm/test-utils/compare.js +2 -0
  44. package/esm/test-utils/compare.js.map +1 -0
  45. package/esm/test-utils/expect.d.ts +278 -0
  46. package/esm/test-utils/expect.d.ts.map +1 -0
  47. package/esm/test-utils/expect.js +2 -0
  48. package/esm/test-utils/expect.js.map +1 -0
  49. package/esm/test-utils/index.d.ts +77 -0
  50. package/esm/test-utils/index.d.ts.map +1 -0
  51. package/esm/{test-utils.js → test-utils/index.js} +9 -5
  52. package/esm/test-utils/index.js.map +1 -0
  53. package/package.json +3 -3
  54. package/script/main/async.d.ts +9 -1
  55. package/script/main/async.d.ts.map +1 -1
  56. package/script/main/async.js.map +1 -1
  57. package/script/main/boolean.d.ts +43 -20
  58. package/script/main/boolean.d.ts.map +1 -1
  59. package/script/main/boolean.js.map +1 -1
  60. package/script/main/control.d.ts +70 -46
  61. package/script/main/control.d.ts.map +1 -1
  62. package/script/main/control.js.map +1 -1
  63. package/script/main/doc.d.ts +33 -7
  64. package/script/main/doc.d.ts.map +1 -1
  65. package/script/main/doc.js.map +1 -1
  66. package/script/main/function.d.ts +11 -5
  67. package/script/main/function.d.ts.map +1 -1
  68. package/script/main/function.js +0 -1
  69. package/script/main/function.js.map +1 -1
  70. package/script/main/index.d.ts +6 -1
  71. package/script/main/index.d.ts.map +1 -1
  72. package/script/main/index.js +8 -1
  73. package/script/main/index.js.map +1 -1
  74. package/script/main/key.d.ts +51 -13
  75. package/script/main/key.d.ts.map +1 -1
  76. package/script/main/key.js.map +1 -1
  77. package/script/main/object.d.ts +74 -35
  78. package/script/main/object.d.ts.map +1 -1
  79. package/script/main/object.js.map +1 -1
  80. package/script/main/tuple.d.ts +64 -0
  81. package/script/main/tuple.d.ts.map +1 -0
  82. package/script/main/{array.js → tuple.js} +1 -1
  83. package/script/main/tuple.js.map +1 -0
  84. package/script/main/type/compare.d.ts +118 -28
  85. package/script/main/type/compare.d.ts.map +1 -1
  86. package/script/main/type/compare.js.map +1 -1
  87. package/script/main/type/index.d.ts.map +1 -1
  88. package/script/main/type/index.js +2 -0
  89. package/script/main/type/index.js.map +1 -1
  90. package/script/main/type/set.d.ts +17 -12
  91. package/script/main/type/set.d.ts.map +1 -1
  92. package/script/main/type/set.js.map +1 -1
  93. package/script/test-utils/compare.d.ts +81 -0
  94. package/script/test-utils/compare.d.ts.map +1 -0
  95. package/script/test-utils/compare.js +3 -0
  96. package/script/test-utils/compare.js.map +1 -0
  97. package/script/test-utils/expect.d.ts +278 -0
  98. package/script/test-utils/expect.d.ts.map +1 -0
  99. package/script/test-utils/expect.js +3 -0
  100. package/script/test-utils/expect.js.map +1 -0
  101. package/script/test-utils/index.d.ts +77 -0
  102. package/script/test-utils/index.d.ts.map +1 -0
  103. package/script/{test-utils.js → test-utils/index.js} +10 -6
  104. package/script/test-utils/index.js.map +1 -0
  105. package/esm/main/array.d.ts +0 -48
  106. package/esm/main/array.d.ts.map +0 -1
  107. package/esm/main/array.js +0 -2
  108. package/esm/main/array.js.map +0 -1
  109. package/esm/test-utils.d.ts +0 -348
  110. package/esm/test-utils.d.ts.map +0 -1
  111. package/esm/test-utils.js.map +0 -1
  112. package/script/main/array.d.ts +0 -48
  113. package/script/main/array.d.ts.map +0 -1
  114. package/script/main/array.js.map +0 -1
  115. package/script/test-utils.d.ts +0 -348
  116. package/script/test-utils.d.ts.map +0 -1
  117. package/script/test-utils.js.map +0 -1
package/README.md CHANGED
@@ -1,18 +1,16 @@
1
- | English | [简体中文](./README-zh.md) |
2
- | ------- | -------------------------- |
1
+ [![GitHub License](https://img.shields.io/github/license/Leawind/lay-sing)](https://github.com/Leawind/lay-sing?tab=MIT-1-ov-file)
2
+ [![NPM Version](https://img.shields.io/npm/v/lay-sing?style=flat&logo=npm)](https://www.npmjs.com/package/lay-sing)
3
+ [![JSR Version](https://jsr.io/badges/@leawind/lay-sing)](https://jsr.io/@leawind/lay-sing)
4
+ [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Leawind/lay-sing/verify.yaml?branch=main&logo=github-actions&label=test)](https://github.com/Leawind/lay-sing/actions/workflows/verify.yaml)
3
5
 
4
- # `lay-sing`
6
+ # Lay-Sing
5
7
 
6
8
  TypeScript utilities for compile-time type testing and utility types
7
9
 
8
- ## What is it
9
-
10
- 1. **Testing Utilities**
11
-
12
10
  ```ts
13
11
  // They do nothing at runtime
14
12
  expect<never>().toBe<never>().success
15
- expect<never>().toBeNever // alias for above
13
+ expect<never>().toBeNever // alias for the above
16
14
  expect<never>().toBe<'should fail'>().fail
17
15
 
18
16
  // Type Error: Property 'success' does not exist on type '{ fail: void; }'.
@@ -20,50 +18,59 @@ expect<never>().toBe<'should fail'>().success
20
18
  // ^^^^^^^
21
19
  ```
22
20
 
23
- 1. **Type Manipulation Tools**
21
+ > [!TIP]
22
+ >
23
+ > I know this library is quite simple and serves a specific purpose, so one of its API design principles is to minimize the cognitive load for users. You just need to remember to **start with an `expect<>()` call** and **end with some property access**. Leave the rest to editor suggestions and inline documentation.
24
+
25
+ ## Install & Import
26
+
27
+ <details>
28
+ <summary>NPM</summary>
29
+
30
+ ```sh
31
+ npm i -D lay-sing
32
+ ```
24
33
 
25
34
  ```ts
26
- // Result is 'Bob'
27
- type Result = Switch<2, [
28
- Case<1, 'Alice'>,
29
- Case<2, 'Bob'>,
30
- Case<3, 'Charlie'>,
31
- ], DefaultCase<'Unknown'>>
35
+ import { expect } from 'lay-sing/test-utils'
32
36
  ```
33
37
 
34
- ## Install
38
+ </details>
35
39
 
36
- > This lib is published to both [NPM](https://www.npmjs.com/package/lay-sing) and [JSR](https://jsr.io/@leawind/lay-sing)
40
+ <details>
41
+ <summary>Deno</summary>
37
42
 
38
- ### NPM
43
+ ### From NPM
39
44
 
40
45
  ```sh
41
- npm i -D lay-sing
46
+ deno add npm:lay-sing
42
47
  ```
43
48
 
44
49
  ```ts
45
- import type { Same } from 'lay-sing'
46
50
  import { expect } from 'lay-sing/test-utils'
47
51
  ```
48
52
 
49
- ### Deno (JSR)
53
+ ### From JSR
54
+
55
+ This library is also published to [JSR (`@leawind/lay-sing`)](https://jsr.io/@leawind/lay-sing)
50
56
 
51
57
  ```sh
52
- deno add jsr:@leawind/lay-sing
58
+ deno add @leawind/lay-sing
53
59
  ```
54
60
 
55
61
  ```ts
56
- import type { Same } from '@leawind/lay-sing'
57
62
  import { expect } from '@leawind/lay-sing/test-utils'
58
63
  ```
59
64
 
60
- Or Import directly:
65
+ ### From Latest commit
61
66
 
62
67
  ```ts
63
- import type { Same } from 'jsr:@leawind/lay-sing@^0.1'
64
- import { expect } from 'jsr:@leawind/lay-sing@^0.1/test-utils'
68
+ import { expect } from 'https://raw.githubusercontent.com/Leawind/lay-sing/refs/heads/main/src/test-utils/index.ts'
69
+ import { Exact } from 'https://raw.githubusercontent.com/Leawind/lay-sing/refs/heads/main/src/main/index.ts'
65
70
  ```
66
71
 
72
+ </details>
73
+
67
74
  ---
68
75
 
69
76
  ## Usage
@@ -71,10 +78,10 @@ import { expect } from 'jsr:@leawind/lay-sing@^0.1/test-utils'
71
78
  ### Testing Utilities
72
79
 
73
80
  ```ts
74
- import { compare, expect, NOOP } from 'lay-sing/test-utils'
81
+ import { expect } from 'lay-sing/test-utils'
75
82
  ```
76
83
 
77
- The `test-utils` module provides utilities for **compile-time** type validation. These utilities have **no runtime effect** — they always return a special [`NOOP`](https://jsr.io/@leawind/lay-sing/doc/test-utils/~/NOOP) value that safely supports almost any property access or method call.
84
+ The `test-utils` module provides utilities for **compile-time** type validation. These utilities have **no runtime impact** — they always return a special [`NOOP`](https://jsr.io/@leawind/lay-sing/doc/test-utils/~/NOOP) value that safely supports almost any property access or method call.
78
85
 
79
86
  A typical type test statement follows this pattern:
80
87
 
@@ -84,63 +91,76 @@ expect<ActualType>().toBe<ExpectedType>().success
84
91
 
85
92
  - It starts with a function call like `expect<T>()` or `compare<T, U>()`
86
93
  - It ends with a property like `.success` or `.fail`
87
- - A **type error occurs only if the assertion fails**, helping you catch incorrect types at compile time
88
- - At runtime, the function always returns the actual value `NOOP`, which performs **no operation**. It can be accessed, called, or chained indefinitely without throwing
94
+ - Type error occurs only if the assertion fails
95
+
96
+ > [!CAUTION]
97
+ >
98
+ > Only statements ending with property access are type assertions. Without property access, type error may never occur:
99
+ >
100
+ > ```diff
101
+ > - expect<true>().toBe<false>() // Type error never occur
102
+ > + expect<true>().toBe<false>().success // Type Error: Property 'success' does not exist on type '{ fail: void; }'.
103
+ > ```
104
+
105
+ At runtime, the function always returns the `NOOP` object, which performs **no operation**. It can be accessed, called, or chained indefinitely without throwing errors.
89
106
 
90
107
  #### Common Usage
91
108
 
92
109
  ```ts
93
- // Exact equality
94
- expect<A>().toBe<B>().success // Passes only if A and B are identical
95
-
96
- // Subtype check
97
- expect<A>().toExtend<B>().success // Passes if A extends B
110
+ // Passes only if A and B are identical
111
+ expect<keyof { a: 2 }>().toBe<'a'>().success
98
112
 
99
- // Property existence
100
- expect<{ name: string }>().toHaveProperty<'name'>().success
113
+ // Passes if A extends B
114
+ expect<12138>().toExtend<number>().success
101
115
 
102
- // Primitive checks
103
- expect<true>().toBeTrue.success
104
- expect<'hello'>().toExtendString.success
116
+ // Passes if mutually assignable
117
+ expect<{ a: 1; b: 2 }>().toEqual<{ a: 1 } & { b: 2 }>().success
105
118
 
106
- // Type comparison
107
- compare<A, B>().same // Available only if A ≡ B
108
- compare<A, B>().different // Available only if A ≠ B
119
+ // Test property existence
120
+ expect<{ name: string }>().toHaveKey<'name'>().success
109
121
  ```
110
122
 
111
- > [!TIP]
112
- >
113
- > There's no need to memorize the full API.
114
- >
115
- > Your editor will show inline documentation and auto-completion for all available methods and properties
123
+ Aliases:
124
+
125
+ ```ts
126
+ expect<never>().toBe<never>().success
127
+ expect<never>().toBeNever
128
+
129
+ expect<'hello'>().toExtend<string>().success
130
+ expect<'hello'>().toExtendString
131
+ ```
116
132
 
117
133
  #### NOOP
118
134
 
119
- A `Proxy`-based no-op object:
135
+ A `Proxy`-based no-op object with the following behavior:
120
136
 
121
- - Most accesses return itself.
122
- - `toString()` returns `"[NOOP]"`.
137
+ - Most property/method accesses return the NOOP object itself.
138
+ - `.toString()`, `.valueOf()` returns string `"[NOOP]"`.
123
139
  - Not thenable (`then` is `undefined`).
124
140
 
141
+ It's used as returned value of `expect()` and `compare()`.
142
+
125
143
  ```ts
126
- NOOP.foo.bar().baz.qux // safe, returns NOOP
144
+ expect().foo.bar().baz.qux // Safe, returns NOOP
127
145
  String(NOOP) // "[NOOP]"
128
- await NOOP // does not await (not thenable)
146
+ await NOOP // Does not await (not thenable)
129
147
  ```
130
148
 
131
149
  ### Type Tools
132
150
 
133
- The main entry point provides a collection of utility types for common type-level programming tasks. All types are flat-exported from the main entry point — you don’t need to import from deep paths.
151
+ The main entry point provides some utility types for common type-level programming tasks. All types are flat-exported from the main entry point — no need to import from nested paths.
134
152
 
135
153
  ```ts
136
- import type { Same } from 'lay-sing'
154
+ import type { Exact } from 'lay-sing'
137
155
  ```
138
156
 
139
- > All types are documented — your editor will show inline documentation on hover
140
-
141
157
  ### Examples
142
158
 
143
159
  ```typescript
160
+ // Test if exactly the same
161
+ type False = Exact<{ a: 1 }, { a?: 1 }> // false
162
+ type Yes = Exact<boolean, true | false, 'yes', 'no'> // 'yes'
163
+
144
164
  // Conditional Types
145
165
  type Result = If<true, 'yes', 'no'> // 'yes'
146
166
 
@@ -155,12 +175,4 @@ type PartialObj = DeepPartial<{ a: string; nested: { b: number } }>
155
175
  // { a?: string; nested?: { b?: number } }
156
176
  ```
157
177
 
158
- > [!NOTE]
159
- >
160
- > [Full API documentation is available on JSR](https://jsr.io/@leawind/lay-sing/doc)
161
-
162
- ---
163
-
164
- > ## _Pronunciation of lay-sing_
165
- >
166
- > _"lay-sing" mimics Mandarin "lèi xíng" ("type") — Say "LAY-sing" with a sharp "LAY" (like a command) followed by a rising "sing" (like a question)._
178
+ [Full API documentation is available on JSR](https://jsr.io/@leawind/lay-sing/doc)
@@ -1,5 +1,13 @@
1
1
  /**
2
- * Represents a value that can be either T or a Promise of T
2
+ * Represents a value that can be either `T` or a Promise of `T`
3
+ *
4
+ * @template T - The underlying type that may or may not be wrapped in a Promise
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * type StringOrPromise = Awaitable<string>
9
+ * // Equivalent to: string | Promise<string>
10
+ * ```
3
11
  */
4
12
  export type Awaitable<T> = Promise<T> | T;
5
13
  //# sourceMappingURL=async.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/main/async.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA"}
1
+ {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/main/async.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/main/async.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a value that can be either T or a Promise of T\n */\nexport type Awaitable<T> = Promise<T> | T\n"]}
1
+ {"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/main/async.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a value that can be either `T` or a Promise of `T`\n *\n * @template T - The underlying type that may or may not be wrapped in a Promise\n *\n * @example\n * ```ts\n * type StringOrPromise = Awaitable<string>\n * // Equivalent to: string | Promise<string>\n * ```\n */\nexport type Awaitable<T> = Promise<T> | T\n"]}
@@ -1,36 +1,59 @@
1
1
  /**
2
- * ### Result
2
+ * Negates a boolean type
3
3
  *
4
- * - `never`: if `T` is `never`
5
- * - `boolean`: if `T` is `boolean` or `any`
6
- * - `false`: if `T` is `true`
7
- * - `true`: if `T` is `false`
4
+ * @template T - The boolean type to negate
8
5
  *
9
- * ### Examples
6
+ * @example
7
+ * ```ts
8
+ * import { expect } from '@leawind/lay-sing/test-utils'
10
9
  *
11
- * | `T` | `Not<T>` |
12
- * | --------- | --------- |
13
- * | `never` | `never` |
14
- * | `true` | `false` |
15
- * | `false` | `true` |
16
- * | `boolean` | `boolean` |
17
- * | `any` | `boolean` |
10
+ * expect<Not<true>>().toBeFalse
11
+ * expect<Not<false>>().toBeTrue
12
+ * expect<Not<boolean>>().toBe<boolean>().success
13
+ * ```
18
14
  */
19
15
  export type Not<T extends boolean> = T extends true ? false : T extends false ? true : boolean;
20
16
  /**
21
- * - `never`: if anyone of A,B is `never`
22
- * - `boolean`: if anyone of A,B is `boolean` or `any`
23
- * - `true`: if both A,B are `true`
24
- * - `false`: otherwise
17
+ * Logical AND operation on two boolean types
18
+ *
19
+ * @template A - The first boolean type to compare
20
+ * @template B - The second boolean type to compare
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { expect } from '@leawind/lay-sing/test-utils'
25
+ *
26
+ * expect<And<true, true>>().toBeTrue
27
+ * expect<And<true, false>>().toBeFalse
28
+ * expect<And<false, true>>().toBeFalse
29
+ * expect<And<false, false>>().toBeFalse
30
+ * expect<And<boolean, boolean>>().toBe<boolean>().success
31
+ * ```
25
32
  */
26
33
  export type And<A extends boolean, B extends boolean> = A extends never ? never : [B] extends [never] ? never : (A extends true ? (B extends true ? true : false) : false);
27
34
  /**
35
+ * Logical OR operation on two boolean types
36
+ *
37
+ * @template A - The first boolean type to compare
38
+ * @template B - The second boolean type to compare
39
+ *
28
40
  * ### Result
29
41
  *
30
- * - `never`: if anyone of A,B is `never`
31
- * - `boolean`: if anyone of A,B is `boolean` or `any`
32
- * - `false`: if both A,B are `false`
42
+ * - `never`: if either `A` or `B` is `never`
43
+ * - `boolean`: if either `A` or `B` is `boolean` or `any`
44
+ * - `false`: if both `A` and `B` are `false`
33
45
  * - `true`: otherwise
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { expect } from '@leawind/lay-sing/test-utils'
50
+ *
51
+ * expect<Or<true, true>>().toBeTrue
52
+ * expect<Or<true, false>>().toBeTrue
53
+ * expect<Or<false, true>>().toBeTrue
54
+ * expect<Or<false, false>>().toBeFalse
55
+ * expect<Or<boolean, false>>().toBe<boolean>().success
56
+ * ```
34
57
  */
35
58
  export type Or<A extends boolean, B extends boolean> = [A] extends [never] ? never : [B] extends [never] ? never : [boolean] extends [A] ? boolean : [boolean] extends [B] ? boolean : true extends A ? true : true extends B ? true : false;
36
59
  //# sourceMappingURL=boolean.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../src/main/boolean.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,GACvD,CAAC,SAAS,KAAK,GAAG,IAAI,GACtB,OAAO,CAAA;AAEX;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CACb,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,IACf,CAAC,SAAS,KAAK,GAAG,KAAK,GACvB,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC3B,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAA;AAE9D;;;;;;;GAOG;AACH,MAAM,MAAM,EAAE,CACZ,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,IACf,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC3B,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC3B,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,GAC/B,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,GAC/B,IAAI,SAAS,CAAC,GAAG,IAAI,GACrB,IAAI,SAAS,CAAC,GAAG,IAAI,GACrB,KAAK,CAAA"}
1
+ {"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../src/main/boolean.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,GACvD,CAAC,SAAS,KAAK,GAAG,IAAI,GACtB,OAAO,CAAA;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,GAAG,CACb,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,IACf,CAAC,SAAS,KAAK,GAAG,KAAK,GACvB,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC3B,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAA;AAE9D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,EAAE,CACZ,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,IACf,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC3B,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC3B,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,GAC/B,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,GAC/B,IAAI,SAAS,CAAC,GAAG,IAAI,GACrB,IAAI,SAAS,CAAC,GAAG,IAAI,GACrB,KAAK,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/main/boolean.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * ### Result\n *\n * - `never`: if `T` is `never`\n * - `boolean`: if `T` is `boolean` or `any`\n * - `false`: if `T` is `true`\n * - `true`: if `T` is `false`\n *\n * ### Examples\n *\n * | `T` | `Not<T>` |\n * | --------- | --------- |\n * | `never` | `never` |\n * | `true` | `false` |\n * | `false` | `true` |\n * | `boolean` | `boolean` |\n * | `any` | `boolean` |\n */\nexport type Not<T extends boolean> = T extends true ? false\n : T extends false ? true\n : boolean\n\n/**\n * - `never`: if anyone of A,B is `never`\n * - `boolean`: if anyone of A,B is `boolean` or `any`\n * - `true`: if both A,B are `true`\n * - `false`: otherwise\n */\nexport type And<\n A extends boolean,\n B extends boolean,\n> = A extends never ? never\n : [B] extends [never] ? never\n : (A extends true ? (B extends true ? true : false) : false)\n\n/**\n * ### Result\n *\n * - `never`: if anyone of A,B is `never`\n * - `boolean`: if anyone of A,B is `boolean` or `any`\n * - `false`: if both A,B are `false`\n * - `true`: otherwise\n */\nexport type Or<\n A extends boolean,\n B extends boolean,\n> = [A] extends [never] ? never\n : [B] extends [never] ? never\n : [boolean] extends [A] ? boolean\n : [boolean] extends [B] ? boolean\n : true extends A ? true\n : true extends B ? true\n : false\n"]}
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/main/boolean.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Negates a boolean type\n *\n * @template T - The boolean type to negate\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<Not<true>>().toBeFalse\n * expect<Not<false>>().toBeTrue\n * expect<Not<boolean>>().toBe<boolean>().success\n * ```\n */\nexport type Not<T extends boolean> = T extends true ? false\n : T extends false ? true\n : boolean\n\n/**\n * Logical AND operation on two boolean types\n *\n * @template A - The first boolean type to compare\n * @template B - The second boolean type to compare\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<And<true, true>>().toBeTrue\n * expect<And<true, false>>().toBeFalse\n * expect<And<false, true>>().toBeFalse\n * expect<And<false, false>>().toBeFalse\n * expect<And<boolean, boolean>>().toBe<boolean>().success\n * ```\n */\nexport type And<\n A extends boolean,\n B extends boolean,\n> = A extends never ? never\n : [B] extends [never] ? never\n : (A extends true ? (B extends true ? true : false) : false)\n\n/**\n * Logical OR operation on two boolean types\n *\n * @template A - The first boolean type to compare\n * @template B - The second boolean type to compare\n *\n * ### Result\n *\n * - `never`: if either `A` or `B` is `never`\n * - `boolean`: if either `A` or `B` is `boolean` or `any`\n * - `false`: if both `A` and `B` are `false`\n * - `true`: otherwise\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<Or<true, true>>().toBeTrue\n * expect<Or<true, false>>().toBeTrue\n * expect<Or<false, true>>().toBeTrue\n * expect<Or<false, false>>().toBeFalse\n * expect<Or<boolean, false>>().toBe<boolean>().success\n * ```\n */\nexport type Or<\n A extends boolean,\n B extends boolean,\n> = [A] extends [never] ? never\n : [B] extends [never] ? never\n : [boolean] extends [A] ? boolean\n : [boolean] extends [B] ? boolean\n : true extends A ? true\n : true extends B ? true\n : false\n"]}
@@ -1,88 +1,112 @@
1
- import type { Same } from './type/compare.js';
1
+ import type { Exact } from './type/compare.js';
2
2
  /**
3
- * Conditional type - returns `T` if condition `C` is true, otherwise returns `F`
3
+ * Conditional type - returns `Yes` if condition `Condition` is true, otherwise returns `No`
4
4
  *
5
- * ### Result
6
- *
7
- * - `never`: if `C` is `never`
8
- * - `T`: if `C` is `true`
9
- * - `F`: if `C` is `false`
10
- *
11
- * ### Examples
5
+ * @template Condition - The boolean condition to check
6
+ * @template Yes - The type to return if condition is true
7
+ * @template No - The type to return if condition is false (defaults to `never`)
12
8
  *
9
+ * @example
13
10
  * ```ts
14
11
  * type Result = If<true, 'yes', 'no'> // 'yes'
15
12
  * type Result2 = If<false, 'yes', 'no'> // 'no'
16
- * type NeverResult = If<never, 'yes', 'no'> // never
13
+ * type BoolResult = If<boolean, 'yes', 'no'> // boolean
17
14
  * ```
18
15
  */
19
- export type If<C extends boolean, T, F = never> = [C] extends [never] ? never : C extends true ? T : F;
16
+ export type If<Condition extends boolean, Yes, No = never> = Condition extends true ? Yes : No;
20
17
  /**
21
- * Conditional type - returns `T` if condition `C` is false, otherwise returns `F`
18
+ * Conditional type - returns `Yes` if condition `Condition` is false, otherwise returns `No`
22
19
  *
23
- * ### Result
20
+ * @template Condition - The boolean condition to check
21
+ * @template Yes - The type to return if condition is false
22
+ * @template No - The type to return if condition is true (defaults to `never`)
24
23
  *
25
- * - `never`: if `C` is `never`
26
- * - `T`: if `C` is `false`
27
- * - `F`: if `C` is `true`
24
+ * ### Result
28
25
  *
29
- * ### Examples
26
+ * - `never`: if `Condition` is `never`
27
+ * - `Yes`: if `Condition` is `false`
28
+ * - `No`: if `Condition` is `true`
30
29
  *
30
+ * @example
31
31
  * ```ts
32
32
  * type Result = IfFalse<false, 'yes', 'no'> // 'yes'
33
33
  * type Result2 = IfFalse<true, 'yes', 'no'> // 'no'
34
- * type NeverResult = IfFalse<never, 'yes', 'no'> // never
34
+ * type BoolResult = IfFalse<boolean, 'yes', 'no'> // boolean
35
35
  * ```
36
36
  */
37
- export type IfFalse<C extends boolean, T, F = never> = [C] extends [never] ? never : C extends false ? T : F;
37
+ export type IfFalse<Condition extends boolean, Yes, No = never> = Condition extends false ? Yes : No;
38
38
  /**
39
- * Used with:
40
- * - {@link Switch}
41
- * - {@link SwitchExtends}
39
+ * Case tuple type used with `SwitchExact` and `SwitchExtends`
40
+ *
41
+ * @template T - The condition type to match against
42
+ * @template Result - The result type to return if match is found
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * type MyCase = Case<1, 'one'>
47
+ * // Equivalent to: [1, 'one']
48
+ * ```
49
+ *
50
+ * @see SwitchExact
42
51
  */
43
- export type Case<T = unknown, Return = unknown> = [T, Return];
52
+ export type Case<T = unknown, Result = unknown> = [T, Result];
44
53
  /**
45
- * Used with:
46
- *
47
- * - {@link Switch}
48
- * - {@link SwitchExtends}
54
+ * Default case type used with `SwitchExact` and `SwitchExtends`
49
55
  *
50
- * ### Examples
56
+ * @template T - The default result type
51
57
  *
58
+ * @example
52
59
  * ```ts
53
- * type NameMap<id> = Switch<id, [
54
- * Case<1, 'Alice'>,
55
- * Case<2, 'Bob'>,
56
- * Case<3, 'Charlie'>,
60
+ * type NameMap<id> = SwitchExact<id, [
61
+ * [1, 'Alice'],
62
+ * [2, 'Bob'],
57
63
  * ], DefaultCase<'Steve'>>
58
64
  * ```
65
+ *
66
+ * @see SwitchExact
59
67
  */
60
68
  export type DefaultCase<T> = T;
61
69
  /**
62
- * ### Examples
70
+ * Switch type that uses exact matching logic
71
+ *
72
+ * **⚠️Important:** `T` parameter is not distributive. When `T` is a union type, it does not check each member separately.
63
73
  *
74
+ * @template T - The type to match against cases
75
+ * @template Cases - Array of case tuples, each tuple has the form [Condition, Result]
76
+ * @template Default - Default result if no exact match is found (defaults to `never`)
77
+ *
78
+ * @example
64
79
  * ```ts
65
- * type Result = Switch<2, [
66
- * Case<1, 'Alice'>,
67
- * Case<2, 'Bob'>,
68
- * Case<3, 'Charlie'>,
80
+ * type Result = SwitchExact<2, [
81
+ * [1, 'Alice'],
82
+ * [2, 'Bob'],
83
+ * [3, 'Charlie'],
69
84
  * ], DefaultCase<'Steve'>>
70
85
  *
71
86
  * // Result: 'Bob'
72
87
  * ```
73
88
  */
74
- export type Switch<T, Cases extends readonly Case[], Default = never> = Cases extends [infer First, ...infer Rest] ? (First extends [infer C, infer R] ? (Same<T, C> extends true ? R : (Switch<T, Rest extends readonly Case[] ? Rest : never, Default>)) : (never)) : Default;
89
+ export type SwitchExact<T, Cases extends readonly [unknown, unknown][], Default = never> = Cases extends [infer First, ...infer Rest] ? (First extends [infer Condition, infer Result] ? (Exact<T, Condition> extends true ? Result : (SwitchExact<T, Rest extends readonly [unknown, unknown][] ? Rest : never, Default>)) : (never)) : Default;
75
90
  /**
76
- * Switch type that uses 'extends' logic instead of 'Same' logic
91
+ * Switch type that uses 'extends' logic instead of 'Exact' logic
92
+ *
93
+ * **⚠️Important:** `T` parameter is not distributive. When `T` is a union type, it does not check each member separately.
77
94
  *
78
- * ### Examples
95
+ * @template T - The type to match against cases
96
+ * @template Cases - Array of case tuples, each tuple has the form [Condition, Result]
97
+ * @template Default - Default result if no match is found (defaults to `never`)
98
+ *
99
+ * @example
79
100
  * ```ts
80
- * type Result = SwitchExtends<string | number, [
81
- * Case<string, 'string type'>,
82
- * Case<number, 'number type'>,
83
- * ], 'other'>
84
- * // Result: 'string type' | 'number type'
101
+ * import { expect } from '@leawind/lay-sing/test-utils'
102
+ *
103
+ * expect<
104
+ * SwitchExtends<string, [
105
+ * [number, boolean],
106
+ * [string, boolean],
107
+ * ], Error>
108
+ * >().toBe<boolean>().success
85
109
  * ```
86
110
  */
87
- export type SwitchExtends<T, Cases extends readonly Case[], Default = never> = Cases extends [infer First, ...infer Rest] ? (First extends [infer C, infer R] ? ([T] extends [C] ? R : SwitchExtends<T, Rest extends readonly Case[] ? Rest : never, Default>) : never) : Default;
111
+ export type SwitchExtends<T, Cases extends readonly [unknown, unknown][], Default = never> = Cases extends [infer First, ...infer Rest] ? (First extends [infer C, infer R] ? ([T] extends [C] ? R : SwitchExtends<T, Rest extends readonly [unknown, unknown][] ? Rest : never, Default>) : never) : Default;
88
112
  //# sourceMappingURL=control.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../src/main/control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAE7C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,EAAE,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GACzE,CAAC,SAAS,IAAI,GAAG,CAAC,GAClB,CAAC,CAAA;AAEL;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC9E,CAAC,SAAS,KAAK,GAAG,CAAC,GACnB,CAAC,CAAA;AAEL;;;;GAIG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAC7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,CAAA;AAE9B;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,MAAM,CAChB,CAAC,EACD,KAAK,SAAS,SAAS,IAAI,EAAE,EAC7B,OAAO,GAAG,KAAK,IACb,KAAK,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAC7C,KAAK,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAC5B,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,SAAS,SAAS,IAAI,EAAE,GAAG,IAAI,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GACjG,CAAC,KAAK,CAAC,CACZ,GACC,OAAO,CAAA;AAEX;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,aAAa,CACvB,CAAC,EACD,KAAK,SAAS,SAAS,IAAI,EAAE,EAC7B,OAAO,GAAG,KAAK,IACb,KAAK,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAC7C,KAAK,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAC5B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE,IAAI,SAAS,SAAS,IAAI,EAAE,GAAG,IAAI,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC,GAC9F,KAAK,CACV,GACC,OAAO,CAAA"}
1
+ {"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../src/main/control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAE9C;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,EAAE,CAAC,SAAS,SAAS,OAAO,EAAE,GAAG,EAAE,EAAE,GAAG,KAAK,IAAI,SAAS,SAAS,IAAI,GAAG,GAAG,GAAG,EAAE,CAAA;AAE9F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,OAAO,CAAC,SAAS,SAAS,OAAO,EAAE,GAAG,EAAE,EAAE,GAAG,KAAK,IAAI,SAAS,SAAS,KAAK,GAAG,GAAG,GAAG,EAAE,CAAA;AAEpG;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAE7D;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,WAAW,CACrB,CAAC,EACD,KAAK,SAAS,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAC3C,OAAO,GAAG,KAAK,IACb,KAAK,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAC7C,KAAK,SAAS,CAAC,MAAM,SAAS,EAAE,MAAM,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,SAAS,IAAI,GAAG,MAAM,GACpF,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,SAAS,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GACvF,CAAC,KAAK,CAAC,CACZ,GACC,OAAO,CAAA;AAEX;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,aAAa,CACvB,CAAC,EACD,KAAK,SAAS,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAC3C,OAAO,GAAG,KAAK,IACb,KAAK,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAC7C,KAAK,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAC5B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE,IAAI,SAAS,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC,GAC5G,KAAK,CACV,GACC,OAAO,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"control.js","sourceRoot":"","sources":["../../src/main/control.ts"],"names":[],"mappings":"","sourcesContent":["import type { Same } from './type/compare.js'\n\n/**\n * Conditional type - returns `T` if condition `C` is true, otherwise returns `F`\n *\n * ### Result\n *\n * - `never`: if `C` is `never`\n * - `T`: if `C` is `true`\n * - `F`: if `C` is `false`\n *\n * ### Examples\n *\n * ```ts\n * type Result = If<true, 'yes', 'no'> // 'yes'\n * type Result2 = If<false, 'yes', 'no'> // 'no'\n * type NeverResult = If<never, 'yes', 'no'> // never\n * ```\n */\nexport type If<C extends boolean, T, F = never> = [C] extends [never] ? never\n : C extends true ? T\n : F\n\n/**\n * Conditional type - returns `T` if condition `C` is false, otherwise returns `F`\n *\n * ### Result\n *\n * - `never`: if `C` is `never`\n * - `T`: if `C` is `false`\n * - `F`: if `C` is `true`\n *\n * ### Examples\n *\n * ```ts\n * type Result = IfFalse<false, 'yes', 'no'> // 'yes'\n * type Result2 = IfFalse<true, 'yes', 'no'> // 'no'\n * type NeverResult = IfFalse<never, 'yes', 'no'> // never\n * ```\n */\nexport type IfFalse<C extends boolean, T, F = never> = [C] extends [never] ? never\n : C extends false ? T\n : F\n\n/**\n * Used with:\n * - {@link Switch}\n * - {@link SwitchExtends}\n */\nexport type Case<T = unknown, Return = unknown> = [T, Return]\n/**\n * Used with:\n *\n * - {@link Switch}\n * - {@link SwitchExtends}\n *\n * ### Examples\n *\n * ```ts\n * type NameMap<id> = Switch<id, [\n * Case<1, 'Alice'>,\n * Case<2, 'Bob'>,\n * Case<3, 'Charlie'>,\n * ], DefaultCase<'Steve'>>\n * ```\n */\nexport type DefaultCase<T> = T\n\n/**\n * ### Examples\n *\n * ```ts\n * type Result = Switch<2, [\n * Case<1, 'Alice'>,\n * Case<2, 'Bob'>,\n * Case<3, 'Charlie'>,\n * ], DefaultCase<'Steve'>>\n *\n * // Result: 'Bob'\n * ```\n */\nexport type Switch<\n T,\n Cases extends readonly Case[],\n Default = never,\n> = Cases extends [infer First, ...infer Rest] ? (\n First extends [infer C, infer R]\n ? (Same<T, C> extends true ? R : (Switch<T, Rest extends readonly Case[] ? Rest : never, Default>))\n : (never)\n )\n : Default\n\n/**\n * Switch type that uses 'extends' logic instead of 'Same' logic\n *\n * ### Examples\n * ```ts\n * type Result = SwitchExtends<string | number, [\n * Case<string, 'string type'>,\n * Case<number, 'number type'>,\n * ], 'other'>\n * // Result: 'string type' | 'number type'\n * ```\n */\nexport type SwitchExtends<\n T,\n Cases extends readonly Case[],\n Default = never,\n> = Cases extends [infer First, ...infer Rest] ? (\n First extends [infer C, infer R]\n ? ([T] extends [C] ? R : SwitchExtends<T, Rest extends readonly Case[] ? Rest : never, Default>)\n : never\n )\n : Default\n"]}
1
+ {"version":3,"file":"control.js","sourceRoot":"","sources":["../../src/main/control.ts"],"names":[],"mappings":"","sourcesContent":["import type { Exact } from './type/compare.js'\n\n/**\n * Conditional type - returns `Yes` if condition `Condition` is true, otherwise returns `No`\n *\n * @template Condition - The boolean condition to check\n * @template Yes - The type to return if condition is true\n * @template No - The type to return if condition is false (defaults to `never`)\n *\n * @example\n * ```ts\n * type Result = If<true, 'yes', 'no'> // 'yes'\n * type Result2 = If<false, 'yes', 'no'> // 'no'\n * type BoolResult = If<boolean, 'yes', 'no'> // boolean\n * ```\n */\nexport type If<Condition extends boolean, Yes, No = never> = Condition extends true ? Yes : No\n\n/**\n * Conditional type - returns `Yes` if condition `Condition` is false, otherwise returns `No`\n *\n * @template Condition - The boolean condition to check\n * @template Yes - The type to return if condition is false\n * @template No - The type to return if condition is true (defaults to `never`)\n *\n * ### Result\n *\n * - `never`: if `Condition` is `never`\n * - `Yes`: if `Condition` is `false`\n * - `No`: if `Condition` is `true`\n *\n * @example\n * ```ts\n * type Result = IfFalse<false, 'yes', 'no'> // 'yes'\n * type Result2 = IfFalse<true, 'yes', 'no'> // 'no'\n * type BoolResult = IfFalse<boolean, 'yes', 'no'> // boolean\n * ```\n */\nexport type IfFalse<Condition extends boolean, Yes, No = never> = Condition extends false ? Yes : No\n\n/**\n * Case tuple type used with `SwitchExact` and `SwitchExtends`\n *\n * @template T - The condition type to match against\n * @template Result - The result type to return if match is found\n *\n * @example\n * ```ts\n * type MyCase = Case<1, 'one'>\n * // Equivalent to: [1, 'one']\n * ```\n *\n * @see SwitchExact\n */\nexport type Case<T = unknown, Result = unknown> = [T, Result]\n\n/**\n * Default case type used with `SwitchExact` and `SwitchExtends`\n *\n * @template T - The default result type\n *\n * @example\n * ```ts\n * type NameMap<id> = SwitchExact<id, [\n * [1, 'Alice'],\n * [2, 'Bob'],\n * ], DefaultCase<'Steve'>>\n * ```\n *\n * @see SwitchExact\n */\nexport type DefaultCase<T> = T\n\n/**\n * Switch type that uses exact matching logic\n *\n * **⚠️Important:** `T` parameter is not distributive. When `T` is a union type, it does not check each member separately.\n *\n * @template T - The type to match against cases\n * @template Cases - Array of case tuples, each tuple has the form [Condition, Result]\n * @template Default - Default result if no exact match is found (defaults to `never`)\n *\n * @example\n * ```ts\n * type Result = SwitchExact<2, [\n * [1, 'Alice'],\n * [2, 'Bob'],\n * [3, 'Charlie'],\n * ], DefaultCase<'Steve'>>\n *\n * // Result: 'Bob'\n * ```\n */\nexport type SwitchExact<\n T,\n Cases extends readonly [unknown, unknown][],\n Default = never,\n> = Cases extends [infer First, ...infer Rest] ? (\n First extends [infer Condition, infer Result] ? (Exact<T, Condition> extends true ? Result\n : (SwitchExact<T, Rest extends readonly [unknown, unknown][] ? Rest : never, Default>))\n : (never)\n )\n : Default\n\n/**\n * Switch type that uses 'extends' logic instead of 'Exact' logic\n *\n * **⚠️Important:** `T` parameter is not distributive. When `T` is a union type, it does not check each member separately.\n *\n * @template T - The type to match against cases\n * @template Cases - Array of case tuples, each tuple has the form [Condition, Result]\n * @template Default - Default result if no match is found (defaults to `never`)\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing/test-utils'\n *\n * expect<\n * SwitchExtends<string, [\n * [number, boolean],\n * [string, boolean],\n * ], Error>\n * >().toBe<boolean>().success\n * ```\n */\nexport type SwitchExtends<\n T,\n Cases extends readonly [unknown, unknown][],\n Default = never,\n> = Cases extends [infer First, ...infer Rest] ? (\n First extends [infer C, infer R]\n ? ([T] extends [C] ? R : SwitchExtends<T, Rest extends readonly [unknown, unknown][] ? Rest : never, Default>)\n : never\n )\n : Default\n"]}
package/esm/main/doc.d.ts CHANGED
@@ -1,30 +1,56 @@
1
1
  /**
2
- * Append documentation or auxiliary metadata to type `A`
2
+ * Append documentation or auxiliary metadata to type `T`
3
3
  * without changing its shape.
4
4
  *
5
- * This type intersects `Doc` onto `A`, but only keeps the keys
6
- * originally defined in `A`. As a result:
5
+ * This type intersects `Doc` onto `T`, but only keeps the keys
6
+ * originally defined in `T`. As a result:
7
7
  *
8
8
  * - `Doc` cannot introduce new properties
9
- * - Existing properties in `A` are preserved
9
+ * - Existing properties in `T` are preserved
10
10
  * - `Doc` may further constrain or annotate existing properties
11
11
  *
12
12
  * This is typically used to attach JSDoc comments, branding,
13
13
  * or editor-only metadata to an existing type while keeping
14
14
  * its public structure intact.
15
+ *
16
+ * @template T - The target type to append documentation to
17
+ * @template Doc - The documentation or metadata type to append
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { expect } from '@leawind/lay-sing/test-utils'
22
+ *
23
+ * type User = { name: string; age: number }
24
+ * type UserWithDoc = AppendDoc<User, { name: string }>
25
+ *
26
+ * expect<UserWithDoc>().toBe<User>().success
27
+ * ```
15
28
  */
16
29
  export type AppendDoc<T, Doc> = Pick<T & Doc, keyof T>;
17
30
  /**
18
- * Prepend documentation or auxiliary metadata to type `A`
31
+ * Prepend documentation or auxiliary metadata to type `T`
19
32
  * without changing its shape.
20
33
  *
21
34
  * This is similar to {@link AppendDoc}, but the intersection order
22
- * is reversed (`Doc & A`), which can affect how property types,
35
+ * is reversed (`Doc & T`), which can affect how property types,
23
36
  * documentation, and hover information are presented by tooling.
24
37
  *
25
38
  * In practice, this allows `Doc` to act as a non-invasive,
26
- * descriptive layer while ensuring `A` remains the authoritative
39
+ * descriptive layer while ensuring `T` remains the authoritative
27
40
  * source of truth for property types.
41
+ *
42
+ * @template T - The target type to prepend documentation to
43
+ * @template Doc - The documentation or metadata type to prepend
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * import { expect } from '@leawind/lay-sing/test-utils'
48
+ *
49
+ * type User = { name: string; age: number }
50
+ * type UserWithDoc = PrependDoc<User, { age: number }>
51
+ *
52
+ * expect<UserWithDoc>().toBe<User>().success
53
+ * ```
28
54
  */
29
55
  export type PrependDoc<T, Doc> = Pick<Doc & T, keyof T>;
30
56
  //# sourceMappingURL=doc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../src/main/doc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../src/main/doc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA"}