inferred-types 0.37.0 → 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/dist/index.d.ts +2745 -0
- package/dist/index.js +854 -0
- package/package.json +6 -12
- 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 -152
- 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,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type utility that provides the _length_ of a given string type in a way which
|
|
3
|
-
* is _not_ limited to TS's recursive string length of roughly 48.
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* // 3
|
|
7
|
-
* type Three = StringLength<"foo">;
|
|
8
|
-
* ```
|
|
9
|
-
*/
|
|
10
|
-
export type StringLength<S extends string, R extends number[] = []>
|
|
11
|
-
= S extends `${infer _First}${infer _Second}${infer _Third}${infer _Fourth}${infer _Fifth}${infer _Sixth}${infer _Sevebnth}${infer _Eighth}${infer _Ninth}${infer _Tenth}${infer Rest}`
|
|
12
|
-
? StringLength<Rest, [...R, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]>
|
|
13
|
-
: S extends `${infer _First}${infer _Second}${infer _Third}${infer _Fourth}${infer _Fifth}${infer _Sixth}${infer _Sevebnth}${infer _Eighth}${infer _Ninth}${infer Rest}`
|
|
14
|
-
? StringLength<Rest, [...R, 1, 1, 1, 1, 1, 1, 1, 1, 1]>
|
|
15
|
-
: S extends `${infer _First}${infer _Second}${infer _Third}${infer _Fourth}${infer _Fifth}${infer _Sixth}${infer _Sevebnth}${infer _Eighth}${infer Rest}`
|
|
16
|
-
? StringLength<Rest, [...R, 1, 1, 1, 1, 1, 1, 1, 1]>
|
|
17
|
-
: S extends `${infer _First}${infer _Second}${infer _Third}${infer _Fourth}${infer _Fifth}${infer _Sixth}${infer _Sevebnth}${infer Rest}`
|
|
18
|
-
? StringLength<Rest, [...R, 1, 1, 1, 1, 1, 1, 1]>
|
|
19
|
-
: S extends `${infer _First}${infer _Second}${infer _Third}${infer _Fourth}${infer _Fifth}${infer _Sixth}${infer Rest}`
|
|
20
|
-
? StringLength<Rest, [...R, 1, 1, 1, 1, 1, 1]>
|
|
21
|
-
: S extends `${infer _First}${infer _Second}${infer _Third}${infer _Fourth}${infer _Fifth}}${infer Rest}`
|
|
22
|
-
? StringLength<Rest, [...R, 1, 1, 1, 1, 1]>
|
|
23
|
-
: S extends `${infer _First}${infer _Second}${infer _Third}${infer _Fourth}${infer Rest}`
|
|
24
|
-
? StringLength<Rest, [...R, 1, 1, 1, 1]>
|
|
25
|
-
: S extends `${infer _First}${infer _Second}${infer _Third}${infer Rest}`
|
|
26
|
-
? StringLength<Rest, [...R, 1, 1, 1]>
|
|
27
|
-
: S extends `${infer _First}${infer _Second}${infer Rest}`
|
|
28
|
-
? StringLength<Rest, [...R, 1, 1]>
|
|
29
|
-
: S extends `${infer _First}${infer Rest}`
|
|
30
|
-
? StringLength<Rest, [...R, 1]>
|
|
31
|
-
: [...R]["length"];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Whitespace } from "../alphabetic";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Trims off blank spaces, `\n` and `\t` characters from both sides of a _string literal_.
|
|
5
|
-
* ```ts
|
|
6
|
-
* // "foobar"
|
|
7
|
-
* type T = Trim<"\n\t foobar ">;
|
|
8
|
-
* // string
|
|
9
|
-
* type T = Trim<string>;
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export type Trim<S extends string> = string extends S ? string :
|
|
13
|
-
S extends `${Whitespace}${infer Right}` ?
|
|
14
|
-
Trim<Right> : S extends `${infer Left}${Whitespace}` ? Trim<Left> : S;
|
|
15
|
-
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Whitespace } from "../alphabetic";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Trims off whitespace on left of string
|
|
5
|
-
* ```ts
|
|
6
|
-
* // "foobar "
|
|
7
|
-
* type T = TrimLeft<"\n\t foobar ">;
|
|
8
|
-
* // string
|
|
9
|
-
* type T = TrimLeft<string>;
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export type TrimLeft<S extends string> = string extends S ? string :
|
|
13
|
-
S extends `${Whitespace}${infer Right}` ?
|
|
14
|
-
TrimLeft<Right> : S;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Whitespace } from "../alphabetic";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Trims off whitespace on left of string
|
|
5
|
-
* ```ts
|
|
6
|
-
* // "\n foobar"
|
|
7
|
-
* type T = TrimRight<"\n foobar \t">;
|
|
8
|
-
* // string
|
|
9
|
-
* type T = TrimRight<string>;
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export type TrimRight<S extends string> = string extends S ? string :
|
|
13
|
-
S extends `${infer Right}${Whitespace}` ?
|
|
14
|
-
TrimRight<Right> : S;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { NumericString } from "../alphabetic/alpha-characters";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* An email address
|
|
5
|
-
*/
|
|
6
|
-
export type Email = `${string}@${string}.${string}`;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type Zip5 = `${NumericString}${NumericString}${string}${NumericString}`;
|
|
10
|
-
type Zip4 = `${NumericString}${string}`;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A relatively strong type for Zip5 or Zip5+4 zip codes
|
|
14
|
-
*/
|
|
15
|
-
export type ZipCode = Zip5 | `${Zip5}-${Zip4}`;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// #autoindex
|
|
2
|
-
// #region auto-indexed files
|
|
3
|
-
// index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
|
|
4
|
-
// hash-code: d0cf1562
|
|
5
|
-
|
|
6
|
-
// file exports
|
|
7
|
-
export * from "./Break";
|
|
8
|
-
export * from "./Concat";
|
|
9
|
-
export * from "./LeftWhitespace";
|
|
10
|
-
export * from "./Replace";
|
|
11
|
-
export * from "./RightWhitespace";
|
|
12
|
-
export * from "./StringLength";
|
|
13
|
-
export * from "./Trim";
|
|
14
|
-
export * from "./TrimLeft";
|
|
15
|
-
export * from "./TrimRight";
|
|
16
|
-
export * from "./form-fields";
|
|
17
|
-
|
|
18
|
-
// #endregion auto-indexed files
|
|
19
|
-
|
|
20
|
-
// see https://github.com/inocan-group/do-devops/docs/autoindex.md
|
|
21
|
-
// for more info
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
|
-
export type DictArrayFilterCallback<K extends keyof T, T extends object, R extends true | false> = (key: K, value: Pick<T, K>) => R;
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* An element in a `DictArray` shaped as a two element tuple: `[key, kv]`.
|
|
6
|
-
*/
|
|
7
|
-
export type DictArrayKv<K extends keyof T, T> = [K, Pick<T, K>];
|
|
8
|
-
|
|
9
|
-
export type DictKvTuple<K extends string> = [K, Record<K, unknown>];
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A an array of `DictArrayKv` tuples which can be reconstructed
|
|
13
|
-
* to a strongly typed dictionary object.
|
|
14
|
-
* ```ts
|
|
15
|
-
* const example: DictArray<{ foo: 1, bar: "hi" }> = [
|
|
16
|
-
* [ "foo", { foo: 1 }],
|
|
17
|
-
* [ "bar", { bar: "hi" }]
|
|
18
|
-
* ]
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export type DictArray<T> = Array<{ [K in keyof T]: DictArrayKv<K, T> }[keyof T]>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Keys } from "../Keys";
|
|
2
|
-
import { UnionToTuple } from "../type-conversion/UnionToTuple";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns the _first_ key in an object.
|
|
6
|
-
*
|
|
7
|
-
* **Note:** key order is not guarenteed so typically this is used
|
|
8
|
-
* for a key/value pair where only one key is expected
|
|
9
|
-
*/
|
|
10
|
-
export type FirstKey<T extends object> = UnionToTuple<Keys<T>>[0];
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FirstKey } from "./FirstKey";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Utility type which operates on a dictionary and provides the **value** of the
|
|
5
|
-
* `First<T>` key of the dictionary. Because dictionary's don't provide assurances
|
|
6
|
-
* about key order, this is typically only used in cases where it's known there is
|
|
7
|
-
* a single key on the object.
|
|
8
|
-
*/
|
|
9
|
-
export type FirstKeyValue<T extends object> = FirstKey<T> extends keyof T ? T[FirstKey<T>] : never;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For a two-dimensional array, returns a _union type_ which combines the first element of the interior
|
|
3
|
-
* array.
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* const test = [ ["foo", 1], ["bar", 2] ];
|
|
7
|
-
* // "foo" | "bar"
|
|
8
|
-
* type F = FirstOfEach<typeof test>;
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export type FirstOfEach<T extends readonly any[][]> = T[number][0] extends T[number][number]
|
|
12
|
-
? T[number][0]
|
|
13
|
-
: never;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ExpandRecursively } from "../ExpandRecursively";
|
|
2
|
-
import { UnionToIntersection } from "../type-conversion";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Typescript utility which receives `T` as shape which resembles `DictArray<D>`
|
|
6
|
-
* and if the type `D` can be inferred it is returned.
|
|
7
|
-
* ```ts
|
|
8
|
-
* // { foo: 1; bar: "hi" }
|
|
9
|
-
* type Dict = FromDictArray<[["foo", { foo: 1 }], ["bar", { bar: "hi" }]]>;
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export type FromDictArray<T extends [string, Record<string, unknown>][]> = ExpandRecursively<
|
|
13
|
-
UnionToIntersection<T[number][1]>
|
|
14
|
-
>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* For a two-dimensional array, returns a _union type_ which combines the first element of the interior
|
|
4
|
-
* array.
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* // 1 | 2
|
|
8
|
-
* type F = SecondOfEach<[ ["foo", 1], ["bar", 2] ]>;
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export type SecondOfEach<T extends any[][]> = T[number][1] extends T[number][number]
|
|
12
|
-
? T[number][1]
|
|
13
|
-
: never;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// #autoindex
|
|
2
|
-
// #region auto-indexed files
|
|
3
|
-
// index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
|
|
4
|
-
// hash-code: 582cd3f6
|
|
5
|
-
|
|
6
|
-
// file exports
|
|
7
|
-
export * from "./DictArray";
|
|
8
|
-
export * from "./FirstKey";
|
|
9
|
-
export * from "./FirstKeyValue";
|
|
10
|
-
export * from "./FirstOfEach";
|
|
11
|
-
export * from "./FromDictArray";
|
|
12
|
-
export * from "./SecondOfEach";
|
|
13
|
-
|
|
14
|
-
// #endregion auto-indexed files
|
|
15
|
-
|
|
16
|
-
// see https://github.com/inocan-group/do-devops/docs/autoindex.md
|
|
17
|
-
// for more info
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
// https://github.com/type-challenges/type-challenges/issues/737
|
|
3
|
-
|
|
4
|
-
import { UnionToIntersection } from "./UnionToIntersection";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* LastInUnion<1 | 2> = 2.
|
|
8
|
-
*/
|
|
9
|
-
export type LastInUnion<U> = UnionToIntersection<U extends unknown ? (x: U) => 0 : never> extends (
|
|
10
|
-
x: infer L
|
|
11
|
-
) => 0
|
|
12
|
-
? L
|
|
13
|
-
: never;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* UnionToTuple<1 | 2> = [1, 2].
|
|
17
|
-
*/
|
|
18
|
-
export type UnionToTuple<U, Last = LastInUnion<U>> = [U] extends [never]
|
|
19
|
-
? []
|
|
20
|
-
: [...UnionToTuple<Exclude<U, Last>>, Last];
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { AnyFunction } from "src/runtime";
|
|
2
|
-
import { TupleToUnion } from "./TupleToUnion";
|
|
3
|
-
|
|
4
|
-
export type Widen<T> = T extends string
|
|
5
|
-
? string
|
|
6
|
-
: T extends number
|
|
7
|
-
? number
|
|
8
|
-
: T extends boolean
|
|
9
|
-
? boolean
|
|
10
|
-
: T extends readonly string[]
|
|
11
|
-
? string[]
|
|
12
|
-
: T extends readonly number[]
|
|
13
|
-
? number[]
|
|
14
|
-
: T extends readonly boolean[]
|
|
15
|
-
? boolean[]
|
|
16
|
-
: T extends readonly AnyFunction[]
|
|
17
|
-
? AnyFunction[]
|
|
18
|
-
: T extends readonly any[]
|
|
19
|
-
? TupleToUnion<T>[]
|
|
20
|
-
: T extends {}
|
|
21
|
-
? {}
|
|
22
|
-
: T;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// #autoindex
|
|
2
|
-
|
|
3
|
-
// #region auto-indexed files
|
|
4
|
-
// index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
|
|
5
|
-
// hash-code: 200001fa
|
|
6
|
-
|
|
7
|
-
// file exports
|
|
8
|
-
export * from "./TupleToUnion";
|
|
9
|
-
export * from "./UnionToIntersection";
|
|
10
|
-
export * from "./UnionToTuple";
|
|
11
|
-
export * from "./Widen";
|
|
12
|
-
|
|
13
|
-
// #endregion auto-indexed files
|
|
14
|
-
|
|
15
|
-
// see https://github.com/inocan-group/do-devops/docs/autoindex.md
|
|
16
|
-
// for more info
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validates that a given type extends another and returns `true` or `false` type
|
|
3
|
-
*/
|
|
4
|
-
export type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE ? true : false;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Validates that a given type extends another and returns `any` or `never` as a type
|
|
8
|
-
*/
|
|
9
|
-
export type AssertExtends<VALUE, EXPECTED> = EXPECTED extends VALUE ? any : never;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Give a type `TValue` and a comparison type `TExtends`
|
|
13
|
-
*/
|
|
14
|
-
export type IfExtendsThen<VALUE, EXPECTED, THEN> = EXPECTED extends VALUE ? THEN : never;
|
package/tests/CamelCase-spec.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { CamelCase } from "../src/types";
|
|
4
|
-
import { Expect, Equal } from "@type-challenges/utils";
|
|
5
|
-
|
|
6
|
-
type camelCase1 = CamelCase<"hello_world_with_types">;
|
|
7
|
-
type camelCase2 = CamelCase<"HELLO_WORLD_WITH_TYPES">;
|
|
8
|
-
type Dash = CamelCase<"hello-world-with-types">;
|
|
9
|
-
|
|
10
|
-
describe("CamelCase type modifier", () => {
|
|
11
|
-
it("camel_case is converted to proper CamelCase", () => {
|
|
12
|
-
type cases = [
|
|
13
|
-
Expect<Equal<camelCase1, "helloWorldWithTypes">>,
|
|
14
|
-
Expect<Equal<camelCase2, "helloWorldWithTypes">>,
|
|
15
|
-
Expect<Equal<Dash, "helloWorldWithTypes">>
|
|
16
|
-
];
|
|
17
|
-
const typeTests: cases = [true, true, true];
|
|
18
|
-
expect(typeTests).toBe(typeTests);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/consistent-function-scoping */
|
|
2
|
-
import { Configurator, IConfigurator } from "../src/utility/state/Configurator";
|
|
3
|
-
import { mySong, Playlist, SimpleTable, Song } from "./data";
|
|
4
|
-
|
|
5
|
-
describe("Configurator => ", () => {
|
|
6
|
-
it("adding basic types to config works", () => {
|
|
7
|
-
const c: IConfigurator = Configurator();
|
|
8
|
-
c.set("foo", 5);
|
|
9
|
-
c.set("bar", 10);
|
|
10
|
-
c.set("baz", "no sir, didn't like it");
|
|
11
|
-
|
|
12
|
-
const t = c.done();
|
|
13
|
-
|
|
14
|
-
expect(t).toHaveProperty("foo", 5);
|
|
15
|
-
expect(t).toHaveProperty("bar", 10);
|
|
16
|
-
expect(t).toHaveProperty("baz", "no sir, didn't like it");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("Fluent API is not exposed; set returns name/value pair instead", () => {
|
|
20
|
-
const c: IConfigurator = Configurator();
|
|
21
|
-
const v1 = c.set("foo", 5);
|
|
22
|
-
|
|
23
|
-
expect(v1).not.toHaveProperty("set");
|
|
24
|
-
expect(v1).not.toHaveProperty("done");
|
|
25
|
-
expect(v1).toStrictEqual({ foo: 5 });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("set() function is able to set a simple value and have type retained", () => {
|
|
29
|
-
const c: IConfigurator = Configurator();
|
|
30
|
-
c.set("songs", SimpleTable(Song));
|
|
31
|
-
c.set("playlists", SimpleTable(Playlist));
|
|
32
|
-
c.set("foo", 15);
|
|
33
|
-
c.set("bar", 1);
|
|
34
|
-
const t = c.done();
|
|
35
|
-
// TODO: get the typeing back to a working state
|
|
36
|
-
expect((t.songs as any).is(mySong)).toBe(true);
|
|
37
|
-
expect((t.songs as any).is({ foo: false })).toBe(false);
|
|
38
|
-
expect(typeof t.songs).toBe("object");
|
|
39
|
-
expect(typeof t.playlists).toBe("object");
|
|
40
|
-
expect(typeof t.foo).toBe("number");
|
|
41
|
-
expect(typeof t.bar).toBe("number");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// TODO: get this back to working
|
|
45
|
-
it.skip("initializing with an interface ensures base types", () => {
|
|
46
|
-
// type ITest = { foo: number; bar: string };
|
|
47
|
-
// const c: IConfigurator<ITest> = Configurator();
|
|
48
|
-
// c.set("foo", 55);
|
|
49
|
-
// const config = c.done();
|
|
50
|
-
// expect(config).toHaveProperty("foo", 55);
|
|
51
|
-
// expect(config).not.toHaveProperty("bar");
|
|
52
|
-
// expect(config.bar).toBe(undefined);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it.skip("initializing with an interface works with more complex types", () => {
|
|
56
|
-
// type ITest = Record<string, any> & { bar: number };
|
|
57
|
-
// const c: IConfigurator<ITest> = Configurator<ITest>();
|
|
58
|
-
// c.set("foo", 55);
|
|
59
|
-
// c.set("songs", SimpleTable(Song));
|
|
60
|
-
// const config = c.done();
|
|
61
|
-
// expect(config.foo).toBe(55);
|
|
62
|
-
// expect(config).not.toHaveProperty("bar");
|
|
63
|
-
// expect(config.songs).toHaveProperty("is");
|
|
64
|
-
// expect(config.songs.select("artist")).toBe("You did it");
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("Passing the configurator object to another function preserves typing", () => {
|
|
68
|
-
const receiver = <T extends Record<string, any>>(obj: T) => {
|
|
69
|
-
expect(obj).toHaveProperty("songs");
|
|
70
|
-
expect(obj.songs).toHaveProperty("is");
|
|
71
|
-
if (obj.songs.is(mySong)) {
|
|
72
|
-
expect(mySong.artist).toBe("Billy Idol");
|
|
73
|
-
}
|
|
74
|
-
expect(obj.songs.select(""));
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const c: IConfigurator = Configurator();
|
|
78
|
-
c.set("songs", SimpleTable(Song));
|
|
79
|
-
const config = c.done();
|
|
80
|
-
|
|
81
|
-
receiver(config);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("using remove in API works as expected", () => {
|
|
85
|
-
const c: IConfigurator = Configurator();
|
|
86
|
-
c.set("foo", 1);
|
|
87
|
-
c.set("bar", 2);
|
|
88
|
-
c.remove("foo");
|
|
89
|
-
c.set("baz", 3);
|
|
90
|
-
|
|
91
|
-
const v = c.done();
|
|
92
|
-
|
|
93
|
-
expect(v.bar).toBeDefined();
|
|
94
|
-
expect(v.baz).toBeDefined();
|
|
95
|
-
expect((v as any).foo).not.toBeDefined();
|
|
96
|
-
|
|
97
|
-
type cases = [
|
|
98
|
-
// TODO: hovering over "remove" it would look like should work
|
|
99
|
-
// but it doesn't remove the type currently
|
|
100
|
-
// Expect<Equal<typeof v, { bar: number; baz: number }>>
|
|
101
|
-
];
|
|
102
|
-
|
|
103
|
-
const cases: cases = [];
|
|
104
|
-
expect(cases).toBe(cases);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { ExplicitFunction } from "../src/runtime";
|
|
4
|
-
import type { Expect, Equal } from "@type-challenges/utils";
|
|
5
|
-
|
|
6
|
-
describe("ExplicitFunction()", () => {
|
|
7
|
-
it("empty params function made explicit", () => {
|
|
8
|
-
const fn = () => 42;
|
|
9
|
-
type F = typeof fn;
|
|
10
|
-
const efn = ExplicitFunction(fn);
|
|
11
|
-
type E = typeof efn;
|
|
12
|
-
|
|
13
|
-
type cases = [Expect<Equal<F, E>>];
|
|
14
|
-
const cases: cases = [true];
|
|
15
|
-
expect(cases).toBe(cases);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("singular param function made explicit", () => {
|
|
19
|
-
const fn = (n: number) => n;
|
|
20
|
-
type F = typeof fn;
|
|
21
|
-
const efn = ExplicitFunction(fn);
|
|
22
|
-
type E = typeof efn;
|
|
23
|
-
|
|
24
|
-
type cases = [Expect<Equal<F, E>>];
|
|
25
|
-
const cases: cases = [true];
|
|
26
|
-
expect(cases).toBe(cases);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("multiple param function made explicit", () => {
|
|
30
|
-
const fn = (n: number, greeting: string) => `${greeting} ${n}`;
|
|
31
|
-
type F = typeof fn;
|
|
32
|
-
const efn = ExplicitFunction(fn);
|
|
33
|
-
type E = typeof efn;
|
|
34
|
-
|
|
35
|
-
type cases = [Expect<Equal<F, E>>];
|
|
36
|
-
const cases: cases = [true];
|
|
37
|
-
expect(cases).toBe(cases);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("higher order function", () => {
|
|
41
|
-
const fn = (g: string) => (n: number) => `${g} ${n}`;
|
|
42
|
-
type F = typeof fn;
|
|
43
|
-
const efn = ExplicitFunction(fn);
|
|
44
|
-
type E = typeof efn;
|
|
45
|
-
|
|
46
|
-
type cases = [Expect<Equal<F, E>>];
|
|
47
|
-
const cases: cases = [true];
|
|
48
|
-
expect(cases).toBe(cases);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Include, Retain } from "../src/types";
|
|
4
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
5
|
-
|
|
6
|
-
// INCLUDE
|
|
7
|
-
describe("Include<T, U> utility", () => {
|
|
8
|
-
it(" wide type test", () => {
|
|
9
|
-
const str = "foo";
|
|
10
|
-
type Foo = Include<typeof str, string>;
|
|
11
|
-
type NotFoo = Include<typeof str, number>;
|
|
12
|
-
|
|
13
|
-
type cases = [Expect<Equal<Foo, "foo">>, Expect<Equal<NotFoo, never>>];
|
|
14
|
-
const c: cases = [true, true];
|
|
15
|
-
expect(c).toBe(c);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("narrow type test", () => {
|
|
19
|
-
const str = "foo";
|
|
20
|
-
type Foo = Include<typeof str, "foo">;
|
|
21
|
-
type NotFoo = Include<typeof str, "bar">;
|
|
22
|
-
type RelatedFoo = Include<typeof str, string>;
|
|
23
|
-
type NotLiteralFoo = Include<typeof str, string, true>;
|
|
24
|
-
|
|
25
|
-
type cases = [
|
|
26
|
-
Expect<Equal<Foo, "foo">>,
|
|
27
|
-
Expect<Equal<NotFoo, never>>,
|
|
28
|
-
// this is the intended outcome but means
|
|
29
|
-
// that this utility has an implicit bias
|
|
30
|
-
// toward wide types; meaning the literal
|
|
31
|
-
// type is not lost but it does match on "string"
|
|
32
|
-
Expect<Equal<RelatedFoo, "foo">>,
|
|
33
|
-
// this behavior is adjusted if you include
|
|
34
|
-
// the optional `L` generic as a true value
|
|
35
|
-
Expect<Equal<NotLiteralFoo, never>>
|
|
36
|
-
];
|
|
37
|
-
const c: cases = [true, true, true, true];
|
|
38
|
-
expect(c).toBe(c);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// RETAIN
|
|
43
|
-
describe("Retain<T, U> utility", () => {
|
|
44
|
-
it("base test", () => {
|
|
45
|
-
const obj = { foo: 1, bar: 2, baz: "hi" };
|
|
46
|
-
type FooBar = Retain<typeof obj, "foo" | "bar">;
|
|
47
|
-
type Baz = Retain<typeof obj, "baz">;
|
|
48
|
-
type FooBaz = Retain<typeof obj, "foo" | "baz">;
|
|
49
|
-
|
|
50
|
-
type cases = [
|
|
51
|
-
Expect<Equal<FooBar, { foo: number; bar: number }>>,
|
|
52
|
-
Expect<Equal<Baz, { baz: string }>>,
|
|
53
|
-
Expect<Equal<FooBaz, { foo: number; baz: string }>>
|
|
54
|
-
];
|
|
55
|
-
const c: cases = [true, true, true];
|
|
56
|
-
expect(c).toBe(c);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("optional params and literals", () => {
|
|
60
|
-
type Obj = { foo: 1; bar?: number; baz: "hi" };
|
|
61
|
-
type FooBar = Retain<Obj, "foo" | "bar">;
|
|
62
|
-
|
|
63
|
-
type cases = [Expect<Equal<FooBar, { foo: 1; bar?: number }>>];
|
|
64
|
-
const c: cases = [true];
|
|
65
|
-
expect(c).toBe(c);
|
|
66
|
-
});
|
|
67
|
-
});
|
package/tests/Includes-spec.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import type { Includes } from "../src/types";
|
|
4
|
-
import type { Equal, Expect } from "@type-challenges/utils";
|
|
5
|
-
|
|
6
|
-
describe("Includes type check", () => {
|
|
7
|
-
it("Includes works on a string source", () => {
|
|
8
|
-
type T = Includes<"Hello World", "Hello">;
|
|
9
|
-
type F = Includes<"Hello World", "nada">;
|
|
10
|
-
type U = Includes<string, "who cares">;
|
|
11
|
-
type N = Includes<"Hello World", string>;
|
|
12
|
-
type cases = [
|
|
13
|
-
Expect<Equal<T, true>>, //
|
|
14
|
-
Expect<Equal<F, false>>,
|
|
15
|
-
Expect<Equal<U, boolean>>,
|
|
16
|
-
Expect<Equal<N, boolean>>
|
|
17
|
-
];
|
|
18
|
-
const typeTests: cases = [true, true, true, true];
|
|
19
|
-
expect(typeTests).toBe(typeTests);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("Includes works on a string[] source", () => {
|
|
23
|
-
type T = Includes<["Hello", "World"], "Hello">;
|
|
24
|
-
type F = Includes<["Hello", "World"], "nada">;
|
|
25
|
-
type U = Includes<string[], "who cares">;
|
|
26
|
-
type N = Includes<["Hello", "World"], string>;
|
|
27
|
-
type cases = [
|
|
28
|
-
Expect<Equal<T, true>>, //
|
|
29
|
-
Expect<Equal<F, false>>,
|
|
30
|
-
Expect<Equal<U, boolean>>,
|
|
31
|
-
Expect<Equal<N, boolean>>
|
|
32
|
-
];
|
|
33
|
-
const typeTests: cases = [true, true, true, true];
|
|
34
|
-
expect(typeTests).toBe(typeTests);
|
|
35
|
-
});
|
|
36
|
-
});
|
package/tests/KebabCase-spec.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import type { KebabCase } from "../src/types";
|
|
4
|
-
import type { Expect, Equal } from "@type-challenges/utils";
|
|
5
|
-
|
|
6
|
-
type Pascal = KebabCase<"HelloWorldWithTypes">;
|
|
7
|
-
type Camel = KebabCase<"helloWorldWithTypes">;
|
|
8
|
-
type Snake = KebabCase<"hello_world_with_types">;
|
|
9
|
-
type Dash = KebabCase<"hello-world-with-types">;
|
|
10
|
-
|
|
11
|
-
describe("KebabCase type modifier", () => {
|
|
12
|
-
it("other naming conventions are converted to kebab-case", () => {
|
|
13
|
-
//@ts-ignore
|
|
14
|
-
type cases = [
|
|
15
|
-
Expect<Equal<Pascal, "hello-world-with-types">>,
|
|
16
|
-
Expect<Equal<Camel, "hello-world-with-types">>,
|
|
17
|
-
Expect<Equal<Snake, "hello-world-with-types">>,
|
|
18
|
-
Expect<Equal<Dash, "hello-world-with-types">>
|
|
19
|
-
];
|
|
20
|
-
});
|
|
21
|
-
});
|
package/tests/PascalCase-spec.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import type { PascalCase } from "../src/types";
|
|
4
|
-
import type { Expect, Equal } from "@type-challenges/utils";
|
|
5
|
-
|
|
6
|
-
type Snake = PascalCase<"hello_world_with_types">;
|
|
7
|
-
type UpperSnake = PascalCase<"HELLO_WORLD_WITH_TYPES">;
|
|
8
|
-
type Camel = PascalCase<"helloWorldWithTypes">;
|
|
9
|
-
type Dash = PascalCase<"hello-world-with-types">;
|
|
10
|
-
|
|
11
|
-
describe("PascalCase type modifier", () => {
|
|
12
|
-
it("pascal_case is converted to proper PascalCase", () => {
|
|
13
|
-
type cases = [
|
|
14
|
-
Expect<Equal<Snake, "HelloWorldWithTypes">>,
|
|
15
|
-
Expect<Equal<UpperSnake, "HelloWorldWithTypes">>,
|
|
16
|
-
Expect<Equal<Camel, "HelloWorldWithTypes">>,
|
|
17
|
-
Expect<Equal<Dash, "HelloWorldWithTypes">>
|
|
18
|
-
];
|
|
19
|
-
const typeTests: cases = [true, true, true, true];
|
|
20
|
-
expect(typeTests).toBe(typeTests);
|
|
21
|
-
});
|
|
22
|
-
});
|