inferred-types 0.36.4 → 0.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{index.mjs → index.js} +0 -0
- package/package.json +15 -21
- package/.eslintrc +0 -77
- package/.github/workflows/main.yml +0 -34
- package/.github/workflows/other.yml +0 -15
- package/.nvmrc +0 -1
- package/.prettierrc.js +0 -3
- package/.vscode/launch.json +0 -27
- package/.vscode/settings.json +0 -19
- package/devops/build.js +0 -243
- package/docs/builder-overview.md +0 -45
- package/docs/builder.md +0 -94
- package/src/errors/ReadOnlyViolation.ts +0 -3
- package/src/errors/index.ts +0 -12
- package/src/index.ts +0 -14
- package/src/runtime/README.md +0 -3
- package/src/runtime/api/api.ts +0 -10
- package/src/runtime/api/index.ts +0 -12
- package/src/runtime/builders/Model.ts +0 -25
- package/src/runtime/builders/url.ts +0 -15
- package/src/runtime/combinators/and.ts +0 -15
- package/src/runtime/combinators/filter.ts +0 -267
- package/src/runtime/combinators/index.ts +0 -4
- package/src/runtime/combinators/not.ts +0 -15
- package/src/runtime/combinators/or.ts +0 -5
- package/src/runtime/createFnWithProps.ts +0 -37
- package/src/runtime/dictionary/arrayToKeyLookup.ts +0 -19
- package/src/runtime/dictionary/defineProperties.ts +0 -35
- package/src/runtime/dictionary/dictArr.ts +0 -69
- package/src/runtime/dictionary/dictionaryTransform.ts +0 -22
- package/src/runtime/dictionary/entries.ts +0 -33
- package/src/runtime/dictionary/index.ts +0 -21
- package/src/runtime/dictionary/kv/dictToKv.ts +0 -21
- package/src/runtime/dictionary/kv/filterDictArray.ts +0 -31
- package/src/runtime/dictionary/kv/index.ts +0 -15
- package/src/runtime/dictionary/kv/kv.ts +0 -18
- package/src/runtime/dictionary/kv/kvToDict.ts +0 -24
- package/src/runtime/dictionary/mapTo.ts +0 -206
- package/src/runtime/dictionary/mapValues.ts +0 -23
- package/src/runtime/dictionary/merge.ts +0 -36
- package/src/runtime/dictionary/strArrayToDict.ts +0 -12
- package/src/runtime/index.ts +0 -23
- package/src/runtime/keys.ts +0 -16
- package/src/runtime/lists/asArray.ts +0 -38
- package/src/runtime/lists/createConverter.ts +0 -62
- package/src/runtime/lists/groupBy.ts +0 -15
- package/src/runtime/lists/index.ts +0 -15
- package/src/runtime/literals/ExplicitFunction.ts +0 -10
- package/src/runtime/literals/Suggest.ts +0 -19
- package/src/runtime/literals/arrayToObject.ts +0 -78
- package/src/runtime/literals/box.ts +0 -98
- package/src/runtime/literals/defineType.ts +0 -20
- package/src/runtime/literals/ensureLeading.ts +0 -17
- package/src/runtime/literals/ensureTrailing.ts +0 -17
- package/src/runtime/literals/identity.ts +0 -12
- package/src/runtime/literals/index.ts +0 -23
- package/src/runtime/literals/literal.ts +0 -48
- package/src/runtime/literals/pathJoin.ts +0 -33
- package/src/runtime/literals/stripLeading.ts +0 -15
- package/src/runtime/literals/stripTrailing.ts +0 -15
- package/src/runtime/literals/wide.ts +0 -13
- package/src/runtime/ruleset.ts +0 -42
- package/src/runtime/runtime/README.md +0 -3
- package/src/runtime/runtime/condition.ts +0 -13
- package/src/runtime/runtime/index.ts +0 -16
- package/src/runtime/runtime/type.ts +0 -127
- package/src/runtime/runtime/withValue.ts +0 -39
- package/src/runtime/state/Configurator.ts +0 -76
- package/src/runtime/state/FluentConfigurator.ts +0 -49
- package/src/runtime/state/index.ts +0 -13
- package/src/runtime/type-checks/ifSameType.ts +0 -20
- package/src/runtime/type-checks/ifTypeOf.ts +0 -124
- package/src/runtime/type-checks/index.ts +0 -24
- package/src/runtime/type-checks/isArray.ts +0 -34
- package/src/runtime/type-checks/isBoolean.ts +0 -24
- package/src/runtime/type-checks/isFalse.ts +0 -29
- package/src/runtime/type-checks/isFunction.ts +0 -26
- package/src/runtime/type-checks/isNull.ts +0 -26
- package/src/runtime/type-checks/isNumber.ts +0 -20
- package/src/runtime/type-checks/isObject.ts +0 -22
- package/src/runtime/type-checks/isString.ts +0 -34
- package/src/runtime/type-checks/isSymbol.ts +0 -3
- package/src/runtime/type-checks/isTrue.ts +0 -31
- package/src/runtime/type-checks/isUndefined.ts +0 -33
- package/src/runtime/type-checks/startsWith.ts +0 -107
- package/src/runtime/valueTypes.ts +0 -48
- package/src/types/Api.ts +0 -16
- package/src/types/Constructor.ts +0 -5
- package/src/types/EnumValues.ts +0 -14
- package/src/types/ExpandRecursively.ts +0 -12
- package/src/types/FunctionType.ts +0 -19
- package/src/types/If.ts +0 -10
- package/src/types/Include.ts +0 -18
- package/src/types/KeyedRecord.ts +0 -21
- package/src/types/Keys.ts +0 -26
- package/src/types/Length.ts +0 -8
- package/src/types/Mutable.ts +0 -8
- package/src/types/Narrowable.ts +0 -5
- package/src/types/Not.ts +0 -13
- package/src/types/Numeric.ts +0 -20
- package/src/types/Opaque.ts +0 -11
- package/src/types/README.md +0 -3
- package/src/types/Retain.ts +0 -16
- package/src/types/SimplifyObject.ts +0 -12
- package/src/types/Transformer.ts +0 -15
- package/src/types/TypeGuard.ts +0 -7
- package/src/types/Where.ts +0 -40
- package/src/types/alphabetic/AllCaps.ts +0 -15
- package/src/types/alphabetic/CamelCase.ts +0 -3
- package/src/types/alphabetic/CapFirstAlpha.ts +0 -23
- package/src/types/alphabetic/CapitalizeWords.ts +0 -9
- package/src/types/alphabetic/Cardinality.ts +0 -80
- package/src/types/alphabetic/DashToSnake.ts +0 -3
- package/src/types/alphabetic/DashUppercase.ts +0 -19
- package/src/types/alphabetic/Dasherize.ts +0 -23
- package/src/types/alphabetic/EnsureLeading.ts +0 -24
- package/src/types/alphabetic/EnsureTrailing.ts +0 -24
- package/src/types/alphabetic/HasUppercase.ts +0 -16
- package/src/types/alphabetic/IsCapitalized.ts +0 -18
- package/src/types/alphabetic/KebabCase.ts +0 -13
- package/src/types/alphabetic/LowerAllCaps.ts +0 -5
- package/src/types/alphabetic/PascalCase.ts +0 -29
- package/src/types/alphabetic/PathJoin.ts +0 -54
- package/src/types/alphabetic/Pluralize.ts +0 -112
- package/src/types/alphabetic/SnakeCase.ts +0 -27
- package/src/types/alphabetic/StripLeading.ts +0 -23
- package/src/types/alphabetic/StripTrailing.ts +0 -23
- package/src/types/alphabetic/Url.ts +0 -29
- package/src/types/alphabetic/alpha-characters.ts +0 -81
- package/src/types/alphabetic/index.ts +0 -32
- package/src/types/append-types.ts +0 -10
- package/src/types/boolean-logic/EndsWith.ts +0 -40
- package/src/types/boolean-logic/Extends.ts +0 -22
- package/src/types/boolean-logic/HasParameters.ts +0 -21
- package/src/types/boolean-logic/Includes.ts +0 -33
- package/src/types/boolean-logic/IsLiteral.ts +0 -101
- package/src/types/boolean-logic/IsScalar.ts +0 -20
- package/src/types/boolean-logic/IsUndefined.ts +0 -20
- package/src/types/boolean-logic/Or.ts +0 -12
- package/src/types/boolean-logic/StartsWith.ts +0 -42
- package/src/types/boolean-logic/TypeDefault.ts +0 -58
- package/src/types/boolean-logic/array.ts +0 -57
- package/src/types/boolean-logic/boolean.ts +0 -84
- package/src/types/boolean-logic/equivalency.ts +0 -15
- package/src/types/boolean-logic/index.ts +0 -14
- package/src/types/boolean-logic/object.ts +0 -30
- package/src/types/boolean-logic/string.ts +0 -21
- package/src/types/dictionary/DictChangeValue.ts +0 -34
- package/src/types/dictionary/DictPartialApplication.ts +0 -30
- package/src/types/dictionary/DictPrependWithFn.ts +0 -23
- package/src/types/dictionary/DictReturnValues.ts +0 -27
- package/src/types/dictionary/Get.ts +0 -14
- package/src/types/dictionary/MapTo.ts +0 -428
- package/src/types/dictionary/MutableProps.ts +0 -19
- package/src/types/dictionary/RequireProps.ts +0 -15
- package/src/types/dictionary/SameKeys.ts +0 -11
- package/src/types/dictionary/index.ts +0 -21
- package/src/types/dictionary/props.ts +0 -145
- package/src/types/fluent/fluent.ts +0 -61
- package/src/types/fluent/index.ts +0 -12
- package/src/types/functions/FinalReturn.ts +0 -12
- package/src/types/functions/LogicFunction.ts +0 -4
- package/src/types/functions/index.ts +0 -13
- package/src/types/index.ts +0 -49
- package/src/types/kv/DictFromKv.ts +0 -3
- package/src/types/kv/KeyValue.ts +0 -12
- package/src/types/kv/KvFrom.ts +0 -8
- package/src/types/kv/KvTuple.ts +0 -14
- package/src/types/kv/index.ts +0 -15
- package/src/types/lists/AfterFirst.ts +0 -10
- package/src/types/lists/ConvertAndMap.ts +0 -151
- package/src/types/lists/FilterTuple.ts +0 -20
- package/src/types/lists/First.ts +0 -8
- package/src/types/lists/FirstString.ts +0 -4
- package/src/types/lists/Split.ts +0 -21
- package/src/types/lists/UniqueForProp.ts +0 -18
- package/src/types/lists/index.ts +0 -18
- package/src/types/literal-unions/OptRequired.ts +0 -4
- package/src/types/literal-unions/index.ts +0 -1
- package/src/types/maybe.ts +0 -9
- package/src/types/ruleset-types.ts +0 -76
- package/src/types/runtime.ts +0 -39
- package/src/types/string-literals/Break.ts +0 -22
- package/src/types/string-literals/Concat.ts +0 -9
- package/src/types/string-literals/LeftWhitespace.ts +0 -13
- package/src/types/string-literals/Replace.ts +0 -17
- package/src/types/string-literals/RightWhitespace.ts +0 -13
- package/src/types/string-literals/StringLength.ts +0 -34
- package/src/types/string-literals/Trim.ts +0 -15
- package/src/types/string-literals/TrimLeft.ts +0 -14
- package/src/types/string-literals/TrimRight.ts +0 -14
- package/src/types/string-literals/form-fields.ts +0 -15
- package/src/types/string-literals/index.ts +0 -21
- package/src/types/tuples/DictArray.ts +0 -21
- package/src/types/tuples/FirstKey.ts +0 -10
- package/src/types/tuples/FirstKeyValue.ts +0 -9
- package/src/types/tuples/FirstOfEach.ts +0 -13
- package/src/types/tuples/FromDictArray.ts +0 -14
- package/src/types/tuples/SecondOfEach.ts +0 -13
- package/src/types/tuples/index.ts +0 -17
- package/src/types/type-conversion/TupleToUnion.ts +0 -9
- package/src/types/type-conversion/UnionToIntersection.ts +0 -9
- package/src/types/type-conversion/UnionToTuple.ts +0 -20
- package/src/types/type-conversion/Widen.ts +0 -22
- package/src/types/type-conversion/index.ts +0 -16
- package/src/types/type-testing.ts +0 -14
- package/tests/CamelCase-spec.ts +0 -20
- package/tests/Configurator-spec.hold +0 -106
- package/tests/ExplicitFunction-spec.ts +0 -50
- package/tests/IncludeAndRetain-spec.ts +0 -67
- package/tests/Includes-spec.ts +0 -36
- package/tests/KebabCase-spec.ts +0 -21
- package/tests/PascalCase-spec.ts +0 -22
- package/tests/Pluralize-spec.ts +0 -23
- package/tests/SnakeCase-spec.ts +0 -21
- package/tests/Where.spec.ts +0 -38
- package/tests/arrayToKeyLookup-spec.ts +0 -17
- package/tests/arrayToObject-spec.ts +0 -115
- package/tests/boolean-logic/Contains.test.ts +0 -55
- package/tests/boolean-logic/HasParameters.ts +0 -29
- package/tests/boolean-logic/IsLiteral.spec.ts +0 -65
- package/tests/boolean-logic/boolean.spec.ts +0 -21
- package/tests/boolean-logic/filter.spec.ts +0 -52
- package/tests/constructor.spec.ts +0 -42
- package/tests/createFnWithProps.spec.ts +0 -14
- package/tests/data/SimpleTable.hold +0 -21
- package/tests/data/index.ts +0 -12
- package/tests/data/playlist.hold +0 -25
- package/tests/data/song.hold +0 -23
- package/tests/defineType-spec.ts +0 -57
- package/tests/dictionary/DictChangeValue.test.ts +0 -30
- package/tests/dictionary/DictPartialApplication.test.ts +0 -43
- package/tests/dictionary/DictReturnValues.test.ts +0 -36
- package/tests/dictionary/Get.spec.ts +0 -28
- package/tests/dictionary/IntersectingKeys.test.ts +0 -42
- package/tests/dictionary/MutableProps.test.ts +0 -30
- package/tests/dictionary/OptionalKeys.test.ts +0 -24
- package/tests/dictionary/PrependValuesWithFunction.test.ts +0 -34
- package/tests/dictionary/RequireProps.test.ts +0 -21
- package/tests/dictionary/RequiredKeys.test.ts +0 -53
- package/tests/dictionary/TypeDefault.test.ts +0 -76
- package/tests/dictionary/mapTo.test.ts +0 -388
- package/tests/dictionary/merge.test.ts +0 -41
- package/tests/dictionaryTransform-spec.ts +0 -280
- package/tests/ifTypeOf-spec.ts +0 -191
- package/tests/kv/KeyValue-spec.ts +0 -22
- package/tests/kv/SameKeys-spec.ts +0 -35
- package/tests/kv/dict-to-kv-and-back.spec.ts +0 -169
- package/tests/kv/entries-spec.ts +0 -65
- package/tests/kv/keys.spec.ts +0 -66
- package/tests/kv/kv-spec.ts +0 -20
- package/tests/lists/First.test.ts +0 -43
- package/tests/lists/Length.test.ts +0 -19
- package/tests/lists/Split.test.ts +0 -29
- package/tests/lists/UniqueForProp.spec.ts +0 -59
- package/tests/lists/asArray.test.ts +0 -109
- package/tests/lists/dictArr.test.ts +0 -110
- package/tests/literal-spec.ts +0 -82
- package/tests/literals/AllCaps.spec.ts +0 -33
- package/tests/literals/CamelCase.spec.ts +0 -109
- package/tests/literals/Dasherize.spec.ts +0 -107
- package/tests/literals/EnsureStripLeadingTrailing.test.ts +0 -79
- package/tests/literals/HasUppercase.spec.ts +0 -33
- package/tests/literals/PascalCase.spec.ts +0 -109
- package/tests/literals/PathJoin.test.ts +0 -111
- package/tests/literals/SnakeCase.spec.ts +0 -109
- package/tests/literals/box.test.ts +0 -85
- package/tests/literals/whitespace-capture.spec.ts +0 -60
- package/tests/mapValues-spec.ts +0 -50
- package/tests/props-spec.ts +0 -234
- package/tests/runtime/condition.spec.ts +0 -19
- package/tests/runtime/if-is.spec.ts +0 -390
- package/tests/runtime/map-and-convert.test.ts +0 -31
- package/tests/runtime/type.spec.ts +0 -190
- package/tests/strArrayToDict-spec.ts +0 -40
- package/tests/tuples/TupleToUnion.spec.ts +0 -20
- package/tests/withValue.spec.ts +0 -173
- package/tsconfig.json +0 -36
- package/vitest.config.ts +0 -17
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Narrowable } from "src/types/Narrowable";
|
|
2
|
-
|
|
3
|
-
export type ValueTuple = [type: any, narrowable: boolean];
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* An API surface for choosing a **type** which is defined for run-time
|
|
7
|
-
* use but is translatable to the type system as well.
|
|
8
|
-
*/
|
|
9
|
-
export type ValueTypes = {
|
|
10
|
-
string: [string, false];
|
|
11
|
-
boolean: [];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const valueTypes = {
|
|
15
|
-
// WIDE
|
|
16
|
-
string: ["" as string, false] as [string, false],
|
|
17
|
-
boolean: [true as boolean, false] as [boolean, false],
|
|
18
|
-
number: [0 as number, false] as [number, false],
|
|
19
|
-
function: [(() => "") as Function, false] as [Function, false],
|
|
20
|
-
object: [{}, false] as [Record<string, any>, false],
|
|
21
|
-
array: <T extends any>(arr: T[] = [] as T[]) => [arr, false] as [T[], false],
|
|
22
|
-
null: [null, false] as [null, false],
|
|
23
|
-
symbol: [Symbol("type") as Symbol, false] as [Symbol, false],
|
|
24
|
-
undefined: [undefined, false] as [undefined, false],
|
|
25
|
-
// NARROW
|
|
26
|
-
true: [true as true, true] as [true, true],
|
|
27
|
-
false: [false as false, true] as [false, true],
|
|
28
|
-
/** pass in a literal type */
|
|
29
|
-
literal: <
|
|
30
|
-
N extends Narrowable,
|
|
31
|
-
T extends Record<any, N> | number | string | boolean | symbol | undefined | null
|
|
32
|
-
>(
|
|
33
|
-
v: T
|
|
34
|
-
) => {
|
|
35
|
-
return [v as T, true] as [T, true];
|
|
36
|
-
},
|
|
37
|
-
literalArray: <
|
|
38
|
-
N extends Narrowable,
|
|
39
|
-
T extends Record<any, N> | number | string | boolean | symbol | undefined | null
|
|
40
|
-
>(
|
|
41
|
-
arr: T[]
|
|
42
|
-
) => [arr, true],
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type ValueTypeFunc<
|
|
46
|
-
N extends Narrowable,
|
|
47
|
-
T extends Record<any, N> | number | string | boolean | symbol | null | Function
|
|
48
|
-
> = (v: ValueTypes) => [T, boolean];
|
package/src/types/Api.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type ApiFunction<P extends any[], R extends any> = (...args: P) => R;
|
|
2
|
-
export type FluentFunction<P extends any[], R extends any> = (...args: P) => R;
|
|
3
|
-
export type ApiValue<V extends any> = V;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Expresses the API in a structured manner while making distinction
|
|
7
|
-
* between a function endpoint and a _fluent_ function endpoint.
|
|
8
|
-
*/
|
|
9
|
-
export type Api<T extends object> = {
|
|
10
|
-
[K in keyof T]: T[K] extends (...args: any) => T
|
|
11
|
-
? FluentFunction<Parameters<T[K]>, ReturnType<T[K]>>
|
|
12
|
-
: T[K] extends (...args: any) => any
|
|
13
|
-
? ApiFunction<Parameters<T[K]>, ReturnType<T[K]>>
|
|
14
|
-
: ApiValue<T[K]>
|
|
15
|
-
};
|
|
16
|
-
|
package/src/types/Constructor.ts
DELETED
package/src/types/EnumValues.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provides the values of an Typescript **enum**:
|
|
3
|
-
* ```ts
|
|
4
|
-
* enum Foo { foo, bar, baz };
|
|
5
|
-
* // "0" | "1" | "2"
|
|
6
|
-
* type NumerericEnum = EnumValues<Foo>;
|
|
7
|
-
* enum Bar { foo = "foey", bar = "barred" };
|
|
8
|
-
* // "foey" | "barred"
|
|
9
|
-
* type StringEnum = EnumValues<Bar>;
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* **Note:** combine with `Numeric` to get number based indexes
|
|
13
|
-
*/
|
|
14
|
-
export type EnumValues<T extends string | number> = `${T}`;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Recursively goes over an object based structure and tries to reduce
|
|
4
|
-
* it down to just a simple key/value type.
|
|
5
|
-
*/
|
|
6
|
-
export type ExpandRecursively<T> = T extends object
|
|
7
|
-
? T extends (...args: any[]) => any
|
|
8
|
-
// Functions should be treated like any other non-object value
|
|
9
|
-
// but will/can identify as an object in JS
|
|
10
|
-
? T
|
|
11
|
-
: { [K in keyof T]: ExpandRecursively<T[K]> }
|
|
12
|
-
: T;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* **FunctionType**
|
|
3
|
-
*
|
|
4
|
-
* Provides a way to correctly match for regular functions _and_ functions which
|
|
5
|
-
* also have a dictionary hash alongside the root function.
|
|
6
|
-
*
|
|
7
|
-
* - without the generic `T` specified it simply matches correctly on both plain functions as well as functions which also have properties on them (this is consistent to how runtime's `typeof` operator works)
|
|
8
|
-
* - with the generic you can specify the shape of the key/values
|
|
9
|
-
*/
|
|
10
|
-
export type FunctionType<T extends {} = {}> = {} extends T
|
|
11
|
-
? Function | (Function & { [key: string]: any })
|
|
12
|
-
: Function | (Function & T);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* **FnShape**
|
|
16
|
-
*
|
|
17
|
-
* Simple way to express the shape of a function's arguments and return type.
|
|
18
|
-
*/
|
|
19
|
-
export type FnShape<A extends any[] = any[], R extends any = any> = (...args: A) => R;
|
package/src/types/If.ts
DELETED
package/src/types/Include.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* **Include<T, U, L>**
|
|
3
|
-
*
|
|
4
|
-
* _Allows_ any value `T` which extends `U` otherwise sets type to `never`. Normally, you'll just ignore
|
|
5
|
-
* the `L` generic but if need the comparison to be literal you can set to `true`:
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* const foo: "foo" = "foo";
|
|
9
|
-
* // "foo"
|
|
10
|
-
* type Normal = Include<typeof foo, string>;
|
|
11
|
-
* // L1 is never, L2 is "foo"
|
|
12
|
-
* type L1 = Include<typeof foo, string, true>;
|
|
13
|
-
* type L2 = Include<typeof foo, "foo", true>;
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export type Include<T, U, L extends boolean = false> = L extends true
|
|
17
|
-
? T extends U ? U extends T ? T : never : never
|
|
18
|
-
: T extends U ? T : never;
|
package/src/types/KeyedRecord.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A "KeyedRecord" is intended to store a value without
|
|
3
|
-
* losing any ability to infer type information later.
|
|
4
|
-
*
|
|
5
|
-
* The structure is always represented as a two-key
|
|
6
|
-
* dictionary, where one key is always `__key` and the value
|
|
7
|
-
* of this key points to the second key.
|
|
8
|
-
*
|
|
9
|
-
* For example:
|
|
10
|
-
* ```ts
|
|
11
|
-
* const song: KeyedRecord = { __key: "song", song: XXX }
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export type KeyedRecord<
|
|
15
|
-
K extends string,
|
|
16
|
-
V extends any,
|
|
17
|
-
T extends { __key: K } = { __key: K },
|
|
18
|
-
U extends keyof T = keyof T & K
|
|
19
|
-
> = {
|
|
20
|
-
[X in U]: T[X];
|
|
21
|
-
} & { K: V };
|
package/src/types/Keys.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A Utility class that provides the same functionality as the built-in
|
|
3
|
-
* `keyof` TS operator but can also:
|
|
4
|
-
*
|
|
5
|
-
* - receive an array of strings and convert that into a union type.
|
|
6
|
-
* - you can exclude literal string from the returned result
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* const t1 = { foo: 1, bar: 2 };
|
|
10
|
-
* // "foo" | "bar"
|
|
11
|
-
* type K = Keys<typeof t1>;
|
|
12
|
-
* const t2 = ["foo", "bar"] as const;
|
|
13
|
-
* // "foo" | "bar"
|
|
14
|
-
* type K = Keys<typeof t2>;
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export type Keys<
|
|
18
|
-
T extends Record<string, any> | readonly string[],
|
|
19
|
-
W extends string | undefined = undefined
|
|
20
|
-
> = T extends readonly string[]
|
|
21
|
-
? W extends string
|
|
22
|
-
? Exclude<T[number], W>
|
|
23
|
-
: T[number]
|
|
24
|
-
: W extends string
|
|
25
|
-
? Exclude<keyof T & string, W>
|
|
26
|
-
: keyof T & string;
|
package/src/types/Length.ts
DELETED
package/src/types/Mutable.ts
DELETED
package/src/types/Narrowable.ts
DELETED
package/src/types/Not.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provides a negation of a type of the type `T` _not_ `U`.
|
|
3
|
-
* ```ts
|
|
4
|
-
* const foo = 42;
|
|
5
|
-
* // 33
|
|
6
|
-
* type NotTheMeaningOfLife = Not<33, 42>;
|
|
7
|
-
* // never
|
|
8
|
-
* type NotTheMeaningOfLife = Not<42, 42>;
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* Note: same as `Exclude`
|
|
12
|
-
*/
|
|
13
|
-
export type Not<T, U> = T extends U ? never : T;
|
package/src/types/Numeric.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
type Digital = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
2
|
-
type MakeArray<S extends string, T extends any[] = []> = S extends `${T["length"]}`
|
|
3
|
-
? T
|
|
4
|
-
: MakeArray<S, [...T, 0]>;
|
|
5
|
-
type Multiply10<T extends any[]> = [...T, ...T, ...T, ...T, ...T, ...T, ...T, ...T, ...T, ...T];
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Converts a string literal to a numeric literal
|
|
9
|
-
* ```ts
|
|
10
|
-
* // 0
|
|
11
|
-
* type Zero = Numeric<"0">;
|
|
12
|
-
* // 10
|
|
13
|
-
* type Ten = Numeric<"10">;
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export type Numeric<S extends string, T extends any[] = []> = S extends `${infer S1}${infer S2}`
|
|
17
|
-
? S1 extends Digital
|
|
18
|
-
? Numeric<S2, [...Multiply10<T>, ...MakeArray<S1>]>
|
|
19
|
-
: never
|
|
20
|
-
: T["length"];
|
package/src/types/Opaque.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* **Opaque**
|
|
4
|
-
*
|
|
5
|
-
* Create an opaque type, which hides its internal details from the public, and
|
|
6
|
-
* can only be created by being used explicitly.
|
|
7
|
-
*
|
|
8
|
-
* Note: taken from [type-fest](https://github.com/sindresorhus/type-fest/blob/main/source/opaque.d.ts)
|
|
9
|
-
* repo.
|
|
10
|
-
*/
|
|
11
|
-
export type Opaque<Type, Token = unknown> = Type & { readonly __opaque__: Token };
|
package/src/types/README.md
DELETED
package/src/types/Retain.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Include } from "./Include";
|
|
2
|
-
/**
|
|
3
|
-
* **Retain<T, K>**
|
|
4
|
-
*
|
|
5
|
-
* Reduces the type system to just the key/values which are represented in `K`.
|
|
6
|
-
* The `L` generic can largely be ignored unless you need _literal_ equality.
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* type Obj = { foo: 1, bar: number, baz: string };
|
|
10
|
-
* // { foo: 1, bar: number }
|
|
11
|
-
* type Retained = Retain<Obj, "foo" | "bar">;
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* **Note:** in essence this is the _opposite_ of `Exclude<T,K>`
|
|
15
|
-
*/
|
|
16
|
-
export type Retain<T, K extends keyof T> = Pick<T, Include<keyof T, K>>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ExpandRecursively } from "./ExpandRecursively";
|
|
2
|
-
import { UnionToIntersection } from "./type-conversion/UnionToIntersection";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Often when mutating the shape of an object you will end up with the union of a number of
|
|
6
|
-
* `Record<string, x>` and `Record<string, y>` which is messy to look at and take away meaning.
|
|
7
|
-
*
|
|
8
|
-
* This type utility will cleanup an object and return a simple dictionary definition for it.
|
|
9
|
-
*/
|
|
10
|
-
export type SimplifyObject<T extends {}> = ExpandRecursively<
|
|
11
|
-
UnionToIntersection<ExpandRecursively<T>>
|
|
12
|
-
>;
|
package/src/types/Transformer.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { SameKeys } from "./dictionary/SameKeys";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* **Transformer**
|
|
5
|
-
*
|
|
6
|
-
* A function responsible for transforming the _values_ of
|
|
7
|
-
* dictionary `I` into different _values_ for dictionary `O`.
|
|
8
|
-
*
|
|
9
|
-
* This type utility assumes that _keys_ of both dictionaries
|
|
10
|
-
* are the same.
|
|
11
|
-
*/
|
|
12
|
-
export type Transformer<I extends object, O extends SameKeys<I>, K extends keyof I = keyof I> = (
|
|
13
|
-
input: I,
|
|
14
|
-
key: K
|
|
15
|
-
) => O[K];
|
package/src/types/TypeGuard.ts
DELETED
package/src/types/Where.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Include } from "./Include";
|
|
2
|
-
/**
|
|
3
|
-
* Allows filtering down `T` to those which extend a given type `U`.
|
|
4
|
-
*
|
|
5
|
-
* - `T` is either a dictionary (where keys will be used to compare) or
|
|
6
|
-
* a readonly sting array.
|
|
7
|
-
* ```ts
|
|
8
|
-
* const arr = ["foo", "bar", "baz"];
|
|
9
|
-
* // "bar" | "baz"
|
|
10
|
-
* type BA = Where<typeof arr, `ba${string}`>;
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export type Where<
|
|
14
|
-
T extends Record<string, any> | readonly string[],
|
|
15
|
-
U
|
|
16
|
-
> = T extends readonly string[]
|
|
17
|
-
? Include<T[number], U>
|
|
18
|
-
: {
|
|
19
|
-
[K in keyof T]: K extends U ? K : never;
|
|
20
|
-
}[keyof T];
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Allows filtering down `T` to those which extend a given type `U`.
|
|
24
|
-
*
|
|
25
|
-
* - `T` is either a dictionary (where keys will be used to compare) or
|
|
26
|
-
* a readonly sting array.
|
|
27
|
-
* ```ts
|
|
28
|
-
* const arr = ["foo", "bar", "baz"];
|
|
29
|
-
* // "foo"
|
|
30
|
-
* type F = WhereNot<typeof arr, `ba${string}`>;
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export type WhereNot<
|
|
34
|
-
T extends Record<string, any> | readonly string[],
|
|
35
|
-
U
|
|
36
|
-
> = T extends readonly string[]
|
|
37
|
-
? Exclude<T[number], U>
|
|
38
|
-
: {
|
|
39
|
-
[K in keyof T]: K extends U ? never : K;
|
|
40
|
-
}[keyof T];
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Indicates whether `T` has _all_ uppercase characters in it.
|
|
4
|
-
* ```ts
|
|
5
|
-
* // true
|
|
6
|
-
* type T = AllCaps<"FOOBAR">;
|
|
7
|
-
* // false
|
|
8
|
-
* type T = AllCaps<"FooBar">;
|
|
9
|
-
* // "unknown"
|
|
10
|
-
* type T = AllCaps<string>;
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export type AllCaps<T extends string> = string extends T
|
|
14
|
-
? "unknown"
|
|
15
|
-
: T extends Uppercase<T> ? true : false;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Replace } from "../string-literals";
|
|
2
|
-
import { NonAlpha } from "./alpha-characters";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Strips the non-alpha characters that lead a string
|
|
6
|
-
*/
|
|
7
|
-
export type StripLeftNonAlpha<S extends string> = S extends `${infer First}${infer Rest}`
|
|
8
|
-
? First extends NonAlpha
|
|
9
|
-
? StripLeftNonAlpha<Rest>
|
|
10
|
-
: S
|
|
11
|
-
: never;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* identifies the leading characters which are _not_ alphabetical
|
|
15
|
-
*/
|
|
16
|
-
export type LeadingNonAlpha<S extends string> = Replace<S, StripLeftNonAlpha<S>, "">;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Capitalize the first alphabetical character in the string
|
|
20
|
-
*/
|
|
21
|
-
export type CapFirstAlpha<T extends string> = LeadingNonAlpha<T> extends string
|
|
22
|
-
? `${LeadingNonAlpha<T>}${Capitalize<Replace<T, LeadingNonAlpha<T>, "">>}`
|
|
23
|
-
: Capitalize<T>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Capitalize all words in a string
|
|
3
|
-
*/
|
|
4
|
-
export type CapitalizeWords<S extends string> =
|
|
5
|
-
S extends `${infer L} ${infer R}` ? `${CapitalizeWords<L>} ${CapitalizeWords<R>}` :
|
|
6
|
-
S extends `${infer L},${infer R}` ? `${CapitalizeWords<L>},${CapitalizeWords<R>}` :
|
|
7
|
-
S extends `${infer L}.${infer R}` ? `${CapitalizeWords<L>}.${CapitalizeWords<R>}` :
|
|
8
|
-
Capitalize<S>;
|
|
9
|
-
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { UnionToTuple } from "../type-conversion";
|
|
2
|
-
|
|
3
|
-
export type OneToOne = `1:1`;
|
|
4
|
-
export type OneToMany = `1:M`;
|
|
5
|
-
export type OneToZero = `1:0`;
|
|
6
|
-
export type ZeroToOne = `0:1`;
|
|
7
|
-
export type ZeroToMany = `0:M`;
|
|
8
|
-
export type ZeroToZero = `0:0`;
|
|
9
|
-
export type ManyToMany = "M:M";
|
|
10
|
-
export type ManyToOne = "M:1";
|
|
11
|
-
export type ManyToZero = "M:0";
|
|
12
|
-
|
|
13
|
-
export type CardinalityNode = "0" | "1" | "M";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Cardinality which expects a singular input and requires
|
|
17
|
-
* 1 or many outputs.
|
|
18
|
-
*
|
|
19
|
-
* Note: choose `CardinalityFilter1` if you want to allow output
|
|
20
|
-
* to have no outputs.
|
|
21
|
-
*/
|
|
22
|
-
export type Cardinality1 = OneToOne | OneToMany;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Cardinality which expects a singular input and maps to 0,
|
|
26
|
-
* 1, or many outputs.
|
|
27
|
-
*/
|
|
28
|
-
export type CardinalityFilter1 = OneToOne | OneToMany | OneToZero;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Cardinality which expects a singular input which is allowed to be
|
|
32
|
-
* _undefined_ or the expected type.
|
|
33
|
-
*/
|
|
34
|
-
export type Cardinality0 = ZeroToOne | ZeroToMany | OneToOne | OneToMany;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Cardinality which expects a singular input -- which is allowed to be
|
|
38
|
-
* _undefined_ -- and maps to 0,
|
|
39
|
-
* 1, or many outputs.
|
|
40
|
-
*/
|
|
41
|
-
export type CardinalityFilter0 =
|
|
42
|
-
| ZeroToOne
|
|
43
|
-
| ZeroToMany
|
|
44
|
-
| OneToOne
|
|
45
|
-
| OneToMany
|
|
46
|
-
| OneToZero
|
|
47
|
-
| ZeroToZero;
|
|
48
|
-
|
|
49
|
-
export type CardinalityExplicit = `${number}:${number}`;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Cardinality of any sort between two types
|
|
53
|
-
*/
|
|
54
|
-
export type Cardinality =
|
|
55
|
-
| CardinalityFilter0
|
|
56
|
-
| CardinalityFilter1
|
|
57
|
-
| ManyToMany
|
|
58
|
-
| ManyToOne
|
|
59
|
-
| ManyToZero
|
|
60
|
-
| CardinalityExplicit;
|
|
61
|
-
|
|
62
|
-
export type CardinalityTuple<T extends Cardinality> = UnionToTuple<T>;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The first or _input_ part of the Cardinality relationship
|
|
66
|
-
*/
|
|
67
|
-
export type CardinalityIn<T extends Cardinality> = T extends `${infer IN}:${string}` ? IN : never;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The second or _output_ part of the Cardinality relationship
|
|
71
|
-
*/
|
|
72
|
-
export type CardinalityOut<T extends Cardinality> = T extends `${string}:${infer OUT}`
|
|
73
|
-
? OUT
|
|
74
|
-
: never;
|
|
75
|
-
|
|
76
|
-
export type CardinalityInput<T, C extends Cardinality> = CardinalityTuple<C>[0] extends 0
|
|
77
|
-
? T | undefined
|
|
78
|
-
: CardinalityTuple<C>[0] extends 1
|
|
79
|
-
? T
|
|
80
|
-
: T[];
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HasUppercase } from "./HasUppercase";
|
|
2
|
-
|
|
3
|
-
type _DU<T extends string> = T extends Lowercase<T> ? T : `-${Lowercase<T>}`;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Converts uppercase characters to a dash and then the lowercase equivalent
|
|
7
|
-
* ```ts
|
|
8
|
-
* // "one-two-three"
|
|
9
|
-
* type T = DashUppercase<"oneTwoThree">;
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* _Intended to be used as a lower level utility; prefer `Dasherize<T>` for more full-fledged
|
|
13
|
-
* dash solution_.
|
|
14
|
-
*/
|
|
15
|
-
export type DashUppercase<T extends string> = HasUppercase<T> extends false ? T :
|
|
16
|
-
T extends `${infer C0}${infer C1}${infer R}` ?
|
|
17
|
-
`${_DU<C0>}${_DU<C1>}${DashUppercase<R>}` :
|
|
18
|
-
T extends `${infer C0}${infer R}` ? `${_DU<C0>}${DashUppercase<R>}` :
|
|
19
|
-
"";
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
|
|
3
|
-
import { Trim } from "../string-literals";
|
|
4
|
-
import { DashUppercase } from "./DashUppercase";
|
|
5
|
-
import { LowerAllCaps } from "./LowerAllCaps";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Converts a string literal into a _dasherized_ format while ignoring _exterior_ whitespace.
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* // "foo-bar"
|
|
12
|
-
* type Dash = Dasherize<"foo_bar">;
|
|
13
|
-
* type Dash = Dasherize<"fooBar">;
|
|
14
|
-
* type Dash = Dasherize<"FooBar">;
|
|
15
|
-
* // "\n foo-bar \t"
|
|
16
|
-
* type Dash = Dasherize<"\n foo bar \t">;
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export type Dasherize<S extends string> = string extends S
|
|
20
|
-
? string
|
|
21
|
-
: DashUppercase<Trim<LowerAllCaps<S>>> extends `${infer Begin}${"_" | " "}${infer Rest}`
|
|
22
|
-
? Dasherize<`${Lowercase<Begin>}-${Rest}`>
|
|
23
|
-
: Lowercase<DashUppercase<Uncapitalize<Trim<LowerAllCaps<S>>>>>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { IfLiteral } from "../boolean-logic/IsLiteral";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* **EnsureLeading**`<T, U>`
|
|
5
|
-
*
|
|
6
|
-
* Will ensure that `T` ends with the _substring_ `U` when
|
|
7
|
-
* both are string literals.
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* type T = " World";
|
|
11
|
-
* type U = "Hello";
|
|
12
|
-
* // "Hello World"
|
|
13
|
-
* type R = EnsureLeading<T,U>;
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export type EnsureLeading<T extends string, U extends string> = IfLiteral<
|
|
17
|
-
// can only operate on literal strings
|
|
18
|
-
T,
|
|
19
|
-
// this path represents successful strip opp
|
|
20
|
-
// but we must never accept `U` being wide
|
|
21
|
-
string extends U ? never : T extends `${U}${string}` ? T : `${U}${T}`,
|
|
22
|
-
// here we must stay wide
|
|
23
|
-
string
|
|
24
|
-
>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { IfLiteral } from "../boolean-logic/IsLiteral";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* **EnsureTrailing**`<T, U>`
|
|
5
|
-
*
|
|
6
|
-
* Will ensure that `T` ends with the substring `U` when
|
|
7
|
-
* both are string literals.
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* type T = "Hello";
|
|
11
|
-
* type U = " World";
|
|
12
|
-
* // "Hello World"
|
|
13
|
-
* type R = EnsureTrailing<T,U>;
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export type EnsureTrailing<T extends string, U extends string> = IfLiteral<
|
|
17
|
-
// can only operate on literal strings
|
|
18
|
-
T,
|
|
19
|
-
// this path represents successful strip opp
|
|
20
|
-
// but we must never accept `U` being wide
|
|
21
|
-
string extends U ? never : T extends `${string}${U}` ? T : `${T}${U}`,
|
|
22
|
-
// here we must stay wide
|
|
23
|
-
string
|
|
24
|
-
>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { UpperAlpha } from "./alpha-characters";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Indicates whether `T` has uppercase characters in it.
|
|
5
|
-
* ```ts
|
|
6
|
-
* // true
|
|
7
|
-
* type T = HasUppercase<"Foobar">;
|
|
8
|
-
* // false
|
|
9
|
-
* type T = HasUppercase<"foobar">;
|
|
10
|
-
* // "unknown"
|
|
11
|
-
* type T = HasUppercase<string>;
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export type HasUppercase<T extends string> = string extends T
|
|
15
|
-
? "unknown"
|
|
16
|
-
: T extends `${string}${UpperAlpha}${string}` ? true : false;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns true or false value based on whether the string literal is capitalized.
|
|
3
|
-
* ```ts
|
|
4
|
-
* // true
|
|
5
|
-
* type T2 = IsCapitalized<"One">;
|
|
6
|
-
* // false
|
|
7
|
-
* type T1 = IsCapitalized<"one">;
|
|
8
|
-
* // "unknown"
|
|
9
|
-
* const a: string = "Hi";
|
|
10
|
-
* type T3 = IsCapitalized<typeof a>;
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Note: _if the value passed in is a "string" then the result will be "unknown"_
|
|
14
|
-
*/
|
|
15
|
-
export type IsCapitalized<T extends string> = string extends T
|
|
16
|
-
? "unknown"
|
|
17
|
-
: T extends Capitalize<T> ? true : false;
|
|
18
|
-
|