lay-sing 0.2.0 → 0.3.0
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 +64 -29
- package/esm/{test-utils → main}/expect.d.ts +79 -9
- package/esm/main/expect.d.ts.map +1 -0
- package/esm/main/expect.js.map +1 -0
- package/esm/main/index.d.ts +29 -11
- package/esm/main/index.d.ts.map +1 -1
- package/esm/main/index.js +10 -13
- package/esm/main/index.js.map +1 -1
- package/esm/main/noop.d.ts +27 -0
- package/esm/main/noop.d.ts.map +1 -0
- package/esm/{test-utils/index.js → main/noop.js} +1 -8
- package/esm/main/noop.js.map +1 -0
- package/esm/utils/compare/assignable.d.ts +30 -0
- package/esm/utils/compare/assignable.d.ts.map +1 -0
- package/esm/utils/compare/assignable.js +2 -0
- package/esm/utils/compare/assignable.js.map +1 -0
- package/esm/utils/compare/exact.d.ts +50 -0
- package/esm/utils/compare/exact.d.ts.map +1 -0
- package/esm/utils/compare/exact.js +2 -0
- package/esm/utils/compare/exact.js.map +1 -0
- package/esm/utils/compare/extends.d.ts +46 -0
- package/esm/utils/compare/extends.d.ts.map +1 -0
- package/esm/utils/compare/extends.js +2 -0
- package/esm/utils/compare/extends.js.map +1 -0
- package/esm/utils/compare/index.d.ts +5 -0
- package/esm/utils/compare/index.d.ts.map +1 -0
- package/esm/utils/compare/index.js +7 -0
- package/esm/utils/compare/index.js.map +1 -0
- package/esm/utils/compare/overlap.d.ts +47 -0
- package/esm/utils/compare/overlap.d.ts.map +1 -0
- package/esm/utils/compare/overlap.js +2 -0
- package/esm/utils/compare/overlap.js.map +1 -0
- package/esm/utils/index.d.ts +10 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +12 -0
- package/esm/utils/index.js.map +1 -0
- package/esm/utils/logic/assert.d.ts +18 -0
- package/esm/utils/logic/assert.d.ts.map +1 -0
- package/esm/utils/logic/assert.js +2 -0
- package/esm/utils/logic/assert.js.map +1 -0
- package/esm/utils/logic/if.d.ts +37 -0
- package/esm/utils/logic/if.d.ts.map +1 -0
- package/esm/utils/logic/if.js +2 -0
- package/esm/utils/logic/if.js.map +1 -0
- package/esm/utils/logic/index.d.ts +4 -0
- package/esm/utils/logic/index.d.ts.map +1 -0
- package/esm/utils/logic/index.js +6 -0
- package/esm/utils/logic/index.js.map +1 -0
- package/esm/utils/logic/switch.d.ts +87 -0
- package/esm/utils/logic/switch.d.ts.map +1 -0
- package/esm/utils/logic/switch.js +2 -0
- package/esm/utils/logic/switch.js.map +1 -0
- package/esm/utils/object/index.d.ts +4 -0
- package/esm/utils/object/index.d.ts.map +1 -0
- package/esm/utils/object/index.js +6 -0
- package/esm/utils/object/index.js.map +1 -0
- package/{script/main/key.d.ts → esm/utils/object/keys.d.ts} +40 -38
- package/esm/utils/object/keys.d.ts.map +1 -0
- package/esm/utils/object/keys.js +2 -0
- package/esm/utils/object/keys.js.map +1 -0
- package/esm/utils/object/pick.d.ts +16 -0
- package/esm/utils/object/pick.d.ts.map +1 -0
- package/esm/utils/object/pick.js +2 -0
- package/esm/utils/object/pick.js.map +1 -0
- package/esm/utils/object/props.d.ts +17 -0
- package/esm/utils/object/props.d.ts.map +1 -0
- package/esm/utils/object/props.js +2 -0
- package/esm/utils/object/props.js.map +1 -0
- package/esm/utils/tuple/append.d.ts +17 -0
- package/esm/utils/tuple/append.d.ts.map +1 -0
- package/esm/utils/tuple/append.js +2 -0
- package/esm/utils/tuple/append.js.map +1 -0
- package/esm/utils/tuple/concat.d.ts +31 -0
- package/esm/utils/tuple/concat.d.ts.map +1 -0
- package/esm/utils/tuple/concat.js +2 -0
- package/esm/utils/tuple/concat.js.map +1 -0
- package/esm/utils/tuple/includes.d.ts +20 -0
- package/esm/utils/tuple/includes.d.ts.map +1 -0
- package/esm/utils/tuple/includes.js +2 -0
- package/esm/utils/tuple/includes.js.map +1 -0
- package/esm/utils/tuple/index.d.ts +4 -0
- package/esm/utils/tuple/index.d.ts.map +1 -0
- package/esm/utils/tuple/index.js +6 -0
- package/esm/utils/tuple/index.js.map +1 -0
- package/package.json +5 -5
- package/script/{test-utils → main}/expect.d.ts +79 -9
- package/script/main/expect.d.ts.map +1 -0
- package/script/main/expect.js.map +1 -0
- package/script/main/index.d.ts +29 -11
- package/script/main/index.d.ts.map +1 -1
- package/script/main/index.js +13 -27
- package/script/main/index.js.map +1 -1
- package/script/main/noop.d.ts +27 -0
- package/script/main/noop.d.ts.map +1 -0
- package/script/{test-utils/index.js → main/noop.js} +1 -10
- package/script/main/noop.js.map +1 -0
- package/script/utils/compare/assignable.d.ts +30 -0
- package/script/utils/compare/assignable.d.ts.map +1 -0
- package/script/utils/compare/assignable.js +3 -0
- package/script/utils/compare/assignable.js.map +1 -0
- package/script/utils/compare/exact.d.ts +50 -0
- package/script/utils/compare/exact.d.ts.map +1 -0
- package/script/{main/async.js → utils/compare/exact.js} +1 -1
- package/script/utils/compare/exact.js.map +1 -0
- package/script/utils/compare/extends.d.ts +46 -0
- package/script/utils/compare/extends.d.ts.map +1 -0
- package/script/{main/boolean.js → utils/compare/extends.js} +1 -1
- package/script/utils/compare/extends.js.map +1 -0
- package/script/utils/compare/index.d.ts +5 -0
- package/script/utils/compare/index.d.ts.map +1 -0
- package/script/utils/compare/index.js +23 -0
- package/script/utils/compare/index.js.map +1 -0
- package/script/utils/compare/overlap.d.ts +47 -0
- package/script/utils/compare/overlap.d.ts.map +1 -0
- package/script/{main/control.js → utils/compare/overlap.js} +1 -1
- package/script/utils/compare/overlap.js.map +1 -0
- package/script/utils/index.d.ts +10 -0
- package/script/utils/index.d.ts.map +1 -0
- package/script/utils/index.js +28 -0
- package/script/utils/index.js.map +1 -0
- package/script/utils/logic/assert.d.ts +18 -0
- package/script/utils/logic/assert.d.ts.map +1 -0
- package/script/utils/logic/assert.js +3 -0
- package/script/utils/logic/assert.js.map +1 -0
- package/script/utils/logic/if.d.ts +37 -0
- package/script/utils/logic/if.d.ts.map +1 -0
- package/script/{main/type/set.js → utils/logic/if.js} +1 -1
- package/script/utils/logic/if.js.map +1 -0
- package/script/utils/logic/index.d.ts +4 -0
- package/script/utils/logic/index.d.ts.map +1 -0
- package/script/utils/logic/index.js +22 -0
- package/script/utils/logic/index.js.map +1 -0
- package/script/utils/logic/switch.d.ts +87 -0
- package/script/utils/logic/switch.d.ts.map +1 -0
- package/script/utils/logic/switch.js +3 -0
- package/script/utils/logic/switch.js.map +1 -0
- package/script/utils/object/index.d.ts +4 -0
- package/script/utils/object/index.d.ts.map +1 -0
- package/script/{main/type → utils/object}/index.js +3 -2
- package/script/utils/object/index.js.map +1 -0
- package/{esm/main/key.d.ts → script/utils/object/keys.d.ts} +40 -38
- package/script/utils/object/keys.d.ts.map +1 -0
- package/script/{main/json.js → utils/object/keys.js} +1 -1
- package/script/utils/object/keys.js.map +1 -0
- package/script/utils/object/pick.d.ts +16 -0
- package/script/utils/object/pick.d.ts.map +1 -0
- package/script/{main/key.js → utils/object/pick.js} +1 -1
- package/script/utils/object/pick.js.map +1 -0
- package/script/utils/object/props.d.ts +17 -0
- package/script/utils/object/props.d.ts.map +1 -0
- package/script/{main/doc.js → utils/object/props.js} +1 -1
- package/script/utils/object/props.js.map +1 -0
- package/script/utils/tuple/append.d.ts +17 -0
- package/script/utils/tuple/append.d.ts.map +1 -0
- package/script/utils/tuple/append.js +3 -0
- package/script/utils/tuple/append.js.map +1 -0
- package/script/utils/tuple/concat.d.ts +31 -0
- package/script/utils/tuple/concat.d.ts.map +1 -0
- package/script/utils/tuple/concat.js +3 -0
- package/script/utils/tuple/concat.js.map +1 -0
- package/script/utils/tuple/includes.d.ts +20 -0
- package/script/utils/tuple/includes.d.ts.map +1 -0
- package/script/utils/tuple/includes.js +3 -0
- package/script/utils/tuple/includes.js.map +1 -0
- package/script/utils/tuple/index.d.ts +4 -0
- package/script/utils/tuple/index.d.ts.map +1 -0
- package/script/utils/tuple/index.js +22 -0
- package/script/utils/tuple/index.js.map +1 -0
- package/esm/main/async.d.ts +0 -5
- package/esm/main/async.d.ts.map +0 -1
- package/esm/main/async.js +0 -2
- package/esm/main/async.js.map +0 -1
- package/esm/main/boolean.d.ts +0 -35
- package/esm/main/boolean.d.ts.map +0 -1
- package/esm/main/boolean.js +0 -2
- package/esm/main/boolean.js.map +0 -1
- package/esm/main/control.d.ts +0 -83
- package/esm/main/control.d.ts.map +0 -1
- package/esm/main/control.js +0 -2
- package/esm/main/control.js.map +0 -1
- package/esm/main/doc.d.ts +0 -30
- package/esm/main/doc.d.ts.map +0 -1
- package/esm/main/doc.js +0 -2
- package/esm/main/doc.js.map +0 -1
- package/esm/main/function.d.ts +0 -19
- package/esm/main/function.d.ts.map +0 -1
- package/esm/main/function.js +0 -3
- package/esm/main/function.js.map +0 -1
- package/esm/main/json.d.ts +0 -44
- package/esm/main/json.d.ts.map +0 -1
- package/esm/main/json.js +0 -2
- package/esm/main/json.js.map +0 -1
- package/esm/main/key.d.ts.map +0 -1
- package/esm/main/key.js +0 -2
- package/esm/main/key.js.map +0 -1
- package/esm/main/object.d.ts +0 -95
- package/esm/main/object.d.ts.map +0 -1
- package/esm/main/object.js +0 -2
- package/esm/main/object.js.map +0 -1
- package/esm/main/tuple.d.ts +0 -40
- package/esm/main/tuple.d.ts.map +0 -1
- package/esm/main/tuple.js +0 -2
- package/esm/main/tuple.js.map +0 -1
- package/esm/main/type/compare.d.ts +0 -79
- package/esm/main/type/compare.d.ts.map +0 -1
- package/esm/main/type/compare.js +0 -2
- package/esm/main/type/compare.js.map +0 -1
- package/esm/main/type/index.d.ts +0 -3
- package/esm/main/type/index.d.ts.map +0 -1
- package/esm/main/type/index.js +0 -5
- package/esm/main/type/index.js.map +0 -1
- package/esm/main/type/set.d.ts +0 -27
- package/esm/main/type/set.d.ts.map +0 -1
- package/esm/main/type/set.js +0 -2
- package/esm/main/type/set.js.map +0 -1
- package/esm/main/typed-array.d.ts +0 -5
- package/esm/main/typed-array.d.ts.map +0 -1
- package/esm/main/typed-array.js +0 -2
- package/esm/main/typed-array.js.map +0 -1
- package/esm/test-utils/compare.d.ts +0 -69
- package/esm/test-utils/compare.d.ts.map +0 -1
- package/esm/test-utils/compare.js +0 -2
- package/esm/test-utils/compare.js.map +0 -1
- package/esm/test-utils/expect.d.ts.map +0 -1
- package/esm/test-utils/expect.js.map +0 -1
- package/esm/test-utils/index.d.ts +0 -72
- package/esm/test-utils/index.d.ts.map +0 -1
- package/esm/test-utils/index.js.map +0 -1
- package/script/main/async.d.ts +0 -5
- package/script/main/async.d.ts.map +0 -1
- package/script/main/async.js.map +0 -1
- package/script/main/boolean.d.ts +0 -35
- package/script/main/boolean.d.ts.map +0 -1
- package/script/main/boolean.js.map +0 -1
- package/script/main/control.d.ts +0 -83
- package/script/main/control.d.ts.map +0 -1
- package/script/main/control.js.map +0 -1
- package/script/main/doc.d.ts +0 -30
- package/script/main/doc.d.ts.map +0 -1
- package/script/main/doc.js.map +0 -1
- package/script/main/function.d.ts +0 -19
- package/script/main/function.d.ts.map +0 -1
- package/script/main/function.js +0 -4
- package/script/main/function.js.map +0 -1
- package/script/main/json.d.ts +0 -44
- package/script/main/json.d.ts.map +0 -1
- package/script/main/json.js.map +0 -1
- package/script/main/key.d.ts.map +0 -1
- package/script/main/key.js.map +0 -1
- package/script/main/object.d.ts +0 -95
- package/script/main/object.d.ts.map +0 -1
- package/script/main/object.js +0 -3
- package/script/main/object.js.map +0 -1
- package/script/main/tuple.d.ts +0 -40
- package/script/main/tuple.d.ts.map +0 -1
- package/script/main/tuple.js +0 -3
- package/script/main/tuple.js.map +0 -1
- package/script/main/type/compare.d.ts +0 -79
- package/script/main/type/compare.d.ts.map +0 -1
- package/script/main/type/compare.js +0 -3
- package/script/main/type/compare.js.map +0 -1
- package/script/main/type/index.d.ts +0 -3
- package/script/main/type/index.d.ts.map +0 -1
- package/script/main/type/index.js.map +0 -1
- package/script/main/type/set.d.ts +0 -27
- package/script/main/type/set.d.ts.map +0 -1
- package/script/main/type/set.js.map +0 -1
- package/script/main/typed-array.d.ts +0 -5
- package/script/main/typed-array.d.ts.map +0 -1
- package/script/main/typed-array.js +0 -3
- package/script/main/typed-array.js.map +0 -1
- package/script/test-utils/compare.d.ts +0 -69
- package/script/test-utils/compare.d.ts.map +0 -1
- package/script/test-utils/compare.js +0 -3
- package/script/test-utils/compare.js.map +0 -1
- package/script/test-utils/expect.d.ts.map +0 -1
- package/script/test-utils/expect.js.map +0 -1
- package/script/test-utils/index.d.ts +0 -72
- package/script/test-utils/index.d.ts.map +0 -1
- package/script/test-utils/index.js.map +0 -1
- /package/esm/{test-utils → main}/expect.js +0 -0
- /package/script/{test-utils → main}/expect.js +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely picks keys `Key` from type `Obj`, excluding non-existent keys
|
|
3
|
+
*
|
|
4
|
+
* @template Obj - The object type to pick keys from
|
|
5
|
+
* @template Key - The keys to pick from the object
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { expect } from '@leawind/lay-sing'
|
|
10
|
+
*
|
|
11
|
+
* type Result = SafePick<{ a: string; b: number }, 'a' | 'c'>
|
|
12
|
+
* expect<Result>().toBe<{ a: string }>().success
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type SafePick<Obj, Key> = Pick<Obj, Key & keyof Obj>;
|
|
16
|
+
//# sourceMappingURL=pick.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pick.d.ts","sourceRoot":"","sources":["../../../src/utils/object/pick.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pick.js","sourceRoot":"","sources":["../../../src/utils/object/pick.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Safely picks keys `Key` from type `Obj`, excluding non-existent keys\n *\n * @template Obj - The object type to pick keys from\n * @template Key - The keys to pick from the object\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * type Result = SafePick<{ a: string; b: number }, 'a' | 'c'>\n * expect<Result>().toBe<{ a: string }>().success\n * ```\n */\nexport type SafePick<Obj, Key> = Pick<Obj, Key & keyof Obj>\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { KeysOfBaseType } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Picks properties from `T` that have values of type `U`
|
|
4
|
+
*
|
|
5
|
+
* @template T - The object type to pick properties from
|
|
6
|
+
* @template U - The value type to match against
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { expect } from '@leawind/lay-sing'
|
|
11
|
+
* type A = { a: string; b: number; c: string }
|
|
12
|
+
* type Strings = PropsOfBaseType<A, string> // { a: string; c: string }
|
|
13
|
+
* expect<PropsOfBaseType<A, string>>().toBe<{ a: string; c: string }>()
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type PropsOfBaseType<T, U> = Pick<T, KeysOfBaseType<Required<T>, U>>;
|
|
17
|
+
//# sourceMappingURL=props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../../src/utils/object/props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../../src/utils/object/props.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeysOfBaseType } from '../index.js'\n\n/**\n * Picks properties from `T` that have values of type `U`\n *\n * @template T - The object type to pick properties from\n * @template U - The value type to match against\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n * type A = { a: string; b: number; c: string }\n * type Strings = PropsOfBaseType<A, string> // { a: string; c: string }\n * expect<PropsOfBaseType<A, string>>().toBe<{ a: string; c: string }>()\n * ```\n */\nexport type PropsOfBaseType<T, U> = Pick<T, KeysOfBaseType<Required<T>, U>>\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IfTupleIncludes } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Appends an element to a tuple only if it doesn't already exist in the tuple
|
|
4
|
+
*
|
|
5
|
+
* @template Tuple - The tuple type to append to
|
|
6
|
+
* @template Element - The element type to append
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { expect } from '@leawind/lay-sing'
|
|
11
|
+
*
|
|
12
|
+
* expect<AppendUnique<[1, 2, 3], 4>>().toBe<[1, 2, 3, 4]>().success
|
|
13
|
+
* expect<AppendUnique<[1, 2, 3], 2>>().toBe<[1, 2, 3]>().success
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type AppendUnique<Tuple extends readonly unknown[], Element> = IfTupleIncludes<Tuple, Element> extends true ? Tuple : [...Tuple, Element];
|
|
17
|
+
//# sourceMappingURL=append.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"append.d.ts","sourceRoot":"","sources":["../../../src/utils/tuple/append.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,YAAY,CACtB,KAAK,SAAS,SAAS,OAAO,EAAE,EAChC,OAAO,IACL,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"append.js","sourceRoot":"","sources":["../../../src/utils/tuple/append.ts"],"names":[],"mappings":"","sourcesContent":["import type { IfTupleIncludes } from '../index.js'\n\n/**\n * Appends an element to a tuple only if it doesn't already exist in the tuple\n *\n * @template Tuple - The tuple type to append to\n * @template Element - The element type to append\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<AppendUnique<[1, 2, 3], 4>>().toBe<[1, 2, 3, 4]>().success\n * expect<AppendUnique<[1, 2, 3], 2>>().toBe<[1, 2, 3]>().success\n * ```\n */\nexport type AppendUnique<\n Tuple extends readonly unknown[],\n Element,\n> = IfTupleIncludes<Tuple, Element> extends true ? Tuple : [...Tuple, Element]\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AppendUnique } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Concatenates two tuples into a single tuple type
|
|
4
|
+
*
|
|
5
|
+
* @template Left - The first tuple type to concatenate
|
|
6
|
+
* @template Right - The second tuple type to concatenate
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { expect } from '@leawind/lay-sing'
|
|
11
|
+
*
|
|
12
|
+
* expect<ConcatTuple<[1, 2], [3, 4]>>().toBe<[1, 2, 3, 4]>().success
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type ConcatTuple<Left extends readonly unknown[], Right extends readonly unknown[]> = Left extends readonly unknown[] ? (Right extends readonly unknown[] ? [...Left, ...Right] : never) : never;
|
|
16
|
+
/**
|
|
17
|
+
* Concatenates two tuples while ensuring uniqueness of elements
|
|
18
|
+
*
|
|
19
|
+
* @template Left - The first tuple type to concatenate
|
|
20
|
+
* @template Right - The second tuple type to concatenate
|
|
21
|
+
* @template R - The intermediate result tuple type (defaults to `Left`)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { expect } from '@leawind/lay-sing'
|
|
26
|
+
*
|
|
27
|
+
* expect<ConcatUniqueTuple<[1, 2, 3], [2, 3, 4]>>().toBe<[1, 2, 3, 4]>().success
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type ConcatUniqueTuple<Left extends readonly unknown[], Right extends readonly unknown[], R extends readonly unknown[] = Left> = Right extends readonly [infer First, ...infer Rest] ? ConcatUniqueTuple<Left, Rest, AppendUnique<R, First>> : R;
|
|
31
|
+
//# sourceMappingURL=concat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concat.d.ts","sourceRoot":"","sources":["../../../src/utils/tuple/concat.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,CACrB,IAAI,SAAS,SAAS,OAAO,EAAE,EAC/B,KAAK,SAAS,SAAS,OAAO,EAAE,IAC9B,IAAI,SAAS,SAAS,OAAO,EAAE,GAAG,CAAC,KAAK,SAAS,SAAS,OAAO,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAA;AAE9G;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,iBAAiB,CAC3B,IAAI,SAAS,SAAS,OAAO,EAAE,EAC/B,KAAK,SAAS,SAAS,OAAO,EAAE,EAChC,CAAC,SAAS,SAAS,OAAO,EAAE,GAAG,IAAI,IACjC,KAAK,SAAS,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concat.js","sourceRoot":"","sources":["../../../src/utils/tuple/concat.ts"],"names":[],"mappings":"","sourcesContent":["// Import needed for ConcatUniqueTuple\nimport type { AppendUnique } from '../index.js'\n\n/**\n * Concatenates two tuples into a single tuple type\n *\n * @template Left - The first tuple type to concatenate\n * @template Right - The second tuple type to concatenate\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<ConcatTuple<[1, 2], [3, 4]>>().toBe<[1, 2, 3, 4]>().success\n * ```\n */\nexport type ConcatTuple<\n Left extends readonly unknown[],\n Right extends readonly unknown[],\n> = Left extends readonly unknown[] ? (Right extends readonly unknown[] ? [...Left, ...Right] : never) : never\n\n/**\n * Concatenates two tuples while ensuring uniqueness of elements\n *\n * @template Left - The first tuple type to concatenate\n * @template Right - The second tuple type to concatenate\n * @template R - The intermediate result tuple type (defaults to `Left`)\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<ConcatUniqueTuple<[1, 2, 3], [2, 3, 4]>>().toBe<[1, 2, 3, 4]>().success\n * ```\n */\nexport type ConcatUniqueTuple<\n Left extends readonly unknown[],\n Right extends readonly unknown[],\n R extends readonly unknown[] = Left,\n> = Right extends readonly [infer First, ...infer Rest] ? ConcatUniqueTuple<Left, Rest, AppendUnique<R, First>> : R\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Exact } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether a tuple includes a specific element type
|
|
4
|
+
*
|
|
5
|
+
* @template Tuple - The tuple type to check
|
|
6
|
+
* @template Element - The element type to look for
|
|
7
|
+
* @template Yes - The result if the element is found (defaults to `true`)
|
|
8
|
+
* @template No - The result if the element is not found (defaults to `false`)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { expect } from '@leawind/lay-sing'
|
|
13
|
+
*
|
|
14
|
+
* expect<IfTupleIncludes<[1, 2, 3], 2>>().toBeTrue
|
|
15
|
+
* expect<IfTupleIncludes<[1, 2, 3], 4>>().toBeFalse
|
|
16
|
+
* expect<IfTupleIncludes<[1, 2, 1], 1>>().toBeTrue
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type IfTupleIncludes<Tuple extends readonly unknown[], Element, Yes = true, No = false> = Exact<Tuple, any> extends true ? never : Tuple extends readonly [infer First, ...infer Rest] ? (Exact<Element, First> extends true ? Yes : IfTupleIncludes<Rest, Element, Yes, No>) : No;
|
|
20
|
+
//# sourceMappingURL=includes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"includes.d.ts","sourceRoot":"","sources":["../../../src/utils/tuple/includes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,eAAe,CACzB,KAAK,SAAS,SAAS,OAAO,EAAE,EAChC,OAAO,EACP,GAAG,GAAG,IAAI,EACV,EAAE,GAAG,KAAK,IACR,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,SAAS,IAAI,GAAG,KAAK,GACtC,KAAK,SAAS,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GACjD,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,IAAI,GAAG,GAAG,GAAG,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,GACtF,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"includes.js","sourceRoot":"","sources":["../../../src/utils/tuple/includes.ts"],"names":[],"mappings":"","sourcesContent":["import type { Exact } from '../index.js'\n\n/**\n * Checks whether a tuple includes a specific element type\n *\n * @template Tuple - The tuple type to check\n * @template Element - The element type to look for\n * @template Yes - The result if the element is found (defaults to `true`)\n * @template No - The result if the element is not found (defaults to `false`)\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<IfTupleIncludes<[1, 2, 3], 2>>().toBeTrue\n * expect<IfTupleIncludes<[1, 2, 3], 4>>().toBeFalse\n * expect<IfTupleIncludes<[1, 2, 1], 1>>().toBeTrue\n * ```\n */\nexport type IfTupleIncludes<\n Tuple extends readonly unknown[],\n Element,\n Yes = true,\n No = false,\n> = Exact<Tuple, any> extends true ? never\n : Tuple extends readonly [infer First, ...infer Rest]\n ? (Exact<Element, First> extends true ? Yes : IfTupleIncludes<Rest, Element, Yes, No>)\n : No\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/tuple/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/tuple/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,+BAA+B","sourcesContent":["// Index start >>>>>>>>>>>>>>>>\nexport * from './append.js'\nexport * from './concat.js'\nexport * from './includes.js'\n// <<<<<<<<<<<<<<<< Index end\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lay-sing",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Utilities for compile-time type testing
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Utilities for compile-time type testing",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/Leawind/lay-sing.git"
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"main": "./esm/index.js",
|
|
11
11
|
"module": "./esm/index.js",
|
|
12
12
|
"exports": {
|
|
13
|
-
"./
|
|
14
|
-
"import": "./esm/
|
|
15
|
-
"require": "./script/
|
|
13
|
+
"./utils": {
|
|
14
|
+
"import": "./esm/utils/index.js",
|
|
15
|
+
"require": "./script/utils/index.js"
|
|
16
16
|
},
|
|
17
17
|
".": {
|
|
18
18
|
"import": "./esm/main/index.js",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Exact, Extends, If, IfTupleIncludes, ProperExtend, SafePick } from '../
|
|
1
|
+
import type { Exact, Extends, If, IfTupleIncludes, MutuallyAssignable, ProperExtend, SafePick } from '../utils/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Represents the result of a type assertion based on a boolean condition.
|
|
4
4
|
*
|
|
@@ -32,12 +32,36 @@ type ExpectTypeMethods<T, H extends PropertyKey = never> = {
|
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
34
|
* ```ts
|
|
35
|
+
* import { expect } from '@leawind/lay-sing'
|
|
36
|
+
*
|
|
35
37
|
* expect<any>().toBe<any>().success
|
|
36
38
|
* expect<never>().toBe<never>().success
|
|
37
39
|
* expect<false>().toBe<true>().fail
|
|
38
40
|
* ```
|
|
39
41
|
*/
|
|
40
|
-
toBe<U>(): TypeAssertionResult<Exact<T, U>>;
|
|
42
|
+
toBe<U>(): TypeAssertionResult<Exact<T, U>, ExpectType<T, H>>;
|
|
43
|
+
toBe<U>(_: U): TypeAssertionResult<Exact<T, U>, ExpectType<T, H>>;
|
|
44
|
+
/**
|
|
45
|
+
* Tests if the current type is mutually assignable with the provided type U.
|
|
46
|
+
*
|
|
47
|
+
* It's like:
|
|
48
|
+
*
|
|
49
|
+
* ```ts ignore
|
|
50
|
+
* [T] extends [U] ? [U] extends [T] ? Yes : No : No
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @template U The type to compare with
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { expect } from '@leawind/lay-sing'
|
|
58
|
+
*
|
|
59
|
+
* expect<{ a: 1; b: 2 }>().toEqual<{ a: 1 } & { b: 2 }>().success
|
|
60
|
+
* expect<1>().toEqual<1 | 2>().fail
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
toEqual<U>(): TypeAssertionResult<MutuallyAssignable<T, U>, ExpectType<T, H>>;
|
|
64
|
+
toEqual<U>(_: U): TypeAssertionResult<MutuallyAssignable<T, U>, ExpectType<T, H>>;
|
|
41
65
|
/**
|
|
42
66
|
* Tests if the current type T extends the provided type U.
|
|
43
67
|
*
|
|
@@ -45,12 +69,15 @@ type ExpectTypeMethods<T, H extends PropertyKey = never> = {
|
|
|
45
69
|
*
|
|
46
70
|
* @example
|
|
47
71
|
* ```ts
|
|
72
|
+
* import { expect } from '@leawind/lay-sing'
|
|
73
|
+
*
|
|
48
74
|
* expect<3.14>().toExtend<number>().success
|
|
49
75
|
* expect<2>().toExtend<string>().fail
|
|
50
76
|
* expect<'hello'>().toExtend<string>().success
|
|
51
77
|
* ```
|
|
52
78
|
*/
|
|
53
|
-
toExtend<U>(): TypeAssertionResult<Extends<T, U>>;
|
|
79
|
+
toExtend<U>(): TypeAssertionResult<Extends<T, U>, ExpectType<T, H>>;
|
|
80
|
+
toExtend<U>(_: U): TypeAssertionResult<Extends<T, U>, ExpectType<T, H>>;
|
|
54
81
|
/**
|
|
55
82
|
* Tests if the current type T properly extends the provided type U (extends but is not the same).
|
|
56
83
|
*
|
|
@@ -58,12 +85,15 @@ type ExpectTypeMethods<T, H extends PropertyKey = never> = {
|
|
|
58
85
|
*
|
|
59
86
|
* @example
|
|
60
87
|
* ```ts
|
|
88
|
+
* import { expect } from '@leawind/lay-sing'
|
|
89
|
+
*
|
|
61
90
|
* expect<2>().toProperExtend<number>().success
|
|
62
91
|
* expect<'a' | 'b'>().toProperExtend<string>().success
|
|
63
92
|
* expect<number>().toProperExtend<number>().fail
|
|
64
93
|
* ```
|
|
65
94
|
*/
|
|
66
|
-
toProperExtend<U>(): TypeAssertionResult<ProperExtend<T, U>>;
|
|
95
|
+
toProperExtend<U>(): TypeAssertionResult<ProperExtend<T, U>, ExpectType<T, H>>;
|
|
96
|
+
toProperExtend<U>(_: U): TypeAssertionResult<ProperExtend<T, U>, ExpectType<T, H>>;
|
|
67
97
|
/**
|
|
68
98
|
* Tests if the current type `T` has a property with key `K`.
|
|
69
99
|
*
|
|
@@ -77,6 +107,8 @@ type ExpectTypeMethods<T, H extends PropertyKey = never> = {
|
|
|
77
107
|
* ### Examples
|
|
78
108
|
*
|
|
79
109
|
* ```ts
|
|
110
|
+
* import { expect } from '@leawind/lay-sing'
|
|
111
|
+
*
|
|
80
112
|
* type WithProp = { prop: string; another: number; may?: 5 }
|
|
81
113
|
*
|
|
82
114
|
* // Single key checks
|
|
@@ -88,8 +120,22 @@ type ExpectTypeMethods<T, H extends PropertyKey = never> = {
|
|
|
88
120
|
* expect<WithProp>().toHaveKey<'may' | 'unexist'>().fail
|
|
89
121
|
* ```
|
|
90
122
|
*/
|
|
91
|
-
toHaveKey<K extends PropertyKey>(): IfTupleIncludes<[
|
|
123
|
+
toHaveKey<K extends PropertyKey>(): IfTupleIncludes<[
|
|
124
|
+
never,
|
|
125
|
+
any
|
|
126
|
+
], K, never, TypeAssertionResult<Extends<K, keyof T>, ExpectType<T, H>>>;
|
|
127
|
+
toHaveKey<K extends PropertyKey>(_: K): IfTupleIncludes<[
|
|
128
|
+
never,
|
|
129
|
+
any
|
|
130
|
+
], K, never, TypeAssertionResult<Extends<K, keyof T>, ExpectType<T, H>>>;
|
|
92
131
|
};
|
|
132
|
+
type ExpectFunction<T, H extends PropertyKey = never> = Exact<T, any> extends true ? unknown : Exact<T, never> extends true ? unknown : [T] extends [(...args: infer Args) => infer R] ? {
|
|
133
|
+
argsType(): ExpectType<Args, H>;
|
|
134
|
+
returnType(): ExpectType<R, H>;
|
|
135
|
+
} : [T] extends [new (...args: infer Args) => infer R] ? {
|
|
136
|
+
argsType(): ExpectType<Args, H>;
|
|
137
|
+
returnType(): ExpectType<R, H>;
|
|
138
|
+
} : unknown;
|
|
93
139
|
/**
|
|
94
140
|
* Type-level testing utility that allows checking various relationships between types.
|
|
95
141
|
* Provides methods to test type equality, extension, properties, and more.
|
|
@@ -99,6 +145,8 @@ type ExpectTypeMethods<T, H extends PropertyKey = never> = {
|
|
|
99
145
|
*
|
|
100
146
|
* @example
|
|
101
147
|
* ```ts
|
|
148
|
+
* import { expect } from '@leawind/lay-sing'
|
|
149
|
+
*
|
|
102
150
|
* // Test if two types are identical
|
|
103
151
|
* expect<number>().toBe<number>().success
|
|
104
152
|
* expect<number>().toBe<string>().fail
|
|
@@ -109,7 +157,7 @@ type ExpectTypeMethods<T, H extends PropertyKey = never> = {
|
|
|
109
157
|
* expect<{name: string}>().toHaveKey<'name'>().success
|
|
110
158
|
* ```
|
|
111
159
|
*/
|
|
112
|
-
export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMethods<T, H> & {
|
|
160
|
+
export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMethods<T, H> & ExpectFunction<T, H> & {
|
|
113
161
|
T: T;
|
|
114
162
|
inspect: {
|
|
115
163
|
[K in keyof T]: T[K];
|
|
@@ -121,7 +169,9 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
121
169
|
*
|
|
122
170
|
* @example
|
|
123
171
|
* ```ts
|
|
124
|
-
*
|
|
172
|
+
* import { expect } from '@leawind/lay-sing'
|
|
173
|
+
*
|
|
174
|
+
* expect<3.14>().toExtendNumber
|
|
125
175
|
* ```
|
|
126
176
|
*/
|
|
127
177
|
toExtendNumber: ExpectType<T, H | 'toExtendNumber' | 'toExtend'>;
|
|
@@ -131,7 +181,9 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
131
181
|
*
|
|
132
182
|
* @example
|
|
133
183
|
* ```ts
|
|
134
|
-
*
|
|
184
|
+
* import { expect } from '@leawind/lay-sing'
|
|
185
|
+
*
|
|
186
|
+
* expect<'hello'>().toExtendString
|
|
135
187
|
* ```
|
|
136
188
|
*/
|
|
137
189
|
toExtendString: ExpectType<T, H | 'toExtendString' | 'toExtend'>;
|
|
@@ -141,7 +193,9 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
141
193
|
*
|
|
142
194
|
* @example
|
|
143
195
|
* ```ts
|
|
144
|
-
*
|
|
196
|
+
* import { expect } from '@leawind/lay-sing'
|
|
197
|
+
*
|
|
198
|
+
* expect<true>().toExtendBoolean
|
|
145
199
|
* ```
|
|
146
200
|
*/
|
|
147
201
|
toExtendBoolean: ExpectType<T, H | 'toExtendBoolean' | 'toExtend'>;
|
|
@@ -150,6 +204,8 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
150
204
|
* Alias for {@link ExpectTypeMethods.toBe} where `U = any`
|
|
151
205
|
*
|
|
152
206
|
* ```ts
|
|
207
|
+
* import { expect } from '@leawind/lay-sing'
|
|
208
|
+
*
|
|
153
209
|
* expect<any>().toBeAny
|
|
154
210
|
* expect<any>().toBe<any>().success
|
|
155
211
|
* ```
|
|
@@ -159,6 +215,8 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
159
215
|
* Alias for {@link ExpectTypeMethods.toBe} where `U = never`
|
|
160
216
|
*
|
|
161
217
|
* ```ts
|
|
218
|
+
* import { expect } from '@leawind/lay-sing'
|
|
219
|
+
*
|
|
162
220
|
* expect<never>().toBeNever
|
|
163
221
|
* expect<never>().toBe<never>().success
|
|
164
222
|
* ```
|
|
@@ -168,6 +226,8 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
168
226
|
* Alias for {@link ExpectTypeMethods.toBe} where `U = unknown`
|
|
169
227
|
*
|
|
170
228
|
* ```ts
|
|
229
|
+
* import { expect } from '@leawind/lay-sing'
|
|
230
|
+
*
|
|
171
231
|
* expect<unknown>().toBeUnknown
|
|
172
232
|
* expect<unknown>().toBe<unknown>().success
|
|
173
233
|
* ```
|
|
@@ -177,6 +237,8 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
177
237
|
* Alias for {@link ExpectTypeMethods.toBe} where `U = void`
|
|
178
238
|
*
|
|
179
239
|
* ```ts
|
|
240
|
+
* import { expect } from '@leawind/lay-sing'
|
|
241
|
+
*
|
|
180
242
|
* expect<void>().toBeVoid
|
|
181
243
|
* expect<void>().toBe<void>().success
|
|
182
244
|
* ```
|
|
@@ -186,6 +248,8 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
186
248
|
* Alias for {@link ExpectTypeMethods.toBe} where `U = null`
|
|
187
249
|
*
|
|
188
250
|
* ```ts
|
|
251
|
+
* import { expect } from '@leawind/lay-sing'
|
|
252
|
+
*
|
|
189
253
|
* expect<null>().toBeNull
|
|
190
254
|
* expect<null>().toBe<null>().success
|
|
191
255
|
* ```
|
|
@@ -195,6 +259,8 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
195
259
|
* Alias for {@link ExpectTypeMethods.toBe} where `U = undefined`
|
|
196
260
|
*
|
|
197
261
|
* ```ts
|
|
262
|
+
* import { expect } from '@leawind/lay-sing'
|
|
263
|
+
*
|
|
198
264
|
* expect<undefined>().toBeUndefined
|
|
199
265
|
* expect<undefined>().toBe<undefined>().success
|
|
200
266
|
* ```
|
|
@@ -204,6 +270,8 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
204
270
|
* Alias for {@link ExpectTypeMethods.toBe} where `U = true`
|
|
205
271
|
*
|
|
206
272
|
* ```ts
|
|
273
|
+
* import { expect } from '@leawind/lay-sing'
|
|
274
|
+
*
|
|
207
275
|
* expect<true>().toBeTrue
|
|
208
276
|
* expect<true>().toBe<true>().success
|
|
209
277
|
* ```
|
|
@@ -213,6 +281,8 @@ export type ExpectType<T, H extends PropertyKey = never> = Omit<(ExpectTypeMetho
|
|
|
213
281
|
* Alias for {@link ExpectTypeMethods.toBe} where `U = false`
|
|
214
282
|
*
|
|
215
283
|
* ```ts
|
|
284
|
+
* import { expect } from '@leawind/lay-sing'
|
|
285
|
+
*
|
|
216
286
|
* expect<false>().toBeFalse
|
|
217
287
|
* expect<false>().toBe<false>().success
|
|
218
288
|
* ```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/main/expect.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/main/expect.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Exact,\n Extends,\n If,\n IfTupleIncludes,\n MutuallyAssignable,\n ProperExtend,\n SafePick,\n} from '../utils/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 `success` 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<B extends boolean, R = void> = Exact<B, never> extends true ? never\n : [boolean] extends [B] ? never\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 success: 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 success, use `.success`\n */\n fail: R\n }\n : never\n\ntype ExpectTypeMethods<T, H extends PropertyKey = never> = {\n /**\n * Tests if the current type is exactly the same as the provided type U.\n *\n * @template U The type to compare with\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<any>().toBe<any>().success\n * expect<never>().toBe<never>().success\n * expect<false>().toBe<true>().fail\n * ```\n */\n toBe<U>(): TypeAssertionResult<Exact<T, U>, ExpectType<T, H>>\n toBe<U>(_: U): TypeAssertionResult<Exact<T, U>, ExpectType<T, H>>\n\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 }>().toEqual<{ a: 1 } & { b: 2 }>().success\n * expect<1>().toEqual<1 | 2>().fail\n * ```\n */\n toEqual<U>(): TypeAssertionResult<MutuallyAssignable<T, U>, ExpectType<T, H>>\n toEqual<U>(_: U): TypeAssertionResult<MutuallyAssignable<T, U>, ExpectType<T, H>>\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>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * expect<'hello'>().toExtend<string>().success\n * ```\n */\n toExtend<U>(): TypeAssertionResult<Extends<T, U>, ExpectType<T, H>>\n toExtend<U>(_: U): TypeAssertionResult<Extends<T, U>, ExpectType<T, H>>\n\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>().toProperExtend<number>().success\n * expect<'a' | 'b'>().toProperExtend<string>().success\n * expect<number>().toProperExtend<number>().fail\n * ```\n */\n toProperExtend<U>(): TypeAssertionResult<ProperExtend<T, U>, ExpectType<T, H>>\n toProperExtend<U>(_: U): TypeAssertionResult<ProperExtend<T, U>, ExpectType<T, H>>\n\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>().toHaveKey<'prop'>().success\n * expect<WithProp>().toHaveKey<'missing'>().fail\n *\n * // Union type checks\n * expect<WithProp>().toHaveKey<'prop' | 'another'>().success\n * expect<WithProp>().toHaveKey<'may' | 'unexist'>().fail\n * ```\n */\n toHaveKey<K extends PropertyKey>(): IfTupleIncludes<\n [never, any],\n K,\n never,\n TypeAssertionResult<Extends<K, keyof T>, ExpectType<T, H>>\n >\n toHaveKey<K extends PropertyKey>(_: K): IfTupleIncludes<\n [never, any],\n K,\n never,\n TypeAssertionResult<Extends<K, keyof T>, ExpectType<T, H>>\n >\n}\n\ntype ExpectFunction<T, H extends PropertyKey = never> = Exact<T, any> extends true ? unknown\n : Exact<T, never> extends true ? unknown\n : [T] extends [(...args: infer Args) => infer R] ? {\n argsType(): ExpectType<Args, H>\n returnType(): ExpectType<R, H>\n }\n : [T] extends [new (...args: infer Args) => infer R] ? {\n argsType(): ExpectType<Args, H>\n returnType(): ExpectType<R, H>\n }\n : unknown\n\n/**\n * Type-level testing utility that allows checking various relationships between types.\n * Provides methods to test type equality, extension, properties, and more.\n *\n * @template T The type being tested\n * @template H Hidden property keys that are already used (internal tracking)\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * // Test if two types are identical\n * expect<number>().toBe<number>().success\n * expect<number>().toBe<string>().fail\n * // Test if one type extends another\n * expect<2>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * // Test if type has a specific property\n * expect<{name: string}>().toHaveKey<'name'>().success\n * ```\n */\nexport type ExpectType<T, H extends PropertyKey = never> = Omit<\n (\n & ExpectTypeMethods<T, H>\n & ExpectFunction<T, H>\n & {\n T: T\n inspect: { [K in keyof T]: T[K] }\n }\n & SafePick<\n {\n /**\n * Tests if the current type extends the Number primitive type.\n * Available only if the current type extends number.\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<3.14>().toExtendNumber\n * ```\n */\n toExtendNumber: ExpectType<T, H | 'toExtendNumber' | 'toExtend'>\n\n /**\n * Tests if the current type extends the String primitive type.\n * Available only if the current type extends string.\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<'hello'>().toExtendString\n * ```\n */\n toExtendString: ExpectType<T, H | 'toExtendString' | 'toExtend'>\n\n /**\n * Tests if the current type extends the Boolean primitive type.\n * Available only if the current type extends boolean.\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<true>().toExtendBoolean\n * ```\n */\n toExtendBoolean: ExpectType<T, H | 'toExtendBoolean' | 'toExtend'>\n },\n | If<Extends<T, number>, 'toExtendNumber'>\n | If<Extends<T, string>, 'toExtendString'>\n | If<Extends<T, boolean>, 'toExtendBoolean'>\n >\n & SafePick<\n {\n /**\n * Alias for {@link ExpectTypeMethods.toBe} where `U = any`\n *\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<any>().toBeAny\n * expect<any>().toBe<any>().success\n * ```\n */\n toBeAny: ExpectType<T, H | 'toBeAny' | 'toBe'>\n\n /**\n * Alias for {@link ExpectTypeMethods.toBe} where `U = never`\n *\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<never>().toBeNever\n * expect<never>().toBe<never>().success\n * ```\n */\n toBeNever: ExpectType<T, H | 'toBeNever' | 'toBe'>\n\n /**\n * Alias for {@link ExpectTypeMethods.toBe} where `U = unknown`\n *\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<unknown>().toBeUnknown\n * expect<unknown>().toBe<unknown>().success\n * ```\n */\n toBeUnknown: ExpectType<T, H | 'toBeUnknown' | 'toBe'>\n\n /**\n * Alias for {@link ExpectTypeMethods.toBe} where `U = void`\n *\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<void>().toBeVoid\n * expect<void>().toBe<void>().success\n * ```\n */\n toBeVoid: ExpectType<T, H | 'toBeVoid' | 'toBe'>\n\n /**\n * Alias for {@link ExpectTypeMethods.toBe} where `U = null`\n *\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<null>().toBeNull\n * expect<null>().toBe<null>().success\n * ```\n */\n toBeNull: ExpectType<T, H | 'toBeNull' | 'toBe'>\n\n /**\n * Alias for {@link ExpectTypeMethods.toBe} where `U = undefined`\n *\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<undefined>().toBeUndefined\n * expect<undefined>().toBe<undefined>().success\n * ```\n */\n toBeUndefined: ExpectType<T, H | 'toBeUndefined' | 'toBe'>\n\n /**\n * Alias for {@link ExpectTypeMethods.toBe} where `U = true`\n *\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<true>().toBeTrue\n * expect<true>().toBe<true>().success\n * ```\n */\n toBeTrue: ExpectType<T, H | 'toBeTrue' | 'toBe' | 'toExtendBoolean'>\n\n /**\n * Alias for {@link ExpectTypeMethods.toBe} where `U = false`\n *\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * expect<false>().toBeFalse\n * expect<false>().toBe<false>().success\n * ```\n */\n toBeFalse: ExpectType<T, H | 'toBeFalse' | 'toBe' | 'toExtendBoolean'>\n },\n | If<Exact<T, any>, 'toBeAny'>\n | If<Exact<T, never>, 'toBeNever'>\n | If<Exact<T, unknown>, 'toBeUnknown'>\n | If<Exact<T, void>, 'toBeVoid'>\n | If<Exact<T, null>, 'toBeNull'>\n | If<Exact<T, undefined>, 'toBeUndefined'>\n | If<Exact<T, true>, 'toBeTrue'>\n | If<Exact<T, false>, 'toBeFalse'>\n >\n ),\n H\n>\n"]}
|
package/script/main/index.d.ts
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
/**
|
|
2
|
+
* [Full API documentation is available on JSR](https://jsr.io/@leawind/lay-sing/doc)
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { ExpectType } from './expect.js';
|
|
7
|
+
export type { ExpectType } from './expect.js';
|
|
8
|
+
export { NOOP } from './noop.js';
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of ExpectType to perform type-level assertions on the given type.
|
|
11
|
+
* This function enables testing various type relationships at compile time.
|
|
12
|
+
* NOTE: This function does nothing at runtime and is purely for type-level testing.
|
|
13
|
+
*
|
|
14
|
+
* @template T The type to be tested
|
|
15
|
+
*
|
|
16
|
+
* @returns An ExpectType instance with methods to test type relationships
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // Test exact type equality
|
|
21
|
+
* expect<number>().toBe<number>().success
|
|
22
|
+
* expect<number>().toBe<string>().fail
|
|
23
|
+
* // Test if one type extends another
|
|
24
|
+
* expect<3.14>().toExtend<number>().success
|
|
25
|
+
* expect<2>().toExtend<string>().fail
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function expect<T>(): ExpectType<T>;
|
|
29
|
+
export declare function expect<T>(_: T): ExpectType<T>;
|
|
12
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAA;AAC1C,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA"}
|
package/script/main/index.js
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
2
|
+
/**
|
|
3
|
+
* [Full API documentation is available on JSR](https://jsr.io/@leawind/lay-sing/doc)
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
16
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
__exportStar(require("./object.js"), exports);
|
|
26
|
-
__exportStar(require("./tuple.js"), exports);
|
|
27
|
-
__exportStar(require("./type/index.js"), exports);
|
|
28
|
-
__exportStar(require("./typed-array.js"), exports);
|
|
29
|
-
// <<<<<<<<<<<<<<<< Index end
|
|
8
|
+
exports.NOOP = void 0;
|
|
9
|
+
exports.expect = expect;
|
|
10
|
+
const noop_js_1 = require("./noop.js");
|
|
11
|
+
var noop_js_2 = require("./noop.js");
|
|
12
|
+
Object.defineProperty(exports, "NOOP", { enumerable: true, get: function () { return noop_js_2.NOOP; } });
|
|
13
|
+
function expect() {
|
|
14
|
+
return noop_js_1.NOOP;
|
|
15
|
+
}
|
|
30
16
|
//# sourceMappingURL=index.js.map
|
package/script/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA6BH,wBAEC;AA5BD,uCAAgC;AAGhC,qCAAgC;AAAvB,+FAAA,IAAI,OAAA;AAuBb,SAAgB,MAAM;IACpB,OAAO,cAAI,CAAA;AACb,CAAC","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.js'\nimport { NOOP } from './noop.js'\n\nexport type { ExpectType } from './expect.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>().toBe<number>().success\n * expect<number>().toBe<string>().fail\n * // Test if one type extends another\n * expect<3.14>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * ```\n */\nexport function expect<T>(): ExpectType<T>\nexport function expect<T>(_: T): ExpectType<T>\nexport function expect<T>(): ExpectType<T> {\n return NOOP\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A universal no-op placeholder implemented via `Proxy`.
|
|
3
|
+
*
|
|
4
|
+
* `NOOP` can be accessed, called, or chained indefinitely without throwing.
|
|
5
|
+
* Every operation returns itself, making it safe to use as a dummy fallback
|
|
6
|
+
* for APIs, optional hooks, or unimplemented interfaces.
|
|
7
|
+
*
|
|
8
|
+
* ### Special behaviors
|
|
9
|
+
*
|
|
10
|
+
* - Callable: invoking `NOOP()` returns `NOOP`
|
|
11
|
+
* - Property access: `NOOP.anything` returns `NOOP`
|
|
12
|
+
* - Promise-safe: `NOOP.then` is `undefined`, so it is not treated as a Promise
|
|
13
|
+
* - Primitive coercion (`toString`, `valueOf`, `Symbol.toPrimitive`) yields
|
|
14
|
+
* a stable string representation: `"[NOOP]"`
|
|
15
|
+
*
|
|
16
|
+
* This is useful in scenarios where a value is required syntactically but
|
|
17
|
+
* should perform no action and never fail at runtime.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* NOOP.foo.bar().baz.qux; // safe, returns NOOP
|
|
22
|
+
* String(NOOP); // "[NOOP]"
|
|
23
|
+
* await NOOP; // does not await (not thenable)
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const NOOP: any;
|
|
27
|
+
//# sourceMappingURL=noop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../src/main/noop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,IAAI,EAAE,GA0BlB,CAAA"}
|