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,109 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
4
|
-
import { CamelCase } from "src/types";
|
|
5
|
-
|
|
6
|
-
const target = "twoThreeFour";
|
|
7
|
-
type TARGET = typeof target;
|
|
8
|
-
|
|
9
|
-
describe("CamelCase<T> type utility", () => {
|
|
10
|
-
it("CamelCase<T> provides an identity to a CamelCased string", () => {
|
|
11
|
-
type T1 = CamelCase<"TwoThreeFour">;
|
|
12
|
-
type T2 = CamelCase<"\n TwoThreeFour ">;
|
|
13
|
-
|
|
14
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
|
|
15
|
-
const c: cases = [true, true];
|
|
16
|
-
expect(c).toBe(c);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("CamelCase<T> transform snake_case type", () => {
|
|
20
|
-
type T1 = CamelCase<"two_three_four">;
|
|
21
|
-
|
|
22
|
-
type cases = [Expect<Equal<T1, TARGET>>];
|
|
23
|
-
const c: cases = [true];
|
|
24
|
-
expect(c).toBe(c);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("CamelCase<T> transforms camelCase type", () => {
|
|
28
|
-
type T1 = CamelCase<"twoThreeFour">;
|
|
29
|
-
type T2 = CamelCase<" twoThreeFour \t">;
|
|
30
|
-
|
|
31
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
|
|
32
|
-
const c: cases = [true, true];
|
|
33
|
-
expect(c).toBe(c);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("CamelCase<T> transforms camelCase type up to any length", () => {
|
|
37
|
-
type T1 = CamelCase<"twoThreeFour">;
|
|
38
|
-
type T2 = CamelCase<"twoThreeFourFive">;
|
|
39
|
-
type T3 = CamelCase<"twoThreeFourFiveSix">;
|
|
40
|
-
type T4 = CamelCase<"twoThreeFourFiveSixSeven">;
|
|
41
|
-
type T5 = CamelCase<"twoThreeFourFiveSixSevenEight">;
|
|
42
|
-
type T6 = CamelCase<"twoThreeFourFiveSixSevenEightNineTenEleven">;
|
|
43
|
-
|
|
44
|
-
type cases = [
|
|
45
|
-
Expect<Equal<T1, TARGET>>,
|
|
46
|
-
Expect<Equal<T2, "twoThreeFourFive">>,
|
|
47
|
-
Expect<Equal<T3, "twoThreeFourFiveSix">>,
|
|
48
|
-
Expect<Equal<T4, "twoThreeFourFiveSixSeven">>,
|
|
49
|
-
Expect<Equal<T5, "twoThreeFourFiveSixSevenEight">>,
|
|
50
|
-
Expect<Equal<T6, "twoThreeFourFiveSixSevenEightNineTenEleven">>
|
|
51
|
-
];
|
|
52
|
-
const c: cases = [true, true, true, true, true, true];
|
|
53
|
-
expect(c).toBe(c);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("CamelCase<T> transforms interior space to CamelCased type", () => {
|
|
57
|
-
type T1 = CamelCase<"two three four">;
|
|
58
|
-
|
|
59
|
-
type cases = [Expect<Equal<T1, TARGET>>];
|
|
60
|
-
const c: cases = [true];
|
|
61
|
-
expect(c).toBe(c);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("CamelCase<T> transforms ALL CAPS to CamelCased type", () => {
|
|
65
|
-
type T1 = CamelCase<"TWO THREE FOUR">;
|
|
66
|
-
type T2 = CamelCase<"\n TWO_THREE_FOUR ">;
|
|
67
|
-
type T3 = CamelCase<"\n TWO-THREE-FOUR ">;
|
|
68
|
-
|
|
69
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>, Expect<Equal<T3, TARGET>>];
|
|
70
|
-
const c: cases = [true, true, true];
|
|
71
|
-
expect(c).toBe(c);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("CamelCase<T> removes leading and trailing whitespace and still converts", () => {
|
|
75
|
-
type T1 = CamelCase<" one two three ">;
|
|
76
|
-
type T2 = CamelCase<"\n one two three ">;
|
|
77
|
-
|
|
78
|
-
type cases = [Expect<Equal<T1, "oneTwoThree">>, Expect<Equal<T2, "oneTwoThree">>];
|
|
79
|
-
const c: cases = [true, true];
|
|
80
|
-
expect(c).toBe(c);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("CamelCase<T> returns 'string' type when passed a non-literal string", () => {
|
|
84
|
-
type T1 = CamelCase<string>;
|
|
85
|
-
|
|
86
|
-
type cases = [Expect<Equal<T1, string>>];
|
|
87
|
-
const c: cases = [true];
|
|
88
|
-
expect(c).toBe(c);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("CamelCase<T> can handle long strings which do not have caps (unless they're ALL CAPS)", () => {
|
|
92
|
-
type T1 = CamelCase<"one two three four five six seven eight nine">;
|
|
93
|
-
type T2 = CamelCase<"one_two_three_four_five_six_seven_eight_nine">;
|
|
94
|
-
type T3 = CamelCase<"ONE_TWO_THREE_FOUR_FIVE_SIX_SEVEN_EIGHT_NINE">;
|
|
95
|
-
// also works for multiple delimiters
|
|
96
|
-
type T4 = CamelCase<"one-two-three-four_five_six_seven_eight_nine">;
|
|
97
|
-
type T5 = CamelCase<"\n one-two-three-four_five_six_seven eight_nine \t">;
|
|
98
|
-
|
|
99
|
-
type cases = [
|
|
100
|
-
Expect<Equal<T1, "oneTwoThreeFourFiveSixSevenEightNine">>,
|
|
101
|
-
Expect<Equal<T2, "oneTwoThreeFourFiveSixSevenEightNine">>,
|
|
102
|
-
Expect<Equal<T3, "oneTwoThreeFourFiveSixSevenEightNine">>,
|
|
103
|
-
Expect<Equal<T4, "oneTwoThreeFourFiveSixSevenEightNine">>,
|
|
104
|
-
Expect<Equal<T5, "oneTwoThreeFourFiveSixSevenEightNine">>
|
|
105
|
-
];
|
|
106
|
-
const c: cases = [true, true, true, true, true];
|
|
107
|
-
expect(c).toBe(c);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
4
|
-
import { Dasherize } from "src/types";
|
|
5
|
-
|
|
6
|
-
const target = "two-three-four";
|
|
7
|
-
type TARGET = typeof target;
|
|
8
|
-
|
|
9
|
-
describe("Dasherize<T> type utility", () => {
|
|
10
|
-
it("Dasherize<T> provides an identity to a dasherized string", () => {
|
|
11
|
-
type T1 = Dasherize<"two-three-four">;
|
|
12
|
-
type T2 = Dasherize<"\n two-three-four ">;
|
|
13
|
-
|
|
14
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
|
|
15
|
-
const c: cases = [true, true];
|
|
16
|
-
expect(c).toBe(c);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("Dasherize<T> transform snake_case type", () => {
|
|
20
|
-
type T1 = Dasherize<"two_three_four">;
|
|
21
|
-
|
|
22
|
-
type cases = [Expect<Equal<T1, TARGET>>];
|
|
23
|
-
const c: cases = [true];
|
|
24
|
-
expect(c).toBe(c);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("Dasherize<T> transforms PascalCase type", () => {
|
|
28
|
-
type T1 = Dasherize<"TwoThreeFour">;
|
|
29
|
-
|
|
30
|
-
type cases = [Expect<Equal<T1, TARGET>>];
|
|
31
|
-
const c: cases = [true];
|
|
32
|
-
expect(c).toBe(c);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("Dasherize<T> transforms camelCase type up to a pretty long length", () => {
|
|
36
|
-
type T1 = Dasherize<"twoThreeFour">;
|
|
37
|
-
type T2 = Dasherize<"twoThreeFourFive">;
|
|
38
|
-
type T3 = Dasherize<"twoThreeFourFiveSix">;
|
|
39
|
-
type T4 = Dasherize<"twoThreeFourFiveSixSeven">;
|
|
40
|
-
type T5 = Dasherize<"twoThreeFourFiveSixSevenEight">;
|
|
41
|
-
// type T6 = Dasherize<"twoThreeFourFiveSixSevenEightNine">;
|
|
42
|
-
|
|
43
|
-
type cases = [
|
|
44
|
-
Expect<Equal<T1, TARGET>>,
|
|
45
|
-
Expect<Equal<T2, "two-three-four-five">>,
|
|
46
|
-
Expect<Equal<T3, "two-three-four-five-six">>,
|
|
47
|
-
Expect<Equal<T4, "two-three-four-five-six-seven">>,
|
|
48
|
-
Expect<Equal<T5, "two-three-four-five-six-seven-eight">>
|
|
49
|
-
// Expect<Equal<T6, "two-three-four-five-six-seven-eight-nine">>,
|
|
50
|
-
];
|
|
51
|
-
const c: cases = [true, true, true, true, true];
|
|
52
|
-
expect(c).toBe(c);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("Dasherize<T> transforms interior space to dasherized type", () => {
|
|
56
|
-
type T1 = Dasherize<"two three four">;
|
|
57
|
-
|
|
58
|
-
type cases = [Expect<Equal<T1, TARGET>>];
|
|
59
|
-
const c: cases = [true];
|
|
60
|
-
expect(c).toBe(c);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("Dasherize<T> transforms ALL CAPS to dasherized type", () => {
|
|
64
|
-
type T1 = Dasherize<"TWO THREE FOUR">;
|
|
65
|
-
type T2 = Dasherize<"\n TWO_THREE_FOUR ">;
|
|
66
|
-
type T3 = Dasherize<"\n TWO-THREE-FOUR ">;
|
|
67
|
-
|
|
68
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>, Expect<Equal<T3, TARGET>>];
|
|
69
|
-
const c: cases = [true, true, true];
|
|
70
|
-
expect(c).toBe(c);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("Dasherize<T> removes leading and trailing whitespace and still converts", () => {
|
|
74
|
-
type T1 = Dasherize<" one two three ">;
|
|
75
|
-
type T2 = Dasherize<"\n one two three ">;
|
|
76
|
-
|
|
77
|
-
type cases = [Expect<Equal<T1, "one-two-three">>, Expect<Equal<T2, "one-two-three">>];
|
|
78
|
-
const c: cases = [true, true];
|
|
79
|
-
expect(c).toBe(c);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("Dasherize<T> returns 'string' type when passed a non-literal string", () => {
|
|
83
|
-
type T1 = Dasherize<string>;
|
|
84
|
-
|
|
85
|
-
type cases = [Expect<Equal<T1, string>>];
|
|
86
|
-
const c: cases = [true];
|
|
87
|
-
expect(c).toBe(c);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("Dasherize<T> can handle long strings which do not have caps (unless they're ALL CAPS)", () => {
|
|
91
|
-
type T1 = Dasherize<"one two three four five six seven eight nine ten">;
|
|
92
|
-
type T2 = Dasherize<"one_two_three_four_five_six_seven_eight_nine_ten">;
|
|
93
|
-
type T3 = Dasherize<"ONE_TWO_THREE_FOUR_FIVE_SIX_SEVEN_EIGHT_NINE_TEN">;
|
|
94
|
-
type T4 = Dasherize<"one-two-three-four_five_six_seven_eight_nine_ten">;
|
|
95
|
-
type T5 = Dasherize<"\n one-two-three-four_five_six_seven_eight_nine_ten \t">;
|
|
96
|
-
|
|
97
|
-
type cases = [
|
|
98
|
-
Expect<Equal<T1, "one-two-three-four-five-six-seven-eight-nine-ten">>,
|
|
99
|
-
Expect<Equal<T2, "one-two-three-four-five-six-seven-eight-nine-ten">>,
|
|
100
|
-
Expect<Equal<T3, "one-two-three-four-five-six-seven-eight-nine-ten">>,
|
|
101
|
-
Expect<Equal<T4, "one-two-three-four-five-six-seven-eight-nine-ten">>,
|
|
102
|
-
Expect<Equal<T5, "one-two-three-four-five-six-seven-eight-nine-ten">>
|
|
103
|
-
];
|
|
104
|
-
const c: cases = [true, true, true, true, true];
|
|
105
|
-
expect(c).toBe(c);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
2
|
-
import { ensureLeading } from "src/runtime/literals/ensureLeading";
|
|
3
|
-
import { ensureTrailing } from "src/runtime/literals/ensureTrailing";
|
|
4
|
-
import { stripLeading } from "src/runtime/literals/stripLeading";
|
|
5
|
-
import { stripTrailing } from "src/runtime/literals/stripTrailing";
|
|
6
|
-
import { EnsureLeading, EnsureTrailing, StripLeading, StripTrailing } from "src/types/alphabetic";
|
|
7
|
-
import { describe, expect, it } from "vitest";
|
|
8
|
-
|
|
9
|
-
// Note: while type tests clearly fail visible inspection, they pass from Vitest
|
|
10
|
-
// standpoint so always be sure to run `tsc --noEmit` over your test files to
|
|
11
|
-
// gain validation that no new type vulnerabilities have cropped up.
|
|
12
|
-
|
|
13
|
-
describe("EnsureLeading", () => {
|
|
14
|
-
it("EnsureLeading<T,U>", () => {
|
|
15
|
-
type T1 = EnsureLeading<"bar", "foo">;
|
|
16
|
-
type T2 = EnsureLeading<"foobar", "foo">;
|
|
17
|
-
|
|
18
|
-
type cases = [Expect<Equal<T1, "foobar">>, Expect<Equal<T2, "foobar">>];
|
|
19
|
-
const cases: cases = [true, true];
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("ensureLeading()", () => {
|
|
23
|
-
const t1 = ensureLeading("bar", "foo");
|
|
24
|
-
const t2 = ensureLeading("foobar", "foo");
|
|
25
|
-
expect(t1).toBe("foobar");
|
|
26
|
-
expect(t2).toBe("foobar");
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe("EnsureTrailing", () => {
|
|
31
|
-
it("EnsureTrailing<T,U>", () => {
|
|
32
|
-
type T1 = EnsureTrailing<"foo", "bar">;
|
|
33
|
-
type T2 = EnsureTrailing<"foobar", "bar">;
|
|
34
|
-
|
|
35
|
-
type cases = [Expect<Equal<T1, "foobar">>, Expect<Equal<T2, "foobar">>];
|
|
36
|
-
const cases: cases = [true, true];
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("ensureTrailing()", () => {
|
|
40
|
-
const t1 = ensureTrailing("foo", "bar");
|
|
41
|
-
const t2 = ensureTrailing("foobar", "bar");
|
|
42
|
-
expect(t1).toBe("foobar");
|
|
43
|
-
expect(t2).toBe("foobar");
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe("StripLeading", () => {
|
|
48
|
-
it("StripLeading<T,U>", () => {
|
|
49
|
-
type T1 = StripLeading<"foobar", "foo">;
|
|
50
|
-
type T2 = StripLeading<"bar", "foo">;
|
|
51
|
-
|
|
52
|
-
type cases = [Expect<Equal<T1, "bar">>, Expect<Equal<T2, "bar">>];
|
|
53
|
-
const cases: cases = [true, true];
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("stripLeading()", () => {
|
|
57
|
-
const t1 = stripLeading("foobar", "foo");
|
|
58
|
-
const t2 = stripLeading("bar", "foo");
|
|
59
|
-
expect(t1).toBe("bar");
|
|
60
|
-
expect(t2).toBe("bar");
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe("StripTrailing", () => {
|
|
65
|
-
it("StripTrailing<T,U>", () => {
|
|
66
|
-
type T1 = StripTrailing<"foobar", "bar">;
|
|
67
|
-
type T2 = StripTrailing<"foo", "bar">;
|
|
68
|
-
|
|
69
|
-
type cases = [Expect<Equal<T1, "foo">>, Expect<Equal<T2, "foo">>];
|
|
70
|
-
const cases: cases = [true, true];
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("stripTrailing()", () => {
|
|
74
|
-
const t1 = stripTrailing("foobar", "bar");
|
|
75
|
-
const t2 = stripTrailing("foo", "bar");
|
|
76
|
-
expect(t1).toBe("foo");
|
|
77
|
-
expect(t2).toBe("foo");
|
|
78
|
-
});
|
|
79
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
4
|
-
import { HasUppercase } from "src/types";
|
|
5
|
-
|
|
6
|
-
describe("HasUppercase<T> type utility", () => {
|
|
7
|
-
it("finds capitals where they exist", () => {
|
|
8
|
-
type T1 = HasUppercase<"Yup">;
|
|
9
|
-
type T2 = HasUppercase<"yUp">;
|
|
10
|
-
type T3 = HasUppercase<"YUP">;
|
|
11
|
-
|
|
12
|
-
type cases = [Expect<Equal<T1, true>>, Expect<Equal<T2, true>>, Expect<Equal<T3, true>>];
|
|
13
|
-
const c: cases = [true, true, true];
|
|
14
|
-
expect(c).toBe(c);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("correctly identifies the absence of capitals", () => {
|
|
18
|
-
type T1 = HasUppercase<"nope">;
|
|
19
|
-
type T2 = HasUppercase<" noo nooo noooooooooooooo">;
|
|
20
|
-
|
|
21
|
-
type cases = [Expect<Equal<T1, false>>, Expect<Equal<T2, false>>];
|
|
22
|
-
const c: cases = [true, true];
|
|
23
|
-
expect(c).toBe(c);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("when passed a non literal string, returns 'unknown'", () => {
|
|
27
|
-
type T1 = HasUppercase<string>;
|
|
28
|
-
|
|
29
|
-
type cases = [Expect<Equal<T1, "unknown">>];
|
|
30
|
-
const c: cases = [true];
|
|
31
|
-
expect(c).toBe(c);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
4
|
-
import { PascalCase } from "src/types";
|
|
5
|
-
|
|
6
|
-
const target = "TwoThreeFour";
|
|
7
|
-
type TARGET = typeof target;
|
|
8
|
-
|
|
9
|
-
describe("PascalCase<T> type utility", () => {
|
|
10
|
-
it("PascalCase<T> provides an identity to a PascalCased string", () => {
|
|
11
|
-
type T1 = PascalCase<"TwoThreeFour">;
|
|
12
|
-
type T2 = PascalCase<"\n TwoThreeFour ">;
|
|
13
|
-
|
|
14
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
|
|
15
|
-
const c: cases = [true, true];
|
|
16
|
-
expect(c).toBe(c);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("PascalCase<T> transform snake_case type", () => {
|
|
20
|
-
type T1 = PascalCase<"two_three_four">;
|
|
21
|
-
|
|
22
|
-
type cases = [Expect<Equal<T1, TARGET>>];
|
|
23
|
-
const c: cases = [true];
|
|
24
|
-
expect(c).toBe(c);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("PascalCase<T> transforms camelCase type", () => {
|
|
28
|
-
type T1 = PascalCase<"twoThreeFour">;
|
|
29
|
-
type T2 = PascalCase<" twoThreeFour \t">;
|
|
30
|
-
|
|
31
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
|
|
32
|
-
const c: cases = [true, true];
|
|
33
|
-
expect(c).toBe(c);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("PascalCase<T> transforms camelCase type up to any length", () => {
|
|
37
|
-
type T1 = PascalCase<"twoThreeFour">;
|
|
38
|
-
type T2 = PascalCase<"twoThreeFourFive">;
|
|
39
|
-
type T3 = PascalCase<"twoThreeFourFiveSix">;
|
|
40
|
-
type T4 = PascalCase<"twoThreeFourFiveSixSeven">;
|
|
41
|
-
type T5 = PascalCase<"twoThreeFourFiveSixSevenEight">;
|
|
42
|
-
type T6 = PascalCase<"twoThreeFourFiveSixSevenEightNineTenEleven">;
|
|
43
|
-
|
|
44
|
-
type cases = [
|
|
45
|
-
Expect<Equal<T1, TARGET>>,
|
|
46
|
-
Expect<Equal<T2, "TwoThreeFourFive">>,
|
|
47
|
-
Expect<Equal<T3, "TwoThreeFourFiveSix">>,
|
|
48
|
-
Expect<Equal<T4, "TwoThreeFourFiveSixSeven">>,
|
|
49
|
-
Expect<Equal<T5, "TwoThreeFourFiveSixSevenEight">>,
|
|
50
|
-
Expect<Equal<T6, "TwoThreeFourFiveSixSevenEightNineTenEleven">>
|
|
51
|
-
];
|
|
52
|
-
const c: cases = [true, true, true, true, true, true];
|
|
53
|
-
expect(c).toBe(c);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("PascalCase<T> transforms interior space to PascalCased type", () => {
|
|
57
|
-
type T1 = PascalCase<"two three four">;
|
|
58
|
-
|
|
59
|
-
type cases = [Expect<Equal<T1, TARGET>>];
|
|
60
|
-
const c: cases = [true];
|
|
61
|
-
expect(c).toBe(c);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("PascalCase<T> transforms ALL CAPS to PascalCased type", () => {
|
|
65
|
-
type T1 = PascalCase<"TWO THREE FOUR">;
|
|
66
|
-
type T2 = PascalCase<"\n TWO_THREE_FOUR ">;
|
|
67
|
-
type T3 = PascalCase<"\n TWO-THREE-FOUR ">;
|
|
68
|
-
|
|
69
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>, Expect<Equal<T3, TARGET>>];
|
|
70
|
-
const c: cases = [true, true, true];
|
|
71
|
-
expect(c).toBe(c);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("PascalCase<T> removes leading and trailing whitespace and still converts", () => {
|
|
75
|
-
type T1 = PascalCase<" one two three ">;
|
|
76
|
-
type T2 = PascalCase<"\n one two three ">;
|
|
77
|
-
|
|
78
|
-
type cases = [Expect<Equal<T1, "OneTwoThree">>, Expect<Equal<T2, "OneTwoThree">>];
|
|
79
|
-
const c: cases = [true, true];
|
|
80
|
-
expect(c).toBe(c);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("PascalCase<T> returns 'string' type when passed a non-literal string", () => {
|
|
84
|
-
type T1 = PascalCase<string>;
|
|
85
|
-
|
|
86
|
-
type cases = [Expect<Equal<T1, string>>];
|
|
87
|
-
const c: cases = [true];
|
|
88
|
-
expect(c).toBe(c);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("PascalCase<T> can handle long strings which do not have caps (unless they're ALL CAPS)", () => {
|
|
92
|
-
type T1 = PascalCase<"one two three four five six seven eight nine">;
|
|
93
|
-
type T2 = PascalCase<"one_two_three_four_five_six_seven_eight_nine">;
|
|
94
|
-
type T3 = PascalCase<"ONE_TWO_THREE_FOUR_FIVE_SIX_SEVEN_EIGHT_NINE">;
|
|
95
|
-
// also works for multiple delimiters
|
|
96
|
-
type T4 = PascalCase<"one-two-three-four_five_six_seven_eight_nine">;
|
|
97
|
-
type T5 = PascalCase<"\n one-two-three-four_five_six_seven eight_nine \t">;
|
|
98
|
-
|
|
99
|
-
type cases = [
|
|
100
|
-
Expect<Equal<T1, "OneTwoThreeFourFiveSixSevenEightNine">>,
|
|
101
|
-
Expect<Equal<T2, "OneTwoThreeFourFiveSixSevenEightNine">>,
|
|
102
|
-
Expect<Equal<T3, "OneTwoThreeFourFiveSixSevenEightNine">>,
|
|
103
|
-
Expect<Equal<T4, "OneTwoThreeFourFiveSixSevenEightNine">>,
|
|
104
|
-
Expect<Equal<T5, "OneTwoThreeFourFiveSixSevenEightNine">>
|
|
105
|
-
];
|
|
106
|
-
const c: cases = [true, true, true, true, true];
|
|
107
|
-
expect(c).toBe(c);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
2
|
-
import { pathJoin } from "src/runtime/literals/pathJoin";
|
|
3
|
-
import { PathJoin } from "src/types/alphabetic/PathJoin";
|
|
4
|
-
import { describe, expect, it } from "vitest";
|
|
5
|
-
|
|
6
|
-
// Note: type tests fail visible inspection but pass from Vitest
|
|
7
|
-
// standpoint so always be sure to run `tsc --noEmit` over your test files to
|
|
8
|
-
// gain validation that no new type vulnerabilities have cropped up.
|
|
9
|
-
|
|
10
|
-
describe("PathJoin<T,U>", () => {
|
|
11
|
-
it("only literals / happy path", () => {
|
|
12
|
-
type T1 = PathJoin<"foo", "bar">;
|
|
13
|
-
type T2 = PathJoin<"foo/", "bar">;
|
|
14
|
-
type T3 = PathJoin<"foo", "/bar">;
|
|
15
|
-
type T4 = PathJoin<"foo/", "/bar">;
|
|
16
|
-
type T5 = PathJoin<"/foo/", "/bar">;
|
|
17
|
-
type T6 = PathJoin<"foo/", "/bar/">;
|
|
18
|
-
|
|
19
|
-
type cases = [
|
|
20
|
-
// neither have divider
|
|
21
|
-
Expect<Equal<T1, "foo/bar">>,
|
|
22
|
-
// one has, one does not
|
|
23
|
-
Expect<Equal<T2, "foo/bar">>,
|
|
24
|
-
Expect<Equal<T3, "foo/bar">>,
|
|
25
|
-
// both have
|
|
26
|
-
Expect<Equal<T4, "foo/bar">>,
|
|
27
|
-
// leading slash
|
|
28
|
-
Expect<Equal<T5, "/foo/bar">>,
|
|
29
|
-
// trailing slash
|
|
30
|
-
Expect<Equal<T6, "foo/bar/">>
|
|
31
|
-
];
|
|
32
|
-
const cases: cases = [true, true, true, true, true, true];
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("PathJoin<T,U> with U as array", () => {
|
|
36
|
-
type T1 = PathJoin<"foo", ["bar", "baz"]>;
|
|
37
|
-
type T2 = PathJoin<"/foo/", ["/bar/", "/baz/"]>;
|
|
38
|
-
type T3 = PathJoin<"/foo/", ["bar", "/baz"]>;
|
|
39
|
-
|
|
40
|
-
type cases = [
|
|
41
|
-
//
|
|
42
|
-
Expect<Equal<T1, "foo/bar/baz">>,
|
|
43
|
-
Expect<Equal<T2, "/foo/bar/baz/">>,
|
|
44
|
-
Expect<Equal<T3, "/foo/bar/baz">>
|
|
45
|
-
];
|
|
46
|
-
const cases: cases = [true, true, true];
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("wide types mixed in", () => {
|
|
50
|
-
type T1 = PathJoin<"foo", string>;
|
|
51
|
-
type T2 = PathJoin<"foo/", string>;
|
|
52
|
-
type T3 = PathJoin<string, "/bar">;
|
|
53
|
-
type T4 = PathJoin<string, "bar">;
|
|
54
|
-
|
|
55
|
-
type cases = [
|
|
56
|
-
Expect<Equal<T1, `foo/${string}`>>,
|
|
57
|
-
Expect<Equal<T2, `foo/${string}`>>,
|
|
58
|
-
Expect<Equal<T3, `${string}/bar`>>,
|
|
59
|
-
Expect<Equal<T4, `${string}bar`>>
|
|
60
|
-
];
|
|
61
|
-
const cases: cases = [true, true, true, true];
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe("pathJoin() runtime util", () => {
|
|
66
|
-
it("no leading or trailing slashes", () => {
|
|
67
|
-
const t1 = pathJoin("foo", "bar");
|
|
68
|
-
const t2 = pathJoin("foo/", "bar");
|
|
69
|
-
const t3 = pathJoin("foo", "/bar");
|
|
70
|
-
const t4 = pathJoin("foo/", "/bar");
|
|
71
|
-
// multi
|
|
72
|
-
const t5 = pathJoin("foo/", "bar", "/baz");
|
|
73
|
-
const t6 = pathJoin("foo/", "bar/", "/baz");
|
|
74
|
-
|
|
75
|
-
[t1, t2, t3, t4].forEach((test) =>
|
|
76
|
-
expect(test, "no leading or trailing slash").toBe("foo/bar")
|
|
77
|
-
);
|
|
78
|
-
[t5, t6].forEach((test) =>
|
|
79
|
-
expect(test, "no leading or trailing slash (with multi U)").toBe("foo/bar/baz")
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("leading and trailing slashes", () => {
|
|
84
|
-
const t1 = pathJoin("/foo", "bar");
|
|
85
|
-
const t2 = pathJoin("foo/", "bar/");
|
|
86
|
-
const t3 = pathJoin("/foo", "bar", "/baz");
|
|
87
|
-
const t4 = pathJoin("foo/", "/bar/", "/baz/");
|
|
88
|
-
// runtime tests
|
|
89
|
-
expect(t1).toBe("/foo/bar");
|
|
90
|
-
expect(t2).toBe("foo/bar/");
|
|
91
|
-
expect(t3).toBe("/foo/bar/baz");
|
|
92
|
-
expect(t4).toBe("foo/bar/baz/");
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("singular value", () => {
|
|
96
|
-
const t1 = pathJoin("foo");
|
|
97
|
-
const t2 = pathJoin("foo/");
|
|
98
|
-
|
|
99
|
-
// runtime
|
|
100
|
-
expect(t1).toBe("foo");
|
|
101
|
-
expect(t2).toBe("foo/");
|
|
102
|
-
|
|
103
|
-
// design time
|
|
104
|
-
type cases = [
|
|
105
|
-
//
|
|
106
|
-
Expect<Equal<typeof t1, "foo">>,
|
|
107
|
-
Expect<Equal<typeof t2, "foo/">>
|
|
108
|
-
];
|
|
109
|
-
const cases: cases = [true, true];
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
4
|
-
import { SnakeCase } from "src/types";
|
|
5
|
-
|
|
6
|
-
const target = "two_three_four";
|
|
7
|
-
type TARGET = typeof target;
|
|
8
|
-
|
|
9
|
-
describe("SnakeCase<T> type utility", () => {
|
|
10
|
-
it("SnakeCase<T> provides an identity to a SnakeCased string", () => {
|
|
11
|
-
type T1 = SnakeCase<"TwoThreeFour">;
|
|
12
|
-
type T2 = SnakeCase<"\n TwoThreeFour ">;
|
|
13
|
-
|
|
14
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
|
|
15
|
-
const c: cases = [true, true];
|
|
16
|
-
expect(c).toBe(c);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("SnakeCase<T> transform snake_case type", () => {
|
|
20
|
-
type T1 = SnakeCase<"two_three_four">;
|
|
21
|
-
|
|
22
|
-
type cases = [Expect<Equal<T1, TARGET>>];
|
|
23
|
-
const c: cases = [true];
|
|
24
|
-
expect(c).toBe(c);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("SnakeCase<T> transforms camelCase type", () => {
|
|
28
|
-
type T1 = SnakeCase<"twoThreeFour">;
|
|
29
|
-
type T2 = SnakeCase<" twoThreeFour \t">;
|
|
30
|
-
|
|
31
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
|
|
32
|
-
const c: cases = [true, true];
|
|
33
|
-
expect(c).toBe(c);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("SnakeCase<T> transforms camelCase type up to a reasonable length", () => {
|
|
37
|
-
type T1 = SnakeCase<"twoThreeFour">;
|
|
38
|
-
type T2 = SnakeCase<"twoThreeFourFive">;
|
|
39
|
-
type T3 = SnakeCase<"twoThreeFourFiveSix">;
|
|
40
|
-
type T4 = SnakeCase<"twoThreeFourFiveSixSeven">;
|
|
41
|
-
type T5 = SnakeCase<"twoThreeFourFiveSixSevenEight">;
|
|
42
|
-
// type T6 = SnakeCase<"twoThreeFourFiveSixSevenEightNineTenEleven">;
|
|
43
|
-
|
|
44
|
-
type cases = [
|
|
45
|
-
Expect<Equal<T1, TARGET>>,
|
|
46
|
-
Expect<Equal<T2, "two_three_four_five">>,
|
|
47
|
-
Expect<Equal<T3, "two_three_four_five_six">>,
|
|
48
|
-
Expect<Equal<T4, "two_three_four_five_six_seven">>,
|
|
49
|
-
Expect<Equal<T5, "two_three_four_five_six_seven_eight">>
|
|
50
|
-
// Expect<Equal<T6, "TwoThreeFourFiveSixSevenEightNineTenEleven">>,
|
|
51
|
-
];
|
|
52
|
-
const c: cases = [true, true, true, true, true];
|
|
53
|
-
expect(c).toBe(c);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("SnakeCase<T> transforms interior space to SnakeCased type", () => {
|
|
57
|
-
type T1 = SnakeCase<"two three four">;
|
|
58
|
-
|
|
59
|
-
type cases = [Expect<Equal<T1, TARGET>>];
|
|
60
|
-
const c: cases = [true];
|
|
61
|
-
expect(c).toBe(c);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("SnakeCase<T> transforms ALL CAPS to SnakeCased type", () => {
|
|
65
|
-
type T1 = SnakeCase<"TWO THREE FOUR">;
|
|
66
|
-
type T2 = SnakeCase<"\n TWO_THREE_FOUR ">;
|
|
67
|
-
type T3 = SnakeCase<"\n TWO-THREE-FOUR ">;
|
|
68
|
-
|
|
69
|
-
type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>, Expect<Equal<T3, TARGET>>];
|
|
70
|
-
const c: cases = [true, true, true];
|
|
71
|
-
expect(c).toBe(c);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("SnakeCase<T> removes leading and trailing whitespace and still converts", () => {
|
|
75
|
-
type T1 = SnakeCase<" one two three ">;
|
|
76
|
-
type T2 = SnakeCase<"\n one two three ">;
|
|
77
|
-
|
|
78
|
-
type cases = [Expect<Equal<T1, "one_two_three">>, Expect<Equal<T2, "one_two_three">>];
|
|
79
|
-
const c: cases = [true, true];
|
|
80
|
-
expect(c).toBe(c);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("SnakeCase<T> returns 'string' type when passed a non-literal string", () => {
|
|
84
|
-
type T1 = SnakeCase<string>;
|
|
85
|
-
|
|
86
|
-
type cases = [Expect<Equal<T1, string>>];
|
|
87
|
-
const c: cases = [true];
|
|
88
|
-
expect(c).toBe(c);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("SnakeCase<T> can handle long strings which do not have caps (unless they're ALL CAPS)", () => {
|
|
92
|
-
type T1 = SnakeCase<"one two three four five six seven eight nine">;
|
|
93
|
-
type T2 = SnakeCase<"one_two_three_four_five_six_seven_eight_nine">;
|
|
94
|
-
type T3 = SnakeCase<"ONE_TWO_THREE_FOUR_FIVE_SIX_SEVEN_EIGHT_NINE">;
|
|
95
|
-
// also works for multiple delimiters
|
|
96
|
-
type T4 = SnakeCase<"one-two-three-four_five_six_seven_eight_nine">;
|
|
97
|
-
type T5 = SnakeCase<"\n one-two-three-four_five_six_seven eight_nine \t">;
|
|
98
|
-
|
|
99
|
-
type cases = [
|
|
100
|
-
Expect<Equal<T1, "one_two_three_four_five_six_seven_eight_nine">>,
|
|
101
|
-
Expect<Equal<T2, "one_two_three_four_five_six_seven_eight_nine">>,
|
|
102
|
-
Expect<Equal<T3, "one_two_three_four_five_six_seven_eight_nine">>,
|
|
103
|
-
Expect<Equal<T4, "one_two_three_four_five_six_seven_eight_nine">>,
|
|
104
|
-
Expect<Equal<T5, "one_two_three_four_five_six_seven_eight_nine">>
|
|
105
|
-
];
|
|
106
|
-
const c: cases = [true, true, true, true, true];
|
|
107
|
-
expect(c).toBe(c);
|
|
108
|
-
});
|
|
109
|
-
});
|