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,13 +0,0 @@
|
|
|
1
|
-
import { Dasherize } from "./Dasherize";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* **KebabCase<T>** is an _alias_ for **Dasherize<T>**.
|
|
5
|
-
* ```ts
|
|
6
|
-
* // "foo-bar"
|
|
7
|
-
* type Kebab = KebabCase<"foo_bar">;
|
|
8
|
-
* type Kebab = KebabCase<"fooBar">;
|
|
9
|
-
* type Kebab = KebabCase<"FooBar">;
|
|
10
|
-
* // "\n foo-bar \t"
|
|
11
|
-
* type Kebab = KebabCase<"\n foo bar \t">;
|
|
12
|
-
* ``` */
|
|
13
|
-
export type KebabCase<T extends string> = Dasherize<T>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-unused-vars: "off" */
|
|
2
|
-
|
|
3
|
-
import { Trim } from "../string-literals";
|
|
4
|
-
import { LowerAllCaps } from "./LowerAllCaps";
|
|
5
|
-
|
|
6
|
-
type Delimiter = "_" | "-" | " ";
|
|
7
|
-
|
|
8
|
-
/** convert all delimiters to dashes */
|
|
9
|
-
type DashDelim<T extends string> = T extends `${infer Begin}${" "}${infer Rest}`
|
|
10
|
-
? DashDelim<`${Begin}-${Rest}`>
|
|
11
|
-
: T extends `${infer Begin}${"_"}${infer Rest}`
|
|
12
|
-
? DashDelim<`${Begin}-${Rest}`>
|
|
13
|
-
: T;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Converts a string literal type to a **PascalCase** representation.
|
|
17
|
-
* ```ts
|
|
18
|
-
* // "FooBar"
|
|
19
|
-
* type T = PascalCase<"fooBar">;
|
|
20
|
-
* type T = PascalCase<"foo-bar">;
|
|
21
|
-
* type T = PascalCase<"foo_bar">;
|
|
22
|
-
* type T = PascalCase<"\n foo_bar \t">;
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export type PascalCase<S extends string> = string extends S
|
|
26
|
-
? string
|
|
27
|
-
: Trim<DashDelim<LowerAllCaps<S>>> extends `${infer Begin}${Delimiter}${infer Rest}`
|
|
28
|
-
? PascalCase<`${Capitalize<Begin>}${Capitalize<Rest>}`>
|
|
29
|
-
: Capitalize<Trim<LowerAllCaps<S>>>;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { IfLiteral } from "../boolean-logic";
|
|
2
|
-
import { AfterFirst, First } from "../lists";
|
|
3
|
-
import { StripTrailing } from "./StripTrailing";
|
|
4
|
-
import { StripLeading } from "./StripLeading";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* **PathJoin**`<T,U>`
|
|
8
|
-
*
|
|
9
|
-
* Type utility meant to bring 2 or more "path" strings together into
|
|
10
|
-
* a valid "path". Where a "path" is represented as nothing more than
|
|
11
|
-
* string characters delimited by a Posix `\` character.
|
|
12
|
-
*
|
|
13
|
-
* Note that the first part of the path will retain it's `\` if present
|
|
14
|
-
* and the last one will preserve it's `\` character if present. You can
|
|
15
|
-
* combine this utility with `EnsureTrailing<T>`, `StripTrailing<T>`,
|
|
16
|
-
* `EnsureStarting<T>`, and `StripStarting<T>` to further shape
|
|
17
|
-
* the type.
|
|
18
|
-
*/
|
|
19
|
-
export type PathJoin<
|
|
20
|
-
// leading string
|
|
21
|
-
T extends string,
|
|
22
|
-
// trailing string or strings
|
|
23
|
-
U extends string | readonly string[]
|
|
24
|
-
> = [] extends U
|
|
25
|
-
? T
|
|
26
|
-
: U extends readonly string[]
|
|
27
|
-
? // eslint-disable-next-line no-use-before-define
|
|
28
|
-
PathMultiJoin<PathJoin<T, "">, [...U]>
|
|
29
|
-
: U extends string
|
|
30
|
-
? IfLiteral<
|
|
31
|
-
T,
|
|
32
|
-
// Literal T guaranteed
|
|
33
|
-
IfLiteral<
|
|
34
|
-
// conditional
|
|
35
|
-
U,
|
|
36
|
-
`${StripTrailing<T, "/">}/${StripLeading<U, "/">}`,
|
|
37
|
-
`${StripTrailing<T, "/">}/${string}`
|
|
38
|
-
>,
|
|
39
|
-
// wide `T` encountered
|
|
40
|
-
IfLiteral<U, `${string}${U}`, string>
|
|
41
|
-
>
|
|
42
|
-
: never;
|
|
43
|
-
|
|
44
|
-
type PathMultiJoin<
|
|
45
|
-
TProcessed extends string,
|
|
46
|
-
TRemaining extends readonly string[]
|
|
47
|
-
> = [] extends TRemaining
|
|
48
|
-
? TProcessed
|
|
49
|
-
: PathMultiJoin<
|
|
50
|
-
// add to the TProcessed string
|
|
51
|
-
PathJoin<TProcessed, First<TRemaining>>,
|
|
52
|
-
// remaining elements after extracting head element
|
|
53
|
-
AfterFirst<TRemaining>
|
|
54
|
-
>;
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-unused-vars: "off" */
|
|
2
|
-
|
|
3
|
-
type Consonant =
|
|
4
|
-
| "b"
|
|
5
|
-
| "c"
|
|
6
|
-
| "d"
|
|
7
|
-
| "f"
|
|
8
|
-
| "g"
|
|
9
|
-
| "h"
|
|
10
|
-
| "j"
|
|
11
|
-
| "k"
|
|
12
|
-
| "l"
|
|
13
|
-
| "m"
|
|
14
|
-
| "n"
|
|
15
|
-
| "p"
|
|
16
|
-
| "q"
|
|
17
|
-
| "r"
|
|
18
|
-
| "s"
|
|
19
|
-
| "t"
|
|
20
|
-
| "v"
|
|
21
|
-
| "w"
|
|
22
|
-
| "x"
|
|
23
|
-
| "z"
|
|
24
|
-
| "y";
|
|
25
|
-
|
|
26
|
-
type Exceptions =
|
|
27
|
-
| "photo => photos"
|
|
28
|
-
| "piano => pianos"
|
|
29
|
-
| "halo => halos"
|
|
30
|
-
| "foot => feet"
|
|
31
|
-
| "man => men"
|
|
32
|
-
| "woman => women"
|
|
33
|
-
| "person => people"
|
|
34
|
-
| "mouse => mice"
|
|
35
|
-
| "series => series"
|
|
36
|
-
| "sheep => sheep"
|
|
37
|
-
| "money => monies"
|
|
38
|
-
| "deer => deer";
|
|
39
|
-
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
type SingularException<T = Exceptions> = T extends `${infer SINGULAR} => ${infer PLURAL}`
|
|
42
|
-
? SINGULAR
|
|
43
|
-
: never;
|
|
44
|
-
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
type PluralException<
|
|
47
|
-
T extends SingularException,
|
|
48
|
-
E extends Exceptions = Exceptions
|
|
49
|
-
> = E extends `${T} => ${infer PLURAL}` ? PLURAL : never;
|
|
50
|
-
|
|
51
|
-
type SingularNoun = "s" | "sh" | "ch" | "x" | "z" | "o";
|
|
52
|
-
type F = "f" | "fe";
|
|
53
|
-
type Y = `${Consonant}y`;
|
|
54
|
-
|
|
55
|
-
type RemoveTrailingY<T> = T extends `${infer HEAD}y` ? HEAD : T;
|
|
56
|
-
|
|
57
|
-
/** validates that a word ends with a pluralization exception */
|
|
58
|
-
type isException<T extends string> = T extends SingularException ? T : never;
|
|
59
|
-
|
|
60
|
-
/** validates that a string literal ends in "is" */
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
type EndsIn_IS<T extends string> = T extends `${infer HEAD}is` ? T : never;
|
|
63
|
-
|
|
64
|
-
/** validates that a string literal is a singular noun */
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
type EndsInSingularNoun<T extends string> = T extends `${infer HEAD}${SingularNoun}` ? T : never;
|
|
67
|
-
|
|
68
|
-
/** validates that a string literal ends in "f" or "fe" */
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
type EndsIn_F<T extends string> = T extends `${infer HEAD}${F}` ? T : never;
|
|
71
|
-
|
|
72
|
-
/** validates that a string literal ends a consonant followed by "y" */
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
type EndsIn_Y<T extends string> = T extends `${infer HEAD}${Y}` ? T : never;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* strings which end in the letters "is" should have an "es" added to the end
|
|
78
|
-
*/
|
|
79
|
-
type PluralizeEndingIn_IS<T extends string> = T extends `${infer HEAD}is` ? `${HEAD}ises` : T;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* singular nouns should have "es" added to the end
|
|
83
|
-
*/
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
type PluralizeEndingSingularNoun<T extends string> = T extends `${infer HEAD}${SingularNoun}`
|
|
86
|
-
? `${T}es`
|
|
87
|
-
: T;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* strings which end in the letters "f" or "fe" should have "ves" replace the ending
|
|
91
|
-
*/
|
|
92
|
-
type PluralizeEnding_F<T extends string> = T extends `${infer HEAD}${F}` ? `${HEAD}ves` : T;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* singular nouns should have "es" added to the end
|
|
96
|
-
*/
|
|
97
|
-
// @ts-ignore
|
|
98
|
-
type PluralizeEndingIn_Y<T extends string> = T extends `${infer HEAD}${Y}`
|
|
99
|
-
? `${RemoveTrailingY<T>}ies`
|
|
100
|
-
: T;
|
|
101
|
-
|
|
102
|
-
export type Pluralize<T extends string> = T extends isException<T>
|
|
103
|
-
? PluralException<T>
|
|
104
|
-
: T extends EndsIn_IS<T>
|
|
105
|
-
? PluralizeEndingIn_IS<T>
|
|
106
|
-
: T extends EndsInSingularNoun<T>
|
|
107
|
-
? PluralizeEndingSingularNoun<T>
|
|
108
|
-
: T extends EndsIn_F<T>
|
|
109
|
-
? PluralizeEnding_F<T>
|
|
110
|
-
: T extends EndsIn_Y<T>
|
|
111
|
-
? PluralizeEndingIn_Y<T>
|
|
112
|
-
: `${T}s`;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-unused-vars: "off" */
|
|
2
|
-
|
|
3
|
-
import { Trim } from "../string-literals";
|
|
4
|
-
import { DashUppercase } from "./DashUppercase";
|
|
5
|
-
import { LowerAllCaps } from "./LowerAllCaps";
|
|
6
|
-
|
|
7
|
-
/** convert space to dash */
|
|
8
|
-
type SpaceToDash<T extends string> = T extends `${infer Begin}${" "}${infer Rest}`
|
|
9
|
-
? SpaceToDash<`${Begin}-${Rest}`>
|
|
10
|
-
: T;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Converts a string literal type to _snake_case_.
|
|
14
|
-
* ```ts
|
|
15
|
-
* // "foo_bar"
|
|
16
|
-
* type T = SnakeCase<"fooBar">;
|
|
17
|
-
* type T = SnakeCase<"FooBar">;
|
|
18
|
-
* type T = SnakeCase<"foo-bar">;
|
|
19
|
-
* type T = SnakeCase<"\n foo bar \t">;
|
|
20
|
-
* ``` */
|
|
21
|
-
export type SnakeCase<S extends string> = string extends S
|
|
22
|
-
? string
|
|
23
|
-
: DashUppercase<
|
|
24
|
-
Uncapitalize<SpaceToDash<Trim<LowerAllCaps<S>>>>
|
|
25
|
-
> extends `${infer Begin}${"-"}${infer Rest}`
|
|
26
|
-
? SnakeCase<`${Lowercase<Begin>}_${Rest}`>
|
|
27
|
-
: Lowercase<DashUppercase<Uncapitalize<Trim<LowerAllCaps<S>>>>>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { IfLiteral } from "../boolean-logic/IsLiteral";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* **StripStarting**`<T, U>`
|
|
5
|
-
*
|
|
6
|
-
* Will strip off of `T` the starting string defined by `U` when
|
|
7
|
-
* both are string literals.
|
|
8
|
-
* ```ts
|
|
9
|
-
* type T = "Hello World";
|
|
10
|
-
* type U = "Hello ";
|
|
11
|
-
* // "World"
|
|
12
|
-
* type R = StripStarting<T,U>;
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export type StripLeading<T extends string, U extends string> = IfLiteral<
|
|
16
|
-
// can only operate on literal strings
|
|
17
|
-
T,
|
|
18
|
-
// this path represents successful strip opp
|
|
19
|
-
// but we must never accept `U` being wide
|
|
20
|
-
string extends U ? never : T extends `${U}${infer After}` ? After : T,
|
|
21
|
-
// here we must stay wide
|
|
22
|
-
string
|
|
23
|
-
>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { IfLiteral } from "../boolean-logic/IsLiteral";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* **StripEnding**`<T, U>`
|
|
5
|
-
*
|
|
6
|
-
* Will strip off of `T` the ending defined by `U` when
|
|
7
|
-
* both are string literals.
|
|
8
|
-
* ```ts
|
|
9
|
-
* type T = "Hello World";
|
|
10
|
-
* type U = " World";
|
|
11
|
-
* // "Hello"
|
|
12
|
-
* type R = StripEnding<T,U>;
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export type StripTrailing<T extends string, U extends string> = IfLiteral<
|
|
16
|
-
// can only operate on literal strings
|
|
17
|
-
T,
|
|
18
|
-
// this path represents successful strip opp
|
|
19
|
-
// but we must never accept `U` being wide
|
|
20
|
-
string extends U ? never : T extends `${infer Before}${U}` ? Before : T,
|
|
21
|
-
// here we must stay wide
|
|
22
|
-
string
|
|
23
|
-
>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { AlphaNumeric, Ipv4, VariableName } from "./alpha-characters";
|
|
2
|
-
|
|
3
|
-
export type NetworkProtocol = "http" | "https" | "file" | "ws" | "wss";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A literal variant of _string_ which is meant to represent a domain name
|
|
7
|
-
* (e.g., `www.someplace.com`, etc.)
|
|
8
|
-
*/
|
|
9
|
-
export type DomainName =
|
|
10
|
-
| `${AlphaNumeric}${string}.${AlphaNumeric}${string}`
|
|
11
|
-
| `${AlphaNumeric}${string}.${AlphaNumeric}${string}.${string}`
|
|
12
|
-
| `${AlphaNumeric}${string}.${AlphaNumeric}${string}.${string}.${string}`;
|
|
13
|
-
|
|
14
|
-
export type RelativeUrl = `${VariableName | "/"}`;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A literal variant of _string_ which forces a string to follow conventions
|
|
18
|
-
* for a fully qualified URL like `https://google.com`. It can't ensure the
|
|
19
|
-
* type is fully valid but does help to avoid some typos.
|
|
20
|
-
*/
|
|
21
|
-
export type FullyQualifiedUrl = `${NetworkProtocol}://${Ipv4 | DomainName}/${string}`;
|
|
22
|
-
|
|
23
|
-
export type UrlBuilder =
|
|
24
|
-
| (<P extends NetworkProtocol, D extends DomainName, B extends RelativeUrl>(
|
|
25
|
-
protocol: P,
|
|
26
|
-
domain: D,
|
|
27
|
-
basePath: B
|
|
28
|
-
) => `${P}://${D}/${B}`)
|
|
29
|
-
| (<U extends RelativeUrl>(url: U) => U);
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
export type LowerAlpha =
|
|
2
|
-
| "a"
|
|
3
|
-
| "b"
|
|
4
|
-
| "c"
|
|
5
|
-
| "d"
|
|
6
|
-
| "e"
|
|
7
|
-
| "f"
|
|
8
|
-
| "g"
|
|
9
|
-
| "h"
|
|
10
|
-
| "i"
|
|
11
|
-
| "j"
|
|
12
|
-
| "k"
|
|
13
|
-
| "l"
|
|
14
|
-
| "m"
|
|
15
|
-
| "n"
|
|
16
|
-
| "o"
|
|
17
|
-
| "p"
|
|
18
|
-
| "q"
|
|
19
|
-
| "r"
|
|
20
|
-
| "s"
|
|
21
|
-
| "t"
|
|
22
|
-
| "u"
|
|
23
|
-
| "v"
|
|
24
|
-
| "w"
|
|
25
|
-
| "x"
|
|
26
|
-
| "y"
|
|
27
|
-
| "z";
|
|
28
|
-
|
|
29
|
-
/** Uppercase alphabetic character */
|
|
30
|
-
export type UpperAlpha = Uppercase<LowerAlpha>;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Alphabetical characters (upper and lower)
|
|
34
|
-
*/
|
|
35
|
-
export type Alpha = UpperAlpha | LowerAlpha;
|
|
36
|
-
|
|
37
|
-
export type Whitespace = " " | "\n" | "\t";
|
|
38
|
-
|
|
39
|
-
export type Punctuation = "." | "," | ";" | "!" | "?";
|
|
40
|
-
/**
|
|
41
|
-
* Characters which typically are used to separate words (but not including a space)
|
|
42
|
-
*/
|
|
43
|
-
export type StringDelimiter = "_" | "-" | "/" | "\\";
|
|
44
|
-
|
|
45
|
-
export type OpeningBracket = "(" | "[" | "{";
|
|
46
|
-
export type ClosingBracket = ")" | "]" | "}";
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Opening and closing parenthesis
|
|
50
|
-
*/
|
|
51
|
-
export type Parenthesis = "(" | ")";
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Opening and closing brackets
|
|
55
|
-
*/
|
|
56
|
-
export type Bracket = OpeningBracket | ClosingBracket;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Numeric string characters
|
|
60
|
-
*/
|
|
61
|
-
export type NumericString = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Any alphabetic or numeric string character
|
|
65
|
-
*/
|
|
66
|
-
export type AlphaNumeric = Alpha | NumericString;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Allows alphanumeric characters and some special characters typically allowed
|
|
70
|
-
* in variable names.
|
|
71
|
-
*/
|
|
72
|
-
export type VariableName = AlphaNumeric | "_" | "." | "-";
|
|
73
|
-
|
|
74
|
-
export type SpecialCharacters = "@" | "~" | "^" | "#" | "&" | "*";
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Non-alphabetic characters including whitespace, string numerals, and
|
|
78
|
-
*/
|
|
79
|
-
export type NonAlpha = Whitespace | Punctuation | NumericString | Bracket | SpecialCharacters;
|
|
80
|
-
|
|
81
|
-
export type Ipv4 = `${number}.${number}.${number}.${number}`;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// #autoindex, exclude: Alpha
|
|
2
|
-
// #region auto-indexed files
|
|
3
|
-
// index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
|
|
4
|
-
// hash-code: b32382ed
|
|
5
|
-
|
|
6
|
-
// file exports
|
|
7
|
-
export * from "./AllCaps";
|
|
8
|
-
export * from "./CamelCase";
|
|
9
|
-
export * from "./CapitalizeWords";
|
|
10
|
-
export * from "./DashToSnake";
|
|
11
|
-
export * from "./DashUppercase";
|
|
12
|
-
export * from "./Cardinality";
|
|
13
|
-
export * from "./Dasherize";
|
|
14
|
-
export * from "./HasUppercase";
|
|
15
|
-
export * from "./EnsureLeading";
|
|
16
|
-
export * from "./EnsureTrailing";
|
|
17
|
-
export * from "./IsCapitalized";
|
|
18
|
-
export * from "./KebabCase";
|
|
19
|
-
export * from "./LowerAllCaps";
|
|
20
|
-
export * from "./PascalCase";
|
|
21
|
-
export * from "./PathJoin";
|
|
22
|
-
export * from "./Pluralize";
|
|
23
|
-
export * from "./SnakeCase";
|
|
24
|
-
export * from "./StripLeading";
|
|
25
|
-
export * from "./StripTrailing";
|
|
26
|
-
export * from "./alpha-characters";
|
|
27
|
-
export * from "./Url";
|
|
28
|
-
|
|
29
|
-
// #endregion auto-indexed files
|
|
30
|
-
|
|
31
|
-
// see https://github.com/inocan-group/do-devops/docs/autoindex.md
|
|
32
|
-
// for more info
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type AppendToObject<T, U extends keyof any, V> = {
|
|
2
|
-
[K in keyof T | U]: K extends keyof T ? T[K] : V;
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Appends a new Key/Value to an existing dictionary <T>
|
|
7
|
-
*/
|
|
8
|
-
export type AppendToDictionary<TDict, TKey extends string, TValue> = {
|
|
9
|
-
[K in keyof TDict | TKey]: K extends keyof TDict ? TDict[K] : TValue;
|
|
10
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { IsStringLiteral } from "src/types/boolean-logic";
|
|
2
|
-
import { Narrowable } from "../Narrowable";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* **EndsWith**<T,U>
|
|
6
|
-
*
|
|
7
|
-
* A type utility which checks whether `T` _ends with_ the string literal `U`.
|
|
8
|
-
*
|
|
9
|
-
* If both `T` and `U` are string literals then the type system will resolve
|
|
10
|
-
* to a literal `true` or `false` but if either is not a literal that it will
|
|
11
|
-
* just resolve to `boolean` as the value can not be known at design time..
|
|
12
|
-
*/
|
|
13
|
-
export type EndsWith<
|
|
14
|
-
TValue extends string,
|
|
15
|
-
TEndsWith extends string
|
|
16
|
-
> = IsStringLiteral<TEndsWith> extends true
|
|
17
|
-
? IsStringLiteral<TValue> extends true // both literals
|
|
18
|
-
? TValue extends `${string}${TEndsWith}`
|
|
19
|
-
? true
|
|
20
|
-
: false
|
|
21
|
-
: boolean
|
|
22
|
-
: boolean;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* **IfEndsWith**<TValue, TEndsWith, IF, ELSE, MAYBE>
|
|
26
|
-
*
|
|
27
|
-
* Type utility which converts type to `IF` type _if_ `TValue` _ends with_ `TEndsWith` but
|
|
28
|
-
* otherwise converts type to `ELSE`. If there are wide types in the mix then the type will
|
|
29
|
-
* result in the union of IF and ELSE.
|
|
30
|
-
*/
|
|
31
|
-
export type IfEndsWith<
|
|
32
|
-
TValue extends string,
|
|
33
|
-
TEndsWith extends string,
|
|
34
|
-
IF extends Narrowable,
|
|
35
|
-
ELSE extends Narrowable
|
|
36
|
-
> = EndsWith<TValue, TEndsWith> extends true
|
|
37
|
-
? IF
|
|
38
|
-
: EndsWith<TValue, TEndsWith> extends false
|
|
39
|
-
? ELSE
|
|
40
|
-
: IF | ELSE;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Narrowable } from "../Narrowable";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* **Extends**`<T, EXTENDS>`
|
|
5
|
-
*
|
|
6
|
-
* Boolean type utility which returns `true` if `T` _extends_ `EXTENDS`.
|
|
7
|
-
*/
|
|
8
|
-
export type Extends<T extends Narrowable, EXTENDS extends Narrowable> = T extends EXTENDS
|
|
9
|
-
? true
|
|
10
|
-
: false;
|
|
11
|
-
/**
|
|
12
|
-
* **IfExtends**
|
|
13
|
-
*
|
|
14
|
-
* Branching type utility which returns type `IF` when `E` _extends_ `T`; otherwise
|
|
15
|
-
* it will return the type `ELSE`.
|
|
16
|
-
*/
|
|
17
|
-
export type IfExtends<
|
|
18
|
-
T extends Narrowable,
|
|
19
|
-
EXTENDS extends Narrowable,
|
|
20
|
-
IF extends Narrowable,
|
|
21
|
-
ELSE extends Narrowable
|
|
22
|
-
> = Extends<T, EXTENDS> extends true ? IF : ELSE;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AnyFunction } from "src/runtime";
|
|
2
|
-
import { Length } from "../Length";
|
|
3
|
-
import { Narrowable } from "../Narrowable";
|
|
4
|
-
import { IsEqual } from "./equivalency";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* **HasParameters**`<T>`
|
|
8
|
-
*
|
|
9
|
-
* Type utility which detects if `T` is both a function and whether that
|
|
10
|
-
* function has at least one type parameter.
|
|
11
|
-
* ```ts
|
|
12
|
-
* const fn = (foo: string) => `${foo}bar`;
|
|
13
|
-
* // true
|
|
14
|
-
* type P = HasParameters<typeof fn>;
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export type HasParameters<T extends Narrowable> = T extends AnyFunction
|
|
18
|
-
? IsEqual<Length<Parameters<T>>, 0> extends true
|
|
19
|
-
? false
|
|
20
|
-
: true
|
|
21
|
-
: false;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { TupleToUnion } from "../type-conversion";
|
|
2
|
-
import { IsLiteral, IsStringLiteral } from "./IsLiteral";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* **Includes**`<TSource, TValue>`
|
|
6
|
-
*
|
|
7
|
-
* Type utility which returns `true` or `false` based on whether `TValue` is found
|
|
8
|
-
* in `TSource`. Where `TSource` can be a string literal or an array of string literals.
|
|
9
|
-
*
|
|
10
|
-
* **Note:** if the source is a _wide_ type (aka, `string` or `string[]`) then there is
|
|
11
|
-
* no way to know at design-time whether the value includes `TValue` and so it will return
|
|
12
|
-
* a type of `boolean`.
|
|
13
|
-
*/
|
|
14
|
-
export type Includes<
|
|
15
|
-
TSource extends string | readonly string[],
|
|
16
|
-
TValue extends string
|
|
17
|
-
> = TSource extends string[]
|
|
18
|
-
? IsStringLiteral<TupleToUnion<TSource>> extends true
|
|
19
|
-
? IsLiteral<TValue> extends true
|
|
20
|
-
? TValue extends TupleToUnion<TSource>
|
|
21
|
-
? true
|
|
22
|
-
: false
|
|
23
|
-
: boolean
|
|
24
|
-
: boolean
|
|
25
|
-
: TSource extends string
|
|
26
|
-
? IsLiteral<TSource> extends true
|
|
27
|
-
? IsLiteral<TValue> extends true
|
|
28
|
-
? TSource extends `${string}${TValue}${string}`
|
|
29
|
-
? true
|
|
30
|
-
: false
|
|
31
|
-
: boolean
|
|
32
|
-
: boolean
|
|
33
|
-
: boolean;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Narrowable } from "../Narrowable";
|
|
2
|
-
import { IsBooleanLiteral } from "./boolean";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* **IsStringLiteral**
|
|
6
|
-
*
|
|
7
|
-
* Type utility which returns true/false if the string a _string literal_ versus
|
|
8
|
-
* just the _string_ type.
|
|
9
|
-
*/
|
|
10
|
-
export type IsStringLiteral<T extends Narrowable> = [T] extends [string]
|
|
11
|
-
? string extends T
|
|
12
|
-
? false
|
|
13
|
-
: true
|
|
14
|
-
: false;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* **IfStringLiteral**
|
|
18
|
-
*
|
|
19
|
-
* Branch utility which returns `IF` type when `T` is a string literal and `ELSE` otherwise
|
|
20
|
-
*/
|
|
21
|
-
export type IfStringLiteral<T extends string, IF extends Narrowable, ELSE extends Narrowable> = [
|
|
22
|
-
IsStringLiteral<T>
|
|
23
|
-
] extends [true]
|
|
24
|
-
? IF
|
|
25
|
-
: ELSE;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* **IsNumericLiteral**
|
|
29
|
-
*
|
|
30
|
-
* Type utility which returns true/false if the numeric value a _numeric literal_ versus
|
|
31
|
-
* just the _number_ type.
|
|
32
|
-
*/
|
|
33
|
-
export type IsNumericLiteral<T extends number> = number extends T ? false : true;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* **IfNumericLiteral**
|
|
37
|
-
*
|
|
38
|
-
* Branch utility which returns `IF` type when `T` is a numeric literal and `ELSE` otherwise
|
|
39
|
-
*/
|
|
40
|
-
export type IfNumericLiteral<
|
|
41
|
-
T extends number,
|
|
42
|
-
IF extends Narrowable,
|
|
43
|
-
ELSE extends Narrowable
|
|
44
|
-
> = IsNumericLiteral<T> extends true ? IF : ELSE;
|
|
45
|
-
|
|
46
|
-
// [note on handling of boolean](https://stackoverflow.com/questions/74213646/detecting-type-literals-works-in-isolation-but-not-when-combined-with-other-lite/74213713#74213713)
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* **IsLiteral**
|
|
50
|
-
*
|
|
51
|
-
* Type utility which returns true/false if the value passed -- a form of a
|
|
52
|
-
* string, number, or boolean -- is a _literal_ value of that type (true) or
|
|
53
|
-
* the more generic wide type (false).
|
|
54
|
-
*/
|
|
55
|
-
export type IsLiteral<T> = [T] extends [string]
|
|
56
|
-
? IsStringLiteral<T>
|
|
57
|
-
: [T] extends [boolean]
|
|
58
|
-
? IsBooleanLiteral<T>
|
|
59
|
-
: [T] extends [number]
|
|
60
|
-
? IsNumericLiteral<T>
|
|
61
|
-
: false;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* **IsOptionalLiteral**
|
|
65
|
-
*
|
|
66
|
-
* Type utility which returns true/false if the value passed -- a form of a
|
|
67
|
-
* string, number, or boolean -- is a _literal_ value of that type (true) or
|
|
68
|
-
* the more generic wide type (false).
|
|
69
|
-
*
|
|
70
|
-
* This type also strips off _undefined_ from any possible union type to evaluate
|
|
71
|
-
* to `true` even when a literal value is in union with _undefined_. If you don't
|
|
72
|
-
* want to test for the union with _undefined_ use the `IsOptional` utility instead.
|
|
73
|
-
*/
|
|
74
|
-
export type IsOptionalLiteral<T> = [Exclude<T, undefined>] extends [string]
|
|
75
|
-
? IsStringLiteral<Exclude<T, undefined>>
|
|
76
|
-
: [Exclude<T, undefined>] extends [boolean]
|
|
77
|
-
? IsBooleanLiteral<Exclude<T, undefined>>
|
|
78
|
-
: [Exclude<T, undefined>] extends [number]
|
|
79
|
-
? IsNumericLiteral<Exclude<T, undefined>>
|
|
80
|
-
: false;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* **IfLiteral**
|
|
84
|
-
*
|
|
85
|
-
* Branch type utility with return `IF` when `T` is a _literal_ value and `ELSE` otherwise
|
|
86
|
-
*/
|
|
87
|
-
export type IfLiteral<T, IF extends Narrowable, ELSE extends Narrowable> = IsLiteral<T> extends true
|
|
88
|
-
? IF
|
|
89
|
-
: ELSE;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* **IfOptionalLiteral**
|
|
93
|
-
*
|
|
94
|
-
* Branch type utility with return `IF` when `T` is a _literal_ value (with possibly
|
|
95
|
-
* the inclusion of _undefined_); otherwise returns the type `ELSE`
|
|
96
|
-
*/
|
|
97
|
-
export type IfOptionalLiteral<
|
|
98
|
-
T,
|
|
99
|
-
IF extends Narrowable,
|
|
100
|
-
ELSE extends Narrowable
|
|
101
|
-
> = IsOptionalLiteral<T> extends true ? IF : ELSE;
|