inferred-types 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/.eslintrc +36 -20
  2. package/.github/workflows/main.yml +34 -0
  3. package/.github/workflows/other.yml +15 -0
  4. package/.vscode/settings.json +10 -2
  5. package/dist/index.d.ts +398 -8541
  6. package/dist/index.js +17 -60
  7. package/dist/index.mjs +8 -48
  8. package/package.json +32 -24
  9. package/src/shared/valueTypes.ts +1 -1
  10. package/src/types/ExpandRecursively.ts +10 -1
  11. package/src/types/SimplifyObject.ts +12 -0
  12. package/src/types/Transformer.ts +1 -1
  13. package/src/types/alphabetic/CamelCase.ts +1 -1
  14. package/src/types/alphabetic/CapFirstAlpha.ts +7 -3
  15. package/src/types/alphabetic/Dasherize.ts +8 -5
  16. package/src/types/alphabetic/KebabCase.ts +1 -1
  17. package/src/types/alphabetic/PascalCase.ts +3 -1
  18. package/src/types/alphabetic/SnakeCase.ts +8 -3
  19. package/src/types/dictionary/DictPartialApplication.ts +30 -0
  20. package/src/types/dictionary/DictPrependWithFn.ts +23 -0
  21. package/src/types/dictionary/DictReturnValues.ts +27 -0
  22. package/src/types/dictionary/RequireProps.ts +15 -0
  23. package/src/types/{type-conversion → dictionary}/SameKeys.ts +0 -0
  24. package/src/types/dictionary/index.ts +8 -3
  25. package/src/types/{props.ts → dictionary/props.ts} +1 -1
  26. package/src/types/functions/FinalReturn.ts +12 -0
  27. package/{on-hold/types → src/types/functions}/index.ts +4 -3
  28. package/src/types/index.ts +4 -3
  29. package/src/types/ruleset-types.ts +3 -3
  30. package/src/types/runtime.ts +18 -18
  31. package/src/types/string-literals/LeftWhitespace.ts +5 -2
  32. package/src/types/string-literals/RightWhitespace.ts +5 -2
  33. package/src/types/tuples/FirstKey.ts +3 -3
  34. package/src/types/tuples/FromDictArray.ts +5 -4
  35. package/src/types/type-conversion/index.ts +2 -5
  36. package/src/utility/api/api.ts +8 -7
  37. package/src/utility/dictionary/dictionaryTransform.ts +5 -4
  38. package/src/utility/dictionary/entries.ts +9 -5
  39. package/src/utility/dictionary/index.ts +2 -3
  40. package/src/utility/dictionary/kv/dictToKv.ts +5 -3
  41. package/src/utility/dictionary/kv/filterDictArray.ts +5 -7
  42. package/src/utility/dictionary/kv/kv.ts +8 -3
  43. package/src/utility/dictionary/kv/kvToDict.ts +3 -2
  44. package/src/utility/dictionary/mapValues.ts +8 -5
  45. package/src/utility/dictionary/strArrayToDict.ts +1 -2
  46. package/src/utility/keys.ts +8 -4
  47. package/src/utility/lists/groupBy.ts +2 -9
  48. package/src/utility/literals/arrayToObject.ts +29 -29
  49. package/src/utility/literals/defineType.ts +6 -6
  50. package/src/utility/literals/identity.ts +5 -2
  51. package/src/utility/literals/literal.ts +3 -3
  52. package/src/utility/ruleset.ts +11 -9
  53. package/src/utility/runtime/condition.ts +1 -1
  54. package/src/utility/runtime/conditions/isFalse.ts +2 -2
  55. package/src/utility/runtime/conditions/isFunction.ts +2 -2
  56. package/src/utility/runtime/conditions/isObject.ts +4 -1
  57. package/src/utility/runtime/conditions/isTrue.ts +1 -1
  58. package/src/utility/runtime/ifTypeOf.ts +1 -1
  59. package/src/utility/runtime/type.ts +3 -1
  60. package/src/utility/runtime/withValue.ts +5 -3
  61. package/src/utility/state/Configurator.ts +2 -2
  62. package/src/utility/state/FluentConfigurator.ts +2 -2
  63. package/src/utility/state/index.ts +2 -3
  64. package/tests/CamelCase-spec.ts +2 -0
  65. package/tests/ExplicitFunction-spec.ts +3 -2
  66. package/tests/IncludeAndRetain-spec.ts +7 -12
  67. package/tests/Includes-spec.ts +2 -0
  68. package/tests/KebabCase-spec.ts +2 -0
  69. package/tests/MutationIdentity-spec.ts +2 -1
  70. package/tests/PascalCase-spec.ts +2 -0
  71. package/tests/Pluralize-spec.ts +2 -0
  72. package/tests/SnakeCase-spec.ts +2 -0
  73. package/tests/Where.spec.ts +9 -10
  74. package/tests/arrayToKeyLookup-spec.ts +5 -5
  75. package/tests/arrayToObject-spec.ts +12 -8
  76. package/tests/constructor.spec.ts +2 -0
  77. package/tests/createFnWithProps.spec.ts +2 -2
  78. package/tests/defineType-spec.ts +17 -11
  79. package/tests/dictionary/DictPartialApplication.test.ts +43 -0
  80. package/tests/dictionary/DictReturnValues.test.ts +32 -0
  81. package/tests/dictionary/Get.spec.ts +5 -3
  82. package/tests/dictionary/PrependValuesWithFunction.ts +34 -0
  83. package/tests/dictionary/RequireProps.test.ts +21 -0
  84. package/tests/dictionaryTransform-spec.ts +3 -3
  85. package/tests/ifTypeOf-spec.ts +31 -20
  86. package/tests/kv/KeyValue-spec.ts +4 -4
  87. package/tests/kv/SameKeys-spec.ts +6 -9
  88. package/tests/kv/dict-to-kv-and-back.spec.ts +5 -4
  89. package/tests/kv/entries-spec.ts +8 -9
  90. package/tests/kv/keys.spec.ts +9 -19
  91. package/tests/kv/kv-spec.ts +4 -4
  92. package/tests/lists/UniqueForProp.spec.ts +3 -1
  93. package/tests/literal-spec.ts +5 -3
  94. package/tests/mapValues-spec.ts +5 -3
  95. package/tests/props-spec.ts +3 -2
  96. package/tests/runtime/condition.spec.ts +2 -1
  97. package/tests/runtime/type.spec.ts +4 -3
  98. package/tests/strArrayToDict-spec.ts +6 -6
  99. package/tests/string-literals/AllCaps.spec.ts +6 -15
  100. package/tests/string-literals/CamelCase.spec.ts +13 -32
  101. package/tests/string-literals/Dasherize.spec.ts +13 -31
  102. package/tests/string-literals/HasUppercase.spec.ts +6 -15
  103. package/tests/string-literals/PascalCase.spec.ts +13 -32
  104. package/tests/string-literals/SnakeCase.spec.ts +13 -32
  105. package/tests/string-literals/whitespace-capture.spec.ts +10 -28
  106. package/tests/tuples/TupleToUnion.spec.ts +3 -1
  107. package/tests/withValue.spec.ts +4 -3
  108. package/tsconfig.json +8 -19
  109. package/vitest.config.ts +13 -0
  110. package/jest.config.ts +0 -20
  111. package/on-hold/Builder/Builder.ts +0 -66
  112. package/on-hold/Builder/BuilderApi.ts +0 -21
  113. package/on-hold/Builder/IdentityToMutationApi.ts +0 -44
  114. package/on-hold/Builder/MutationToFluentApi.ts +0 -60
  115. package/on-hold/Builder/index.ts +0 -35
  116. package/on-hold/tests/Builder-spec.ts +0 -310
  117. package/on-hold/tests/RuleSet-spec.ts +0 -59
  118. package/on-hold/tests/ToFluent-spec.ts +0 -60
  119. package/on-hold/tests/api-spec.ts +0 -73
  120. package/on-hold/tests/data/builder-data.ts +0 -53
  121. package/on-hold/tests/filterDictArray-spec.ts +0 -50
  122. package/on-hold/tests/run-time-spec.ts +0 -44
  123. package/on-hold/type.ts +0 -20
  124. package/on-hold/types/object.ts +0 -19
  125. package/on-hold/types/prop.ts +0 -28
  126. package/on-hold/types/scalar.ts +0 -37
  127. package/src/types/dictionary/NotEmptyObject.ts +0 -9
  128. package/src/types/type-conversion/UnwrapValue.ts +0 -13
  129. package/src/types/type-conversion/WrapValue.ts +0 -15
  130. package/src/utility/dictionary/valuesOfProp.ts +0 -13
  131. package/src/utility/state/KeyStorage.ts +0 -23
