lay-sing 0.3.0 → 0.4.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 +17 -17
- package/esm/main/expect/index.d.ts +31 -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 +13 -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/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 +31 -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 +13 -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/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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Creates an intersection of all types in the provided tuple\n *\n * ## `IntersectionOf<[A, B, ... T]>` = `A & B & ... & T`\n *\n * @template Types - A tuple of types to create an intersection from\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * type Result = IntersectionOf<[{ a: string }, { b: number }, { c: boolean }]>\n * expect<Result>().to.extend<{ a: string } & { b: number } & { c: boolean }>().pass\n * expect<Result>().to.extend<{ a: string; b: number; c: boolean }>().pass\n * ```\n */\nexport type IntersectionOf<Types extends readonly unknown[]> = Types extends [infer First, ...infer Rest]\n ? First & IntersectionOf<Rest>\n : unknown\n\n/**\n * Creates a union of all types in the provided tuple\n *\n * ## `UnionOf<[A, B, ... T]>` = `A | B | ... | T`\n *\n * @template Types - A tuple of types to create a union from\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * type Result = UnionOf<[string, number, boolean]>\n * expect<Result>().to.be<string | number | boolean>().pass\n * ```\n */\nexport type UnionOf<Types extends readonly unknown[]> = Types extends [infer First, ...infer Rest]\n ? First | UnionOf<Rest>\n : never\n"]}
|
|
@@ -14,17 +14,17 @@ import type { Exact } from '../index.js';
|
|
|
14
14
|
*
|
|
15
15
|
* // Basic usage: match exact type (non-optional property)
|
|
16
16
|
* type A = { a: 1; b: 2; c: 1 };
|
|
17
|
-
* expect<KeysOfExactType<A, 1>>().
|
|
17
|
+
* expect<KeysOfExactType<A, 1>>().to.be<'a' | 'c'>().pass
|
|
18
18
|
*
|
|
19
19
|
* // Key difference: optional property matching (requires undefined in `ValueType`)
|
|
20
20
|
* type B = { a?: string };
|
|
21
|
-
* expect<KeysOfExactType<B, string | undefined>>().
|
|
22
|
-
* expect<KeysOfExactType<B, string>>().
|
|
21
|
+
* expect<KeysOfExactType<B, string | undefined>>().to.be<'a'>().pass // matches complete type
|
|
22
|
+
* expect<KeysOfExactType<B, string>>().to.be<never>().pass // does not match complete type
|
|
23
23
|
*
|
|
24
24
|
* type C = { a: never; b: any; c: unknown };
|
|
25
|
-
* expect<KeysOfExactType<C, never>>().
|
|
26
|
-
* expect<KeysOfExactType<C, any>>().
|
|
27
|
-
* expect<KeysOfExactType<C, unknown>>().
|
|
25
|
+
* expect<KeysOfExactType<C, never>>().to.be<'a'>().pass
|
|
26
|
+
* expect<KeysOfExactType<C, any>>().to.be<'b'>().pass
|
|
27
|
+
* expect<KeysOfExactType<C, unknown>>().to.be<'c'>().pass
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
export type KeysOfExactType<Obj, ValueType> = Exclude<{
|
|
@@ -45,17 +45,17 @@ export type KeysOfExactType<Obj, ValueType> = Exclude<{
|
|
|
45
45
|
*
|
|
46
46
|
* // Basic usage: match base type (non-optional property)
|
|
47
47
|
* type A = { a: 1; b: 2; c: 1 };
|
|
48
|
-
* expect<KeysOfBaseType<A, 1>>().
|
|
48
|
+
* expect<KeysOfBaseType<A, 1>>().to.be<'a' | 'c'>().pass
|
|
49
49
|
*
|
|
50
50
|
* // Key difference: optional property matching (ignores undefined)
|
|
51
51
|
* type B = { a?: string; b: string };
|
|
52
|
-
* expect<KeysOfBaseType<B, string>>().
|
|
53
|
-
* expect<KeysOfBaseType<B, string | undefined>>().
|
|
52
|
+
* expect<KeysOfBaseType<B, string>>().to.be<'a' | 'b'>().pass // matches base type of both
|
|
53
|
+
* expect<KeysOfBaseType<B, string | undefined>>().to.be<never>().pass // base type does not include undefined
|
|
54
54
|
*
|
|
55
55
|
* type C = { a: never; b: any; c: unknown };
|
|
56
|
-
* expect<KeysOfBaseType<C, never>>().
|
|
57
|
-
* expect<KeysOfBaseType<C, any>>().
|
|
58
|
-
* expect<KeysOfBaseType<C, unknown>>().
|
|
56
|
+
* expect<KeysOfBaseType<C, never>>().to.be<'a'>().pass
|
|
57
|
+
* expect<KeysOfBaseType<C, any>>().to.be<'b'>().pass
|
|
58
|
+
* expect<KeysOfBaseType<C, unknown>>().to.be<'c'>().pass
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
61
|
export type KeysOfBaseType<Obj, ValueType> = Exclude<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../src/utils/object/keys.ts"],"names":[],"mappings":"","sourcesContent":["import type { Exact } from '../index.js'\n\n/**\n * Extracts the keys of an object whose **complete value type** exactly matches the specified `ValueType` (including undefined for optional properties).\n *\n * This utility strictly matches the full type of each property (including `undefined` added by optional modifiers `?`).\n * For optional properties (e.g., `a?: string`), the type is treated as `string | undefined` – to match, `ValueType` must include `undefined`.\n *\n * @template Obj - The target object type to extract keys from.\n * @template ValueType - The exact type to match against property values (including undefined for optional properties).\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * // Basic usage: match exact type (non-optional property)\n * type A = { a: 1; b: 2; c: 1 };\n * expect<KeysOfExactType<A, 1>>().
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../src/utils/object/keys.ts"],"names":[],"mappings":"","sourcesContent":["import type { Exact } from '../index.js'\n\n/**\n * Extracts the keys of an object whose **complete value type** exactly matches the specified `ValueType` (including undefined for optional properties).\n *\n * This utility strictly matches the full type of each property (including `undefined` added by optional modifiers `?`).\n * For optional properties (e.g., `a?: string`), the type is treated as `string | undefined` – to match, `ValueType` must include `undefined`.\n *\n * @template Obj - The target object type to extract keys from.\n * @template ValueType - The exact type to match against property values (including undefined for optional properties).\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * // Basic usage: match exact type (non-optional property)\n * type A = { a: 1; b: 2; c: 1 };\n * expect<KeysOfExactType<A, 1>>().to.be<'a' | 'c'>().pass\n *\n * // Key difference: optional property matching (requires undefined in `ValueType`)\n * type B = { a?: string };\n * expect<KeysOfExactType<B, string | undefined>>().to.be<'a'>().pass // matches complete type\n * expect<KeysOfExactType<B, string>>().to.be<never>().pass // does not match complete type\n *\n * type C = { a: never; b: any; c: unknown };\n * expect<KeysOfExactType<C, never>>().to.be<'a'>().pass\n * expect<KeysOfExactType<C, any>>().to.be<'b'>().pass\n * expect<KeysOfExactType<C, unknown>>().to.be<'c'>().pass\n * ```\n */\nexport type KeysOfExactType<Obj, ValueType> = Exclude<\n { [K in keyof Obj]: Exact<Obj[K], ValueType> extends true ? K : never }[keyof Obj],\n undefined\n>\n\n/**\n * Extracts the keys of an object whose **base value type** matches the specified `ValueType` (ignoring undefined from optional properties).\n *\n * This utility matches the underlying/base type of each property (stripping `undefined` added by optional modifiers `?`).\n * For optional properties (e.g., `a?: string`), the type is treated as `string` – no need to include `undefined` in `ValueType` to match.\n *\n * @template Obj - The target object type to extract keys from.\n * @template ValueType - The base type to match against property values (ignoring undefined from optional properties).\n *\n * @example\n * ```ts\n * import { expect } from '@leawind/lay-sing'\n *\n * // Basic usage: match base type (non-optional property)\n * type A = { a: 1; b: 2; c: 1 };\n * expect<KeysOfBaseType<A, 1>>().to.be<'a' | 'c'>().pass\n *\n * // Key difference: optional property matching (ignores undefined)\n * type B = { a?: string; b: string };\n * expect<KeysOfBaseType<B, string>>().to.be<'a' | 'b'>().pass // matches base type of both\n * expect<KeysOfBaseType<B, string | undefined>>().to.be<never>().pass // base type does not include undefined\n *\n * type C = { a: never; b: any; c: unknown };\n * expect<KeysOfBaseType<C, never>>().to.be<'a'>().pass\n * expect<KeysOfBaseType<C, any>>().to.be<'b'>().pass\n * expect<KeysOfBaseType<C, unknown>>().to.be<'c'>().pass\n * ```\n */\nexport type KeysOfBaseType<Obj, ValueType> = Exclude<\n {\n [K in keyof Obj]: Exact<Required<Obj>[K], ValueType> extends true ? K : never\n }[keyof Obj],\n undefined\n>\n"]}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* import { expect } from '@leawind/lay-sing'
|
|
10
10
|
*
|
|
11
11
|
* type Result = SafePick<{ a: string; b: number }, 'a' | 'c'>
|
|
12
|
-
* expect<Result>().
|
|
12
|
+
* expect<Result>().to.be<{ a: string }>().pass
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export type SafePick<Obj, Key> = Pick<Obj, Key & keyof Obj>;
|
|
@@ -1 +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>().
|
|
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>().to.be<{ a: string }>().pass\n * ```\n */\nexport type SafePick<Obj, Key> = Pick<Obj, Key & keyof Obj>\n"]}
|
|
@@ -10,7 +10,7 @@ import type { KeysOfBaseType } from '../index.js';
|
|
|
10
10
|
* import { expect } from '@leawind/lay-sing'
|
|
11
11
|
* type A = { a: string; b: number; c: string }
|
|
12
12
|
* type Strings = PropsOfBaseType<A, string> // { a: string; c: string }
|
|
13
|
-
* expect<PropsOfBaseType<A, string>>().
|
|
13
|
+
* expect<PropsOfBaseType<A, string>>().to.be<{ a: string; c: string }>()
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export type PropsOfBaseType<T, U> = Pick<T, KeysOfBaseType<Required<T>, U>>;
|
|
@@ -1 +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>>().
|
|
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>>().to.be<{ a: string; c: string }>()\n * ```\n */\nexport type PropsOfBaseType<T, U> = Pick<T, KeysOfBaseType<Required<T>, U>>\n"]}
|
|
@@ -9,8 +9,8 @@ import type { IfTupleIncludes } from '../index.js';
|
|
|
9
9
|
* ```ts
|
|
10
10
|
* import { expect } from '@leawind/lay-sing'
|
|
11
11
|
*
|
|
12
|
-
* expect<AppendUnique<[1, 2, 3], 4>>().
|
|
13
|
-
* expect<AppendUnique<[1, 2, 3], 2>>().
|
|
12
|
+
* expect<AppendUnique<[1, 2, 3], 4>>().to.be<[1, 2, 3, 4]>().pass
|
|
13
|
+
* expect<AppendUnique<[1, 2, 3], 2>>().to.be<[1, 2, 3]>().pass
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export type AppendUnique<Tuple extends readonly unknown[], Element> = IfTupleIncludes<Tuple, Element> extends true ? Tuple : [...Tuple, Element];
|
|
@@ -1 +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>>().
|
|
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>>().to.be<[1, 2, 3, 4]>().pass\n * expect<AppendUnique<[1, 2, 3], 2>>().to.be<[1, 2, 3]>().pass\n * ```\n */\nexport type AppendUnique<\n Tuple extends readonly unknown[],\n Element,\n> = IfTupleIncludes<Tuple, Element> extends true ? Tuple : [...Tuple, Element]\n"]}
|
|
@@ -9,7 +9,7 @@ import type { AppendUnique } from '../index.js';
|
|
|
9
9
|
* ```ts
|
|
10
10
|
* import { expect } from '@leawind/lay-sing'
|
|
11
11
|
*
|
|
12
|
-
* expect<ConcatTuple<[1, 2], [3, 4]>>().
|
|
12
|
+
* expect<ConcatTuple<[1, 2], [3, 4]>>().to.be<[1, 2, 3, 4]>().pass
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export type ConcatTuple<Left extends readonly unknown[], Right extends readonly unknown[]> = Left extends readonly unknown[] ? (Right extends readonly unknown[] ? [...Left, ...Right] : never) : never;
|
|
@@ -24,7 +24,7 @@ export type ConcatTuple<Left extends readonly unknown[], Right extends readonly
|
|
|
24
24
|
* ```ts
|
|
25
25
|
* import { expect } from '@leawind/lay-sing'
|
|
26
26
|
*
|
|
27
|
-
* expect<ConcatUniqueTuple<[1, 2, 3], [2, 3, 4]>>().
|
|
27
|
+
* expect<ConcatUniqueTuple<[1, 2, 3], [2, 3, 4]>>().to.be<[1, 2, 3, 4]>().pass
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
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;
|
|
@@ -1 +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]>>().
|
|
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]>>().to.be<[1, 2, 3, 4]>().pass\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]>>().to.be<[1, 2, 3, 4]>().pass\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"]}
|
|
@@ -11,9 +11,9 @@ import type { Exact } from '../index.js';
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* import { expect } from '@leawind/lay-sing'
|
|
13
13
|
*
|
|
14
|
-
* expect<IfTupleIncludes<[1, 2, 3], 2>>().
|
|
15
|
-
* expect<IfTupleIncludes<[1, 2, 3], 4>>().
|
|
16
|
-
* expect<IfTupleIncludes<[1, 2, 1], 1>>().
|
|
14
|
+
* expect<IfTupleIncludes<[1, 2, 3], 2>>().to.be.true
|
|
15
|
+
* expect<IfTupleIncludes<[1, 2, 3], 4>>().to.be.false
|
|
16
|
+
* expect<IfTupleIncludes<[1, 2, 1], 1>>().to.be.true
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
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;
|
|
@@ -1 +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>>().
|
|
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>>().to.be.true\n * expect<IfTupleIncludes<[1, 2, 3], 4>>().to.be.false\n * expect<IfTupleIncludes<[1, 2, 1], 1>>().to.be.true\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"]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Exact } from '../../utils/index.js';
|
|
2
|
+
import type { To } from './to/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents the result of a type assertion based on a boolean condition.
|
|
5
|
+
*
|
|
6
|
+
* - If `true`, the result has a `pass` property;
|
|
7
|
+
* - If `false`, the result has a `fail` property;
|
|
8
|
+
* - Otherwise, the result is `never`
|
|
9
|
+
*
|
|
10
|
+
* @template B The boolean condition result (true or false)
|
|
11
|
+
* @template R The type of the result value (default is void)
|
|
12
|
+
*/
|
|
13
|
+
export type TypeAssertionResult<B extends boolean, R = void> = Exact<B, never> extends true ? never : [boolean] extends [B] ? never : [B] extends [true] ? {
|
|
14
|
+
/**
|
|
15
|
+
* This field exist only when this type assertion succeed
|
|
16
|
+
*
|
|
17
|
+
* If you expect this assertion to fail, use `.fail`
|
|
18
|
+
*/
|
|
19
|
+
pass: R;
|
|
20
|
+
} : [B] extends [false] ? {
|
|
21
|
+
/**
|
|
22
|
+
* This field exist only when this type assertion failed
|
|
23
|
+
*
|
|
24
|
+
* If you expect this assertion to pass, use `.pass`
|
|
25
|
+
*/
|
|
26
|
+
fail: R;
|
|
27
|
+
} : never;
|
|
28
|
+
export type ExpectType<T> = {
|
|
29
|
+
to: To<T>;
|
|
30
|
+
};
|
|
31
|
+
//# 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,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,eAAe,CAAA;AAEvC;;;;;;;;;GASG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,IAAI,GAAG,KAAK,GAC/F,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,GAC7B,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG;IACnB;;;;OAIG;IACH,IAAI,EAAE,CAAC,CAAA;CACR,GACD,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 { Exact } from '../../utils/index.js'\nimport 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<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 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 } from '../../../utils/index.js';
|
|
2
|
+
import type { TypeAssertionResult } from '../index.js';
|
|
3
|
+
export type Be<T> = {
|
|
4
|
+
<U>(): TypeAssertionResult<Exact<T, U>>;
|
|
5
|
+
<U>(_: U): TypeAssertionResult<Exact<T, U>>;
|
|
6
|
+
} & If<Exact<T, any>, {
|
|
7
|
+
any: void;
|
|
8
|
+
}, {}> & If<Exact<T, never>, {
|
|
9
|
+
never: void;
|
|
10
|
+
}, {}> & If<Exact<T, unknown>, {
|
|
11
|
+
unknown: void;
|
|
12
|
+
}, {}> & If<Exact<T, void>, {
|
|
13
|
+
void: void;
|
|
14
|
+
}, {}> & If<Exact<T, null>, {
|
|
15
|
+
null: void;
|
|
16
|
+
}, {}> & If<Exact<T, undefined>, {
|
|
17
|
+
undefined: void;
|
|
18
|
+
}, {}> & If<Exact<T, true>, {
|
|
19
|
+
true: void;
|
|
20
|
+
}, {}> & If<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,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,MAAM,EAAE,CAAC,CAAC,IACZ;IACA,CAAC,CAAC,KAAK,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACvC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;CAC5C,GACC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GACpC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GACxC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAC5C,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GACtC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GACtC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAChD,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GACtC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,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 } from '../../../utils/index.js'\nimport type { TypeAssertionResult } from '../index.js'\n\nexport type Be<T> =\n & {\n <U>(): TypeAssertionResult<Exact<T, U>>\n <U>(_: U): TypeAssertionResult<Exact<T, U>>\n }\n & If<Exact<T, any>, { any: void }, {}>\n & If<Exact<T, never>, { never: void }, {}>\n & If<Exact<T, unknown>, { unknown: void }, {}>\n & If<Exact<T, void>, { void: void }, {}>\n & If<Exact<T, null>, { null: void }, {}>\n & If<Exact<T, undefined>, { undefined: void }, {}>\n & If<Exact<T, true>, { true: void }, {}>\n & If<Exact<T, false>, { false: void }, {}>\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MutuallyAssignable } from '../../../utils/index.js';
|
|
2
|
+
import type { TypeAssertionResult } from '../index.js';
|
|
3
|
+
export type Equal<T> = {
|
|
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<MutuallyAssignable<T, U>>;
|
|
24
|
+
<U>(_: U): TypeAssertionResult<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,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI;IACrB;;;;;;;;;;;;;;;;;;OAkBG;IACH,CAAC,CAAC,KAAK,mBAAmB,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACpD,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;CACzD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"equal.js","sourceRoot":"","sources":["../../../../src/main/expect/to/equal.ts"],"names":[],"mappings":"","sourcesContent":["import type { MutuallyAssignable } from '../../../utils/index.js'\nimport type { TypeAssertionResult } from '../index.js'\n\nexport type Equal<T> = {\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<MutuallyAssignable<T, U>>\n <U>(_: U): TypeAssertionResult<MutuallyAssignable<T, U>>\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Extends, If } from '../../../utils/index.js';
|
|
2
|
+
import type { TypeAssertionResult } from '../index.js';
|
|
3
|
+
export type Extend<T> = {
|
|
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<Extends<T, U>>;
|
|
19
|
+
<U>(_: U): TypeAssertionResult<Extends<T, U>>;
|
|
20
|
+
} & If<Extends<T, number>, {
|
|
21
|
+
number: void;
|
|
22
|
+
}, {}> & If<Extends<T, bigint>, {
|
|
23
|
+
bigint: void;
|
|
24
|
+
}, {}> & If<Extends<T, string>, {
|
|
25
|
+
string: void;
|
|
26
|
+
}, {}> & If<Extends<T, boolean>, {
|
|
27
|
+
boolean: void;
|
|
28
|
+
}, {}> & If<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,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,MAAM,MAAM,CAAC,CAAC,IAChB;IACA;;;;;;;;;;;;;OAaG;IACH,CAAC,CAAC,KAAK,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACzC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;CAC9C,GACC,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAC5C,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAC5C,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAC5C,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,EAAE,EAAE,CAAC,GAC9C,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,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 } from '../../../utils/index.js'\nimport type { TypeAssertionResult } from '../index.js'\n\nexport type Extend<T> =\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<Extends<T, U>>\n <U>(_: U): TypeAssertionResult<Extends<T, U>>\n }\n & If<Extends<T, number>, { number: void }, {}>\n & If<Extends<T, bigint>, { bigint: void }, {}>\n & If<Extends<T, string>, { string: void }, {}>\n & If<Extends<T, boolean>, { boolean: void }, {}>\n & If<Extends<T, symbol>, { symbol: void }, {}>\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Extends, IfTupleIncludes } from '../../../utils/index.js';
|
|
2
|
+
import type { TypeAssertionResult } from '../index.js';
|
|
3
|
+
type Result<T, K extends PropertyKey> = IfTupleIncludes<[
|
|
4
|
+
never,
|
|
5
|
+
any
|
|
6
|
+
], K, never, TypeAssertionResult<Extends<K, keyof T>>>;
|
|
7
|
+
export type HaveKey<T> = {
|
|
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>;
|
|
35
|
+
<K extends PropertyKey>(_: K): Result<T, K>;
|
|
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,MAAM,yBAAyB,CAAA;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,IAAI,eAAe,CACrD;IAAC,KAAK;IAAE,GAAG;CAAC,EACZ,CAAC,EACD,KAAK,EACL,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CACzC,CAAA;AAED,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACvB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,CAAC,CAAC,SAAS,WAAW,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACvC,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CAC5C,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 } from '../../../utils/index.js'\nimport type { TypeAssertionResult } from '../index.js'\n\ntype Result<T, K extends PropertyKey> = IfTupleIncludes<\n [never, any],\n K,\n never,\n TypeAssertionResult<Extends<K, keyof T>>\n>\n\nexport type HaveKey<T> = {\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>\n <K extends PropertyKey>(_: K): Result<T, K>\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Be } from './be.js';
|
|
2
|
+
import type { Equal } from './equal.js';
|
|
3
|
+
import type { Extend } from './extend.js';
|
|
4
|
+
import type { ProperExtends } from './proper-extends.js';
|
|
5
|
+
import type { HaveKey } from './have-key.js';
|
|
6
|
+
export type To<T> = {
|
|
7
|
+
be: Be<T>;
|
|
8
|
+
equal: Equal<T>;
|
|
9
|
+
extend: Extend<T>;
|
|
10
|
+
properExtend: ProperExtends<T>;
|
|
11
|
+
haveKey: HaveKey<T>;
|
|
12
|
+
};
|
|
13
|
+
//# 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,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,IAAI;IAClB,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IACT,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IACf,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IACjB,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IAC9B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;CACpB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/main/expect/to/index.ts"],"names":[],"mappings":"","sourcesContent":["import 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> = {\n be: Be<T>\n equal: Equal<T>\n extend: Extend<T>\n properExtend: ProperExtends<T>\n haveKey: HaveKey<T>\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProperExtend } from '../../../utils/index.js';
|
|
2
|
+
import type { TypeAssertionResult } from '../index.js';
|
|
3
|
+
export type ProperExtends<T> = {
|
|
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<ProperExtend<T, U>>;
|
|
19
|
+
<U>(_: U): TypeAssertionResult<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,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B;;;;;;;;;;;;;OAaG;IACH,CAAC,CAAC,KAAK,mBAAmB,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC9C,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;CACnD,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 } from '../../../utils/index.js'\nimport type { TypeAssertionResult } from '../index.js'\n\nexport type ProperExtends<T> = {\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<ProperExtend<T, U>>\n <U>(_: U): TypeAssertionResult<ProperExtend<T, U>>\n}\n"]}
|
package/script/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
|
|
@@ -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/script/main/index.js
CHANGED
|
@@ -5,12 +5,28 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.NOOP = void 0;
|
|
9
|
-
exports.expect = expect;
|
|
8
|
+
exports.expect = exports.NOOP = void 0;
|
|
10
9
|
const noop_js_1 = require("./noop.js");
|
|
11
10
|
var noop_js_2 = require("./noop.js");
|
|
12
11
|
Object.defineProperty(exports, "NOOP", { enumerable: true, get: function () { return noop_js_2.NOOP; } });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of ExpectType to perform type-level assertions on the given type.
|
|
14
|
+
* This function enables testing various type relationships at compile time.
|
|
15
|
+
* NOTE: This function does nothing at runtime and is purely for type-level testing.
|
|
16
|
+
*
|
|
17
|
+
* @template T The type to be tested
|
|
18
|
+
*
|
|
19
|
+
* @returns An ExpectType instance with methods to test type relationships
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* // Test exact type equality
|
|
24
|
+
* expect<number>().to.be<number>().pass
|
|
25
|
+
* expect<number>().to.be<string>().fail
|
|
26
|
+
* // Test if one type extends another
|
|
27
|
+
* expect<3.14>().to.extend<number>().pass
|
|
28
|
+
* expect<2>().to.extend<string>().fail
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
exports.expect = noop_js_1.NOOP;
|
|
16
32
|
//# 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":";AAAA;;;;GAIG;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAGH,uCAAgC;AAGhC,qCAAgC;AAAvB,+FAAA,IAAI,OAAA;AAEb;;;;;;;;;;;;;;;;;;GAkBG;AACU,QAAA,MAAM,GAGf,cAAI,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;
|