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.
Files changed (280) hide show
  1. package/dist/index.d.ts +2745 -0
  2. package/dist/index.js +854 -0
  3. package/package.json +6 -12
  4. package/.eslintrc +0 -77
  5. package/.github/workflows/main.yml +0 -34
  6. package/.github/workflows/other.yml +0 -15
  7. package/.nvmrc +0 -1
  8. package/.prettierrc.js +0 -3
  9. package/.vscode/launch.json +0 -27
  10. package/.vscode/settings.json +0 -19
  11. package/devops/build.js +0 -243
  12. package/docs/builder-overview.md +0 -45
  13. package/docs/builder.md +0 -94
  14. package/src/errors/ReadOnlyViolation.ts +0 -3
  15. package/src/errors/index.ts +0 -12
  16. package/src/index.ts +0 -14
  17. package/src/runtime/README.md +0 -3
  18. package/src/runtime/api/api.ts +0 -10
  19. package/src/runtime/api/index.ts +0 -12
  20. package/src/runtime/builders/Model.ts +0 -25
  21. package/src/runtime/builders/url.ts +0 -15
  22. package/src/runtime/combinators/and.ts +0 -15
  23. package/src/runtime/combinators/filter.ts +0 -267
  24. package/src/runtime/combinators/index.ts +0 -4
  25. package/src/runtime/combinators/not.ts +0 -15
  26. package/src/runtime/combinators/or.ts +0 -5
  27. package/src/runtime/createFnWithProps.ts +0 -37
  28. package/src/runtime/dictionary/arrayToKeyLookup.ts +0 -19
  29. package/src/runtime/dictionary/defineProperties.ts +0 -35
  30. package/src/runtime/dictionary/dictArr.ts +0 -69
  31. package/src/runtime/dictionary/dictionaryTransform.ts +0 -22
  32. package/src/runtime/dictionary/entries.ts +0 -33
  33. package/src/runtime/dictionary/index.ts +0 -21
  34. package/src/runtime/dictionary/kv/dictToKv.ts +0 -21
  35. package/src/runtime/dictionary/kv/filterDictArray.ts +0 -31
  36. package/src/runtime/dictionary/kv/index.ts +0 -15
  37. package/src/runtime/dictionary/kv/kv.ts +0 -18
  38. package/src/runtime/dictionary/kv/kvToDict.ts +0 -24
  39. package/src/runtime/dictionary/mapTo.ts +0 -206
  40. package/src/runtime/dictionary/mapValues.ts +0 -23
  41. package/src/runtime/dictionary/merge.ts +0 -36
  42. package/src/runtime/dictionary/strArrayToDict.ts +0 -12
  43. package/src/runtime/index.ts +0 -23
  44. package/src/runtime/keys.ts +0 -16
  45. package/src/runtime/lists/asArray.ts +0 -38
  46. package/src/runtime/lists/createConverter.ts +0 -62
  47. package/src/runtime/lists/groupBy.ts +0 -15
  48. package/src/runtime/lists/index.ts +0 -15
  49. package/src/runtime/literals/ExplicitFunction.ts +0 -10
  50. package/src/runtime/literals/Suggest.ts +0 -19
  51. package/src/runtime/literals/arrayToObject.ts +0 -78
  52. package/src/runtime/literals/box.ts +0 -98
  53. package/src/runtime/literals/defineType.ts +0 -20
  54. package/src/runtime/literals/ensureLeading.ts +0 -17
  55. package/src/runtime/literals/ensureTrailing.ts +0 -17
  56. package/src/runtime/literals/identity.ts +0 -12
  57. package/src/runtime/literals/index.ts +0 -23
  58. package/src/runtime/literals/literal.ts +0 -48
  59. package/src/runtime/literals/pathJoin.ts +0 -33
  60. package/src/runtime/literals/stripLeading.ts +0 -15
  61. package/src/runtime/literals/stripTrailing.ts +0 -15
  62. package/src/runtime/literals/wide.ts +0 -13
  63. package/src/runtime/ruleset.ts +0 -42
  64. package/src/runtime/runtime/README.md +0 -3
  65. package/src/runtime/runtime/condition.ts +0 -13
  66. package/src/runtime/runtime/index.ts +0 -16
  67. package/src/runtime/runtime/type.ts +0 -127
  68. package/src/runtime/runtime/withValue.ts +0 -39
  69. package/src/runtime/state/Configurator.ts +0 -76
  70. package/src/runtime/state/FluentConfigurator.ts +0 -49
  71. package/src/runtime/state/index.ts +0 -13
  72. package/src/runtime/type-checks/ifSameType.ts +0 -20
  73. package/src/runtime/type-checks/ifTypeOf.ts +0 -124
  74. package/src/runtime/type-checks/index.ts +0 -24
  75. package/src/runtime/type-checks/isArray.ts +0 -34
  76. package/src/runtime/type-checks/isBoolean.ts +0 -24
  77. package/src/runtime/type-checks/isFalse.ts +0 -29
  78. package/src/runtime/type-checks/isFunction.ts +0 -26
  79. package/src/runtime/type-checks/isNull.ts +0 -26
  80. package/src/runtime/type-checks/isNumber.ts +0 -20
  81. package/src/runtime/type-checks/isObject.ts +0 -22
  82. package/src/runtime/type-checks/isString.ts +0 -34
  83. package/src/runtime/type-checks/isSymbol.ts +0 -3
  84. package/src/runtime/type-checks/isTrue.ts +0 -31
  85. package/src/runtime/type-checks/isUndefined.ts +0 -33
  86. package/src/runtime/type-checks/startsWith.ts +0 -107
  87. package/src/runtime/valueTypes.ts +0 -48
  88. package/src/types/Api.ts +0 -16
  89. package/src/types/Constructor.ts +0 -5
  90. package/src/types/EnumValues.ts +0 -14
  91. package/src/types/ExpandRecursively.ts +0 -12
  92. package/src/types/FunctionType.ts +0 -19
  93. package/src/types/If.ts +0 -10
  94. package/src/types/Include.ts +0 -18
  95. package/src/types/KeyedRecord.ts +0 -21
  96. package/src/types/Keys.ts +0 -26
  97. package/src/types/Length.ts +0 -8
  98. package/src/types/Mutable.ts +0 -8
  99. package/src/types/Narrowable.ts +0 -5
  100. package/src/types/Not.ts +0 -13
  101. package/src/types/Numeric.ts +0 -20
  102. package/src/types/Opaque.ts +0 -11
  103. package/src/types/README.md +0 -3
  104. package/src/types/Retain.ts +0 -16
  105. package/src/types/SimplifyObject.ts +0 -12
  106. package/src/types/Transformer.ts +0 -15
  107. package/src/types/TypeGuard.ts +0 -7
  108. package/src/types/Where.ts +0 -40
  109. package/src/types/alphabetic/AllCaps.ts +0 -15
  110. package/src/types/alphabetic/CamelCase.ts +0 -3
  111. package/src/types/alphabetic/CapFirstAlpha.ts +0 -23
  112. package/src/types/alphabetic/CapitalizeWords.ts +0 -9
  113. package/src/types/alphabetic/Cardinality.ts +0 -80
  114. package/src/types/alphabetic/DashToSnake.ts +0 -3
  115. package/src/types/alphabetic/DashUppercase.ts +0 -19
  116. package/src/types/alphabetic/Dasherize.ts +0 -23
  117. package/src/types/alphabetic/EnsureLeading.ts +0 -24
  118. package/src/types/alphabetic/EnsureTrailing.ts +0 -24
  119. package/src/types/alphabetic/HasUppercase.ts +0 -16
  120. package/src/types/alphabetic/IsCapitalized.ts +0 -18
  121. package/src/types/alphabetic/KebabCase.ts +0 -13
  122. package/src/types/alphabetic/LowerAllCaps.ts +0 -5
  123. package/src/types/alphabetic/PascalCase.ts +0 -29
  124. package/src/types/alphabetic/PathJoin.ts +0 -54
  125. package/src/types/alphabetic/Pluralize.ts +0 -112
  126. package/src/types/alphabetic/SnakeCase.ts +0 -27
  127. package/src/types/alphabetic/StripLeading.ts +0 -23
  128. package/src/types/alphabetic/StripTrailing.ts +0 -23
  129. package/src/types/alphabetic/Url.ts +0 -29
  130. package/src/types/alphabetic/alpha-characters.ts +0 -81
  131. package/src/types/alphabetic/index.ts +0 -32
  132. package/src/types/append-types.ts +0 -10
  133. package/src/types/boolean-logic/EndsWith.ts +0 -40
  134. package/src/types/boolean-logic/Extends.ts +0 -22
  135. package/src/types/boolean-logic/HasParameters.ts +0 -21
  136. package/src/types/boolean-logic/Includes.ts +0 -33
  137. package/src/types/boolean-logic/IsLiteral.ts +0 -101
  138. package/src/types/boolean-logic/IsScalar.ts +0 -20
  139. package/src/types/boolean-logic/IsUndefined.ts +0 -20
  140. package/src/types/boolean-logic/Or.ts +0 -12
  141. package/src/types/boolean-logic/StartsWith.ts +0 -42
  142. package/src/types/boolean-logic/TypeDefault.ts +0 -58
  143. package/src/types/boolean-logic/array.ts +0 -57
  144. package/src/types/boolean-logic/boolean.ts +0 -84
  145. package/src/types/boolean-logic/equivalency.ts +0 -15
  146. package/src/types/boolean-logic/index.ts +0 -14
  147. package/src/types/boolean-logic/object.ts +0 -30
  148. package/src/types/boolean-logic/string.ts +0 -21
  149. package/src/types/dictionary/DictChangeValue.ts +0 -34
  150. package/src/types/dictionary/DictPartialApplication.ts +0 -30
  151. package/src/types/dictionary/DictPrependWithFn.ts +0 -23
  152. package/src/types/dictionary/DictReturnValues.ts +0 -27
  153. package/src/types/dictionary/Get.ts +0 -14
  154. package/src/types/dictionary/MapTo.ts +0 -428
  155. package/src/types/dictionary/MutableProps.ts +0 -19
  156. package/src/types/dictionary/RequireProps.ts +0 -15
  157. package/src/types/dictionary/SameKeys.ts +0 -11
  158. package/src/types/dictionary/index.ts +0 -21
  159. package/src/types/dictionary/props.ts +0 -145
  160. package/src/types/fluent/fluent.ts +0 -61
  161. package/src/types/fluent/index.ts +0 -12
  162. package/src/types/functions/FinalReturn.ts +0 -12
  163. package/src/types/functions/LogicFunction.ts +0 -4
  164. package/src/types/functions/index.ts +0 -13
  165. package/src/types/index.ts +0 -49
  166. package/src/types/kv/DictFromKv.ts +0 -3
  167. package/src/types/kv/KeyValue.ts +0 -12
  168. package/src/types/kv/KvFrom.ts +0 -8
  169. package/src/types/kv/KvTuple.ts +0 -14
  170. package/src/types/kv/index.ts +0 -15
  171. package/src/types/lists/AfterFirst.ts +0 -10
  172. package/src/types/lists/ConvertAndMap.ts +0 -152
  173. package/src/types/lists/FilterTuple.ts +0 -20
  174. package/src/types/lists/First.ts +0 -8
  175. package/src/types/lists/FirstString.ts +0 -4
  176. package/src/types/lists/Split.ts +0 -21
  177. package/src/types/lists/UniqueForProp.ts +0 -18
  178. package/src/types/lists/index.ts +0 -18
  179. package/src/types/literal-unions/OptRequired.ts +0 -4
  180. package/src/types/literal-unions/index.ts +0 -1
  181. package/src/types/maybe.ts +0 -9
  182. package/src/types/ruleset-types.ts +0 -76
  183. package/src/types/runtime.ts +0 -39
  184. package/src/types/string-literals/Break.ts +0 -22
  185. package/src/types/string-literals/Concat.ts +0 -9
  186. package/src/types/string-literals/LeftWhitespace.ts +0 -13
  187. package/src/types/string-literals/Replace.ts +0 -17
  188. package/src/types/string-literals/RightWhitespace.ts +0 -13
  189. package/src/types/string-literals/StringLength.ts +0 -34
  190. package/src/types/string-literals/Trim.ts +0 -15
  191. package/src/types/string-literals/TrimLeft.ts +0 -14
  192. package/src/types/string-literals/TrimRight.ts +0 -14
  193. package/src/types/string-literals/form-fields.ts +0 -15
  194. package/src/types/string-literals/index.ts +0 -21
  195. package/src/types/tuples/DictArray.ts +0 -21
  196. package/src/types/tuples/FirstKey.ts +0 -10
  197. package/src/types/tuples/FirstKeyValue.ts +0 -9
  198. package/src/types/tuples/FirstOfEach.ts +0 -13
  199. package/src/types/tuples/FromDictArray.ts +0 -14
  200. package/src/types/tuples/SecondOfEach.ts +0 -13
  201. package/src/types/tuples/index.ts +0 -17
  202. package/src/types/type-conversion/TupleToUnion.ts +0 -9
  203. package/src/types/type-conversion/UnionToIntersection.ts +0 -9
  204. package/src/types/type-conversion/UnionToTuple.ts +0 -20
  205. package/src/types/type-conversion/Widen.ts +0 -22
  206. package/src/types/type-conversion/index.ts +0 -16
  207. package/src/types/type-testing.ts +0 -14
  208. package/tests/CamelCase-spec.ts +0 -20
  209. package/tests/Configurator-spec.hold +0 -106
  210. package/tests/ExplicitFunction-spec.ts +0 -50
  211. package/tests/IncludeAndRetain-spec.ts +0 -67
  212. package/tests/Includes-spec.ts +0 -36
  213. package/tests/KebabCase-spec.ts +0 -21
  214. package/tests/PascalCase-spec.ts +0 -22
  215. package/tests/Pluralize-spec.ts +0 -23
  216. package/tests/SnakeCase-spec.ts +0 -21
  217. package/tests/Where.spec.ts +0 -38
  218. package/tests/arrayToKeyLookup-spec.ts +0 -17
  219. package/tests/arrayToObject-spec.ts +0 -115
  220. package/tests/boolean-logic/Contains.test.ts +0 -55
  221. package/tests/boolean-logic/HasParameters.ts +0 -29
  222. package/tests/boolean-logic/IsLiteral.spec.ts +0 -65
  223. package/tests/boolean-logic/boolean.spec.ts +0 -21
  224. package/tests/boolean-logic/filter.spec.ts +0 -52
  225. package/tests/constructor.spec.ts +0 -42
  226. package/tests/createFnWithProps.spec.ts +0 -14
  227. package/tests/data/SimpleTable.hold +0 -21
  228. package/tests/data/index.ts +0 -12
  229. package/tests/data/playlist.hold +0 -25
  230. package/tests/data/song.hold +0 -23
  231. package/tests/defineType-spec.ts +0 -57
  232. package/tests/dictionary/DictChangeValue.test.ts +0 -30
  233. package/tests/dictionary/DictPartialApplication.test.ts +0 -43
  234. package/tests/dictionary/DictReturnValues.test.ts +0 -36
  235. package/tests/dictionary/Get.spec.ts +0 -28
  236. package/tests/dictionary/IntersectingKeys.test.ts +0 -42
  237. package/tests/dictionary/MutableProps.test.ts +0 -30
  238. package/tests/dictionary/OptionalKeys.test.ts +0 -24
  239. package/tests/dictionary/PrependValuesWithFunction.test.ts +0 -34
  240. package/tests/dictionary/RequireProps.test.ts +0 -21
  241. package/tests/dictionary/RequiredKeys.test.ts +0 -53
  242. package/tests/dictionary/TypeDefault.test.ts +0 -76
  243. package/tests/dictionary/mapTo.test.ts +0 -388
  244. package/tests/dictionary/merge.test.ts +0 -41
  245. package/tests/dictionaryTransform-spec.ts +0 -280
  246. package/tests/ifTypeOf-spec.ts +0 -191
  247. package/tests/kv/KeyValue-spec.ts +0 -22
  248. package/tests/kv/SameKeys-spec.ts +0 -35
  249. package/tests/kv/dict-to-kv-and-back.spec.ts +0 -169
  250. package/tests/kv/entries-spec.ts +0 -65
  251. package/tests/kv/keys.spec.ts +0 -66
  252. package/tests/kv/kv-spec.ts +0 -20
  253. package/tests/lists/First.test.ts +0 -43
  254. package/tests/lists/Length.test.ts +0 -19
  255. package/tests/lists/Split.test.ts +0 -29
  256. package/tests/lists/UniqueForProp.spec.ts +0 -59
  257. package/tests/lists/asArray.test.ts +0 -109
  258. package/tests/lists/dictArr.test.ts +0 -110
  259. package/tests/literal-spec.ts +0 -82
  260. package/tests/literals/AllCaps.spec.ts +0 -33
  261. package/tests/literals/CamelCase.spec.ts +0 -109
  262. package/tests/literals/Dasherize.spec.ts +0 -107
  263. package/tests/literals/EnsureStripLeadingTrailing.test.ts +0 -79
  264. package/tests/literals/HasUppercase.spec.ts +0 -33
  265. package/tests/literals/PascalCase.spec.ts +0 -109
  266. package/tests/literals/PathJoin.test.ts +0 -111
  267. package/tests/literals/SnakeCase.spec.ts +0 -109
  268. package/tests/literals/box.test.ts +0 -85
  269. package/tests/literals/whitespace-capture.spec.ts +0 -60
  270. package/tests/mapValues-spec.ts +0 -50
  271. package/tests/props-spec.ts +0 -234
  272. package/tests/runtime/condition.spec.ts +0 -19
  273. package/tests/runtime/if-is.spec.ts +0 -390
  274. package/tests/runtime/map-and-convert.test.ts +0 -31
  275. package/tests/runtime/type.spec.ts +0 -190
  276. package/tests/strArrayToDict-spec.ts +0 -40
  277. package/tests/tuples/TupleToUnion.spec.ts +0 -20
  278. package/tests/withValue.spec.ts +0 -173
  279. package/tsconfig.json +0 -36
  280. package/vitest.config.ts +0 -17