@@ -1,19 +1,17 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import { Equal, Expect } from "@type-challenges/utils";
2
- import { Dasherize } from "~/types";
4
+ import { Dasherize } from "src/types";
3
5
 
4
6
  const target = "two-three-four";
5
7
  type TARGET = typeof target;
6
8
 
7
9
  describe("Dasherize<T> type utility", () => {
8
-
9
10
  it("Dasherize<T> provides an identity to a dasherized string", () => {
10
11
  type T1 = Dasherize<"two-three-four">;
11
12
  type T2 = Dasherize<"\n two-three-four ">;
12
13
 
13
- type cases = [
14
- Expect<Equal<T1, TARGET>>,
15
- Expect<Equal<T2, TARGET>>,
16
- ];
14
+ type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
17
15
  const c: cases = [true, true];
18
16
  expect(c).toBe(c);
19
17
  });
@@ -21,9 +19,7 @@ describe("Dasherize<T> type utility", () => {
21
19
  it("Dasherize<T> transform snake_case type", () => {
22
20
  type T1 = Dasherize<"two_three_four">;
23
21
 
24
- type cases = [
25
- Expect<Equal<T1, TARGET>>
26
- ];
22
+ type cases = [Expect<Equal<T1, TARGET>>];
27
23
  const c: cases = [true];
28
24
  expect(c).toBe(c);
29
25
  });
@@ -31,9 +27,7 @@ describe("Dasherize<T> type utility", () => {
31
27
  it("Dasherize<T> transforms PascalCase type", () => {
32
28
  type T1 = Dasherize<"TwoThreeFour">;
33
29
 
34
- type cases = [
35
- Expect<Equal<T1, TARGET>>
36
- ];
30
+ type cases = [Expect<Equal<T1, TARGET>>];
37
31
  const c: cases = [true];
38
32
  expect(c).toBe(c);
39
33
  });
@@ -51,7 +45,7 @@ describe("Dasherize<T> type utility", () => {
51
45
  Expect<Equal<T2, "two-three-four-five">>,
52
46
  Expect<Equal<T3, "two-three-four-five-six">>,
53
47
  Expect<Equal<T4, "two-three-four-five-six-seven">>,
54
- Expect<Equal<T5, "two-three-four-five-six-seven-eight">>,
48
+ Expect<Equal<T5, "two-three-four-five-six-seven-eight">>
55
49
  // Expect<Equal<T6, "two-three-four-five-six-seven-eight-nine">>,
56
50
  ];
57
51
  const c: cases = [true, true, true, true, true];
@@ -61,9 +55,7 @@ describe("Dasherize<T> type utility", () => {
61
55
  it("Dasherize<T> transforms interior space to dasherized type", () => {
62
56
  type T1 = Dasherize<"two three four">;
63
57
 
64
- type cases = [
65
- Expect<Equal<T1, TARGET>>
66
- ];
58
+ type cases = [Expect<Equal<T1, TARGET>>];
67
59
  const c: cases = [true];
68
60
  expect(c).toBe(c);
69
61
  });
@@ -73,11 +65,7 @@ describe("Dasherize<T> type utility", () => {
73
65
  type T2 = Dasherize<"\n TWO_THREE_FOUR ">;
74
66
  type T3 = Dasherize<"\n TWO-THREE-FOUR ">;
75
67
 
76
- type cases = [
77
- Expect<Equal<T1, TARGET>>,
78
- Expect<Equal<T2, TARGET>>,
79
- Expect<Equal<T3, TARGET>>,
80
- ];
68
+ type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>, Expect<Equal<T3, TARGET>>];
81
69
  const c: cases = [true, true, true];
82
70
  expect(c).toBe(c);
83
71
  });
@@ -86,10 +74,7 @@ describe("Dasherize<T> type utility", () => {
86
74
  type T1 = Dasherize<" one two three ">;
87
75
  type T2 = Dasherize<"\n one two three ">;
88
76
 
89
- type cases = [
90
- Expect<Equal<T1, "one-two-three">>,
91
- Expect<Equal<T2, "one-two-three">>,
92
- ];
77
+ type cases = [Expect<Equal<T1, "one-two-three">>, Expect<Equal<T2, "one-two-three">>];
93
78
  const c: cases = [true, true];
94
79
  expect(c).toBe(c);
95
80
  });
@@ -97,9 +82,7 @@ describe("Dasherize<T> type utility", () => {
97
82
  it("Dasherize<T> returns 'string' type when passed a non-literal string", () => {
98
83
  type T1 = Dasherize<string>;
99
84
 
100
- type cases = [
101
- Expect<Equal<T1, string>>,
102
- ];
85
+ type cases = [Expect<Equal<T1, string>>];
103
86
  const c: cases = [true];
104
87
  expect(c).toBe(c);
105
88
  });
@@ -116,10 +99,9 @@ describe("Dasherize<T> type utility", () => {
116
99
  Expect<Equal<T2, "one-two-three-four-five-six-seven-eight-nine-ten">>,
117
100
  Expect<Equal<T3, "one-two-three-four-five-six-seven-eight-nine-ten">>,
118
101
  Expect<Equal<T4, "one-two-three-four-five-six-seven-eight-nine-ten">>,
119
- Expect<Equal<T5, "one-two-three-four-five-six-seven-eight-nine-ten">>,
102
+ Expect<Equal<T5, "one-two-three-four-five-six-seven-eight-nine-ten">>
120
103
  ];
121
104
  const c: cases = [true, true, true, true, true];
122
105
  expect(c).toBe(c);
123
106
  });
124
-
125
- });
107
+ });
@@ -1,18 +1,15 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import { Equal, Expect } from "@type-challenges/utils";
2
- import { HasUppercase } from "~/types";
4
+ import { HasUppercase } from "src/types";
3
5
 
4
6
  describe("HasUppercase<T> type utility", () => {
5
-
6
7
  it("finds capitals where they exist", () => {
7
8
  type T1 = HasUppercase<"Yup">;
8
9
  type T2 = HasUppercase<"yUp">;
9
10
  type T3 = HasUppercase<"YUP">;
10
11
 
11
- type cases = [
12
- Expect<Equal<T1, true>>,
13
- Expect<Equal<T2, true>>,
14
- Expect<Equal<T3, true>>,
15
- ];
12
+ type cases = [Expect<Equal<T1, true>>, Expect<Equal<T2, true>>, Expect<Equal<T3, true>>];
16
13
  const c: cases = [true, true, true];
17
14
  expect(c).toBe(c);
18
15
  });
@@ -21,10 +18,7 @@ describe("HasUppercase<T> type utility", () => {
21
18
  type T1 = HasUppercase<"nope">;
22
19
  type T2 = HasUppercase<" noo nooo noooooooooooooo">;
23
20
 
24
- type cases = [
25
- Expect<Equal<T1, false>>,
26
- Expect<Equal<T2, false>>,
27
- ];
21
+ type cases = [Expect<Equal<T1, false>>, Expect<Equal<T2, false>>];
28
22
  const c: cases = [true, true];
29
23
  expect(c).toBe(c);
30
24
  });
@@ -32,11 +26,8 @@ describe("HasUppercase<T> type utility", () => {
32
26
  it("when passed a non literal string, returns 'unknown'", () => {
33
27
  type T1 = HasUppercase<string>;
34
28
 
35
- type cases = [
36
- Expect<Equal<T1, "unknown">>,
37
- ];
29
+ type cases = [Expect<Equal<T1, "unknown">>];
38
30
  const c: cases = [true];
39
31
  expect(c).toBe(c);
40
32
  });
41
-
42
33
  });
@@ -1,19 +1,17 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import { Equal, Expect } from "@type-challenges/utils";
2
- import { PascalCase } from "~/types";
4
+ import { PascalCase } from "src/types";
3
5
 
4
6
  const target = "TwoThreeFour";
5
7
  type TARGET = typeof target;
6
8
 
7
9
  describe("PascalCase<T> type utility", () => {
8
-
9
10
  it("PascalCase<T> provides an identity to a PascalCased string", () => {
10
11
  type T1 = PascalCase<"TwoThreeFour">;
11
12
  type T2 = PascalCase<"\n TwoThreeFour ">;
12
13
 
13
- type cases = [
14
- Expect<Equal<T1, TARGET>>,
15
- Expect<Equal<T2, TARGET>>,
16
- ];
14
+ type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
17
15
  const c: cases = [true, true];
18
16
  expect(c).toBe(c);
19
17
  });
@@ -21,9 +19,7 @@ describe("PascalCase<T> type utility", () => {
21
19
  it("PascalCase<T> transform snake_case type", () => {
22
20
  type T1 = PascalCase<"two_three_four">;
23
21
 
24
- type cases = [
25
- Expect<Equal<T1, TARGET>>
26
- ];
22
+ type cases = [Expect<Equal<T1, TARGET>>];
27
23
  const c: cases = [true];
28
24
  expect(c).toBe(c);
29
25
  });
@@ -32,10 +28,7 @@ describe("PascalCase<T> type utility", () => {
32
28
  type T1 = PascalCase<"twoThreeFour">;
33
29
  type T2 = PascalCase<" twoThreeFour \t">;
34
30
 
35
- type cases = [
36
- Expect<Equal<T1, TARGET>>,
37
- Expect<Equal<T2, TARGET>>,
38
- ];
31
+ type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
39
32
  const c: cases = [true, true];
40
33
  expect(c).toBe(c);
41
34
  });
@@ -54,7 +47,7 @@ describe("PascalCase<T> type utility", () => {
54
47
  Expect<Equal<T3, "TwoThreeFourFiveSix">>,
55
48
  Expect<Equal<T4, "TwoThreeFourFiveSixSeven">>,
56
49
  Expect<Equal<T5, "TwoThreeFourFiveSixSevenEight">>,
57
- Expect<Equal<T6, "TwoThreeFourFiveSixSevenEightNineTenEleven">>,
50
+ Expect<Equal<T6, "TwoThreeFourFiveSixSevenEightNineTenEleven">>
58
51
  ];
59
52
  const c: cases = [true, true, true, true, true, true];
60
53
  expect(c).toBe(c);
@@ -63,9 +56,7 @@ describe("PascalCase<T> type utility", () => {
63
56
  it("PascalCase<T> transforms interior space to PascalCased type", () => {
64
57
  type T1 = PascalCase<"two three four">;
65
58
 
66
- type cases = [
67
- Expect<Equal<T1, TARGET>>
68
- ];
59
+ type cases = [Expect<Equal<T1, TARGET>>];
69
60
  const c: cases = [true];
70
61
  expect(c).toBe(c);
71
62
  });
@@ -75,11 +66,7 @@ describe("PascalCase<T> type utility", () => {
75
66
  type T2 = PascalCase<"\n TWO_THREE_FOUR ">;
76
67
  type T3 = PascalCase<"\n TWO-THREE-FOUR ">;
77
68
 
78
- type cases = [
79
- Expect<Equal<T1, TARGET>>,
80
- Expect<Equal<T2, TARGET>>,
81
- Expect<Equal<T3, TARGET>>,
82
- ];
69
+ type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>, Expect<Equal<T3, TARGET>>];
83
70
  const c: cases = [true, true, true];
84
71
  expect(c).toBe(c);
85
72
  });
@@ -88,10 +75,7 @@ describe("PascalCase<T> type utility", () => {
88
75
  type T1 = PascalCase<" one two three ">;
89
76
  type T2 = PascalCase<"\n one two three ">;
90
77
 
91
- type cases = [
92
- Expect<Equal<T1, "OneTwoThree">>,
93
- Expect<Equal<T2, "OneTwoThree">>,
94
- ];
78
+ type cases = [Expect<Equal<T1, "OneTwoThree">>, Expect<Equal<T2, "OneTwoThree">>];
95
79
  const c: cases = [true, true];
96
80
  expect(c).toBe(c);
97
81
  });
@@ -99,9 +83,7 @@ describe("PascalCase<T> type utility", () => {
99
83
  it("PascalCase<T> returns 'string' type when passed a non-literal string", () => {
100
84
  type T1 = PascalCase<string>;
101
85
 
102
- type cases = [
103
- Expect<Equal<T1, string>>,
104
- ];
86
+ type cases = [Expect<Equal<T1, string>>];
105
87
  const c: cases = [true];
106
88
  expect(c).toBe(c);
107
89
  });
@@ -119,10 +101,9 @@ describe("PascalCase<T> type utility", () => {
119
101
  Expect<Equal<T2, "OneTwoThreeFourFiveSixSevenEightNine">>,
120
102
  Expect<Equal<T3, "OneTwoThreeFourFiveSixSevenEightNine">>,
121
103
  Expect<Equal<T4, "OneTwoThreeFourFiveSixSevenEightNine">>,
122
- Expect<Equal<T5, "OneTwoThreeFourFiveSixSevenEightNine">>,
104
+ Expect<Equal<T5, "OneTwoThreeFourFiveSixSevenEightNine">>
123
105
  ];
124
106
  const c: cases = [true, true, true, true, true];
125
107
  expect(c).toBe(c);
126
108
  });
127
-
128
- });
109
+ });
@@ -1,19 +1,17 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import { Equal, Expect } from "@type-challenges/utils";
2
- import { SnakeCase } from "~/types";
4
+ import { SnakeCase } from "src/types";
3
5
 
4
6
  const target = "two_three_four";
5
7
  type TARGET = typeof target;
6
8
 
7
9
  describe("SnakeCase<T> type utility", () => {
8
-
9
10
  it("SnakeCase<T> provides an identity to a SnakeCased string", () => {
10
11
  type T1 = SnakeCase<"TwoThreeFour">;
11
12
  type T2 = SnakeCase<"\n TwoThreeFour ">;
12
13
 
13
- type cases = [
14
- Expect<Equal<T1, TARGET>>,
15
- Expect<Equal<T2, TARGET>>,
16
- ];
14
+ type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
17
15
  const c: cases = [true, true];
18
16
  expect(c).toBe(c);
19
17
  });
@@ -21,9 +19,7 @@ describe("SnakeCase<T> type utility", () => {
21
19
  it("SnakeCase<T> transform snake_case type", () => {
22
20
  type T1 = SnakeCase<"two_three_four">;
23
21
 
24
- type cases = [
25
- Expect<Equal<T1, TARGET>>
26
- ];
22
+ type cases = [Expect<Equal<T1, TARGET>>];
27
23
  const c: cases = [true];
28
24
  expect(c).toBe(c);
29
25
  });
@@ -32,10 +28,7 @@ describe("SnakeCase<T> type utility", () => {
32
28
  type T1 = SnakeCase<"twoThreeFour">;
33
29
  type T2 = SnakeCase<" twoThreeFour \t">;
34
30
 
35
- type cases = [
36
- Expect<Equal<T1, TARGET>>,
37
- Expect<Equal<T2, TARGET>>,
38
- ];
31
+ type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>];
39
32
  const c: cases = [true, true];
40
33
  expect(c).toBe(c);
41
34
  });
@@ -53,7 +46,7 @@ describe("SnakeCase<T> type utility", () => {
53
46
  Expect<Equal<T2, "two_three_four_five">>,
54
47
  Expect<Equal<T3, "two_three_four_five_six">>,
55
48
  Expect<Equal<T4, "two_three_four_five_six_seven">>,
56
- Expect<Equal<T5, "two_three_four_five_six_seven_eight">>,
49
+ Expect<Equal<T5, "two_three_four_five_six_seven_eight">>
57
50
  // Expect<Equal<T6, "TwoThreeFourFiveSixSevenEightNineTenEleven">>,
58
51
  ];
59
52
  const c: cases = [true, true, true, true, true];
@@ -63,9 +56,7 @@ describe("SnakeCase<T> type utility", () => {
63
56
  it("SnakeCase<T> transforms interior space to SnakeCased type", () => {
64
57
  type T1 = SnakeCase<"two three four">;
65
58
 
66
- type cases = [
67
- Expect<Equal<T1, TARGET>>
68
- ];
59
+ type cases = [Expect<Equal<T1, TARGET>>];
69
60
  const c: cases = [true];
70
61
  expect(c).toBe(c);
71
62
  });
@@ -75,11 +66,7 @@ describe("SnakeCase<T> type utility", () => {
75
66
  type T2 = SnakeCase<"\n TWO_THREE_FOUR ">;
76
67
  type T3 = SnakeCase<"\n TWO-THREE-FOUR ">;
77
68
 
78
- type cases = [
79
- Expect<Equal<T1, TARGET>>,
80
- Expect<Equal<T2, TARGET>>,
81
- Expect<Equal<T3, TARGET>>,
82
- ];
69
+ type cases = [Expect<Equal<T1, TARGET>>, Expect<Equal<T2, TARGET>>, Expect<Equal<T3, TARGET>>];
83
70
  const c: cases = [true, true, true];
84
71
  expect(c).toBe(c);
85
72
  });
@@ -88,10 +75,7 @@ describe("SnakeCase<T> type utility", () => {
88
75
  type T1 = SnakeCase<" one two three ">;
89
76
  type T2 = SnakeCase<"\n one two three ">;
90
77
 
91
- type cases = [
92
- Expect<Equal<T1, "one_two_three">>,
93
- Expect<Equal<T2, "one_two_three">>,
94
- ];
78
+ type cases = [Expect<Equal<T1, "one_two_three">>, Expect<Equal<T2, "one_two_three">>];
95
79
  const c: cases = [true, true];
96
80
  expect(c).toBe(c);
97
81
  });
@@ -99,9 +83,7 @@ describe("SnakeCase<T> type utility", () => {
99
83
  it("SnakeCase<T> returns 'string' type when passed a non-literal string", () => {
100
84
  type T1 = SnakeCase<string>;
101
85
 
102
- type cases = [
103
- Expect<Equal<T1, string>>,
104
- ];
86
+ type cases = [Expect<Equal<T1, string>>];
105
87
  const c: cases = [true];
106
88
  expect(c).toBe(c);
107
89
  });
@@ -119,10 +101,9 @@ describe("SnakeCase<T> type utility", () => {
119
101
  Expect<Equal<T2, "one_two_three_four_five_six_seven_eight_nine">>,
120
102
  Expect<Equal<T3, "one_two_three_four_five_six_seven_eight_nine">>,
121
103
  Expect<Equal<T4, "one_two_three_four_five_six_seven_eight_nine">>,
122
- Expect<Equal<T5, "one_two_three_four_five_six_seven_eight_nine">>,
104
+ Expect<Equal<T5, "one_two_three_four_five_six_seven_eight_nine">>
123
105
  ];
124
106
  const c: cases = [true, true, true, true, true];
125
107
  expect(c).toBe(c);
126
108
  });
127
-
128
- });
109
+ });
@@ -1,16 +1,14 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import { Equal, Expect } from "@type-challenges/utils";
2
- import { LeftWhitespace, RightWhitespace } from "~/types";
4
+ import { LeftWhitespace, RightWhitespace } from "src/types";
3
5
 
4
6
  describe("LeftWhitespace<T> utility", () => {
5
-
6
7
  it("no whitespace results in empty string literal", () => {
7
8
  type T1 = LeftWhitespace<"foobar">;
8
9
  type T2 = LeftWhitespace<"foobar \n">;
9
10
 
10
- type cases = [
11
- Expect<Equal<T1, "">>,
12
- Expect<Equal<T2, "">>,
13
- ];
11
+ type cases = [Expect<Equal<T1, "">>, Expect<Equal<T2, "">>];
14
12
  const c: cases = [true, true];
15
13
  expect(c).toBe(c);
16
14
  });
@@ -19,10 +17,7 @@ describe("LeftWhitespace<T> utility", () => {
19
17
  type T1 = LeftWhitespace<" foobar">;
20
18
  type T2 = LeftWhitespace<"\n\t foobar \n">;
21
19
 
22
- type cases = [
23
- Expect<Equal<T1, " ">>,
24
- Expect<Equal<T2, "\n\t ">>,
25
- ];
20
+ type cases = [Expect<Equal<T1, " ">>, Expect<Equal<T2, "\n\t ">>];
26
21
  const c: cases = [true, true];
27
22
  expect(c).toBe(c);
28
23
  });
@@ -30,25 +25,18 @@ describe("LeftWhitespace<T> utility", () => {
30
25
  it("a 'string' type passed in returns a string", () => {
31
26
  type T1 = LeftWhitespace<string>;
32
27
 
33
- type cases = [
34
- Expect<Equal<T1, string>>,
35
- ];
28
+ type cases = [Expect<Equal<T1, string>>];
36
29
  const c: cases = [true];
37
30
  expect(c).toBe(c);
38
31
  });
39
-
40
32
  });
41
33
 
42
34
  describe("RightWhitespace<T> utility", () => {
43
-
44
35
  it("no whitespace results in empty string literal", () => {
45
36
  type T1 = RightWhitespace<"foobar">;
46
37
  type T2 = RightWhitespace<"\n\tfoobar">;
47
38
 
48
- type cases = [
49
- Expect<Equal<T1, "">>,
50
- Expect<Equal<T2, "">>,
51
- ];
39
+ type cases = [Expect<Equal<T1, "">>, Expect<Equal<T2, "">>];
52
40
  const c: cases = [true, true];
53
41
  expect(c).toBe(c);
54
42
  });
@@ -57,10 +45,7 @@ describe("RightWhitespace<T> utility", () => {
57
45
  type T1 = RightWhitespace<"foobar ">;
58
46
  type T2 = RightWhitespace<"\n\t foobar \n">;
59
47
 
60
- type cases = [
61
- Expect<Equal<T1, " ">>,
62
- Expect<Equal<T2, " \n">>,
63
- ];
48
+ type cases = [Expect<Equal<T1, " ">>, Expect<Equal<T2, " \n">>];
64
49
  const c: cases = [true, true];
65
50
  expect(c).toBe(c);
66
51
  });
@@ -68,11 +53,8 @@ describe("RightWhitespace<T> utility", () => {
68
53
  it("a 'string' type passed in returns a string", () => {
69
54
  type T1 = RightWhitespace<string>;
70
55
 
71
- type cases = [
72
- Expect<Equal<T1, string>>,
73
- ];
56
+ type cases = [Expect<Equal<T1, string>>];
74
57
  const c: cases = [true];
75
58
  expect(c).toBe(c);
76
59
  });
77
-
78
- });
60
+ });
@@ -1,4 +1,6 @@
1
- import { TupleToUnion } from "~/types";
1
+ import { describe, it, expect } from "vitest";
2
+
3
+ import { TupleToUnion } from "src/types";
2
4
  import { Expect, Equal } from "@type-challenges/utils";
3
5
 
4
6
  describe("TupleToUnion<T> type utility", () => {
@@ -1,7 +1,8 @@
1
- import { createFnWithProps, type, withValue } from "~/utility";
1
+ import { describe, it, expect } from "vitest";
2
2
  import type { Expect, Equal } from "@type-challenges/utils";
3
- import { WithValue } from "~/types/props";
4
- import { FunctionType } from "~/types";
3
+
4
+ import { createFnWithProps, type, withValue } from "../src/utility";
5
+ import { FunctionType, WithValue } from "../src";
5
6
 
6
7
  describe("withValue()() utility", () => {
7
8
  it("type reduction with WithValue<T> works as expected", () => {
package/tsconfig.json CHANGED
@@ -3,37 +3,26 @@
3
3
  "module": "ESNEXT",
4
4
  "target": "ESNEXT",
5
5
  "moduleResolution": "node",
6
-
7
6
  "sourceMap": true,
8
7
  "noEmit": true,
9
8
  "incremental": true,
10
9
  "resolveJsonModule": true,
11
-
12
10
  "strict": true,
13
11
  "skipLibCheck": true,
14
12
  "noUnusedLocals": true,
15
13
  "noUnusedParameters": true,
16
14
  "noImplicitReturns": true,
17
15
  "allowSyntheticDefaultImports": true,
18
-
19
- "lib": ["ES2020"],
20
-
16
+ "lib": [
17
+ "ES2020"
18
+ ],
21
19
  "baseUrl": ".",
22
20
  "declaration": true,
23
21
  "outDir": "dist",
24
22
  "tsBuildInfoFile": ".tsbuildinfo",
25
-
26
- "paths": {
27
- "~/*": ["src/*"],
28
- "/~/*": ["src/*"]
29
- },
30
- "plugins": [
31
- // Transform paths in output .js files
32
- { "transform": "typescript-transform-paths" },
33
-
34
- // Transform paths in output .d.ts files (Include this line if you output declarations files)
35
- { "transform": "typescript-transform-paths", "afterDeclarations": true }
36
- ]
37
23
  },
38
- "include": ["src", "tests"]
39
- }
24
+ "include": [
25
+ "src",
26
+ "tests"
27
+ ]
28
+ }
@@ -0,0 +1,13 @@
1
+ /// <reference types="vitest" />
2
+ import { defineConfig } from "vite";
3
+
4
+ // used for testing, library code uses TSUP to build exports
5
+ export default defineConfig({
6
+ test: {
7
+ dir: "tests",
8
+ api: {
9
+ host: "0.0.0.0",
10
+ },
11
+ },
12
+ plugins: [],
13
+ });
package/jest.config.ts DELETED
@@ -1,20 +0,0 @@
1
- /* eslint-disable unicorn/import-style */
2
- import type { Config } from "@jest/types";
3
- import { resolve } from "path";
4
-
5
- const config: Config.InitialOptions = {
6
- verbose: true,
7
- // roots: ["tests", "src"],
8
- transform: {
9
- "^.+\\.tsx?$": "ts-jest",
10
- },
11
- testPathIgnorePatterns: ["/node_modules/", "/on-hold/"],
12
- moduleNameMapper: {
13
- "^[/]{0,1}~/(.*)$": resolve(process.cwd(), "src", "$1"),
14
- },
15
- testMatch: ["**/?(*[-.])+(spec|test).ts"],
16
- setupFilesAfterEnv: ["jest-extended"],
17
- testEnvironment: "node",
18
- };
19
-
20
- export default config;
@@ -1,66 +0,0 @@
1
- import { TypeGuard } from "~/types";
2
-
3
- import { MutationIdentity } from "../Mutation";
4
- import { IdentityToMutationApi, MutationToFluentApi } from "./index";
5
-
6
- /* eslint-disable no-use-before-define */
7
-
8
- export type BuilderComplete<C, S> = C extends infer U ? (U extends S ? "" : "unwrap") : never;
9
-
10
- /**
11
- * **Builder**
12
- *
13
- * Creates a builder pattern that provides a user-friendly (and strongly typed)
14
- * means of configuring a defined data structure.
15
- *
16
- * The _first_ function call establishes a type-guard to validate when the desired
17
- * configuration has been achieved as well as the fluent API surface that should
18
- * be used to configure this builder.
19
- *
20
- * The _second_ function call allows for setting an initial configuration state.
21
- *
22
- * **Example:**
23
- *
24
- * ```ts
25
- * // configure
26
- * type Config = { foo: number };
27
- * const typeGuard = (thing: unknown): thing is Config { ... };
28
- * const config = Builder(typeGuard, api)();
29
- * // use (and unwrap)
30
- * const myConfig = config.set(5).add(3).unwrap();
31
- * ```
32
- */
33
- export function Builder<
34
- TState extends object,
35
- TApi extends { [key: string]: MutationIdentity<any, any> }
36
- >(validate: TypeGuard<TState>, apiDefinition: TApi) {
37
- /**
38
- * The non-fluent API component of the Builder API
39
- */
40
- type IEscape<T extends object = {}> = { unwrap: () => TState; current: Partial<TState> } & T;
41
-
42
- return <TCurrent extends Partial<TState>>(state: TCurrent) => {
43
- const escapeApi: IEscape = {
44
- current: state,
45
- unwrap: () => {
46
- if (!validate(state)) {
47
- throw new Error(
48
- `Attempt to unwrap() the state prior to it being completed! The configuration at this point is:\n${JSON.stringify(
49
- state,
50
- null,
51
- 2
52
- )}`
53
- );
54
- }
55
- return state;
56
- },
57
- };
58
-
59
- // provide state to identity functions to make them mutation functions
60
- const mutationApi = IdentityToMutationApi(state)(apiDefinition);
61
- // determine the exclusions
62
- type Complete = BuilderComplete<TCurrent, TState>;
63
- // transform mutation API to fluent API
64
- return MutationToFluentApi<TState, TApi, IEscape, Complete>(validate, apiDefinition)(mutationApi, escapeApi);
65
- };
66
- }
@@ -1,21 +0,0 @@
1
- /* eslint-disable no-use-before-define */
2
- import { MutationIdentity } from "~/Mutation";
3
-
4
- /**
5
- * Used to facilitate building **Identity APIs** to be used
6
- * in the `Builder` primitive.
7
- */
8
- export function BuilderApi<T extends object>() {
9
- return function BuilderKeyValue<
10
- // identity function (s => fn => s)
11
- V extends MutationIdentity<PT, any>,
12
- // API property
13
- K extends string,
14
- // KV pair
15
- O extends Record<K, V>,
16
- /** Provide structure of Partial<T> while using extends to preserve type info */
17
- PT extends Partial<T>
18
- >(key: K, value: V): O {
19
- return { [key as K]: value } as O;
20
- };
21
- }