lay-sing 0.3.0 → 0.4.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 +17 -17
- package/esm/main/expect/index.d.ts +30 -0
- package/esm/main/expect/index.d.ts.map +1 -0
- package/esm/main/expect/index.js +2 -0
- package/esm/main/expect/index.js.map +1 -0
- package/esm/main/expect/to/be.d.ts +23 -0
- package/esm/main/expect/to/be.d.ts.map +1 -0
- package/esm/main/expect/to/be.js +2 -0
- package/esm/main/expect/to/be.js.map +1 -0
- package/esm/main/expect/to/equal.d.ts +26 -0
- package/esm/main/expect/to/equal.d.ts.map +1 -0
- package/esm/main/expect/to/equal.js +2 -0
- package/esm/main/expect/to/equal.js.map +1 -0
- package/esm/main/expect/to/extend.d.ts +31 -0
- package/esm/main/expect/to/extend.d.ts.map +1 -0
- package/esm/main/expect/to/extend.js +2 -0
- package/esm/main/expect/to/extend.js.map +1 -0
- package/esm/main/expect/to/have-key.d.ts +38 -0
- package/esm/main/expect/to/have-key.d.ts.map +1 -0
- package/esm/main/expect/to/have-key.js +2 -0
- package/esm/main/expect/to/have-key.js.map +1 -0
- package/esm/main/expect/to/index.d.ts +15 -0
- package/esm/main/expect/to/index.d.ts.map +1 -0
- package/esm/main/expect/to/index.js +2 -0
- package/esm/main/expect/to/index.js.map +1 -0
- package/esm/main/expect/to/proper-extends.d.ts +21 -0
- package/esm/main/expect/to/proper-extends.d.ts.map +1 -0
- package/esm/main/expect/to/proper-extends.js +2 -0
- package/esm/main/expect/to/proper-extends.js.map +1 -0
- package/esm/main/index.d.ts +10 -8
- package/esm/main/index.d.ts.map +1 -1
- package/esm/main/index.js +20 -3
- package/esm/main/index.js.map +1 -1
- package/esm/utils/compare/exact.d.ts +8 -8
- package/esm/utils/compare/exact.js.map +1 -1
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +1 -0
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/logic/assert.d.ts +3 -3
- package/esm/utils/logic/assert.js.map +1 -1
- package/esm/utils/logic/boolean.d.ts +60 -0
- package/esm/utils/logic/boolean.d.ts.map +1 -0
- package/esm/utils/logic/boolean.js +2 -0
- package/esm/utils/logic/boolean.js.map +1 -0
- package/esm/utils/logic/index.d.ts +1 -0
- package/esm/utils/logic/index.d.ts.map +1 -1
- package/esm/utils/logic/index.js +1 -0
- package/esm/utils/logic/index.js.map +1 -1
- package/esm/utils/logic/switch.d.ts +1 -1
- package/esm/utils/logic/switch.js.map +1 -1
- package/esm/utils/misc.d.ts +34 -0
- package/esm/utils/misc.d.ts.map +1 -0
- package/esm/utils/misc.js +2 -0
- package/esm/utils/misc.js.map +1 -0
- package/esm/utils/object/keys.d.ts +12 -12
- package/esm/utils/object/keys.js.map +1 -1
- package/esm/utils/object/pick.d.ts +1 -1
- package/esm/utils/object/pick.js.map +1 -1
- package/esm/utils/object/props.d.ts +1 -1
- package/esm/utils/object/props.js.map +1 -1
- package/esm/utils/tuple/append.d.ts +2 -2
- package/esm/utils/tuple/append.js.map +1 -1
- package/esm/utils/tuple/concat.d.ts +2 -2
- package/esm/utils/tuple/concat.js.map +1 -1
- package/esm/utils/tuple/includes.d.ts +3 -3
- package/esm/utils/tuple/includes.js.map +1 -1
- package/package.json +1 -1
- package/script/main/expect/index.d.ts +30 -0
- package/script/main/expect/index.d.ts.map +1 -0
- package/script/main/{expect.js → expect/index.js} +1 -1
- package/script/main/expect/index.js.map +1 -0
- package/script/main/expect/to/be.d.ts +23 -0
- package/script/main/expect/to/be.d.ts.map +1 -0
- package/script/main/expect/to/be.js +3 -0
- package/script/main/expect/to/be.js.map +1 -0
- package/script/main/expect/to/equal.d.ts +26 -0
- package/script/main/expect/to/equal.d.ts.map +1 -0
- package/script/main/expect/to/equal.js +3 -0
- package/script/main/expect/to/equal.js.map +1 -0
- package/script/main/expect/to/extend.d.ts +31 -0
- package/script/main/expect/to/extend.d.ts.map +1 -0
- package/script/main/expect/to/extend.js +3 -0
- package/script/main/expect/to/extend.js.map +1 -0
- package/script/main/expect/to/have-key.d.ts +38 -0
- package/script/main/expect/to/have-key.d.ts.map +1 -0
- package/script/main/expect/to/have-key.js +3 -0
- package/script/main/expect/to/have-key.js.map +1 -0
- package/script/main/expect/to/index.d.ts +15 -0
- package/script/main/expect/to/index.d.ts.map +1 -0
- package/script/main/expect/to/index.js +3 -0
- package/script/main/expect/to/index.js.map +1 -0
- package/script/main/expect/to/proper-extends.d.ts +21 -0
- package/script/main/expect/to/proper-extends.d.ts.map +1 -0
- package/script/main/expect/to/proper-extends.js +3 -0
- package/script/main/expect/to/proper-extends.js.map +1 -0
- package/script/main/index.d.ts +10 -8
- package/script/main/index.d.ts.map +1 -1
- package/script/main/index.js +21 -5
- package/script/main/index.js.map +1 -1
- package/script/utils/compare/exact.d.ts +8 -8
- package/script/utils/compare/exact.js.map +1 -1
- package/script/utils/index.d.ts +1 -0
- package/script/utils/index.d.ts.map +1 -1
- package/script/utils/index.js +1 -0
- package/script/utils/index.js.map +1 -1
- package/script/utils/logic/assert.d.ts +3 -3
- package/script/utils/logic/assert.js.map +1 -1
- package/script/utils/logic/boolean.d.ts +60 -0
- package/script/utils/logic/boolean.d.ts.map +1 -0
- package/script/utils/logic/boolean.js +3 -0
- package/script/utils/logic/boolean.js.map +1 -0
- package/script/utils/logic/index.d.ts +1 -0
- package/script/utils/logic/index.d.ts.map +1 -1
- package/script/utils/logic/index.js +1 -0
- package/script/utils/logic/index.js.map +1 -1
- package/script/utils/logic/switch.d.ts +1 -1
- package/script/utils/logic/switch.js.map +1 -1
- package/script/utils/misc.d.ts +34 -0
- package/script/utils/misc.d.ts.map +1 -0
- package/script/utils/misc.js +3 -0
- package/script/utils/misc.js.map +1 -0
- package/script/utils/object/keys.d.ts +12 -12
- package/script/utils/object/keys.js.map +1 -1
- package/script/utils/object/pick.d.ts +1 -1
- package/script/utils/object/pick.js.map +1 -1
- package/script/utils/object/props.d.ts +1 -1
- package/script/utils/object/props.js.map +1 -1
- package/script/utils/tuple/append.d.ts +2 -2
- package/script/utils/tuple/append.js.map +1 -1
- package/script/utils/tuple/concat.d.ts +2 -2
- package/script/utils/tuple/concat.js.map +1 -1
- package/script/utils/tuple/includes.d.ts +3 -3
- package/script/utils/tuple/includes.js.map +1 -1
- package/esm/main/expect.d.ts +0 -293
- package/esm/main/expect.d.ts.map +0 -1
- package/esm/main/expect.js +0 -2
- package/esm/main/expect.js.map +0 -1
- package/script/main/expect.d.ts +0 -293
- package/script/main/expect.d.ts.map +0 -1
- package/script/main/expect.js.map +0 -1
package/README.md
CHANGED
|
@@ -9,12 +9,12 @@ TypeScript utilities for compile-time type testing and utility types
|
|
|
9
9
|
|
|
10
10
|
```ts
|
|
11
11
|
// They do nothing at runtime
|
|
12
|
-
expect<never>().
|
|
13
|
-
expect<never>().
|
|
14
|
-
expect<never>().
|
|
12
|
+
expect<never>().to.be<never>().pass
|
|
13
|
+
expect<never>().to.be.never // alias for the above
|
|
14
|
+
expect<never>().to.be<'should fail'>().fail
|
|
15
15
|
|
|
16
|
-
// Type Error: Property '
|
|
17
|
-
expect<never>().
|
|
16
|
+
// Type Error: Property 'pass' does not exist on type '{ fail: void; }'.
|
|
17
|
+
expect<never>().to.be<'should fail'>().pass
|
|
18
18
|
// ^^^^^^^
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -84,11 +84,11 @@ The main module provides utilities for **compile-time** type validation. These u
|
|
|
84
84
|
A typical type test statement follows this pattern:
|
|
85
85
|
|
|
86
86
|
```ts
|
|
87
|
-
expect<ActualType>().
|
|
87
|
+
expect<ActualType>().to.be<ExpectedType>().pass
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
- It starts with a function call like `expect<T>()` or `compare<T, U>()`
|
|
91
|
-
- It ends with a property like `.
|
|
91
|
+
- It ends with a property like `.pass` or `.fail`
|
|
92
92
|
- Type error occurs only if the assertion fails
|
|
93
93
|
|
|
94
94
|
> [!CAUTION]
|
|
@@ -96,8 +96,8 @@ expect<ActualType>().toBe<ExpectedType>().success
|
|
|
96
96
|
> Only statements ending with property access are type assertions. Without property access, type error may never occur:
|
|
97
97
|
>
|
|
98
98
|
> ```diff
|
|
99
|
-
> - expect<true>().
|
|
100
|
-
> + expect<true>().
|
|
99
|
+
> - expect<true>().to.be<false>() // Type error never occur
|
|
100
|
+
> + expect<true>().to.be<false>().pass // Type Error: Property 'pass' does not exist on type '{ fail: void; }'.
|
|
101
101
|
> ```
|
|
102
102
|
|
|
103
103
|
At runtime, the function always returns the `NOOP` object, which performs **no operation**. It can be accessed, called, or chained indefinitely without throwing errors.
|
|
@@ -106,26 +106,26 @@ At runtime, the function always returns the `NOOP` object, which performs **no o
|
|
|
106
106
|
|
|
107
107
|
```ts
|
|
108
108
|
// Passes only if A and B are identical
|
|
109
|
-
expect<keyof { a: 2 }>().
|
|
109
|
+
expect<keyof { a: 2 }>().to.be<'a'>().pass
|
|
110
110
|
|
|
111
111
|
// Passes if A extends B
|
|
112
|
-
expect<12138>().
|
|
112
|
+
expect<12138>().to.extend<number>().pass
|
|
113
113
|
|
|
114
114
|
// Passes if mutually assignable
|
|
115
|
-
expect<{ a: 1; b: 2 }>().
|
|
115
|
+
expect<{ a: 1; b: 2 }>().to.equal<{ a: 1 } & { b: 2 }>().pass
|
|
116
116
|
|
|
117
117
|
// Test property existence
|
|
118
|
-
expect<{ name: string }>().
|
|
118
|
+
expect<{ name: string }>().to.haveKey<'name'>().pass
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
Aliases:
|
|
122
122
|
|
|
123
123
|
```ts
|
|
124
|
-
expect<never>().
|
|
125
|
-
expect<never>().
|
|
124
|
+
expect<never>().to.be<never>().pass
|
|
125
|
+
expect<never>().to.be.never
|
|
126
126
|
|
|
127
|
-
expect<'hello'>().
|
|
128
|
-
expect<'hello'>().
|
|
127
|
+
expect<'hello'>().to.extend<string>().pass
|
|
128
|
+
expect<'hello'>().to.extend.string
|
|
129
129
|
```
|
|
130
130
|
|
|
131
131
|
#### NOOP
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { To } from './to/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the result of a type assertion based on a boolean condition.
|
|
4
|
+
*
|
|
5
|
+
* - If `true`, the result has a `pass` property;
|
|
6
|
+
* - If `false`, the result has a `fail` property;
|
|
7
|
+
* - Otherwise, the result is `never`
|
|
8
|
+
*
|
|
9
|
+
* @template B The boolean condition result (true or false)
|
|
10
|
+
* @template R The type of the result value (default is void)
|
|
11
|
+
*/
|
|
12
|
+
export type TypeAssertionResult<T, B extends boolean, R = ExpectType<T>> = [B] extends [true] ? {
|
|
13
|
+
/**
|
|
14
|
+
* This field exist only when this type assertion succeed
|
|
15
|
+
*
|
|
16
|
+
* If you expect this assertion to fail, use `.fail`
|
|
17
|
+
*/
|
|
18
|
+
pass: R;
|
|
19
|
+
} : [B] extends [false] ? {
|
|
20
|
+
/**
|
|
21
|
+
* This field exist only when this type assertion failed
|
|
22
|
+
*
|
|
23
|
+
* If you expect this assertion to pass, use `.pass`
|
|
24
|
+
*/
|
|
25
|
+
fail: R;
|
|
26
|
+
} : never;
|
|
27
|
+
export type ExpectType<T> = {
|
|
28
|
+
to: To<T>;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/main/expect/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,eAAe,CAAA;AAEvC;;;;;;;;;GASG;AACH,MAAM,MAAM,mBAAmB,CAC7B,CAAC,EACD,CAAC,SAAS,OAAO,EACjB,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,IACf,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG;IACrB;;;;OAIG;IACH,IAAI,EAAE,CAAC,CAAA;CACR,GACC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG;IACpB;;;;OAIG;IACH,IAAI,EAAE,CAAC,CAAA;CACR,GACD,KAAK,CAAA;AAET,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC1B,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;CACV,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/main/expect/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { To } from './to/index.js'\n\n/**\n * Represents the result of a type assertion based on a boolean condition.\n *\n * - If `true`, the result has a `pass` property;\n * - If `false`, the result has a `fail` property;\n * - Otherwise, the result is `never`\n *\n * @template B The boolean condition result (true or false)\n * @template R The type of the result value (default is void)\n */\nexport type TypeAssertionResult<\n T,\n B extends boolean,\n R = ExpectType<T>,\n> = [B] extends [true] ? {\n /**\n * This field exist only when this type assertion succeed\n *\n * If you expect this assertion to fail, use `.fail`\n */\n pass: R\n }\n : [B] extends [false] ? {\n /**\n * This field exist only when this type assertion failed\n *\n * If you expect this assertion to pass, use `.pass`\n */\n fail: R\n }\n : never\n\nexport type ExpectType<T> = {\n to: To<T>\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Exact, If, Xor } from '../../../utils/index.js';
|
|
2
|
+
import type { TypeAssertionResult } from '../index.js';
|
|
3
|
+
export type Be<T, Inv extends boolean = false> = {
|
|
4
|
+
<U>(): TypeAssertionResult<T, Xor<Inv, Exact<T, U>>>;
|
|
5
|
+
<U>(_: U): TypeAssertionResult<T, Xor<Inv, Exact<T, U>>>;
|
|
6
|
+
} & If<Xor<Inv, Exact<T, any>>, {
|
|
7
|
+
any: void;
|
|
8
|
+
}, {}> & If<Xor<Inv, Exact<T, never>>, {
|
|
9
|
+
never: void;
|
|
10
|
+
}, {}> & If<Xor<Inv, Exact<T, unknown>>, {
|
|
11
|
+
unknown: void;
|
|
12
|
+
}, {}> & If<Xor<Inv, Exact<T, void>>, {
|
|
13
|
+
void: void;
|
|
14
|
+
}, {}> & If<Xor<Inv, Exact<T, null>>, {
|
|
15
|
+
null: void;
|
|
16
|
+
}, {}> & If<Xor<Inv, Exact<T, undefined>>, {
|
|
17
|
+
undefined: void;
|
|
18
|
+
}, {}> & If<Xor<Inv, Exact<T, true>>, {
|
|
19
|
+
true: void;
|
|
20
|
+
}, {}> & If<Xor<Inv, Exact<T, false>>, {
|
|
21
|
+
false: void;
|
|
22
|
+
}, {}>;
|
|
23
|
+
//# sourceMappingURL=be.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"be.d.ts","sourceRoot":"","sources":["../../../../src/main/expect/to/be.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,OAAO,GAAG,KAAK,IACzC;IACA,CAAC,CAAC,KAAK,mBAAmB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;CACzD,GACC,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAC9C,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAClD,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GACtD,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAChD,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAChD,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAC1D,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAChD,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"be.js","sourceRoot":"","sources":["../../../../src/main/expect/to/be.ts"],"names":[],"mappings":"","sourcesContent":["import type { Exact, If, Xor } from '../../../utils/index.js'\nimport type { TypeAssertionResult } from '../index.js'\n\nexport type Be<T, Inv extends boolean = false> =\n & {\n <U>(): TypeAssertionResult<T, Xor<Inv, Exact<T, U>>>\n <U>(_: U): TypeAssertionResult<T, Xor<Inv, Exact<T, U>>>\n }\n & If<Xor<Inv, Exact<T, any>>, { any: void }, {}>\n & If<Xor<Inv, Exact<T, never>>, { never: void }, {}>\n & If<Xor<Inv, Exact<T, unknown>>, { unknown: void }, {}>\n & If<Xor<Inv, Exact<T, void>>, { void: void }, {}>\n & If<Xor<Inv, Exact<T, null>>, { null: void }, {}>\n & If<Xor<Inv, Exact<T, undefined>>, { undefined: void }, {}>\n & If<Xor<Inv, Exact<T, true>>, { true: void }, {}>\n & If<Xor<Inv, Exact<T, false>>, { false: void }, {}>\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MutuallyAssignable, Xor } from '../../../utils/index.js';
|
|
2
|
+
import type { TypeAssertionResult } from '../index.js';
|
|
3
|
+
export type Equal<T, Inv extends boolean = false> = {
|
|
4
|
+
/**
|
|
5
|
+
* Tests if the current type is mutually assignable with the provided type U.
|
|
6
|
+
*
|
|
7
|
+
* It's like:
|
|
8
|
+
*
|
|
9
|
+
* ```ts ignore
|
|
10
|
+
* [T] extends [U] ? [U] extends [T] ? Yes : No : No
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @template U The type to compare with
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { expect } from '@leawind/lay-sing'
|
|
18
|
+
*
|
|
19
|
+
* expect<{ a: 1; b: 2 }>().to.equal<{ a: 1 } & { b: 2 }>().pass
|
|
20
|
+
* expect<1>().to.equal<1 | 2>().fail
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
<U>(): TypeAssertionResult<T, Xor<Inv, MutuallyAssignable<T, U>>>;
|
|
24
|
+
<U>(_: U): TypeAssertionResult<T, Xor<Inv, MutuallyAssignable<T, U>>>;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=equal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"equal.d.ts","sourceRoot":"","sources":["../../../../src/main/expect/to/equal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,GAAG,SAAS,OAAO,GAAG,KAAK,IAAI;IAClD;;;;;;;;;;;;;;;;;;OAkBG;IACH,CAAC,CAAC,KAAK,mBAAmB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACjE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;CACtE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"equal.js","sourceRoot":"","sources":["../../../../src/main/expect/to/equal.ts"],"names":[],"mappings":"","sourcesContent":["import type { MutuallyAssignable, Xor } from '../../../utils/index.js'\nimport type { TypeAssertionResult } from '../index.js'\n\nexport type Equal<T, Inv extends boolean = false> = {\n /**\n * Tests if the current type is mutually assignable with the provided type U.\n *\n * It's like:\n *\n * ```ts ignore\n * [T] extends [U] ? [U] extends [T] ? Yes : No : No\n * ```\n *\n * @template U The type to compare with\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<{ a: 1; b: 2 }>().to.equal<{ a: 1 } & { b: 2 }>().pass\n * expect<1>().to.equal<1 | 2>().fail\n * ```\n */\n <U>(): TypeAssertionResult<T, Xor<Inv, MutuallyAssignable<T, U>>>\n <U>(_: U): TypeAssertionResult<T, Xor<Inv, MutuallyAssignable<T, U>>>\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Extends, If, Xor } from '../../../utils/index.js';
|
|
2
|
+
import type { TypeAssertionResult } from '../index.js';
|
|
3
|
+
export type Extend<T, Inv extends boolean = false> = {
|
|
4
|
+
/**
|
|
5
|
+
* Tests if the current type T extends the provided type U.
|
|
6
|
+
*
|
|
7
|
+
* @template U The type to check extension against
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { expect } from '@leawind/lay-sing'
|
|
12
|
+
*
|
|
13
|
+
* expect<3.14>().to.extend<number>().pass
|
|
14
|
+
* expect<2>().to.extend<string>().fail
|
|
15
|
+
* expect<'hello'>().to.extend<string>().pass
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
<U>(): TypeAssertionResult<T, Xor<Inv, Extends<T, U>>>;
|
|
19
|
+
<U>(_: U): TypeAssertionResult<T, Xor<Inv, Extends<T, U>>>;
|
|
20
|
+
} & If<Xor<Inv, Extends<T, number>>, {
|
|
21
|
+
number: void;
|
|
22
|
+
}, {}> & If<Xor<Inv, Extends<T, bigint>>, {
|
|
23
|
+
bigint: void;
|
|
24
|
+
}, {}> & If<Xor<Inv, Extends<T, string>>, {
|
|
25
|
+
string: void;
|
|
26
|
+
}, {}> & If<Xor<Inv, Extends<T, boolean>>, {
|
|
27
|
+
boolean: void;
|
|
28
|
+
}, {}> & If<Xor<Inv, Extends<T, symbol>>, {
|
|
29
|
+
symbol: void;
|
|
30
|
+
}, {}>;
|
|
31
|
+
//# sourceMappingURL=extend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../../../../src/main/expect/to/extend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,OAAO,GAAG,KAAK,IAC7C;IACA;;;;;;;;;;;;;OAaG;IACH,CAAC,CAAC,KAAK,mBAAmB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACtD,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;CAC3D,GACC,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GACtD,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GACtD,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GACtD,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GACxD,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extend.js","sourceRoot":"","sources":["../../../../src/main/expect/to/extend.ts"],"names":[],"mappings":"","sourcesContent":["import type { Extends, If, Xor } from '../../../utils/index.js'\nimport type { TypeAssertionResult } from '../index.js'\n\nexport type Extend<T, Inv extends boolean = false> =\n & {\n /**\n * Tests if the current type T extends the provided type U.\n *\n * @template U The type to check extension against\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<3.14>().to.extend<number>().pass\n * expect<2>().to.extend<string>().fail\n * expect<'hello'>().to.extend<string>().pass\n * ```\n */\n <U>(): TypeAssertionResult<T, Xor<Inv, Extends<T, U>>>\n <U>(_: U): TypeAssertionResult<T, Xor<Inv, Extends<T, U>>>\n }\n & If<Xor<Inv, Extends<T, number>>, { number: void }, {}>\n & If<Xor<Inv, Extends<T, bigint>>, { bigint: void }, {}>\n & If<Xor<Inv, Extends<T, string>>, { string: void }, {}>\n & If<Xor<Inv, Extends<T, boolean>>, { boolean: void }, {}>\n & If<Xor<Inv, Extends<T, symbol>>, { symbol: void }, {}>\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Extends, IfTupleIncludes, Xor } from '../../../utils/index.js';
|
|
2
|
+
import type { TypeAssertionResult } from '../index.js';
|
|
3
|
+
type Result<T, K extends PropertyKey, Inv extends boolean = false> = IfTupleIncludes<[
|
|
4
|
+
never,
|
|
5
|
+
any
|
|
6
|
+
], K, never, TypeAssertionResult<T, Xor<Inv, Extends<K, keyof T>>>>;
|
|
7
|
+
export type HaveKey<T, Inv extends boolean = false> = {
|
|
8
|
+
/**
|
|
9
|
+
* Tests if the current type `T` has a property with key `K`.
|
|
10
|
+
*
|
|
11
|
+
* @template K The property key to check for
|
|
12
|
+
*
|
|
13
|
+
* ### Behavior
|
|
14
|
+
*
|
|
15
|
+
* - For single keys: succeeds if the key exists in `T`
|
|
16
|
+
* - For union types: succeeds only if **all** keys in the union exist in `T`
|
|
17
|
+
*
|
|
18
|
+
* ### Examples
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { expect } from '@leawind/lay-sing'
|
|
22
|
+
*
|
|
23
|
+
* type WithProp = { prop: string; another: number; may?: 5 }
|
|
24
|
+
*
|
|
25
|
+
* // Single key checks
|
|
26
|
+
* expect<WithProp>().to.haveKey<'prop'>().pass
|
|
27
|
+
* expect<WithProp>().to.haveKey<'missing'>().fail
|
|
28
|
+
*
|
|
29
|
+
* // Union type checks
|
|
30
|
+
* expect<WithProp>().to.haveKey<'prop' | 'another'>().pass
|
|
31
|
+
* expect<WithProp>().to.haveKey<'may' | 'unexist'>().fail
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
<K extends PropertyKey>(): Result<T, K, Inv>;
|
|
35
|
+
<K extends PropertyKey>(_: K): Result<T, K, Inv>;
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=have-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"have-key.d.ts","sourceRoot":"","sources":["../../../../src/main/expect/to/have-key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAAE,GAAG,SAAS,OAAO,GAAG,KAAK,IAAI,eAAe,CAClF;IAAC,KAAK;IAAE,GAAG;CAAC,EACZ,CAAC,EACD,KAAK,EACL,mBAAmB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CACtD,CAAA;AAED,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,GAAG,SAAS,OAAO,GAAG,KAAK,IAAI;IACpD;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,CAAC,CAAC,SAAS,WAAW,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;IAC5C,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;CACjD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"have-key.js","sourceRoot":"","sources":["../../../../src/main/expect/to/have-key.ts"],"names":[],"mappings":"","sourcesContent":["import type { Extends, IfTupleIncludes, Xor } from '../../../utils/index.js'\nimport type { TypeAssertionResult } from '../index.js'\n\ntype Result<T, K extends PropertyKey, Inv extends boolean = false> = IfTupleIncludes<\n [never, any],\n K,\n never,\n TypeAssertionResult<T, Xor<Inv, Extends<K, keyof T>>>\n>\n\nexport type HaveKey<T, Inv extends boolean = false> = {\n /**\n * Tests if the current type `T` has a property with key `K`.\n *\n * @template K The property key to check for\n *\n * ### Behavior\n *\n * - For single keys: succeeds if the key exists in `T`\n * - For union types: succeeds only if **all** keys in the union exist in `T`\n *\n * ### Examples\n *\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * type WithProp = { prop: string; another: number; may?: 5 }\n *\n * // Single key checks\n * expect<WithProp>().to.haveKey<'prop'>().pass\n * expect<WithProp>().to.haveKey<'missing'>().fail\n *\n * // Union type checks\n * expect<WithProp>().to.haveKey<'prop' | 'another'>().pass\n * expect<WithProp>().to.haveKey<'may' | 'unexist'>().fail\n * ```\n */\n <K extends PropertyKey>(): Result<T, K, Inv>\n <K extends PropertyKey>(_: K): Result<T, K, Inv>\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Not } from '../../../utils/logic/boolean.js';
|
|
2
|
+
import type { Be } from './be.js';
|
|
3
|
+
import type { Equal } from './equal.js';
|
|
4
|
+
import type { Extend } from './extend.js';
|
|
5
|
+
import type { ProperExtends } from './proper-extends.js';
|
|
6
|
+
import type { HaveKey } from './have-key.js';
|
|
7
|
+
export type To<T, Inv extends boolean = false> = {
|
|
8
|
+
not: To<T, Not<Inv>>;
|
|
9
|
+
be: Be<T, Inv>;
|
|
10
|
+
equal: Equal<T, Inv>;
|
|
11
|
+
extend: Extend<T, Inv>;
|
|
12
|
+
properExtend: ProperExtends<T, Inv>;
|
|
13
|
+
haveKey: HaveKey<T, Inv>;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/main/expect/to/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAA;AAC1D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,MAAM,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,OAAO,GAAG,KAAK,IAAI;IAC/C,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IACpB,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACd,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACpB,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACtB,YAAY,EAAE,aAAa,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACnC,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;CACzB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/main/expect/to/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { Not } from '../../../utils/logic/boolean.js'\nimport type { Be } from './be.js'\nimport type { Equal } from './equal.js'\nimport type { Extend } from './extend.js'\nimport type { ProperExtends } from './proper-extends.js'\nimport type { HaveKey } from './have-key.js'\n\nexport type To<T, Inv extends boolean = false> = {\n not: To<T, Not<Inv>>\n be: Be<T, Inv>\n equal: Equal<T, Inv>\n extend: Extend<T, Inv>\n properExtend: ProperExtends<T, Inv>\n haveKey: HaveKey<T, Inv>\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProperExtend, Xor } from '../../../utils/index.js';
|
|
2
|
+
import type { TypeAssertionResult } from '../index.js';
|
|
3
|
+
export type ProperExtends<T, Inv extends boolean = false> = {
|
|
4
|
+
/**
|
|
5
|
+
* Tests if the current type T properly extends the provided type U (extends but is not the same).
|
|
6
|
+
*
|
|
7
|
+
* @template U The type to check proper extension against
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { expect } from '@leawind/lay-sing'
|
|
12
|
+
*
|
|
13
|
+
* expect<2>().to.properExtend<number>().pass
|
|
14
|
+
* expect<'a' | 'b'>().to.properExtend<string>().pass
|
|
15
|
+
* expect<number>().to.properExtend<number>().fail
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
<U>(): TypeAssertionResult<T, Xor<Inv, ProperExtend<T, U>>>;
|
|
19
|
+
<U>(_: U): TypeAssertionResult<T, Xor<Inv, ProperExtend<T, U>>>;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=proper-extends.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proper-extends.d.ts","sourceRoot":"","sources":["../../../../src/main/expect/to/proper-extends.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,GAAG,SAAS,OAAO,GAAG,KAAK,IAAI;IAC1D;;;;;;;;;;;;;OAaG;IACH,CAAC,CAAC,KAAK,mBAAmB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3D,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;CAChE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proper-extends.js","sourceRoot":"","sources":["../../../../src/main/expect/to/proper-extends.ts"],"names":[],"mappings":"","sourcesContent":["import type { ProperExtend, Xor } from '../../../utils/index.js'\nimport type { TypeAssertionResult } from '../index.js'\n\nexport type ProperExtends<T, Inv extends boolean = false> = {\n /**\n * Tests if the current type T properly extends the provided type U (extends but is not the same).\n *\n * @template U The type to check proper extension against\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<2>().to.properExtend<number>().pass\n * expect<'a' | 'b'>().to.properExtend<string>().pass\n * expect<number>().to.properExtend<number>().fail\n * ```\n */\n <U>(): TypeAssertionResult<T, Xor<Inv, ProperExtend<T, U>>>\n <U>(_: U): TypeAssertionResult<T, Xor<Inv, ProperExtend<T, U>>>\n}\n"]}
|
package/esm/main/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { ExpectType } from './expect.js';
|
|
7
|
-
export type { ExpectType } from './expect.js';
|
|
6
|
+
import type { ExpectType } from './expect/index.js';
|
|
7
|
+
export type { ExpectType } from './expect/index.js';
|
|
8
8
|
export { NOOP } from './noop.js';
|
|
9
9
|
/**
|
|
10
10
|
* Creates an instance of ExpectType to perform type-level assertions on the given type.
|
|
@@ -18,13 +18,15 @@ export { NOOP } from './noop.js';
|
|
|
18
18
|
* @example
|
|
19
19
|
* ```ts
|
|
20
20
|
* // Test exact type equality
|
|
21
|
-
* expect<number>().
|
|
22
|
-
* expect<number>().
|
|
21
|
+
* expect<number>().to.be<number>().pass
|
|
22
|
+
* expect<number>().to.be<string>().fail
|
|
23
23
|
* // Test if one type extends another
|
|
24
|
-
* expect<3.14>().
|
|
25
|
-
* expect<2>().
|
|
24
|
+
* expect<3.14>().to.extend<number>().pass
|
|
25
|
+
* expect<2>().to.extend<string>().fail
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export declare
|
|
29
|
-
|
|
28
|
+
export declare const expect: {
|
|
29
|
+
<T>(): ExpectType<T>;
|
|
30
|
+
<T>(_: T): ExpectType<T>;
|
|
31
|
+
};
|
|
30
32
|
//# 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;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAGnD,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,MAAM,EAAE;IACnB,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAA;IACpB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;CAClB,CAAA"}
|
package/esm/main/index.js
CHANGED
|
@@ -5,7 +5,24 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { NOOP } from './noop.js';
|
|
7
7
|
export { NOOP } from './noop.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of ExpectType to perform type-level assertions on the given type.
|
|
10
|
+
* This function enables testing various type relationships at compile time.
|
|
11
|
+
* NOTE: This function does nothing at runtime and is purely for type-level testing.
|
|
12
|
+
*
|
|
13
|
+
* @template T The type to be tested
|
|
14
|
+
*
|
|
15
|
+
* @returns An ExpectType instance with methods to test type relationships
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // Test exact type equality
|
|
20
|
+
* expect<number>().to.be<number>().pass
|
|
21
|
+
* expect<number>().to.be<string>().fail
|
|
22
|
+
* // Test if one type extends another
|
|
23
|
+
* expect<3.14>().to.extend<number>().pass
|
|
24
|
+
* expect<2>().to.extend<string>().fail
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const expect = NOOP;
|
|
11
28
|
//# 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;;;;GAIG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,MAAM,GAGf,IAAI,CAAA","sourcesContent":["/**\n * [Full API documentation is available on JSR](https://jsr.io/@leawind/lay-sing/doc)\n *\n * @module\n */\n\nimport type { ExpectType } from './expect/index.js'\nimport { NOOP } from './noop.js'\n\nexport type { ExpectType } from './expect/index.js'\nexport { NOOP } from './noop.js'\n\n/**\n * Creates an instance of ExpectType to perform type-level assertions on the given type.\n * This function enables testing various type relationships at compile time.\n * NOTE: This function does nothing at runtime and is purely for type-level testing.\n *\n * @template T The type to be tested\n *\n * @returns An ExpectType instance with methods to test type relationships\n *\n * @example\n * ```ts\n * // Test exact type equality\n * expect<number>().to.be<number>().pass\n * expect<number>().to.be<string>().fail\n * // Test if one type extends another\n * expect<3.14>().to.extend<number>().pass\n * expect<2>().to.extend<string>().fail\n * ```\n */\nexport const expect: {\n <T>(): ExpectType<T>\n <T>(_: T): ExpectType<T>\n} = NOOP\n"]}
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
* ```ts
|
|
18
18
|
* import { expect } from '@leawind/lay-sing'
|
|
19
19
|
*
|
|
20
|
-
* expect<Exact<string, string>>().
|
|
21
|
-
* expect<Exact<never, never>>().
|
|
22
|
-
* expect<Exact<any, any>>().
|
|
23
|
-
*
|
|
24
|
-
* expect<Exact<{ a: 3 }, { a?: 3 }>>().
|
|
25
|
-
* expect<Exact<1 | 2, 1>>().
|
|
26
|
-
* expect<Exact<1, number>>().
|
|
27
|
-
* expect<Exact<() => void, () => undefined>>().
|
|
20
|
+
* expect<Exact<string, string>>().to.be.true
|
|
21
|
+
* expect<Exact<never, never>>().to.be.true
|
|
22
|
+
* expect<Exact<any, any>>().to.be.true
|
|
23
|
+
*
|
|
24
|
+
* expect<Exact<{ a: 3 }, { a?: 3 }>>().to.be.false
|
|
25
|
+
* expect<Exact<1 | 2, 1>>().to.be.false
|
|
26
|
+
* expect<Exact<1, number>>().to.be.false
|
|
27
|
+
* expect<Exact<() => void, () => undefined>>().to.be.false
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
export type Exact<A, B, Yes = true, No = false> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? Yes : No;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exact.js","sourceRoot":"","sources":["../../../src/utils/compare/exact.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Checks whether two types are exactly the same.\n *\n * **⚠️Important:** parameter `A` and `B` are not distributive. When they are union type, it does not check each member separately.\n *\n * @template A - The first type to compare\n * @template B - The second type to compare\n * @template Yes - The result if types are exactly the same (defaults to `true`)\n * @template No - The result if types are not exactly the same (defaults to `false`)\n *\n * ### Result\n *\n * - `Yes`: `A` and `B` are exactly the same\n * - `No`: Otherwise\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<Exact<string, string>>().
|
|
1
|
+
{"version":3,"file":"exact.js","sourceRoot":"","sources":["../../../src/utils/compare/exact.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Checks whether two types are exactly the same.\n *\n * **⚠️Important:** parameter `A` and `B` are not distributive. When they are union type, it does not check each member separately.\n *\n * @template A - The first type to compare\n * @template B - The second type to compare\n * @template Yes - The result if types are exactly the same (defaults to `true`)\n * @template No - The result if types are not exactly the same (defaults to `false`)\n *\n * ### Result\n *\n * - `Yes`: `A` and `B` are exactly the same\n * - `No`: Otherwise\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<Exact<string, string>>().to.be.true\n * expect<Exact<never, never>>().to.be.true\n * expect<Exact<any, any>>().to.be.true\n *\n * expect<Exact<{ a: 3 }, { a?: 3 }>>().to.be.false\n * expect<Exact<1 | 2, 1>>().to.be.false\n * expect<Exact<1, number>>().to.be.false\n * expect<Exact<() => void, () => undefined>>().to.be.false\n * ```\n */\nexport type Exact<\n A,\n B,\n Yes = true,\n No = false,\n> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? Yes : No\n\n/**\n * Checks whether two types are not exactly the same.\n *\n * This is the logical negation of `Exact<A, B>`.\n *\n * @template A - The first type to compare\n * @template B - The second type to compare\n * @template Yes - The result if types are not exactly the same (defaults to `true`)\n * @template No - The result if types are exactly the same (defaults to `false`)\n *\n * @example\n * ```ts\n * type T1 = NotExact<number, string> // true\n * type T2 = NotExact<1, number> // true\n * type F1 = NotExact<number, number> // false\n * type F2 = NotExact<1, 1> // false\n * ```\n */\nexport type NotExact<\n A,\n B,\n Yes = true,\n No = false,\n> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? No : Yes\n"]}
|
package/esm/utils/index.d.ts
CHANGED
package/esm/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA"}
|
package/esm/utils/index.js
CHANGED
package/esm/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+BAA+B;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,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 './compare/index.js'\nexport * from './logic/index.js'\nexport * from './object/index.js'\nexport * from './tuple/index.js'\n// <<<<<<<<<<<<<<<< Index end\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+BAA+B;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,mBAAmB,CAAA;AACjC,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 './compare/index.js'\nexport * from './logic/index.js'\nexport * from './misc.js'\nexport * from './object/index.js'\nexport * from './tuple/index.js'\n// <<<<<<<<<<<<<<<< Index end\n"]}
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* ```ts
|
|
10
10
|
* import { expect } from '@leawind/lay-sing'
|
|
11
11
|
*
|
|
12
|
-
* expect<AssertExtends<string, number>>().
|
|
13
|
-
* expect<AssertExtends<1 | 2, 1>>().
|
|
14
|
-
* expect<AssertExtends<1, 1 | 2>>().
|
|
12
|
+
* expect<AssertExtends<string, number>>().to.be.never
|
|
13
|
+
* expect<AssertExtends<1 | 2, 1>>().to.be.never
|
|
14
|
+
* expect<AssertExtends<1, 1 | 2>>().to.be<1>().pass
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
export type AssertExtends<T, U> = [T] extends [U] ? T : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../../src/utils/logic/assert.ts"],"names":[],"mappings":"","sourcesContent":["/**\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'\n *\n * expect<AssertExtends<string, number>>().
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../../src/utils/logic/assert.ts"],"names":[],"mappings":"","sourcesContent":["/**\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'\n *\n * expect<AssertExtends<string, number>>().to.be.never\n * expect<AssertExtends<1 | 2, 1>>().to.be.never\n * expect<AssertExtends<1, 1 | 2>>().to.be<1>().pass\n * ```\n */\nexport type AssertExtends<T, U> = [T] extends [U] ? T : never\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Negates a boolean type
|
|
3
|
+
*
|
|
4
|
+
* @template T - The boolean type to negate
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { expect } from '@leawind/lay-sing'
|
|
9
|
+
*
|
|
10
|
+
* expect<Not<true>>().to.be.false
|
|
11
|
+
* expect<Not<false>>().to.be.true
|
|
12
|
+
* expect<Not<boolean>>().to.be<boolean>().pass
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type Not<T extends boolean> = T extends true ? false : T extends false ? true : boolean;
|
|
16
|
+
/**
|
|
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'
|
|
25
|
+
*
|
|
26
|
+
* expect<And<true, true>>().to.be.true
|
|
27
|
+
* expect<And<true, false>>().to.be.false
|
|
28
|
+
* expect<And<false, true>>().to.be.false
|
|
29
|
+
* expect<And<false, false>>().to.be.false
|
|
30
|
+
* expect<And<boolean, boolean>>().to.be<boolean>().pass
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
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);
|
|
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
|
+
*
|
|
40
|
+
* ### Result
|
|
41
|
+
*
|
|
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`
|
|
45
|
+
* - `true`: otherwise
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { expect } from '@leawind/lay-sing'
|
|
50
|
+
*
|
|
51
|
+
* expect<Or<true, true>>().to.be.true
|
|
52
|
+
* expect<Or<true, false>>().to.be.true
|
|
53
|
+
* expect<Or<false, true>>().to.be.true
|
|
54
|
+
* expect<Or<false, false>>().to.be.false
|
|
55
|
+
* expect<Or<boolean, false>>().to.be<boolean>().pass
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
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;
|
|
59
|
+
export type Xor<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 extends B ? false : true) : true extends B ? (true extends A ? false : true) : false;
|
|
60
|
+
//# sourceMappingURL=boolean.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../../src/utils/logic/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;AAET,MAAM,MAAM,GAAG,CACb,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,CAAC,IAAI,SAAS,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,GAChD,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,GAChD,KAAK,CAAA"}
|