@@ -1,20 +0,0 @@
1
- import { Narrowable } from "../Narrowable";
2
-
3
- export type IsScalar<T extends Narrowable> = [T] extends [string]
4
- ? true
5
- : [T] extends [number]
6
- ? true
7
- : [T] extends [boolean]
8
- ? true
9
- : false;
10
-
11
- /**
12
- * **IfScalar**`<T, IF, ELSE>`
13
- *
14
- * Branch type utility which returns `IF` when `T` is a scalar value (aka, string, number, or boolean) and `ELSE` otherwise
15
- */
16
- export type IfScalar<
17
- T extends Narrowable,
18
- IF extends Narrowable,
19
- ELSE extends Narrowable
20
- > = IsScalar<T> extends true ? IF : ELSE;
@@ -1,20 +0,0 @@
1
- import { Narrowable } from "../Narrowable";
2
-
3
- /**
4
- * **IsUndefined**
5
- *
6
- * Boolean type utility returns `true` if `T` is undefined; `false` otherwise
7
- */
8
- export type IsUndefined<T extends Narrowable> = T extends undefined ? true : false;
9
-
10
- /**
11
- * **IfUndefined**`<T, IF, ELSE>`
12
- *
13
- * Type utility which returns `IF` type when `T` is an _undefined_
14
- * otherwise returns `ELSE` type.
15
- */
16
- export type IfUndefined<
17
- T,
18
- IF extends Narrowable,
19
- ELSE extends Narrowable
20
- > = IsUndefined<T> extends true ? IF : ELSE;
@@ -1,12 +0,0 @@
1
- import { NarrowlyContains } from "./array";
2
-
3
- /**
4
- * **Or**`<T>`
5
- *
6
- * Takes an array of boolean values and produces a boolean OR across these values
7
- */
8
- export type Or<T extends readonly boolean[]> = NarrowlyContains<true, T> extends true
9
- ? true
10
- : NarrowlyContains<boolean, T> extends true
11
- ? boolean
12
- : false;
@@ -1,42 +0,0 @@
1
- import { IsStringLiteral } from "src/types/boolean-logic";
2
- import { Narrowable } from "../Narrowable";
3
- /**
4
- * **StartsWith**<TValue, TStartsWith>
5
- *
6
- * A type utility which checks whether `T` _starts with_ the string literal `U`.
7
- *
8
- * If both `T` and `U` are string literals then the type system will resolve
9
- * to a literal `true` or `false` but if either is not a literal that it will
10
- * just resolve to `boolean` as the value can not be known at design time..
11
- */
12
- export type StartsWith<
13
- TValue extends string,
14
- TStartsWith extends string
15
- > = IsStringLiteral<TStartsWith> extends true
16
- ? IsStringLiteral<TValue> extends true // both literals
17
- ? TValue extends `${TStartsWith}${string}`
18
- ? true
19
- : false
20
- : boolean
21
- : boolean;
22
-
23
- /**
24
- * **IfStartsWith**<TValue, TStartsWith, IF, ELSE, MAYBE>
25
- *
26
- * Type utility which converts type to `IF` type _if_ TValue _starts with_ `TStartsWith` but
27
- * otherwise converts type to `ELSE`.
28
- *
29
- * Note, that there is also an optional `MAYBE` type
30
- * which can be stated for cases where TValue or TStartsWith _might_ be the wider `string`
31
- * type and therefore the type is unknown at design time.
32
- */
33
- export type IfStartsWith<
34
- TValue extends string,
35
- TStartsWith extends string,
36
- IF extends Narrowable,
37
- ELSE extends Narrowable
38
- > = StartsWith<TValue, TStartsWith> extends true
39
- ? IF
40
- : StartsWith<TValue, TStartsWith> extends false
41
- ? ELSE
42
- : IF | ELSE;
@@ -1,58 +0,0 @@
1
- import { IsObject } from "src/types/boolean-logic";
2
- import { SimplifyObject } from "../SimplifyObject";
3
- import { IfExtends } from "./Extends";
4
- import { IfOptionalLiteral } from "./IsLiteral";
5
- import { IfUndefined } from "./IsUndefined";
6
-
7
- /**
8
- * **TypeDefault**
9
- *
10
- * A type utility designed to help maintain strong and narrow types where
11
- * you have a value `T` which _might_ be **undefined** and a type `D` which
12
- * defines all the _default_ type for `T`.
13
- *
14
- * - In all cases we compare first whether `T` is undefined and replace it's
15
- * type with `D` 1-for-1 if it is
16
- * - To address a larger set of use cases, when `D` _extends_ an object we will
17
- * compare each property of `D` against `T`
18
- * ```ts
19
- * type I = { foo?: "foo" | undefined; bar?: 42 | 53 | undefined };
20
- * type D = { foo: "foo"; bar: 53 };
21
- * type DF = TypeDefault<I,D>; // `D`
22
- * const i = { foo: undefined, bar: 99 } as const;
23
- * type DF2 = TypeDefault<typeof i, D>; // `{ foo: "foo"; bar: 99 }`
24
- * ```
25
- */
26
- export type TypeDefault<T, D> = //
27
- IsObject<D> extends true //
28
- ? IsObject<T> extends true
29
- ? // both T and D are objects; start by iterating over D
30
- SimplifyObject<{
31
- [K in keyof D]: K extends keyof T
32
- ? // both D[T] and K[T] are present
33
- TypeDefault<T[K], D[K]>
34
- : // only D[K] present
35
- D[K];
36
- }>
37
- : // T is not an object, but D is
38
- IfUndefined<
39
- T, // check if T is undefined
40
- D, // use D as the type
41
- Exclude<T, undefined> // use T as the type but remove "undefined"
42
- >
43
- : // neither D or T is an object
44
- IfUndefined<
45
- T, // check whether is T is undefined
46
- D, // assign to D if it is
47
- IfOptionalLiteral<
48
- T, // if T is a literal
49
- IfExtends<
50
- D,
51
- T,
52
- D, // use D since it extends the value of T
53
- Exclude<T, undefined> // use T's literal value minus "undefined"
54
- >,
55
- // T is a wide type
56
- Exclude<T, undefined>
57
- >
58
- >;
@@ -1,57 +0,0 @@
1
- import { IsEqual } from "./equivalency";
2
- import { AfterFirst, First } from "../lists";
3
- import { Narrowable } from "../Narrowable";
4
-
5
- export type IsArray<T> = [T] extends [any[]] ? true : [T] extends [readonly any[]] ? true : false;
6
- export type IsReadonlyArray<T> = T extends readonly any[] ? true : false;
7
-
8
- /**
9
- * **IfArray**`<T, IF, ELSE>`
10
- *
11
- * Type utility which convert to type `IF` or `ELSE` based on whether `T` is an array
12
- */
13
- export type IfArray<
14
- T extends Narrowable,
15
- IF extends Narrowable,
16
- ELSE extends Narrowable
17
- > = IsArray<T> extends true ? IF : ELSE;
18
-
19
- /**
20
- * **IfArray**`<T, IF, ELSE>`
21
- *
22
- * Type utility which convert to type `IF` or `ELSE` based on whether `T` is a readonly array
23
- */
24
- export type IfReadonlyArray<
25
- T extends Narrowable,
26
- IF extends Narrowable,
27
- ELSE extends Narrowable
28
- > = IsReadonlyArray<T> extends true ? IF : ELSE;
29
-
30
- /**
31
- * **Contains**`<T, A>`
32
- *
33
- * Type utility which checks whether a type `T` exists within an array `A`. Result is
34
- * `true` if `T` _extends_ any element in `A` making it match widely against `A`. If you
35
- * prefer a narrower match you can use `NarrowlyContains<T,A>` instead.
36
- */
37
- export type Contains<T extends Narrowable, A extends readonly any[]> = First<A> extends T
38
- ? true
39
- : [] extends AfterFirst<A>
40
- ? false
41
- : Contains<T, AfterFirst<A>>;
42
-
43
- /**
44
- * **NarrowlyContains**`<T, A>`
45
- *
46
- * Type utility which checks whether a type `T` exists within an array `A`. Result is
47
- * `true` if `T` _extends_ any element in `A` making it match widely against `A`. If you
48
- * prefer a wider match you can use `Contains<T,A>` instead.
49
- */
50
- export type NarrowlyContains<T extends Narrowable, A extends readonly any[]> = IsEqual<
51
- First<A>,
52
- T
53
- > extends true
54
- ? true
55
- : [] extends AfterFirst<A>
56
- ? false
57
- : NarrowlyContains<T, AfterFirst<A>>;
@@ -1,84 +0,0 @@
1
- import { Narrowable } from "../Narrowable";
2
-
3
- export type IsBoolean<T> = [T] extends [boolean] ? true : false;
4
-
5
- /**
6
- * Type utility which returns `true` or `false` based on
7
- * whether the type holds the narrow "true" type.
8
- * ```ts
9
- * // true
10
- * type T = IsTrue<true>;
11
- * // boolean
12
- * type U = IsTrue<boolean>;
13
- * // false
14
- * type F = IsTrue<false>;
15
- * type F2 = IsTrue<"false">;
16
- * ```
17
- */
18
- export type IsTrue<T extends Narrowable> = IsBoolean<T> extends true
19
- ? // is a boolean
20
- T extends true
21
- ? true
22
- : T extends false
23
- ? false
24
- : unknown
25
- : // not a boolean
26
- false;
27
-
28
- export type IsFalse<T extends Narrowable> = IsBoolean<T> extends true
29
- ? // is a boolean
30
- T extends false
31
- ? true
32
- : true extends T
33
- ? false
34
- : // is of boolean type; therefore narrow type is unknown
35
- unknown
36
- : // not a boolean
37
- false;
38
-
39
- /**
40
- * Type utility which checks for literal `true` value and then switches type
41
- * to the IF, ELSE, or MAYBE generic types passed in where _maybe_ is when T
42
- * is the wide type of `boolean`
43
- */
44
- export type IfTrue<
45
- T extends boolean,
46
- IF extends Narrowable,
47
- ELSE extends Narrowable,
48
- MAYBE extends Narrowable
49
- > = IsTrue<T> extends true ? IF : IsTrue<T> extends false ? ELSE : MAYBE;
50
-
51
- /**
52
- * Type utility which checks for literal `false` value and then switches type
53
- * to the IF, ELSE, or MAYBE generic types passed in where _maybe_ is when T
54
- * is the wide type of `boolean`
55
- */
56
- export type IfFalse<
57
- T extends Narrowable,
58
- IF extends Narrowable,
59
- ELSE extends Narrowable,
60
- MAYBE extends Narrowable
61
- > = IsFalse<T> extends true ? IF : IsTrue<T> extends false ? ELSE : MAYBE;
62
-
63
- /**
64
- * **IsBooleanLiteral**
65
- *
66
- * Type utility which returns true/false if the boolean value is a _boolean literal_ versus
67
- * just the wider _boolean_ type.
68
- */
69
- export type IsBooleanLiteral<T extends Narrowable> = IsTrue<T> extends true
70
- ? true
71
- : IsFalse<T> extends true
72
- ? true
73
- : false;
74
-
75
- /**
76
- * **IfBooleanLiteral**
77
- *
78
- * Branch utility which returns `IF` type when `T` is a boolean literal and `ELSE` otherwise
79
- */
80
- export type IfBooleanLiteral<
81
- T extends boolean,
82
- IF extends Narrowable,
83
- ELSE extends Narrowable
84
- > = IsBooleanLiteral<T> extends true ? IF : ELSE;
@@ -1,15 +0,0 @@
1
- /**
2
- * **Equal**`<X,Y>`
3
- *
4
- * Type utility which tests whether two types -- `X` and `Y` -- are exactly the same type
5
- */
6
- export type IsEqual<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
7
- ? true
8
- : false;
9
-
10
- /**
11
- * **NotEqual**`<X,Y>`
12
- *
13
- * Type utility which tests whether two types -- `X` and `Y` -- are _not_ exactly the same type
14
- */
15
- export type NotEqual<X, Y> = true extends IsEqual<X, Y> ? false : true;
@@ -1,14 +0,0 @@
1
- export * from "./array";
2
- export * from "./Includes";
3
- export * from "./boolean";
4
- export * from "./IsScalar";
5
- export * from "./IsLiteral";
6
- export * from "./IsUndefined";
7
- export * from "./Extends";
8
- export * from "./HasParameters";
9
- export * from "./TypeDefault";
10
- export * from "./object";
11
- export * from "./StartsWith";
12
- export * from "./EndsWith";
13
- export * from "./Or";
14
- export * from "./equivalency";
@@ -1,30 +0,0 @@
1
- import { FunctionType } from "../FunctionType";
2
- import { Mutable } from "../Mutable";
3
- import { Narrowable } from "../Narrowable";
4
-
5
- /**
6
- * **IsObject**
7
- *
8
- * Boolean type utility used to check whether a type `T` is an object
9
- */
10
- export type IsObject<T> = Mutable<T> extends Record<string, any>
11
- ? // an object of some type
12
- T extends FunctionType
13
- ? // when a function with props is found, categorize as a function not object
14
- false
15
- : Mutable<T> extends any[]
16
- ? // Array's are objects too but in our narrower definition we're looking only
17
- // dictionary based arrays.
18
- false
19
- : true
20
- : false;
21
-
22
- /**
23
- * **IfObject**
24
- *
25
- * Branch type utility with return `IF` when `T` extends an object type
26
- * and `ELSE` otherwise
27
- */
28
- export type IfObject<T, IF extends Narrowable, ELSE extends Narrowable> = IsObject<T> extends true
29
- ? IF
30
- : ELSE;
@@ -1,21 +0,0 @@
1
- import { Narrowable } from "src/types";
2
-
3
- /**
4
- * **IsString**
5
- *
6
- * Type utility which returns true/false based on whether `T` is a
7
- * string (wide or narrow).
8
- */
9
- export type IsString<T> = T extends string ? true : false;
10
-
11
- /**
12
- * **IfString**
13
- *
14
- * Type utility which determines if `T` is a _string_ (wide or narrow) and
15
- * returns `IF` type if it is, otherwise returns the type `ELSE`.
16
- */
17
- export type IfString<
18
- T extends Narrowable, //
19
- IF extends Narrowable,
20
- ELSE extends Narrowable
21
- > = IsString<T> extends true ? IF : IsString<T> extends false ? ELSE : IF | ELSE;
@@ -1,34 +0,0 @@
1
- import { SimplifyObject } from "../SimplifyObject";
2
-
3
- /**
4
- * Allow a dictionary have it's value's type changed to `T` while maintaining the keys in
5
- * the original object `I` so long as the original value for the KV pair extends `V`.
6
- *
7
- * If `V` is not specified then it defaults to _any_ and therefore all KVs are preserved.
8
- *
9
- * ```ts
10
- * type Obj = { foo: "hello", bar: 42, baz: () => "world" };
11
- * // { foo: number, bar: number, baz: number };
12
- * type AllNumbers = DictChangeValue<Obj, number>;
13
- * // { foo: number }
14
- * type StringToBool = DictChangeValue<Obj, boolean, string>
15
- * ```
16
- */
17
- export type DictChangeValue<
18
- /** the object who's value-type we're changing */
19
- I extends Record<string, any>,
20
- /** the return type that functions should be modified to have */
21
- T extends any,
22
- /**
23
- *The type we expect in the value; if the value extends type `V` then the value will
24
- * be converted to type `O`; if not then the KV pair will be discarded
25
- */
26
- V extends any = any
27
- > = SimplifyObject<
28
- {
29
- [K in keyof I]: I[K] extends V
30
- ? // it's a function (or at least the scoped down type of function we're looking for)
31
- Record<K, T>
32
- : never;
33
- }[keyof I]
34
- >;
@@ -1,30 +0,0 @@
1
- import { SimplifyObject } from "../SimplifyObject";
2
-
3
- /**
4
- * Given a dictionary of key/values, where the value is a function, this
5
- * type utility will maintain the keys but change the values to whatever
6
- * the `ReturnType` of the function was.
7
- * ```ts
8
- * const api = {
9
- * val: 42,
10
- * hi: (name: string) => `hi ${name}`,
11
- * bye: (name: string) => `bye ${name}`
12
- * };
13
- * // { hi: string; bye: string }
14
- * type Test = UnwrapValue<typeof api>
15
- * // { val: number; foo: string; bar: string }
16
- * type Test2 = UnwrapValue<typeof api, false>
17
- * ```
18
- */
19
- export type DictPartialApplication<
20
- T extends Record<string, any>,
21
- I extends boolean = true
22
- > = SimplifyObject<
23
- {
24
- [K in keyof T]: T[K] extends (...args: any[]) => any
25
- ? Record<K, ReturnType<T[K]>>
26
- : true extends I
27
- ? never
28
- : Record<K, T[K]>;
29
- }[keyof T]
30
- >;
@@ -1,23 +0,0 @@
1
- import { SimplifyObject } from "../SimplifyObject";
2
-
3
- /**
4
- * **DictPrependWithFn**
5
- *
6
- * Given a strongly typed object `<T>`, this utility will inject a function call with
7
- * arguments `<A>` and then return what had subsequently been the value of the property.
8
- *
9
- * Should you only want to apply this treatment to _some_ of the properties you can
10
- * pass in a value `<E>` which will ensure that only properties which _extend_ `E` will be
11
- * modified.
12
- */
13
- export type DictPrependWithFn<
14
- T extends Record<string, any>,
15
- A extends any[],
16
- E extends any = any
17
- > = SimplifyObject<
18
- {
19
- [K in keyof T]: T[K] extends E
20
- ? Record<K, (...args: A) => T[K]>
21
- : Record<K, T[K]>;
22
- }[keyof T]
23
- >;
@@ -1,27 +0,0 @@
1
- import { SimplifyObject } from "../SimplifyObject";
2
-
3
- /**
4
- * **DictReturnValues**
5
- *
6
- * A type utility which receives an object `<T>` and then modifies
7
- * the return type of any properties which are a function to have this
8
- * new **ReturnType** `<R>`. Optionally you can specify a particular return type which
9
- * you are targeting and then
10
- */
11
- export type DictReturnValues<
12
- /** the object which we expect to have props with function values */
13
- T extends Record<string, any>,
14
- /** the return type that functions should be modified to have */
15
- R extends any,
16
- /** optionally this utility can target only functions with a certain existing return value */
17
- O extends (...args: any[]) => any = (...args: any[]) => any
18
- > = SimplifyObject<
19
- {
20
- [K in keyof T]: T[K] extends O
21
- ? // it's a function (or at least the scoped down type of function we're looking for)
22
- T[K] extends (...args: infer A) => any
23
- ? Record<K, (...args: A) => R>
24
- : Record<K, T[K]>
25
- : Record<K, T[K]>;
26
- }[keyof T]
27
- >;
@@ -1,14 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- /**
3
- * Get the type of a property of an object:
4
- * ```ts
5
- * const car = { make: "Chevy", model: "Malibu", }
6
- * ```
7
- */
8
- export type Get<T, K> = K extends `${infer FK}.${infer L}`
9
- ? FK extends keyof T
10
- ? Get<T[FK], L>
11
- : never
12
- : K extends keyof T
13
- ? T[K]
14
- : never;