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,49 +0,0 @@
1
- import { ExpandRecursively } from "src/types/ExpandRecursively";
2
-
3
- export interface IFluentConfigurator<C> {
4
- /**
5
- * **set**
6
- *
7
- * Sets a new key/value pair to the configurator.
8
- *
9
- * @param key the key to put this new configuration item
10
- * @param value the value of the configuration item
11
- */
12
- set<V, K extends string, KV = { [U in K]: V }>(key: K, value: V): IFluentConfigurator<C & KV>;
13
- done(): ExpandRecursively<C>;
14
- }
15
-
16
- /**
17
- * This function will return a basic _configurator_ API surface which allows
18
- * you to add name/value pairs to a growing dictionary of strongly typed data.
19
- *
20
- * When configuration is complete, you call the `done()` endpoint and the typed
21
- * configuration will be returned with the API removed.
22
- *
23
- * > **Note:** the approach taken here requires that you configure using a **fluent style**
24
- * exclusively. If you don't the non-fluent properties set will not show up
25
- * in the typing or the run-time object.
26
- */
27
- export function FluentConfigurator<I>(initial: I = {} as I) {
28
- const api = <C>(current: C): IFluentConfigurator<C> => {
29
- return {
30
- set<V, K extends string, KV = { [U in K]: V }>(key: K, value: V) {
31
- const keyValue = { [key]: value as V } as unknown as KV;
32
- const updated = { ...keyValue, ...current };
33
-
34
- return api<C & KV>(updated);
35
- },
36
- done() {
37
- return current as ExpandRecursively<C>;
38
- },
39
- };
40
- };
41
-
42
- if (initial && typeof initial !== "object") {
43
- throw new Error(
44
- "The FluentConfigurator was passed a non-object based value as the initial value. This is not allowed."
45
- );
46
- }
47
-
48
- return initial ? api(initial) : api({});
49
- }
@@ -1,13 +0,0 @@
1
- // #autoindex
2
- // #region auto-indexed files
3
- // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
- // hash-code: 397c607b
5
-
6
- // file exports
7
- export * from "./Configurator";
8
- export * from "./FluentConfigurator";
9
-
10
- // #endregion auto-indexed files
11
-
12
- // see https://github.com/inocan-group/do-devops/docs/autoindex.md
13
- // for more info
@@ -1,20 +0,0 @@
1
- import { Narrowable, Not, Widen } from "src/types";
2
-
3
- export function ifSameType<
4
- TValue extends Narrowable,
5
- TType extends string | number | boolean | object,
6
- IF extends Narrowable,
7
- ELSE extends Narrowable
8
- >(
9
- value: TValue,
10
- comparisonType: TType,
11
- ifExtends: <T extends TType & TValue>(v: T) => IF,
12
- doesNotExtend: (v: Not<TValue, TType>) => ELSE
13
- ) {
14
- return (
15
- // runtime values match
16
- (
17
- typeof value === typeof comparisonType ? ifExtends(value as any) : doesNotExtend(value as any)
18
- ) as Widen<TValue> extends Widen<TType> ? IF : ELSE
19
- );
20
- }
@@ -1,124 +0,0 @@
1
- import { Narrowable } from "src/types/Narrowable";
2
- import { keys } from "../keys";
3
-
4
- function runtimeExtendsCheck<TValue extends any, TBase extends any>(
5
- val: TValue,
6
- base: TBase,
7
- narrow: boolean = false
8
- ): TValue extends TBase ? true : false {
9
- if (typeof val !== typeof base) {
10
- return false as TValue extends TBase ? true : false;
11
- }
12
-
13
- switch (typeof val) {
14
- case "boolean":
15
- case "string":
16
- case "number":
17
- case "symbol":
18
- case "bigint":
19
- return narrow
20
- ? ((val === base) as TValue extends TBase ? true : false)
21
- : (true as TValue extends TBase ? true : false);
22
- case "undefined":
23
- return true as TValue extends TBase ? true : false;
24
- case "function":
25
- if (narrow) {
26
- throw new Error(`Use of narrowlyExtends with a function is not possible!`);
27
- }
28
- return true as TValue extends TBase ? true : false;
29
- case "object":
30
- if (val === null && base === null) {
31
- return true as TValue extends TBase ? true : false;
32
- } else {
33
- return keys(base as object).every((i) =>
34
- runtimeExtendsCheck((val as TValue)[i], base[i], narrow)
35
- ) as TValue extends TBase ? true : false;
36
- }
37
- }
38
- }
39
-
40
- /**
41
- * A conditional clause used in the application of the `ifTypeOf` utility
42
- */
43
- export type ExtendsClause<
44
- N extends Narrowable,
45
- TValue extends Record<keyof TValue, N> | number | string | boolean | symbol
46
- > = <TBase extends any>(base: TBase) => TValue extends TBase ? true : false;
47
-
48
- /**
49
- * A conditional clause used in the application of the `ifTypeOf` utility
50
- */
51
- export type ExtendsNarrowlyClause<
52
- N extends Narrowable,
53
- TValue extends Record<keyof TValue, N> | number | string | boolean | symbol
54
- > = <
55
- NB extends Narrowable,
56
- TBase extends Record<keyof TBase, NB> | number | string | boolean | symbol
57
- >(
58
- base: TBase
59
- ) => TValue extends TBase ? true : false;
60
-
61
- /**
62
- * **TypeCondition**
63
- *
64
- * A partially applied type from the `ifTypeOf` utility where the base type has been
65
- * defined and we now need to express the type which is intended to extend it.
66
- *
67
- * - `extends` - compares with _wide_ types
68
- * - `narrowlyExtends` - compares with _narrow_ / _literal_ types
69
- */
70
- export type TypeCondition<
71
- N extends Narrowable,
72
- TValue extends Record<keyof TValue, N> | number | string | boolean | symbol
73
- > = {
74
- extends: ExtendsClause<N, TValue>;
75
- narrowlyExtends: ExtendsNarrowlyClause<N, TValue>;
76
- };
77
-
78
- export const ifTypeOf = <
79
- N extends Narrowable,
80
- TValue extends Record<keyof TValue, N> | number | string | boolean | symbol
81
- >(
82
- val: TValue
83
- ): TypeCondition<N, TValue> => ({
84
- extends: <TBase extends any>(base: TBase) => {
85
- const valid = runtimeExtendsCheck(val, base, false);
86
- const trueFalse = (valid ? true : false) as TValue extends TBase ? true : false;
87
- return (
88
- {
89
- then: <TResult extends any>(then?: TResult) => ({
90
- else: <TElse extends any>(elseVal: TElse) => {
91
- return (
92
- valid ? (typeof then === "undefined" ? val : then) : elseVal
93
- ) as TValue extends TBase ? (TResult extends undefined ? TValue : TResult) : TElse;
94
- },
95
- }),
96
- else: <TElse extends any>(elseVal: TElse) =>
97
- valid ? val : (elseVal as TValue extends TBase ? TValue : TElse),
98
- } && trueFalse
99
- );
100
- },
101
-
102
- narrowlyExtends: <
103
- NB extends Narrowable,
104
- TBase extends Record<keyof TBase, NB> | number | string | boolean | symbol
105
- >(
106
- base: TBase
107
- ) => {
108
- const valid = runtimeExtendsCheck(val, base, true);
109
- const trueFalse = (valid ? true : false) as TValue extends TBase ? true : false;
110
- return (
111
- {
112
- then: <TResult extends any>(then?: TResult) => ({
113
- else: <TElse extends any>(elseVal: TElse) => {
114
- return (
115
- valid ? (typeof then === "undefined" ? val : then) : elseVal
116
- ) as TValue extends TBase ? (TResult extends undefined ? TValue : TResult) : TElse;
117
- },
118
- }),
119
- else: <TElse extends any>(elseVal: TElse) =>
120
- valid ? val : (elseVal as TValue extends TBase ? TValue : TElse),
121
- } && trueFalse
122
- );
123
- },
124
- });
@@ -1,24 +0,0 @@
1
- // #autoindex
2
-
3
- // #region auto-indexed files
4
- // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
5
- // hash-code: 4324574d
6
-
7
- // file exports
8
- export * from "./ifSameType";
9
- export * from "./isArray";
10
- export * from "./isBoolean";
11
- export * from "./isFalse";
12
- export * from "./isFunction";
13
- export * from "./isNull";
14
- export * from "./isNumber";
15
- export * from "./isObject";
16
- export * from "./isString";
17
- export * from "./isSymbol";
18
- export * from "./isTrue";
19
- export * from "./isUndefined";
20
-
21
- // #endregion auto-indexed files
22
-
23
- // see https://github.com/inocan-group/do-devops/docs/autoindex.md
24
- // for more info
@@ -1,34 +0,0 @@
1
- import { IsArray, IfArray } from "src/types/boolean-logic/array";
2
- import { Narrowable } from "src/types/Narrowable";
3
-
4
- export function isArray<T>(i: T) {
5
- return (Array.isArray(i) === true) as IsArray<T>;
6
- }
7
-
8
- /**
9
- * **ifArray**(T, IF, ELSE)
10
- *
11
- * A utility which evaluates a type `T` for whether it is an array and then
12
- */
13
- export function ifArray<
14
- // value which is possibly an array
15
- T extends Narrowable,
16
- // functions which return a known type
17
- IF extends Narrowable,
18
- ELSE extends Narrowable
19
- >(
20
- val: T,
21
- isAnArray: <N extends T & readonly any[]>(arr: N) => IF,
22
- isNotAnArray: <N extends Exclude<T, any[]>>(nonArr: N) => ELSE
23
- ) {
24
- return (isArray(val) ? isAnArray(val as any) : isNotAnArray(val as any)) as IfArray<T, IF, ELSE>;
25
- }
26
-
27
- export function ifArrayPartial<T extends Narrowable>() {
28
- return <IF extends Narrowable, ELSE extends Narrowable>(
29
- isAnArray: <N extends T & readonly any[]>(arr: N) => IF,
30
- isNotAnArray: <N extends Exclude<T, any[]>>(nonArr: N) => ELSE
31
- ) => {
32
- return <V extends T>(val: V) => ifArray(val, isAnArray, isNotAnArray);
33
- };
34
- }
@@ -1,24 +0,0 @@
1
- import { Narrowable } from "src/types";
2
- import { IsBoolean } from "src/types/boolean-logic";
3
-
4
- /**
5
- * Runtime and type checks whether a variable is a boolean value.
6
- */
7
- export function isBoolean<T extends Narrowable>(i: T): IsBoolean<T> {
8
- return (typeof i === "boolean") as IsBoolean<T>;
9
- }
10
-
11
- /**
12
- * **ifBoolean**
13
- *
14
- * Strongly type-aware conditional statement which checks whether a value is
15
- * a _boolean_ and returns one of two values (strongly typed) based on the evaluation
16
- * of this criteria.
17
- *
18
- * @param val the value being tested
19
- * @param ifVal the value (strongly typed) returned if val is _boolean_
20
- * @param elseVal the value (strongly typed) returned if val is NOT a _boolean
21
- */
22
- export function ifBoolean<T, IF, ELSE>(val: T, ifVal: IF, elseVal: ELSE) {
23
- return (isBoolean(val) ? ifVal : elseVal) as IsBoolean<T> extends true ? IF : ELSE;
24
- }
@@ -1,29 +0,0 @@
1
- import { IfFalse, IsFalse } from "src/types/boolean-logic/boolean";
2
- import { Narrowable } from "src/types/Narrowable";
3
-
4
- export function isFalse<T>(i: T) {
5
- return (typeof i === "boolean" && !i) as IsFalse<T>;
6
- }
7
-
8
- /**
9
- * **ifTrue**
10
- *
11
- * Strongly type-aware conditional statement which checks whether a value is
12
- * a _true_ and returns one of two values (strongly typed) based on the evaluation
13
- * of this criteria.
14
- *
15
- * @param val the value being tested
16
- * @param ifVal the value (strongly typed) returned if val is _true_ value
17
- * @param elseVal the value (strongly typed) returned if val is NOT a _true_ value
18
- *
19
- * Note: at runtime there's no way to distinguish if the value was widely or loosely
20
- * typed so unlike the type utility there is no "MAYBE" state but if a wide type if
21
- * encountered the _type_ will the union of `IF` and `ELSE`.
22
- */
23
- export function ifFalse<T extends boolean, IF extends Narrowable, ELSE extends Narrowable>(
24
- val: T,
25
- ifVal: IF,
26
- elseVal: ELSE
27
- ) {
28
- return (isFalse(val) ? ifVal : elseVal) as IfFalse<T, IF, ELSE, IF | ELSE>;
29
- }
@@ -1,26 +0,0 @@
1
- import { FunctionType } from "src/types/FunctionType";
2
-
3
- export type IsFunction<T> = T extends FunctionType ? true : false;
4
-
5
- export type HybridFunction<TProps extends {}> = (<TArgs extends any[]>(...args: TArgs) => any) &
6
- TProps;
7
-
8
- export type SimpleFunction = (...args: any[]) => any;
9
-
10
- export type AnyFunction<TProps extends {} = {}> = SimpleFunction | HybridFunction<TProps>;
11
-
12
- /**
13
- * Checks whether a passed in value is a function and ensures run-time and types
14
- * are consistent.
15
- * ```ts
16
- * // true
17
- * const yup = isFunction(() => "hello world");
18
- * ```
19
- *
20
- * Note: the runtime `typeof [variable]` will correctly say "function" when a function is
21
- * encountered but if that function also has object types defined then the type will be a big
22
- * and ugly union type. This function will give you a proper boolean value in both cases.
23
- */
24
- export function isFunction<T>(input: T): IsFunction<T> {
25
- return (typeof input === "function" ? true : false) as IsFunction<T>;
26
- }
@@ -1,26 +0,0 @@
1
- import { Narrowable } from "src/types";
2
-
3
- export type IsNull<T> = T extends null ? true : false;
4
-
5
- export function isNull<T extends Narrowable>(i: T) {
6
- return (i === null) as T extends null ? true : false;
7
- }
8
-
9
- /**
10
- * **ifNull**
11
- *
12
- * Strongly type-aware conditional statement which checks whether a value is
13
- * Null and returns one of two values (strongly typed) based on the evaluation
14
- * of this criteria.
15
- *
16
- * @param val the value being tested
17
- * @param ifVal the value (strongly typed) returned if val is `null`
18
- * @param elseVal the value (strongly typed) returned if val is NOT `null`
19
- */
20
- export function ifNull<T extends Narrowable, IF extends Narrowable, ELSE extends Narrowable>(
21
- val: T,
22
- ifVal: IF,
23
- elseVal: ELSE
24
- ) {
25
- return (isNull(val) ? ifVal : elseVal) as IsNull<T> extends true ? IF : ELSE;
26
- }
@@ -1,20 +0,0 @@
1
- export type IsNumber<T> = T extends number ? true : false;
2
-
3
- export function isNumber<T>(i: T) {
4
- return (typeof i === "number") as T extends number ? true : false;
5
- }
6
-
7
- /**
8
- * **ifNumber**
9
- *
10
- * Strongly type-aware conditional statement which checks whether a value is
11
- * a _number_ and returns one of two values (strongly typed) based on the evaluation
12
- * of this criteria.
13
- *
14
- * @param val the value being tested
15
- * @param ifVal the value (strongly typed) returned if val is number
16
- * @param elseVal the value (strongly typed) returned if val is NOT a number
17
- */
18
- export function ifNumber<T, IF, ELSE>(val: T, ifVal: IF, elseVal: ELSE) {
19
- return (isNumber(val) ? ifVal : elseVal) as IsNumber<T> extends true ? IF : ELSE;
20
- }
@@ -1,22 +0,0 @@
1
- import { FunctionType, Narrowable, Not } from "src/types";
2
- import { IfObject, IsObject } from "src/types/boolean-logic";
3
-
4
- export type ObjectType = Not<Record<string, Narrowable>, FunctionType>;
5
-
6
- /**
7
- * Detects whether the passed in `v` is of type "object" where an object
8
- * is defined to be a string keyed dictionary style object. This means that
9
- * arrays are excluded, as well as functions which also have properties hanging
10
- * off of them.
11
- */
12
- export function isObject<T extends Narrowable>(i: T) {
13
- return (typeof i === "object" && i !== null && Array.isArray(i) === false) as IsObject<T>;
14
- }
15
-
16
- export function ifObject<T extends Narrowable, IF extends Narrowable, ELSE extends Narrowable>(
17
- val: T,
18
- ifObj: IF,
19
- notObj: ELSE
20
- ): IfObject<T, IF, ELSE> {
21
- return (isObject(val) ? ifObj : notObj) as IfObject<T, IF, ELSE>;
22
- }
@@ -1,34 +0,0 @@
1
- import { Narrowable } from "src/types/Narrowable";
2
- import { IfString, IsString } from "src/types/boolean-logic/string";
3
-
4
- /**
5
- * **isString**
6
- *
7
- * Returns true or false on whether the passed in parameter is a
8
- * string (either a wide string or a string literal).
9
- *
10
- * The boolean return is traceable by the type system as well as the
11
- * runtime system.
12
- */
13
- export function isString<T>(i: T) {
14
- return (typeof i === "string") as IsString<T>;
15
- }
16
-
17
- /**
18
- * **ifString**
19
- *
20
- * Strongly type-aware conditional statement which checks whether a value is
21
- * a _string_ and returns one of two values (strongly typed) based on the evaluation
22
- * of this criteria.
23
- *
24
- * @param val the value being tested for being a string
25
- * @param ifVal the value (strongly typed) returned if val is _string_
26
- * @param elseVal the value (strongly typed) returned if val is NOT a _string
27
- */
28
- export function ifString<T extends Narrowable, IF extends Narrowable, ELSE extends Narrowable>(
29
- val: T,
30
- ifVal: <E extends string>(t: E & T) => IF,
31
- elseVal: ELSE
32
- ) {
33
- return (isString(val) ? ifVal : elseVal) as IfString<T, IF, ELSE>;
34
- }
@@ -1,3 +0,0 @@
1
- export function isSymbol<T>(i: T) {
2
- return (typeof i === "symbol") as T extends symbol ? true : false;
3
- }
@@ -1,31 +0,0 @@
1
- import { IfTrue, IsTrue } from "src/types/boolean-logic";
2
- import { Narrowable } from "src/types/Narrowable";
3
-
4
- /**
5
- * Run-time and type checking of whether a variable is `true`.
6
- */
7
- export function isTrue<T extends Narrowable>(i: T) {
8
- return (typeof i === "boolean" && i === true) as IsTrue<T>;
9
- }
10
-
11
- /**
12
- * **ifTrue**
13
- *
14
- * Strongly type-aware conditional statement which checks whether a value is
15
- * _true_.
16
- *
17
- * @param val the value being tested
18
- * @param ifVal the value (strongly typed) returned if val is _true_ value
19
- * @param elseVal the value (strongly typed) returned if val is NOT a _true_ value
20
- *
21
- * Note: at runtime there's no way to distinguish if the value was widely or loosely
22
- * typed so unlike the type utility there is no "MAYBE" state but if a wide type if
23
- * encountered the _type_ will the union of `IF` and `ELSE`.
24
- */
25
- export function ifTrue<T extends boolean, IF extends Narrowable, ELSE extends Narrowable>(
26
- val: T,
27
- ifVal: IF,
28
- elseVal: ELSE
29
- ) {
30
- return (isTrue(val) ? ifVal : elseVal) as IfTrue<T, IF, ELSE, IF | ELSE>;
31
- }
@@ -1,33 +0,0 @@
1
- import { Narrowable } from "src/types";
2
- import { IsUndefined } from "src/types/boolean-logic/IsUndefined";
3
-
4
- export function isUndefined<T extends Narrowable>(i: T) {
5
- return (typeof i === "undefined") as undefined extends T ? true : false;
6
- }
7
-
8
- /**
9
- * **ifUndefined**
10
- *
11
- * Strongly type-aware conditional statement which checks whether a value is
12
- * _undefined_ and returns one of two values (strongly typed) based on the evaluation
13
- * of this criteria.
14
- *
15
- * @param val the value being tested
16
- * @param ifVal the value (strongly typed) returned if val is `undefined`
17
- * @param elseVal the value (strongly typed) returned if val is NOT `undefined`
18
- */
19
- export function ifUndefined<T extends Narrowable, IF extends Narrowable, ELSE extends Narrowable>(
20
- val: T,
21
- ifVal: IF,
22
- elseVal: ELSE
23
- ) {
24
- return (isUndefined(val) ? ifVal : elseVal) as IsUndefined<T> extends true ? IF : ELSE;
25
- }
26
-
27
- export function ifDefined<T extends Narrowable, IF extends Narrowable, ELSE extends Narrowable>(
28
- val: T,
29
- ifVal: <V extends Exclude<T, undefined>>(v: V) => IF,
30
- elseVal: ELSE
31
- ) {
32
- return (isUndefined(val) ? ifVal : elseVal) as IsUndefined<T> extends true ? IF : ELSE;
33
- }
@@ -1,107 +0,0 @@
1
- import { Narrowable } from "src/types";
2
- import { IfStartsWith, StartsWith } from "src/types/boolean-logic";
3
- import { IfUndefined } from "src/types/boolean-logic/IsUndefined";
4
- import { createFnWithProps } from "../createFnWithProps";
5
- import { box, Box } from "../literals";
6
- import { ifTrue } from "./isTrue";
7
-
8
- /**
9
- * **startsWith**
10
- *
11
- * A higher-order and type strong way to checking whether a string literal `<T>` starts with
12
- * another known string literal `<S>`:
13
- * ```ts
14
- * const answer = startsWith("foo")("foobar");
15
- * ```
16
- */
17
- export const startsWith =
18
- <S extends string>(
19
- /** The starting string you will test for */
20
- start: S
21
- ) =>
22
- <T extends string>(
23
- /** The text being tested */
24
- input: T
25
- ): StartsWith<T, S> => {
26
- return input.startsWith(start) as StartsWith<T, S>;
27
- };
28
-
29
- /**
30
- * **IfStartsWithFn**
31
- *
32
- * A function which comes from a partial application of the `ifStartsWith()`
33
- * utility. This type will receive a value `<T>` and _if_ this values starts
34
- * with `<S>` then the callback function will executed in a type strong manner.
35
- */
36
- export type IfStartsWith__Fn<
37
- /** The "start with" constraint */
38
- TStartsWith extends string,
39
- TIf extends Box<<T extends string>(i: `${TStartsWith}${T}`) => any>,
40
- TElse extends Box<(<T extends string>(i: T) => any) | undefined>
41
- > = <T extends string>(
42
- val: T
43
- ) => IfStartsWith<
44
- T, //
45
- TStartsWith,
46
- // Condition Passes
47
- ReturnType<TIf["value"]>,
48
- // Condition Fails
49
- IfUndefined<
50
- TElse, //
51
- undefined,
52
- Exclude<TElse, undefined>
53
- >
54
- >;
55
-
56
- export type NarrowFn<N extends string> = <F extends <T extends string>(input: T) => any>(
57
- fn: F
58
- ) => (input: N) => Box<F>["unbox"];
59
-
60
- export const stringLiteralFn = <F extends <T extends string>(input: T) => any>(fn: F) => {
61
- const b = box(fn);
62
- const api = {
63
- narrow<N extends string>() {
64
- return (input: N) => b.unbox()(input);
65
- },
66
- };
67
-
68
- return createFnWithProps(fn, api);
69
- };
70
-
71
- export type StringLiteralFn<S extends string = string> = <T extends S>(input: T) => any;
72
-
73
- /**
74
- * **ifStartsWith**
75
- *
76
- * Type strong way to move into a conditional execution block:
77
- * ```ts
78
- * // partial application
79
- * const mutate = ifStartsWith(
80
- * "foo",
81
- * i => `${i} is a foo`,
82
- * i => `${i} ain't welcome in this town`
83
- * );
84
- * // type: `foobar is a foo`
85
- * const outcome = mutate("foobar");
86
- * ```
87
- *
88
- * Where the variable `i` will _extend_ a string and function which this utility
89
- * returns is able to
90
- */
91
- export const ifStartsWith =
92
- <TStartsWith extends string, TIf extends Narrowable, TElse extends Narrowable>(
93
- /** the string literal _start value_ which a string must begin with */
94
- start: TStartsWith,
95
- /** a mutation function when a value _does_ start with `TStartsWith` */
96
- isTrue: <T extends string>(input: T) => TIf,
97
- /** an optional mutation function */
98
- isFalse: <T extends string>(input: T) => TElse
99
- ) =>
100
- <TTextValue extends string>(input: TTextValue) =>
101
- ifTrue(
102
- // condition
103
- startsWith(start)(input),
104
- // handlers
105
- isTrue(input),
106
- isFalse(input)
107
- );