lay-sing 0.1.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/LICENSE +21 -0
- package/README.md +151 -0
- package/esm/main/array.d.ts +48 -0
- package/esm/main/array.d.ts.map +1 -0
- package/esm/main/array.js +2 -0
- package/esm/main/array.js.map +1 -0
- package/esm/main/async.d.ts +5 -0
- package/esm/main/async.d.ts.map +1 -0
- package/esm/main/async.js +2 -0
- package/esm/main/async.js.map +1 -0
- package/esm/main/boolean.d.ts +36 -0
- package/esm/main/boolean.d.ts.map +1 -0
- package/esm/main/boolean.js +2 -0
- package/esm/main/boolean.js.map +1 -0
- package/esm/main/control.d.ts +88 -0
- package/esm/main/control.d.ts.map +1 -0
- package/esm/main/control.js +2 -0
- package/esm/main/control.js.map +1 -0
- package/esm/main/doc.d.ts +30 -0
- package/esm/main/doc.d.ts.map +1 -0
- package/esm/main/doc.js +2 -0
- package/esm/main/doc.js.map +1 -0
- package/esm/main/function.d.ts +21 -0
- package/esm/main/function.d.ts.map +1 -0
- package/esm/main/function.js +3 -0
- package/esm/main/function.js.map +1 -0
- package/esm/main/index.d.ts +12 -0
- package/esm/main/index.d.ts.map +1 -0
- package/esm/main/index.js +12 -0
- package/esm/main/index.js.map +1 -0
- package/esm/main/json.d.ts +44 -0
- package/esm/main/json.d.ts.map +1 -0
- package/esm/main/json.js +2 -0
- package/esm/main/json.js.map +1 -0
- package/esm/main/key.d.ts +26 -0
- package/esm/main/key.d.ts.map +1 -0
- package/esm/main/key.js +2 -0
- package/esm/main/key.js.map +1 -0
- package/esm/main/object.d.ts +81 -0
- package/esm/main/object.d.ts.map +1 -0
- package/esm/main/object.js +2 -0
- package/esm/main/object.js.map +1 -0
- package/esm/main/type/compare.d.ts +79 -0
- package/esm/main/type/compare.d.ts.map +1 -0
- package/esm/main/type/compare.js +2 -0
- package/esm/main/type/compare.js.map +1 -0
- package/esm/main/type/index.d.ts +3 -0
- package/esm/main/type/index.d.ts.map +1 -0
- package/esm/main/type/index.js +3 -0
- package/esm/main/type/index.js.map +1 -0
- package/esm/main/type/set.d.ts +29 -0
- package/esm/main/type/set.d.ts.map +1 -0
- package/esm/main/type/set.js +2 -0
- package/esm/main/type/set.js.map +1 -0
- package/esm/main/typed-array.d.ts +5 -0
- package/esm/main/typed-array.d.ts.map +1 -0
- package/esm/main/typed-array.js +2 -0
- package/esm/main/typed-array.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/test-utils.d.ts +348 -0
- package/esm/test-utils.d.ts.map +1 -0
- package/esm/test-utils.js +49 -0
- package/esm/test-utils.js.map +1 -0
- package/package.json +29 -0
- package/script/main/array.d.ts +48 -0
- package/script/main/array.d.ts.map +1 -0
- package/script/main/array.js +3 -0
- package/script/main/array.js.map +1 -0
- package/script/main/async.d.ts +5 -0
- package/script/main/async.d.ts.map +1 -0
- package/script/main/async.js +3 -0
- package/script/main/async.js.map +1 -0
- package/script/main/boolean.d.ts +36 -0
- package/script/main/boolean.d.ts.map +1 -0
- package/script/main/boolean.js +3 -0
- package/script/main/boolean.js.map +1 -0
- package/script/main/control.d.ts +88 -0
- package/script/main/control.d.ts.map +1 -0
- package/script/main/control.js +3 -0
- package/script/main/control.js.map +1 -0
- package/script/main/doc.d.ts +30 -0
- package/script/main/doc.d.ts.map +1 -0
- package/script/main/doc.js +3 -0
- package/script/main/doc.js.map +1 -0
- package/script/main/function.d.ts +21 -0
- package/script/main/function.d.ts.map +1 -0
- package/script/main/function.js +4 -0
- package/script/main/function.js.map +1 -0
- package/script/main/index.d.ts +12 -0
- package/script/main/index.d.ts.map +1 -0
- package/script/main/index.js +28 -0
- package/script/main/index.js.map +1 -0
- package/script/main/json.d.ts +44 -0
- package/script/main/json.d.ts.map +1 -0
- package/script/main/json.js +3 -0
- package/script/main/json.js.map +1 -0
- package/script/main/key.d.ts +26 -0
- package/script/main/key.d.ts.map +1 -0
- package/script/main/key.js +3 -0
- package/script/main/key.js.map +1 -0
- package/script/main/object.d.ts +81 -0
- package/script/main/object.d.ts.map +1 -0
- package/script/main/object.js +3 -0
- package/script/main/object.js.map +1 -0
- package/script/main/type/compare.d.ts +79 -0
- package/script/main/type/compare.d.ts.map +1 -0
- package/script/main/type/compare.js +3 -0
- package/script/main/type/compare.js.map +1 -0
- package/script/main/type/index.d.ts +3 -0
- package/script/main/type/index.d.ts.map +1 -0
- package/script/main/type/index.js +19 -0
- package/script/main/type/index.js.map +1 -0
- package/script/main/type/set.d.ts +29 -0
- package/script/main/type/set.d.ts.map +1 -0
- package/script/main/type/set.js +3 -0
- package/script/main/type/set.js.map +1 -0
- package/script/main/typed-array.d.ts +5 -0
- package/script/main/typed-array.d.ts.map +1 -0
- package/script/main/typed-array.js +3 -0
- package/script/main/typed-array.js.map +1 -0
- package/script/package.json +3 -0
- package/script/test-utils.d.ts +348 -0
- package/script/test-utils.d.ts.map +1 -0
- package/script/test-utils.js +54 -0
- package/script/test-utils.js.map +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
* ### Examples
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* NOOP.foo.bar().baz.qux; // safe, returns NOOP
|
|
23
|
+
* String(NOOP); // "[NOOP]"
|
|
24
|
+
* await NOOP; // does not await (not thenable)
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const NOOP = new Proxy(function () {
|
|
28
|
+
return NOOP;
|
|
29
|
+
}, {
|
|
30
|
+
get(_, prop) {
|
|
31
|
+
switch (prop) {
|
|
32
|
+
case 'then':
|
|
33
|
+
return undefined;
|
|
34
|
+
case 'valueOf':
|
|
35
|
+
case 'toString':
|
|
36
|
+
case Symbol.toPrimitive:
|
|
37
|
+
return () => '[NOOP]';
|
|
38
|
+
default:
|
|
39
|
+
return NOOP;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
export function expect() {
|
|
44
|
+
return NOOP;
|
|
45
|
+
}
|
|
46
|
+
export function compare() {
|
|
47
|
+
return NOOP;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=test-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,IAAI,GAAQ,IAAI,KAAK,CAChC;IACE,OAAO,IAAI,CAAA;AACb,CAAC,EACD;IACE,GAAG,CAAC,CAAC,EAAE,IAAI;QACT,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,MAAM;gBACT,OAAO,SAAS,CAAA;YAClB,KAAK,SAAS,CAAC;YACf,KAAK,UAAU,CAAC;YAChB,KAAK,MAAM,CAAC,WAAW;gBACrB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAA;YACvB;gBACE,OAAO,IAAI,CAAA;QACf,CAAC;IACH,CAAC;CACF,CACF,CAAA;AAkQD,MAAM,UAAU,MAAM;IACpB,OAAO,IAAI,CAAA;AACb,CAAC;AA+GD,MAAM,UAAU,OAAO;IACrB,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["// deno-lint-ignore-file no-explicit-any\nimport type {\n Diff,\n Disjoint,\n Extends,\n If,\n MutuallyAssignable,\n Overlap,\n ProperExtend,\n SafePick,\n Same,\n} from './main/index.js'\n\n/**\n * A universal no-op placeholder implemented via `Proxy`.\n *\n * `NOOP` can be accessed, called, or chained indefinitely without throwing.\n * Every operation returns itself, making it safe to use as a dummy fallback\n * for APIs, optional hooks, or unimplemented interfaces.\n *\n * ### Special behaviors\n *\n * - Callable: invoking `NOOP()` returns `NOOP`\n * - Property access: `NOOP.anything` returns `NOOP`\n * - Promise-safe: `NOOP.then` is `undefined`, so it is not treated as a Promise\n * - Primitive coercion (`toString`, `valueOf`, `Symbol.toPrimitive`) yields\n * a stable string representation: `\"[NOOP]\"`\n *\n * This is useful in scenarios where a value is required syntactically but\n * should perform no action and never fail at runtime.\n *\n * ### Examples\n *\n * ```ts\n * NOOP.foo.bar().baz.qux; // safe, returns NOOP\n * String(NOOP); // \"[NOOP]\"\n * await NOOP; // does not await (not thenable)\n * ```\n */\nexport const NOOP: any = new Proxy(\n function () {\n return NOOP\n },\n {\n get(_, prop) {\n switch (prop) {\n case 'then':\n return undefined\n case 'valueOf':\n case 'toString':\n case Symbol.toPrimitive:\n return () => '[NOOP]'\n default:\n return NOOP\n }\n },\n },\n)\n\n/**\n * Represents the result of a type assertion based on a boolean condition.\n * If the condition is true, the result has a `success` property; otherwise, it has a `fail` property.\n *\n * @template B The boolean condition result (true or false)\n * @template R The type of the result value (default is void)\n */\ntype Result<B extends true | false, R = void> = B extends true ? {\n /**\n * ## Expect to succeed without type error\n */\n success: R\n }\n : {\n /**\n * ## Expect to fail with type error\n */\n fail: R\n }\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 * ### Examples\n *\n * ```ts\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}>().toHaveProperty<'name'>().success\n * ```\n */\nexport type ExpectType<T, H extends PropertyKey = never> = Omit<\n (\n & {\n T: T\n inspect: { [K in keyof T]: T[K] }\n\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 * ### Examples\n *\n * ```ts\n * expect<any>().toBe<any>().success\n * expect<never>().toBe<never>().success\n * expect<false>().toBe<true>().fail\n * ```\n */\n toBe<U>(): Result<Same<T, U>>\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 * ### Examples\n *\n * ```ts\n * expect<3.14>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * expect<'hello'>().toExtend<string>().success\n * ```\n */\n toExtend<U>(): Result<Extends<T, U>>\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 * ### Examples\n *\n * ```ts\n * expect<2>().toProperExtend<number>().success\n * expect<'a' | 'b'>().toProperExtend<string>().success\n * expect<number>().toProperExtend<number>().fail\n * ```\n */\n toProperExtend<U>(): Result<ProperExtend<T, U>>\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 * ### Examples\n *\n * ```ts\n * type WithProp = { prop: string; another: number }\n * expect<WithProp>().toHaveProperty<'prop'>().success\n * expect<WithProp>().toHaveProperty<'another'>().success\n * expect<WithProp>().toHaveProperty<'missing'>().fail\n * ```\n */\n toHaveProperty<K extends PropertyKey>(): Result<Extends<K, keyof T>>\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 * ### Examples\n *\n * ```ts\n * expect<3.14>().toExtendNumber // Available and would succeed\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 * ### Examples\n *\n * ```ts\n * expect<'hello'>().toExtendString // Available and would succeed\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 * ### Examples\n *\n * ```ts\n * expect<true>().toExtendBoolean // Available and would succeed\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 * Tests if the current type is exactly `any`.\n * Available only if the current type is `any`.\n *\n * ### Examples\n *\n * ```ts\n * expect<any>().toBeAny // Available and would succeed\n * ```\n */\n toBeAny: ExpectType<T, H | 'toBeAny' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `never`.\n * Available only if the current type is `never`.\n *\n * ### Examples\n *\n * ```ts\n * expect<never>().toBeNever // Available and would succeed\n * ```\n */\n toBeNever: ExpectType<T, H | 'toBeNever' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `unknown`.\n * Available only if the current type is `unknown`.\n *\n * ### Examples\n *\n * ```ts\n * expect<unknown>().toBeUnknown // Available and would succeed\n * ```\n */\n toBeUnknown: ExpectType<T, H | 'toBeUnknown' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `void`.\n * Available only if the current type is `void`.\n *\n * ### Examples\n *\n * ```ts\n * expect<void>().toBeVoid // Available and would succeed\n * ```\n */\n toBeVoid: ExpectType<T, H | 'toBeVoid' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `true` (boolean literal).\n * Available only if the current type is `true`.\n *\n * ### Examples\n *\n * ```ts\n * expect<true>().toBeTrue // Available and would succeed\n * ```\n */\n toBeTrue: ExpectType<T, H | 'toBeTrue' | 'toBe' | 'toExtendBoolean'>\n\n /**\n * Tests if the current type is exactly `false` (boolean literal).\n * Available only if the current type is `false`.\n *\n * ### Examples\n *\n * ```ts\n * expect<false>().toBeFalse // Available and would succeed\n * ```\n */\n toBeFalse: ExpectType<T, H | 'toBeFalse' | 'toBe' | 'toExtendBoolean'>\n },\n | If<Same<T, any>, 'toBeAny'>\n | If<Same<T, never>, 'toBeNever'>\n | If<Same<T, unknown>, 'toBeUnknown'>\n | If<Same<T, void>, 'toBeVoid'>\n | If<Same<T, true>, 'toBeTrue'>\n | If<Same<T, false>, 'toBeFalse'>\n >\n ),\n H\n>\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 * ### Examples\n *\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\n/**\n * Type-level utility that compares two types and provides methods to test their relationship.\n * Offers options to check if types are same, different, overlapping, disjoint, or mutually assignable.\n *\n * @template T First type to compare\n * @template U Second type to compare\n * @template H Hidden property keys that are already used (internal tracking)\n *\n * ### Examples\n *\n * ```ts\n * // Check if two types are the same\n * compare<number, number>().same // Available\n * // Check if two types are different\n * compare<number, string>().different // Available\n * // Check if two types overlap\n * compare<4, number>().overlap.different // Available\n * ```\n */\nexport type CompareTypes<T, U, H extends PropertyKey = never> = Omit<\n SafePick<\n {\n /**\n * Available when types T and U are exactly the same.\n *\n * ### Examples\n *\n * ```ts\n * compare<3, 3>().same // Available\n * compare<boolean, boolean>().same // Available\n * ```\n */\n same: CompareTypes<T, U, H | 'same'>\n\n /**\n * Available when types T and U are different.\n *\n * ### Examples\n *\n * ```ts\n * compare<4, 'abc'>().different // Available\n * compare<number, 4>().different // Available\n * ```\n */\n different: CompareTypes<T, U, H | 'different'>\n\n /**\n * Available when types T and U have some overlap.\n *\n * ### Examples\n *\n * ```ts\n * compare<4, number>().overlap // Available since 4 overlaps with number\n * ```\n */\n overlap: CompareTypes<T, U, H | 'overlap'>\n\n /**\n * Available when types T and U have no overlap (are disjoint).\n *\n * ### Examples\n *\n * ```ts\n * compare<4, 'abc'>().different.disjoint // Available since 4 and 'abc' are disjoint\n * ```\n */\n disjoint: CompareTypes<T, U, H | 'disjoint'>\n\n /**\n * Available when types T and U are mutually assignable (each type can be assigned to the other).\n *\n * ### Examples\n *\n * ```ts\n * compare<1 | 2, 1 | 2>().mutuallyAssignable // Available since identical union types are mutually assignable\n * ```\n */\n mutuallyAssignable: CompareTypes<T, U, H | 'mutuallyAssignable'>\n },\n | If<Same<T, U>, 'same'>\n | If<Diff<T, U>, 'different'>\n | If<Overlap<T, U>, 'overlap'>\n | If<Disjoint<T, U>, 'disjoint'>\n | If<MutuallyAssignable<T, U>, 'mutuallyAssignable'>\n >,\n H\n>\n\n/**\n * Creates an instance of CompareTypes to perform type-level comparisons between two types.\n * This function enables testing various relationships between types at compile time.\n * NOTE: This function does nothing at runtime and is purely for type-level testing.\n *\n * @template T First type to compare\n * @template U Second type to compare\n *\n * @returns A CompareTypes instance with methods to test relationships between T and U\n *\n * ### Examples\n *\n * ```ts\n * // Compare two identical types\n * compare<number, number>().same // Results in an available property\n * // Compare two different but overlapping types\n * compare<4, number>().overlap.different // Results in available properties\n * ```\n */\nexport function compare<T, U>(): CompareTypes<T, U>\nexport function compare<T, U>(t: T, u: U): CompareTypes<T, U>\nexport function compare<T, U>(): CompareTypes<T, U> {\n return NOOP\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lay-sing",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Leawind/lay-sing.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"main": "./esm/index.js",
|
|
11
|
+
"module": "./esm/index.js",
|
|
12
|
+
"exports": {
|
|
13
|
+
"./test-utils": {
|
|
14
|
+
"import": "./esm/test-utils.js",
|
|
15
|
+
"require": "./script/test-utils.js"
|
|
16
|
+
},
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./esm/main/index.js",
|
|
19
|
+
"require": "./script/main/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"private": false,
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"_generatedBy": "dnt@dev"
|
|
29
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Same } from './type/compare.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a readonly array of type T
|
|
4
|
+
*/
|
|
5
|
+
export type ReadonlyArray<T = unknown> = readonly T[];
|
|
6
|
+
/**
|
|
7
|
+
* Concatenates two tuples into a single tuple type
|
|
8
|
+
*
|
|
9
|
+
* ### Examples
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* type Result = ConcatTuple<[1, 2], [3, 4]> // [1, 2, 3, 4]
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type ConcatTuple<Left extends readonly unknown[], Right extends readonly unknown[]> = Left extends readonly unknown[] ? (Right extends readonly unknown[] ? [...Left, ...Right] : never) : never;
|
|
16
|
+
/**
|
|
17
|
+
* Checks whether a tuple includes a specific element type
|
|
18
|
+
*
|
|
19
|
+
* ### Examples
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* type HasTwo = TupleIncludes<[1, 2, 3], 2> // true
|
|
23
|
+
* type HasFour = TupleIncludes<[1, 2, 3], 4> // false
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export type TupleIncludes<Tuple extends readonly unknown[], Element> = Tuple extends readonly [infer First, ...infer Rest] ? (Same<Element, First> extends true ? true : TupleIncludes<Rest, Element>) : false;
|
|
27
|
+
/**
|
|
28
|
+
* Appends an element to a tuple only if it doesn't already exist in the tuple
|
|
29
|
+
*
|
|
30
|
+
* ### Examples
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* type Result1 = AppendUnique<[1, 2, 3], 4> // [1, 2, 3, 4]
|
|
34
|
+
* type Result2 = AppendUnique<[1, 2, 3], 2> // [1, 2, 3]
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export type AppendUnique<Tuple extends readonly unknown[], Element> = TupleIncludes<Tuple, Element> extends true ? Tuple : [...Tuple, Element];
|
|
38
|
+
/**
|
|
39
|
+
* Concatenates two tuples while ensuring uniqueness of elements
|
|
40
|
+
*
|
|
41
|
+
* ### Examples
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* type Result = ConcatUniqueTuple<[1, 2, 3], [2, 3, 4]> // [1, 2, 3, 4]
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export type ConcatUniqueTuple<A extends readonly unknown[], B extends readonly unknown[], R extends readonly unknown[] = A> = B extends readonly [infer First, ...infer Rest] ? ConcatUniqueTuple<A, Rest, AppendUnique<R, First>> : R;
|
|
48
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/main/array.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAE7C;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI,SAAS,CAAC,EAAE,CAAA;AAErD;;;;;;;;GAQG;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;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,CACvB,KAAK,SAAS,SAAS,OAAO,EAAE,EAChC,OAAO,IACL,KAAK,SAAS,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GACnD,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,GACzE,KAAK,CAAA;AAET;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,CACtB,KAAK,SAAS,SAAS,OAAO,EAAE,EAChC,OAAO,IACL,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,CAAA;AAE5E;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,CAC3B,CAAC,SAAS,SAAS,OAAO,EAAE,EAC5B,CAAC,SAAS,SAAS,OAAO,EAAE,EAC5B,CAAC,SAAS,SAAS,OAAO,EAAE,GAAG,CAAC,IAC9B,CAAC,SAAS,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,iBAAiB,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/main/array.ts"],"names":[],"mappings":"","sourcesContent":["import type { Same } from './type/compare.js'\n\n/**\n * Represents a readonly array of type T\n */\nexport type ReadonlyArray<T = unknown> = readonly T[]\n\n/**\n * Concatenates two tuples into a single tuple type\n *\n * ### Examples\n *\n * ```ts\n * type Result = ConcatTuple<[1, 2], [3, 4]> // [1, 2, 3, 4]\n * ```\n */\nexport type ConcatTuple<\n Left extends readonly unknown[],\n Right extends readonly unknown[],\n> = Left extends readonly unknown[] ? (Right extends readonly unknown[] ? [...Left, ...Right] : never) : never\n\n/**\n * Checks whether a tuple includes a specific element type\n *\n * ### Examples\n *\n * ```ts\n * type HasTwo = TupleIncludes<[1, 2, 3], 2> // true\n * type HasFour = TupleIncludes<[1, 2, 3], 4> // false\n * ```\n */\nexport type TupleIncludes<\n Tuple extends readonly unknown[],\n Element,\n> = Tuple extends readonly [infer First, ...infer Rest]\n ? (Same<Element, First> extends true ? true : TupleIncludes<Rest, Element>)\n : false\n\n/**\n * Appends an element to a tuple only if it doesn't already exist in the tuple\n *\n * ### Examples\n *\n * ```ts\n * type Result1 = AppendUnique<[1, 2, 3], 4> // [1, 2, 3, 4]\n * type Result2 = AppendUnique<[1, 2, 3], 2> // [1, 2, 3]\n * ```\n */\nexport type AppendUnique<\n Tuple extends readonly unknown[],\n Element,\n> = TupleIncludes<Tuple, Element> extends true ? Tuple : [...Tuple, Element]\n\n/**\n * Concatenates two tuples while ensuring uniqueness of elements\n *\n * ### Examples\n *\n * ```ts\n * type Result = ConcatUniqueTuple<[1, 2, 3], [2, 3, 4]> // [1, 2, 3, 4]\n * ```\n */\nexport type ConcatUniqueTuple<\n A extends readonly unknown[],\n B extends readonly unknown[],\n R extends readonly unknown[] = A,\n> = B extends readonly [infer First, ...infer Rest] ? ConcatUniqueTuple<A, Rest, AppendUnique<R, First>> : R\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/main/async.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/main/async.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a value that can be either T or a Promise of T\n */\nexport type Awaitable<T> = Promise<T> | T\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ### Result
|
|
3
|
+
*
|
|
4
|
+
* - `never`: if `T` is `never`
|
|
5
|
+
* - `boolean`: if `T` is `boolean` or `any`
|
|
6
|
+
* - `false`: if `T` is `true`
|
|
7
|
+
* - `true`: if `T` is `false`
|
|
8
|
+
*
|
|
9
|
+
* ### Examples
|
|
10
|
+
*
|
|
11
|
+
* | `T` | `Not<T>` |
|
|
12
|
+
* | --------- | --------- |
|
|
13
|
+
* | `never` | `never` |
|
|
14
|
+
* | `true` | `false` |
|
|
15
|
+
* | `false` | `true` |
|
|
16
|
+
* | `boolean` | `boolean` |
|
|
17
|
+
* | `any` | `boolean` |
|
|
18
|
+
*/
|
|
19
|
+
export type Not<T extends boolean> = T extends true ? false : T extends false ? true : boolean;
|
|
20
|
+
/**
|
|
21
|
+
* - `never`: if anyone of A,B is `never`
|
|
22
|
+
* - `boolean`: if anyone of A,B is `boolean` or `any`
|
|
23
|
+
* - `true`: if both A,B are `true`
|
|
24
|
+
* - `false`: otherwise
|
|
25
|
+
*/
|
|
26
|
+
export type And<A extends boolean, B extends boolean> = A extends never ? never : [B] extends [never] ? never : (A extends true ? (B extends true ? true : false) : false);
|
|
27
|
+
/**
|
|
28
|
+
* ### Result
|
|
29
|
+
*
|
|
30
|
+
* - `never`: if anyone of A,B is `never`
|
|
31
|
+
* - `boolean`: if anyone of A,B is `boolean` or `any`
|
|
32
|
+
* - `false`: if both A,B are `false`
|
|
33
|
+
* - `true`: otherwise
|
|
34
|
+
*/
|
|
35
|
+
export type Or<A extends boolean, B extends boolean> = [A] extends [never] ? never : [B] extends [never] ? never : [boolean] extends [A] ? boolean : [boolean] extends [B] ? boolean : true extends A ? true : true extends B ? true : false;
|
|
36
|
+
//# sourceMappingURL=boolean.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../src/main/boolean.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,GACvD,CAAC,SAAS,KAAK,GAAG,IAAI,GACtB,OAAO,CAAA;AAEX;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CACb,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,IACf,CAAC,SAAS,KAAK,GAAG,KAAK,GACvB,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC3B,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAA;AAE9D;;;;;;;GAOG;AACH,MAAM,MAAM,EAAE,CACZ,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,IACf,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC3B,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC3B,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,GAC/B,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,GAC/B,IAAI,SAAS,CAAC,GAAG,IAAI,GACrB,IAAI,SAAS,CAAC,GAAG,IAAI,GACrB,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/main/boolean.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * ### Result\n *\n * - `never`: if `T` is `never`\n * - `boolean`: if `T` is `boolean` or `any`\n * - `false`: if `T` is `true`\n * - `true`: if `T` is `false`\n *\n * ### Examples\n *\n * | `T` | `Not<T>` |\n * | --------- | --------- |\n * | `never` | `never` |\n * | `true` | `false` |\n * | `false` | `true` |\n * | `boolean` | `boolean` |\n * | `any` | `boolean` |\n */\nexport type Not<T extends boolean> = T extends true ? false\n : T extends false ? true\n : boolean\n\n/**\n * - `never`: if anyone of A,B is `never`\n * - `boolean`: if anyone of A,B is `boolean` or `any`\n * - `true`: if both A,B are `true`\n * - `false`: otherwise\n */\nexport type And<\n A extends boolean,\n B extends boolean,\n> = A extends never ? never\n : [B] extends [never] ? never\n : (A extends true ? (B extends true ? true : false) : false)\n\n/**\n * ### Result\n *\n * - `never`: if anyone of A,B is `never`\n * - `boolean`: if anyone of A,B is `boolean` or `any`\n * - `false`: if both A,B are `false`\n * - `true`: otherwise\n */\nexport type Or<\n A extends boolean,\n B extends boolean,\n> = [A] extends [never] ? never\n : [B] extends [never] ? never\n : [boolean] extends [A] ? boolean\n : [boolean] extends [B] ? boolean\n : true extends A ? true\n : true extends B ? true\n : false\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Same } from './type/compare.js';
|
|
2
|
+
/**
|
|
3
|
+
* Conditional type - returns `T` if condition `C` is true, otherwise returns `F`
|
|
4
|
+
*
|
|
5
|
+
* ### Result
|
|
6
|
+
*
|
|
7
|
+
* - `never`: if `C` is `never`
|
|
8
|
+
* - `T`: if `C` is `true`
|
|
9
|
+
* - `F`: if `C` is `false`
|
|
10
|
+
*
|
|
11
|
+
* ### Examples
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* type Result = If<true, 'yes', 'no'> // 'yes'
|
|
15
|
+
* type Result2 = If<false, 'yes', 'no'> // 'no'
|
|
16
|
+
* type NeverResult = If<never, 'yes', 'no'> // never
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type If<C extends boolean, T, F = never> = [C] extends [never] ? never : C extends true ? T : F;
|
|
20
|
+
/**
|
|
21
|
+
* Conditional type - returns `T` if condition `C` is false, otherwise returns `F`
|
|
22
|
+
*
|
|
23
|
+
* ### Result
|
|
24
|
+
*
|
|
25
|
+
* - `never`: if `C` is `never`
|
|
26
|
+
* - `T`: if `C` is `false`
|
|
27
|
+
* - `F`: if `C` is `true`
|
|
28
|
+
*
|
|
29
|
+
* ### Examples
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* type Result = IfFalse<false, 'yes', 'no'> // 'yes'
|
|
33
|
+
* type Result2 = IfFalse<true, 'yes', 'no'> // 'no'
|
|
34
|
+
* type NeverResult = IfFalse<never, 'yes', 'no'> // never
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export type IfFalse<C extends boolean, T, F = never> = [C] extends [never] ? never : C extends false ? T : F;
|
|
38
|
+
/**
|
|
39
|
+
* Used with:
|
|
40
|
+
* - {@link Switch}
|
|
41
|
+
* - {@link SwitchExtends}
|
|
42
|
+
*/
|
|
43
|
+
export type Case<T = unknown, Return = unknown> = [T, Return];
|
|
44
|
+
/**
|
|
45
|
+
* Used with:
|
|
46
|
+
*
|
|
47
|
+
* - {@link Switch}
|
|
48
|
+
* - {@link SwitchExtends}
|
|
49
|
+
*
|
|
50
|
+
* ### Examples
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* type NameMap<id> = Switch<id, [
|
|
54
|
+
* Case<1, 'Alice'>,
|
|
55
|
+
* Case<2, 'Bob'>,
|
|
56
|
+
* Case<3, 'Charlie'>,
|
|
57
|
+
* ], DefaultCase<'Steve'>>
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export type DefaultCase<T> = T;
|
|
61
|
+
/**
|
|
62
|
+
* ### Examples
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* type Result = Switch<2, [
|
|
66
|
+
* Case<1, 'Alice'>,
|
|
67
|
+
* Case<2, 'Bob'>,
|
|
68
|
+
* Case<3, 'Charlie'>,
|
|
69
|
+
* ], DefaultCase<'Steve'>>
|
|
70
|
+
*
|
|
71
|
+
* // Result: 'Bob'
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export type Switch<T, Cases extends readonly Case[], Default = never> = Cases extends [infer First, ...infer Rest] ? (First extends [infer C, infer R] ? (Same<T, C> extends true ? R : (Switch<T, Rest extends readonly Case[] ? Rest : never, Default>)) : (never)) : Default;
|
|
75
|
+
/**
|
|
76
|
+
* Switch type that uses 'extends' logic instead of 'Same' logic
|
|
77
|
+
*
|
|
78
|
+
* ### Examples
|
|
79
|
+
* ```ts
|
|
80
|
+
* type Result = SwitchExtends<string | number, [
|
|
81
|
+
* Case<string, 'string type'>,
|
|
82
|
+
* Case<number, 'number type'>,
|
|
83
|
+
* ], 'other'>
|
|
84
|
+
* // Result: 'string type' | 'number type'
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export type SwitchExtends<T, Cases extends readonly Case[], Default = never> = Cases extends [infer First, ...infer Rest] ? (First extends [infer C, infer R] ? ([T] extends [C] ? R : SwitchExtends<T, Rest extends readonly Case[] ? Rest : never, Default>) : never) : Default;
|
|
88
|
+
//# sourceMappingURL=control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../src/main/control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAE7C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,EAAE,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GACzE,CAAC,SAAS,IAAI,GAAG,CAAC,GAClB,CAAC,CAAA;AAEL;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAC9E,CAAC,SAAS,KAAK,GAAG,CAAC,GACnB,CAAC,CAAA;AAEL;;;;GAIG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAC7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,CAAA;AAE9B;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,MAAM,CAChB,CAAC,EACD,KAAK,SAAS,SAAS,IAAI,EAAE,EAC7B,OAAO,GAAG,KAAK,IACb,KAAK,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAC7C,KAAK,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAC5B,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,SAAS,SAAS,IAAI,EAAE,GAAG,IAAI,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GACjG,CAAC,KAAK,CAAC,CACZ,GACC,OAAO,CAAA;AAEX;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,aAAa,CACvB,CAAC,EACD,KAAK,SAAS,SAAS,IAAI,EAAE,EAC7B,OAAO,GAAG,KAAK,IACb,KAAK,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAC7C,KAAK,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAC5B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE,IAAI,SAAS,SAAS,IAAI,EAAE,GAAG,IAAI,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC,GAC9F,KAAK,CACV,GACC,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.js","sourceRoot":"","sources":["../../src/main/control.ts"],"names":[],"mappings":"","sourcesContent":["import type { Same } from './type/compare.js'\n\n/**\n * Conditional type - returns `T` if condition `C` is true, otherwise returns `F`\n *\n * ### Result\n *\n * - `never`: if `C` is `never`\n * - `T`: if `C` is `true`\n * - `F`: if `C` is `false`\n *\n * ### Examples\n *\n * ```ts\n * type Result = If<true, 'yes', 'no'> // 'yes'\n * type Result2 = If<false, 'yes', 'no'> // 'no'\n * type NeverResult = If<never, 'yes', 'no'> // never\n * ```\n */\nexport type If<C extends boolean, T, F = never> = [C] extends [never] ? never\n : C extends true ? T\n : F\n\n/**\n * Conditional type - returns `T` if condition `C` is false, otherwise returns `F`\n *\n * ### Result\n *\n * - `never`: if `C` is `never`\n * - `T`: if `C` is `false`\n * - `F`: if `C` is `true`\n *\n * ### Examples\n *\n * ```ts\n * type Result = IfFalse<false, 'yes', 'no'> // 'yes'\n * type Result2 = IfFalse<true, 'yes', 'no'> // 'no'\n * type NeverResult = IfFalse<never, 'yes', 'no'> // never\n * ```\n */\nexport type IfFalse<C extends boolean, T, F = never> = [C] extends [never] ? never\n : C extends false ? T\n : F\n\n/**\n * Used with:\n * - {@link Switch}\n * - {@link SwitchExtends}\n */\nexport type Case<T = unknown, Return = unknown> = [T, Return]\n/**\n * Used with:\n *\n * - {@link Switch}\n * - {@link SwitchExtends}\n *\n * ### Examples\n *\n * ```ts\n * type NameMap<id> = Switch<id, [\n * Case<1, 'Alice'>,\n * Case<2, 'Bob'>,\n * Case<3, 'Charlie'>,\n * ], DefaultCase<'Steve'>>\n * ```\n */\nexport type DefaultCase<T> = T\n\n/**\n * ### Examples\n *\n * ```ts\n * type Result = Switch<2, [\n * Case<1, 'Alice'>,\n * Case<2, 'Bob'>,\n * Case<3, 'Charlie'>,\n * ], DefaultCase<'Steve'>>\n *\n * // Result: 'Bob'\n * ```\n */\nexport type Switch<\n T,\n Cases extends readonly Case[],\n Default = never,\n> = Cases extends [infer First, ...infer Rest] ? (\n First extends [infer C, infer R]\n ? (Same<T, C> extends true ? R : (Switch<T, Rest extends readonly Case[] ? Rest : never, Default>))\n : (never)\n )\n : Default\n\n/**\n * Switch type that uses 'extends' logic instead of 'Same' logic\n *\n * ### Examples\n * ```ts\n * type Result = SwitchExtends<string | number, [\n * Case<string, 'string type'>,\n * Case<number, 'number type'>,\n * ], 'other'>\n * // Result: 'string type' | 'number type'\n * ```\n */\nexport type SwitchExtends<\n T,\n Cases extends readonly Case[],\n Default = never,\n> = Cases extends [infer First, ...infer Rest] ? (\n First extends [infer C, infer R]\n ? ([T] extends [C] ? R : SwitchExtends<T, Rest extends readonly Case[] ? Rest : never, Default>)\n : never\n )\n : Default\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append documentation or auxiliary metadata to type `A`
|
|
3
|
+
* without changing its shape.
|
|
4
|
+
*
|
|
5
|
+
* This type intersects `Doc` onto `A`, but only keeps the keys
|
|
6
|
+
* originally defined in `A`. As a result:
|
|
7
|
+
*
|
|
8
|
+
* - `Doc` cannot introduce new properties
|
|
9
|
+
* - Existing properties in `A` are preserved
|
|
10
|
+
* - `Doc` may further constrain or annotate existing properties
|
|
11
|
+
*
|
|
12
|
+
* This is typically used to attach JSDoc comments, branding,
|
|
13
|
+
* or editor-only metadata to an existing type while keeping
|
|
14
|
+
* its public structure intact.
|
|
15
|
+
*/
|
|
16
|
+
export type AppendDoc<T, Doc> = Pick<T & Doc, keyof T>;
|
|
17
|
+
/**
|
|
18
|
+
* Prepend documentation or auxiliary metadata to type `A`
|
|
19
|
+
* without changing its shape.
|
|
20
|
+
*
|
|
21
|
+
* This is similar to {@link AppendDoc}, but the intersection order
|
|
22
|
+
* is reversed (`Doc & A`), which can affect how property types,
|
|
23
|
+
* documentation, and hover information are presented by tooling.
|
|
24
|
+
*
|
|
25
|
+
* In practice, this allows `Doc` to act as a non-invasive,
|
|
26
|
+
* descriptive layer while ensuring `A` remains the authoritative
|
|
27
|
+
* source of truth for property types.
|
|
28
|
+
*/
|
|
29
|
+
export type PrependDoc<T, Doc> = Pick<Doc & T, keyof T>;
|
|
30
|
+
//# sourceMappingURL=doc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../src/main/doc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc.js","sourceRoot":"","sources":["../../src/main/doc.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Append documentation or auxiliary metadata to type `A`\n * without changing its shape.\n *\n * This type intersects `Doc` onto `A`, but only keeps the keys\n * originally defined in `A`. As a result:\n *\n * - `Doc` cannot introduce new properties\n * - Existing properties in `A` are preserved\n * - `Doc` may further constrain or annotate existing properties\n *\n * This is typically used to attach JSDoc comments, branding,\n * or editor-only metadata to an existing type while keeping\n * its public structure intact.\n */\nexport type AppendDoc<T, Doc> = Pick<T & Doc, keyof T>\n\n/**\n * Prepend documentation or auxiliary metadata to type `A`\n * without changing its shape.\n *\n * This is similar to {@link AppendDoc}, but the intersection order\n * is reversed (`Doc & A`), which can affect how property types,\n * documentation, and hover information are presented by tooling.\n *\n * In practice, this allows `Doc` to act as a non-invasive,\n * descriptive layer while ensuring `A` remains the authoritative\n * source of truth for property types.\n */\nexport type PrependDoc<T, Doc> = Pick<Doc & T, keyof T>\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a function with any parameters and a specific return type
|
|
3
|
+
*
|
|
4
|
+
* ### Examples
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* type _ = AnyFunction<string, [number]> // (arg: number) => string
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export type AnyFunction<Return = any, Params extends any[] = any[]> = (...args: Params) => Return;
|
|
11
|
+
/**
|
|
12
|
+
* Represents a constructor with any parameters and a specific return type
|
|
13
|
+
*
|
|
14
|
+
* ### Examples
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* type _ = Constructor<string, [number]> // new (arg: number) => string
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type Constructor<Return = any, Params extends any[] = any[]> = new (...args: Params) => Return;
|
|
21
|
+
//# sourceMappingURL=function.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/main/function.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CACrB,MAAM,GAAG,GAAG,EACZ,MAAM,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE,IAC1B,CAAC,GAAG,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;AAE/B;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CACrB,MAAM,GAAG,GAAG,EACZ,MAAM,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE,IAC1B,KAAK,GAAG,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/main/function.ts"],"names":[],"mappings":";AAAA,wCAAwC","sourcesContent":["// deno-lint-ignore-file no-explicit-any\n\n/**\n * Represents a function with any parameters and a specific return type\n *\n * ### Examples\n *\n * ```ts\n * type _ = AnyFunction<string, [number]> // (arg: number) => string\n * ```\n */\nexport type AnyFunction<\n Return = any,\n Params extends any[] = any[],\n> = (...args: Params) => Return\n\n/**\n * Represents a constructor with any parameters and a specific return type\n *\n * ### Examples\n *\n * ```ts\n * type _ = Constructor<string, [number]> // new (arg: number) => string\n * ```\n */\nexport type Constructor<\n Return = any,\n Params extends any[] = any[],\n> = new (...args: Params) => Return\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './array.js';
|
|
2
|
+
export * from './async.js';
|
|
3
|
+
export * from './boolean.js';
|
|
4
|
+
export * from './control.js';
|
|
5
|
+
export * from './doc.js';
|
|
6
|
+
export * from './function.js';
|
|
7
|
+
export * from './json.js';
|
|
8
|
+
export * from './key.js';
|
|
9
|
+
export * from './object.js';
|
|
10
|
+
export * from './type/index.js';
|
|
11
|
+
export * from './typed-array.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
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
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./array.js"), exports);
|
|
18
|
+
__exportStar(require("./async.js"), exports);
|
|
19
|
+
__exportStar(require("./boolean.js"), exports);
|
|
20
|
+
__exportStar(require("./control.js"), exports);
|
|
21
|
+
__exportStar(require("./doc.js"), exports);
|
|
22
|
+
__exportStar(require("./function.js"), exports);
|
|
23
|
+
__exportStar(require("./json.js"), exports);
|
|
24
|
+
__exportStar(require("./key.js"), exports);
|
|
25
|
+
__exportStar(require("./object.js"), exports);
|
|
26
|
+
__exportStar(require("./type/index.js"), exports);
|
|
27
|
+
__exportStar(require("./typed-array.js"), exports);
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,6CAA0B;AAC1B,+CAA4B;AAC5B,+CAA4B;AAC5B,2CAAwB;AACxB,gDAA6B;AAC7B,4CAAyB;AACzB,2CAAwB;AACxB,8CAA2B;AAC3B,kDAA+B;AAC/B,mDAAgC","sourcesContent":["export * from './array.js'\nexport * from './async.js'\nexport * from './boolean.js'\nexport * from './control.js'\nexport * from './doc.js'\nexport * from './function.js'\nexport * from './json.js'\nexport * from './key.js'\nexport * from './object.js'\nexport * from './type/index.js'\nexport * from './typed-array.js'\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Primitive values allowed by the JSON specification.
|
|
3
|
+
*
|
|
4
|
+
* This represents the set of non-object, non-array values
|
|
5
|
+
* that can appear in valid JSON data.
|
|
6
|
+
*/
|
|
7
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
8
|
+
/**
|
|
9
|
+
* A JSON array.
|
|
10
|
+
*
|
|
11
|
+
* Each element of the array must itself be a valid `JsonValue`.
|
|
12
|
+
*/
|
|
13
|
+
export type JsonArray = JsonValue[];
|
|
14
|
+
/**
|
|
15
|
+
* A JSON object.
|
|
16
|
+
*
|
|
17
|
+
* Keys are strings, and values must be valid `JsonValue`s.
|
|
18
|
+
* This mirrors the object structure defined by the JSON specification.
|
|
19
|
+
*/
|
|
20
|
+
export type JsonObject = {
|
|
21
|
+
[key: string]: JsonValue;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Any valid JSON value.
|
|
25
|
+
*
|
|
26
|
+
* This is a strict representation of JSON data, suitable for
|
|
27
|
+
* describing the result of `JSON.parse`, serialized payloads,
|
|
28
|
+
* or schema-level JSON structures.
|
|
29
|
+
*/
|
|
30
|
+
export type JsonValue = JsonPrimitive | JsonArray | JsonObject;
|
|
31
|
+
/**
|
|
32
|
+
* A JavaScript value that can be safely serialized to JSON.
|
|
33
|
+
*
|
|
34
|
+
* Unlike `JsonValue`, this type represents values *before*
|
|
35
|
+
* serialization, describing the set of recursive structures
|
|
36
|
+
* that `JSON.stringify` can handle.
|
|
37
|
+
*
|
|
38
|
+
* This is useful for constraining inputs that are expected to
|
|
39
|
+
* be JSON-serializable, rather than already being JSON data.
|
|
40
|
+
*/
|
|
41
|
+
export type Jsonable = string | number | boolean | null | Jsonable[] | {
|
|
42
|
+
[key: string]: Jsonable;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/main/json.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;AAE5D;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,EAAE,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,GAAG,UAAU,CAAA;AAE9D;;;;;;;;;GASG;AACH,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,QAAQ,EAAE,GACV;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/main/json.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Primitive values allowed by the JSON specification.\n *\n * This represents the set of non-object, non-array values\n * that can appear in valid JSON data.\n */\nexport type JsonPrimitive = string | number | boolean | null\n\n/**\n * A JSON array.\n *\n * Each element of the array must itself be a valid `JsonValue`.\n */\nexport type JsonArray = JsonValue[]\n\n/**\n * A JSON object.\n *\n * Keys are strings, and values must be valid `JsonValue`s.\n * This mirrors the object structure defined by the JSON specification.\n */\nexport type JsonObject = { [key: string]: JsonValue }\n\n/**\n * Any valid JSON value.\n *\n * This is a strict representation of JSON data, suitable for\n * describing the result of `JSON.parse`, serialized payloads,\n * or schema-level JSON structures.\n */\nexport type JsonValue = JsonPrimitive | JsonArray | JsonObject\n\n/**\n * A JavaScript value that can be safely serialized to JSON.\n *\n * Unlike `JsonValue`, this type represents values *before*\n * serialization, describing the set of recursive structures\n * that `JSON.stringify` can handle.\n *\n * This is useful for constraining inputs that are expected to\n * be JSON-serializable, rather than already being JSON data.\n */\nexport type Jsonable =\n | string\n | number\n | boolean\n | null\n | Jsonable[]\n | { [key: string]: Jsonable }\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Same } from './type/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the keys of type T that have values of type U
|
|
4
|
+
*
|
|
5
|
+
* ### Examples
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* type A = { a: 1; b: 2; c: 1 }
|
|
9
|
+
* type Keys = KeysOfType<A, 1> // 'a' | 'c'
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type KeysOfType<T, U> = Exclude<{
|
|
13
|
+
[K in keyof T]: Same<T[K], U> extends true ? K : never;
|
|
14
|
+
}[keyof T], undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Extracts the keys of type T that do not have values of type U
|
|
17
|
+
*
|
|
18
|
+
* ### Examples
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* type A = { a: 1; b: 2; c: 1 }
|
|
22
|
+
* type Keys = KeysOfOtherType<A, 1> // 'b'
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export type KeysOfOtherType<T, U> = Exclude<keyof T, KeysOfType<T, U>>;
|
|
26
|
+
//# sourceMappingURL=key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../../src/main/key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAE3C;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,KAAK;CAAE,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;AAEtH;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../src/main/key.ts"],"names":[],"mappings":"","sourcesContent":["import type { Same } from './type/index.js'\n\n/**\n * Extracts the keys of type T that have values of type U\n *\n * ### Examples\n *\n * ```ts\n * type A = { a: 1; b: 2; c: 1 }\n * type Keys = KeysOfType<A, 1> // 'a' | 'c'\n * ```\n */\nexport type KeysOfType<T, U> = Exclude<{ [K in keyof T]: Same<T[K], U> extends true ? K : never }[keyof T], undefined>\n\n/**\n * Extracts the keys of type T that do not have values of type U\n *\n * ### Examples\n *\n * ```ts\n * type A = { a: 1; b: 2; c: 1 }\n * type Keys = KeysOfOtherType<A, 1> // 'b'\n * ```\n */\nexport type KeysOfOtherType<T, U> = Exclude<keyof T, KeysOfType<T, U>>\n"]}
|