inferred-types 0.20.0 → 0.22.5

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 (161) 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 +426 -8547
  6. package/dist/index.js +57 -76
  7. package/dist/index.mjs +47 -63
  8. package/package.json +38 -26
  9. package/src/Mutation/index.ts +6 -29
  10. package/src/index.ts +6 -29
  11. package/src/shared/index.ts +6 -29
  12. package/src/shared/valueTypes.ts +1 -1
  13. package/src/types/ExpandRecursively.ts +10 -1
  14. package/src/types/Keys.ts +10 -6
  15. package/src/types/SimplifyObject.ts +12 -0
  16. package/src/types/Transformer.ts +1 -1
  17. package/src/types/alphabetic/CamelCase.ts +2 -2
  18. package/src/types/alphabetic/CapFirstAlpha.ts +7 -3
  19. package/src/types/alphabetic/Dasherize.ts +8 -5
  20. package/src/types/alphabetic/KebabCase.ts +1 -1
  21. package/src/types/alphabetic/PascalCase.ts +3 -1
  22. package/src/types/alphabetic/SnakeCase.ts +8 -3
  23. package/src/types/alphabetic/alpha-characters.ts +33 -9
  24. package/src/types/alphabetic/index.ts +6 -29
  25. package/src/types/dictionary/DictChangeValue.ts +26 -0
  26. package/src/types/dictionary/DictPartialApplication.ts +30 -0
  27. package/src/types/dictionary/DictPrependWithFn.ts +23 -0
  28. package/src/types/dictionary/DictReturnValues.ts +27 -0
  29. package/src/types/dictionary/MutableProps.ts +19 -0
  30. package/src/types/dictionary/RequireProps.ts +15 -0
  31. package/src/types/{type-conversion → dictionary}/SameKeys.ts +0 -0
  32. package/src/types/dictionary/index.ts +13 -30
  33. package/src/types/{props.ts → dictionary/props.ts} +2 -2
  34. package/src/types/fluent/index.ts +6 -29
  35. package/src/types/functions/FinalReturn.ts +12 -0
  36. package/src/types/functions/index.ts +12 -0
  37. package/src/types/index.ts +8 -30
  38. package/src/types/kv/index.ts +6 -29
  39. package/src/types/lists/index.ts +6 -29
  40. package/src/types/ruleset-types.ts +3 -3
  41. package/src/types/runtime.ts +18 -18
  42. package/src/types/string-literals/LeftWhitespace.ts +5 -2
  43. package/src/types/string-literals/RightWhitespace.ts +5 -2
  44. package/src/types/string-literals/index.ts +6 -29
  45. package/src/types/tuples/FirstKey.ts +3 -3
  46. package/src/types/tuples/FromDictArray.ts +5 -4
  47. package/src/types/tuples/index.ts +6 -29
  48. package/src/types/type-conversion/index.ts +6 -32
  49. package/src/utility/api/api.ts +8 -7
  50. package/src/utility/api/index.ts +6 -29
  51. package/src/utility/dictionary/defineProperties.ts +35 -0
  52. package/src/utility/dictionary/dictionaryTransform.ts +5 -4
  53. package/src/utility/dictionary/entries.ts +9 -5
  54. package/src/utility/dictionary/index.ts +7 -30
  55. package/src/utility/dictionary/kv/dictToKv.ts +5 -3
  56. package/src/utility/dictionary/kv/filterDictArray.ts +5 -7
  57. package/src/utility/dictionary/kv/index.ts +6 -29
  58. package/src/utility/dictionary/kv/kv.ts +8 -3
  59. package/src/utility/dictionary/kv/kvToDict.ts +3 -2
  60. package/src/utility/dictionary/mapValues.ts +8 -5
  61. package/src/utility/dictionary/strArrayToDict.ts +1 -2
  62. package/src/utility/errors/ReadOnlyViolation.ts +3 -0
  63. package/src/utility/errors/index.ts +12 -0
  64. package/src/utility/index.ts +7 -29
  65. package/src/utility/keys.ts +8 -4
  66. package/src/utility/lists/groupBy.ts +2 -9
  67. package/src/utility/lists/index.ts +6 -29
  68. package/src/utility/literals/arrayToObject.ts +29 -29
  69. package/src/utility/literals/defineType.ts +6 -6
  70. package/src/utility/literals/identity.ts +5 -2
  71. package/src/utility/literals/index.ts +6 -29
  72. package/src/utility/literals/literal.ts +3 -3
  73. package/src/utility/map-reduce/index.ts +6 -29
  74. package/src/utility/modelling/index.ts +6 -29
  75. package/src/utility/ruleset.ts +11 -9
  76. package/src/utility/runtime/condition.ts +1 -1
  77. package/src/utility/runtime/conditions/index.ts +6 -30
  78. package/src/utility/runtime/conditions/isFalse.ts +2 -2
  79. package/src/utility/runtime/conditions/isFunction.ts +2 -2
  80. package/src/utility/runtime/conditions/isObject.ts +4 -1
  81. package/src/utility/runtime/conditions/isTrue.ts +1 -1
  82. package/src/utility/runtime/ifTypeOf.ts +5 -4
  83. package/src/utility/runtime/index.ts +6 -29
  84. package/src/utility/runtime/type.ts +3 -1
  85. package/src/utility/runtime/withValue.ts +5 -3
  86. package/src/utility/state/Configurator.ts +2 -2
  87. package/src/utility/state/FluentConfigurator.ts +2 -2
  88. package/src/utility/state/index.ts +6 -30
  89. package/tests/CamelCase-spec.ts +2 -0
  90. package/tests/ExplicitFunction-spec.ts +3 -2
  91. package/tests/IncludeAndRetain-spec.ts +7 -12
  92. package/tests/Includes-spec.ts +2 -0
  93. package/tests/KebabCase-spec.ts +2 -0
  94. package/tests/MutationIdentity-spec.ts +2 -1
  95. package/tests/PascalCase-spec.ts +2 -0
  96. package/tests/Pluralize-spec.ts +2 -0
  97. package/tests/SnakeCase-spec.ts +2 -0
  98. package/tests/Where.spec.ts +9 -10
  99. package/tests/arrayToKeyLookup-spec.ts +5 -5
  100. package/tests/arrayToObject-spec.ts +12 -8
  101. package/tests/constructor.spec.ts +2 -0
  102. package/tests/createFnWithProps.spec.ts +2 -2
  103. package/tests/data/index.ts +6 -29
  104. package/tests/defineType-spec.ts +17 -11
  105. package/tests/dictionary/DictChangeValue.test.ts +30 -0
  106. package/tests/dictionary/DictPartialApplication.test.ts +43 -0
  107. package/tests/dictionary/DictReturnValues.test.ts +36 -0
  108. package/tests/dictionary/Get.spec.ts +5 -3
  109. package/tests/dictionary/MutableProps.test.ts +30 -0
  110. package/tests/dictionary/PrependValuesWithFunction.ts +34 -0
  111. package/tests/dictionary/RequireProps.test.ts +21 -0
  112. package/tests/dictionaryTransform-spec.ts +3 -3
  113. package/tests/ifTypeOf-spec.ts +31 -20
  114. package/tests/kv/KeyValue-spec.ts +4 -4
  115. package/tests/kv/SameKeys-spec.ts +6 -9
  116. package/tests/kv/dict-to-kv-and-back.spec.ts +5 -4
  117. package/tests/kv/entries-spec.ts +8 -9
  118. package/tests/kv/keys.spec.ts +9 -19
  119. package/tests/kv/kv-spec.ts +4 -4
  120. package/tests/lists/UniqueForProp.spec.ts +3 -1
  121. package/tests/literal-spec.ts +5 -3
  122. package/tests/mapValues-spec.ts +5 -3
  123. package/tests/props-spec.ts +3 -2
  124. package/tests/runtime/condition.spec.ts +2 -1
  125. package/tests/runtime/type.spec.ts +4 -3
  126. package/tests/strArrayToDict-spec.ts +6 -6
  127. package/tests/string-literals/AllCaps.spec.ts +6 -15
  128. package/tests/string-literals/CamelCase.spec.ts +13 -32
  129. package/tests/string-literals/Dasherize.spec.ts +13 -31
  130. package/tests/string-literals/HasUppercase.spec.ts +6 -15
  131. package/tests/string-literals/PascalCase.spec.ts +13 -32
  132. package/tests/string-literals/SnakeCase.spec.ts +13 -32
  133. package/tests/string-literals/whitespace-capture.spec.ts +10 -28
  134. package/tests/tuples/TupleToUnion.spec.ts +3 -1
  135. package/tests/withValue.spec.ts +4 -3
  136. package/tsconfig.json +8 -19
  137. package/vitest.config.ts +13 -0
  138. package/jest.config.ts +0 -20
  139. package/on-hold/Builder/Builder.ts +0 -66
  140. package/on-hold/Builder/BuilderApi.ts +0 -21
  141. package/on-hold/Builder/IdentityToMutationApi.ts +0 -44
  142. package/on-hold/Builder/MutationToFluentApi.ts +0 -60
  143. package/on-hold/Builder/index.ts +0 -35
  144. package/on-hold/tests/Builder-spec.ts +0 -310
  145. package/on-hold/tests/RuleSet-spec.ts +0 -59
  146. package/on-hold/tests/ToFluent-spec.ts +0 -60
  147. package/on-hold/tests/api-spec.ts +0 -73
  148. package/on-hold/tests/data/builder-data.ts +0 -53
  149. package/on-hold/tests/filterDictArray-spec.ts +0 -50
  150. package/on-hold/tests/run-time-spec.ts +0 -44
  151. package/on-hold/type.ts +0 -20
  152. package/on-hold/types/index.ts +0 -34
  153. package/on-hold/types/object.ts +0 -19
  154. package/on-hold/types/prop.ts +0 -28
  155. package/on-hold/types/scalar.ts +0 -37
  156. package/src/types/dictionary/NotEmptyObject.ts +0 -9
  157. package/src/types/type-conversion/UnwrapValue.ts +0 -13
  158. package/src/types/type-conversion/WrapValue.ts +0 -15
  159. package/src/utility/dictionary/valuesOfProp.ts +0 -13
  160. package/src/utility/runtime/conditions/isLiteral.ts +0 -7
  161. package/src/utility/state/KeyStorage.ts +0 -23
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  // #autoindex
2
2
 
3
- // #region autoindexed files
4
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
5
- // hash-code: 3f75741a
3
+ // #region auto-indexed files
4
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
5
+ // hash-code: 5ddbbf55
6
6
 
7
7
  // directory exports
8
8
  export * from "./Mutation/index";
@@ -10,30 +10,7 @@ export * from "./shared/index";
10
10
  export * from "./types/index";
11
11
  export * from "./utility/index";
12
12
 
13
- // #endregion
13
+ // #endregion auto-indexed files
14
14
 
15
- // This file was created by running: "dd autoindex"; it assumes you have
16
- // the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
17
- //
18
- // By default it assumes that exports are named exports but this can be changed by
19
- // adding a modifier to the '// #autoindex' syntax:
20
- //
21
- // - autoindex:named same as default, exports "named symbols"
22
- // - autoindex:default assumes each file is exporting a default export and
23
- // converts the default export to the name of the file
24
- // - autoindex:offset assumes files export "named symbols" but that each
25
- // file's symbols should be offset by the file's name
26
- //
27
- // You may also exclude certain files or directories by adding it to the
28
- // autoindex command. As an example:
29
- //
30
- // - autoindex:named, exclude: foo,bar,baz
31
- //
32
- // Inversely, if you state a file to be an "orphan" then autoindex files
33
- // below this file will not reference this autoindex file:
34
- //
35
- // - autoindex:named, orphan
36
- //
37
- // All content outside the "// #region" section in this file will be
38
- // preserved in situations where you need to do something paricularly awesome.
39
- // Keep on being awesome.
15
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
16
+ // for more info
@@ -1,38 +1,15 @@
1
1
  // #autoindex: orphan
2
2
 
3
- // #region autoindexed files
4
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
5
- // hash-code: 58ead14b
3
+ // #region auto-indexed files
4
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
5
+ // hash-code: 3305143b
6
6
 
7
7
  // file exports
8
8
  export * from "./randomString";
9
9
  export * from "./uuid";
10
10
  export * from "./valueTypes";
11
11
 
12
- // #endregion
12
+ // #endregion auto-indexed files
13
13
 
14
- // This file was created by running: "dd autoindex"; it assumes you have
15
- // the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
16
- //
17
- // By default it assumes that exports are named exports but this can be changed by
18
- // adding a modifier to the '// #autoindex' syntax:
19
- //
20
- // - autoindex:named same as default, exports "named symbols"
21
- // - autoindex:default assumes each file is exporting a default export and
22
- // converts the default export to the name of the file
23
- // - autoindex:offset assumes files export "named symbols" but that each
24
- // file's symbols should be offset by the file's name
25
- //
26
- // You may also exclude certain files or directories by adding it to the
27
- // autoindex command. As an example:
28
- //
29
- // - autoindex:named, exclude: foo,bar,baz
30
- //
31
- // Inversely, if you state a file to be an "orphan" then autoindex files
32
- // below this file will not reference this autoindex file:
33
- //
34
- // - autoindex:named, orphan
35
- //
36
- // All content outside the "// #region" section in this file will be
37
- // preserved in situations where you need to do something paricularly awesome.
38
- // Keep on being awesome.
14
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
15
+ // for more info
@@ -1,4 +1,4 @@
1
- import { Narrowable } from "~/types/Narrowable";
1
+ import { Narrowable } from "src/types/Narrowable";
2
2
 
3
3
  export type ValueTuple = [type: any, narrowable: boolean];
4
4
 
@@ -1,3 +1,12 @@
1
+
2
+ /**
3
+ * Recursively goes over an object based structure and tries to reduce
4
+ * it down to just a simple key/value type.
5
+ */
1
6
  export type ExpandRecursively<T> = T extends object
2
- ? { [K in keyof T]: ExpandRecursively<T[K]> }
7
+ ? T extends (...args: any[]) => any
8
+ // Functions should be treated like any other non-object value
9
+ // but will/can identify as an object in JS
10
+ ? T
11
+ : { [K in keyof T]: ExpandRecursively<T[K]> }
3
12
  : T;
package/src/types/Keys.ts CHANGED
@@ -1,10 +1,10 @@
1
- /**
1
+ /**
2
2
  * A Utility class that provides the same functionality as the built-in
3
3
  * `keyof` TS operator but can also:
4
- *
4
+ *
5
5
  * - receive an array of strings and convert that into a union type.
6
6
  * - you can exclude literal string from the returned result
7
- *
7
+ *
8
8
  * ```ts
9
9
  * const t1 = { foo: 1, bar: 2 };
10
10
  * // "foo" | "bar"
@@ -17,6 +17,10 @@
17
17
  export type Keys<
18
18
  T extends Record<string, any> | readonly string[],
19
19
  W extends string | undefined = undefined
20
- > = T extends readonly string[]
21
- ? W extends string ? Exclude<T[number], W> : T[number]
22
- : W extends string ? Exclude<keyof T & string, W> : keyof T & string;
20
+ > = T extends readonly string[]
21
+ ? W extends string
22
+ ? Exclude<T[number], W>
23
+ : T[number]
24
+ : W extends string
25
+ ? Exclude<keyof T & string, W>
26
+ : keyof T & string;
@@ -0,0 +1,12 @@
1
+ import { ExpandRecursively } from "./ExpandRecursively";
2
+ import { UnionToIntersection } from "./type-conversion/UnionToIntersection";
3
+
4
+ /**
5
+ * Often when mutating the shape of an object you will end up with the union of a number of
6
+ * `Record<string, x>` and `Record<string, y>` which is messy to look at and take away meaning.
7
+ *
8
+ * This type utility will cleanup an object and return a simple dictionary definition for it.
9
+ */
10
+ export type SimplifyObject<T extends {}> = ExpandRecursively<
11
+ UnionToIntersection<ExpandRecursively<T>>
12
+ >;
@@ -1,4 +1,4 @@
1
- import { SameKeys } from "./type-conversion/SameKeys";
1
+ import { SameKeys } from "./dictionary/SameKeys";
2
2
 
3
3
  /**
4
4
  * **Transformer**
@@ -1,3 +1,3 @@
1
- import { PascalCase } from "~/types/alphabetic";
1
+ import { PascalCase } from "./PascalCase";
2
2
 
3
- export type CamelCase<S extends string> = Uncapitalize<PascalCase<S>>;
3
+ export type CamelCase<S extends string> = string extends S ? string : Uncapitalize<PascalCase<S>>;
@@ -1,9 +1,14 @@
1
- import type { NonAlpha, Replace } from "~/types";
1
+ import { Replace } from "../string-literals";
2
+ import { NonAlpha } from "./alpha-characters";
2
3
 
3
4
  /**
4
5
  * Strips the non-alpha characters that lead a string
5
6
  */
6
- export type StripLeftNonAlpha<S extends string> = S extends `${infer First}${infer Rest}` ? First extends NonAlpha ? StripLeftNonAlpha<Rest> : S : never;
7
+ export type StripLeftNonAlpha<S extends string> = S extends `${infer First}${infer Rest}`
8
+ ? First extends NonAlpha
9
+ ? StripLeftNonAlpha<Rest>
10
+ : S
11
+ : never;
7
12
 
8
13
  /**
9
14
  * identifies the leading characters which are _not_ alphabetical
@@ -16,4 +21,3 @@ export type LeadingNonAlpha<S extends string> = Replace<S, StripLeftNonAlpha<S>,
16
21
  export type CapFirstAlpha<T extends string> = LeadingNonAlpha<T> extends string
17
22
  ? `${LeadingNonAlpha<T>}${Capitalize<Replace<T, LeadingNonAlpha<T>, "">>}`
18
23
  : Capitalize<T>;
19
-
@@ -1,10 +1,12 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import { DashUppercase, LowerAllCaps } from "~/types";
2
+
3
3
  import { Trim } from "../string-literals";
4
+ import { DashUppercase } from "./DashUppercase";
5
+ import { LowerAllCaps } from "./LowerAllCaps";
4
6
 
5
7
  /**
6
- * Converts a string literal into a _dasherized_ format while ignoring _exterior_ whitepace.
7
- *
8
+ * Converts a string literal into a _dasherized_ format while ignoring _exterior_ whitespace.
9
+ *
8
10
  * ```ts
9
11
  * // "foo-bar"
10
12
  * type Dash = Dasherize<"foo_bar">;
@@ -14,7 +16,8 @@ import { Trim } from "../string-literals";
14
16
  * type Dash = Dasherize<"\n foo bar \t">;
15
17
  * ```
16
18
  */
17
- export type Dasherize<S extends string> = string extends S ? string :
18
- DashUppercase<Trim<LowerAllCaps<S>>> extends `${infer Begin}${"_" | " "}${infer Rest}`
19
+ export type Dasherize<S extends string> = string extends S
20
+ ? string
21
+ : DashUppercase<Trim<LowerAllCaps<S>>> extends `${infer Begin}${"_" | " "}${infer Rest}`
19
22
  ? Dasherize<`${Lowercase<Begin>}-${Rest}`>
20
23
  : Lowercase<DashUppercase<Uncapitalize<Trim<LowerAllCaps<S>>>>>;
@@ -1,4 +1,4 @@
1
- import type { Dasherize } from "~/types/alphabetic";
1
+ import { Dasherize } from "./Dasherize";
2
2
 
3
3
  /**
4
4
  * **KebabCase<T>** is an _alias_ for **Dasherize<T>**.
@@ -1,5 +1,7 @@
1
1
  /* eslint @typescript-eslint/no-unused-vars: "off" */
2
- import type { LowerAllCaps, Trim } from "~/types";
2
+
3
+ import { Trim } from "../string-literals";
4
+ import { LowerAllCaps } from "./LowerAllCaps";
3
5
 
4
6
  type Delimiter = "_" | "-" | " ";
5
7
 
@@ -1,6 +1,8 @@
1
1
  /* eslint @typescript-eslint/no-unused-vars: "off" */
2
2
 
3
- import type { DashUppercase, LowerAllCaps, Trim } from "~/types";
3
+ import { Trim } from "../string-literals";
4
+ import { DashUppercase } from "./DashUppercase";
5
+ import { LowerAllCaps } from "./LowerAllCaps";
4
6
 
5
7
  /** convert space to dash */
6
8
  type SpaceToDash<T extends string> = T extends `${infer Begin}${" "}${infer Rest}`
@@ -16,7 +18,10 @@ type SpaceToDash<T extends string> = T extends `${infer Begin}${" "}${infer Rest
16
18
  * type T = SnakeCase<"foo-bar">;
17
19
  * type T = SnakeCase<"\n foo bar \t">;
18
20
  * ``` */
19
- export type SnakeCase<S extends string> = string extends S ? string :
20
- DashUppercase<Uncapitalize<SpaceToDash<Trim<LowerAllCaps<S>>>>> extends `${infer Begin}${"-"}${infer Rest}`
21
+ export type SnakeCase<S extends string> = string extends S
22
+ ? string
23
+ : DashUppercase<
24
+ Uncapitalize<SpaceToDash<Trim<LowerAllCaps<S>>>>
25
+ > extends `${infer Begin}${"-"}${infer Rest}`
21
26
  ? SnakeCase<`${Lowercase<Begin>}_${Rest}`>
22
27
  : Lowercase<DashUppercase<Uncapitalize<Trim<LowerAllCaps<S>>>>>;
@@ -1,4 +1,30 @@
1
- export type LowerAlpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
1
+ export type LowerAlpha =
2
+ | "a"
3
+ | "b"
4
+ | "c"
5
+ | "d"
6
+ | "e"
7
+ | "f"
8
+ | "g"
9
+ | "h"
10
+ | "i"
11
+ | "j"
12
+ | "k"
13
+ | "l"
14
+ | "m"
15
+ | "n"
16
+ | "o"
17
+ | "p"
18
+ | "q"
19
+ | "r"
20
+ | "s"
21
+ | "t"
22
+ | "u"
23
+ | "v"
24
+ | "w"
25
+ | "x"
26
+ | "y"
27
+ | "z";
2
28
 
3
29
  /** Uppercase alphabetic character */
4
30
  export type UpperAlpha = Uppercase<LowerAlpha>;
@@ -8,7 +34,6 @@ export type UpperAlpha = Uppercase<LowerAlpha>;
8
34
  */
9
35
  export type Alpha = UpperAlpha | LowerAlpha;
10
36
 
11
-
12
37
  export type Whitespace = " " | "\n" | "\t";
13
38
 
14
39
  export type Punctuation = "." | "," | ";" | "!" | "?";
@@ -17,18 +42,18 @@ export type Punctuation = "." | "," | ";" | "!" | "?";
17
42
  */
18
43
  export type StringDelimiter = "_" | "-" | "/" | "\\";
19
44
 
20
- export type OpenningBracket = "(" | "[" | "{";
45
+ export type OpeningBracket = "(" | "[" | "{";
21
46
  export type ClosingBracket = ")" | "]" | "}";
22
47
 
23
48
  /**
24
- * Openning and closing parenthesis
49
+ * Opening and closing parenthesis
25
50
  */
26
51
  export type Parenthesis = "(" | ")";
27
52
 
28
53
  /**
29
- * Openning and closing brackets
54
+ * Opening and closing brackets
30
55
  */
31
- export type Bracket = OpenningBracket | ClosingBracket;
56
+ export type Bracket = OpeningBracket | ClosingBracket;
32
57
 
33
58
  /**
34
59
  * Numeric string characters
@@ -40,10 +65,9 @@ export type NumericString = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8"
40
65
  */
41
66
  export type AlphaNumeric = Alpha | NumericString;
42
67
 
43
-
44
68
  export type SpecialCharacters = "@" | "~" | "^" | "#" | "&" | "*";
45
69
 
46
70
  /**
47
- * Non-alphabetic characters including whitespace, string numerals, and
71
+ * Non-alphabetic characters including whitespace, string numerals, and
48
72
  */
49
- export type NonAlpha = Whitespace | Punctuation | NumericString | Bracket | SpecialCharacters;
73
+ export type NonAlpha = Whitespace | Punctuation | NumericString | Bracket | SpecialCharacters;
@@ -1,7 +1,7 @@
1
1
  // #autoindex, exclude: Alpha
2
- // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: fcf9c4b
2
+ // #region auto-indexed files
3
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
+ // hash-code: b32382ed
5
5
 
6
6
  // file exports
7
7
  export * from "./AllCaps";
@@ -19,30 +19,7 @@ export * from "./Pluralize";
19
19
  export * from "./SnakeCase";
20
20
  export * from "./alpha-characters";
21
21
 
22
- // #endregion
22
+ // #endregion auto-indexed files
23
23
 
24
- // This file was created by running: "dd autoindex"; it assumes you have
25
- // the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
26
- //
27
- // By default it assumes that exports are named exports but this can be changed by
28
- // adding a modifier to the '// #autoindex' syntax:
29
- //
30
- // - autoindex:named same as default, exports "named symbols"
31
- // - autoindex:default assumes each file is exporting a default export and
32
- // converts the default export to the name of the file
33
- // - autoindex:offset assumes files export "named symbols" but that each
34
- // file's symbols should be offset by the file's name
35
- //
36
- // You may also exclude certain files or directories by adding it to the
37
- // autoindex command. As an example:
38
- //
39
- // - autoindex:named, exclude: foo,bar,baz
40
- //
41
- // Inversely, if you state a file to be an "orphan" then autoindex files
42
- // below this file will not reference this autoindex file:
43
- //
44
- // - autoindex:named, orphan
45
- //
46
- // All content outside the "// #region" section in this file will be
47
- // preserved in situations where you need to do something paricularly awesome.
48
- // Keep on being awesome.
24
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
25
+ // for more info
@@ -0,0 +1,26 @@
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
+ export type DictChangeValue<
10
+ /** the object who's value-type we're changing */
11
+ I extends Record<string, any>,
12
+ /** the return type that functions should be modified to have */
13
+ T extends any,
14
+ /**
15
+ *The type we expect in the value; if the value extends type `V` then the value will
16
+ * be converted to type `O`; if not then the KV pair will be discarded
17
+ */
18
+ V extends any = any
19
+ > = SimplifyObject<
20
+ {
21
+ [K in keyof I]: I[K] extends V
22
+ ? // it's a function (or at least the scoped down type of function we're looking for)
23
+ Record<K, T>
24
+ : never;
25
+ }[keyof I]
26
+ >;
@@ -0,0 +1,30 @@
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
+ >;
@@ -0,0 +1,23 @@
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
+ >;
@@ -0,0 +1,27 @@
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
+ >;
@@ -0,0 +1,19 @@
1
+ import { ExpandRecursively } from "../ExpandRecursively";
2
+ import { Keys } from "../Keys";
3
+ import { Mutable } from "../Mutable";
4
+
5
+ /**
6
+ * Given a dictionary of type `<T>`, this utility function will
7
+ * make the `<M>` generic property _mutable_ and all other _read-only_.
8
+ *
9
+ * ```ts
10
+ * // { foo: string, bar?: Readonly<number> }
11
+ * type Example = MutableProps<{
12
+ * foo: Readonly<string>,
13
+ * bar?: number
14
+ * }, "foo">;
15
+ * ```
16
+ */
17
+ export type MutableProps<T extends {}, M extends keyof T & string> = ExpandRecursively<
18
+ Mutable<Pick<T, M>> & Readonly<Pick<T, Keys<T, M>>>
19
+ >;
@@ -0,0 +1,15 @@
1
+ import { ExpandRecursively } from "../ExpandRecursively";
2
+
3
+ /**
4
+ * Given a dictionary of type `<T>`, this utility function will
5
+ * make the `<R>` generic property _required_ (use a union to make
6
+ * more than one prop required).
7
+ *
8
+ * ```ts
9
+ * // { foo: string, bar?: number }
10
+ * type Example = RequireProps<{foo?: string, bar?: number}, "foo">;
11
+ * ```
12
+ */
13
+ export type RequireProps<T extends {}, R extends keyof T> = ExpandRecursively<
14
+ Required<Pick<T, R>> & T
15
+ >;
@@ -1,36 +1,19 @@
1
1
  // #autoindex
2
- // #region autoindexed files
3
- // index last changed at: 6th Jun, 2022, 03:36 AM ( GMT-7 )
4
- // hash-code: 1f3a5076
2
+ // #region auto-indexed files
3
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
+ // hash-code: 55881f7d
5
5
 
6
6
  // file exports
7
+ export * from "./DictPartialApplication";
8
+ export * from "./DictPrependWithFn";
9
+ export * from "./DictReturnValues";
7
10
  export * from "./Get";
8
- export * from "./NotEmptyObject";
11
+ export * from "./MutableProps";
12
+ export * from "./RequireProps";
13
+ export * from "./SameKeys";
14
+ export * from "./props";
9
15
 
10
- // #endregion
16
+ // #endregion auto-indexed files
11
17
 
12
- // This file was created by running: "dd autoindex"; it assumes you have
13
- // the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
14
- //
15
- // By default it assumes that exports are named exports but this can be changed by
16
- // adding a modifier to the '// #autoindex' syntax:
17
- //
18
- // - autoindex:named same as default, exports "named symbols"
19
- // - autoindex:default assumes each file is exporting a default export and
20
- // converts the default export to the name of the file
21
- // - autoindex:offset assumes files export "named symbols" but that each
22
- // file's symbols should be offset by the file's name
23
- //
24
- // You may also exclude certain files or directories by adding it to the
25
- // autoindex command. As an example:
26
- //
27
- // - autoindex:named, exclude: foo,bar,baz
28
- //
29
- // Inversely, if you state a file to be an "orphan" then autoindex files
30
- // below this file will not reference this autoindex file:
31
- //
32
- // - autoindex:named, orphan
33
- //
34
- // All content outside the "// #region" section in this file will be
35
- // preserved in situations where you need to do something paricularly awesome.
36
- // Keep on being awesome.
18
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
19
+ // for more info
@@ -1,4 +1,4 @@
1
- import { Alpha } from "common-types";
1
+ import { Alpha } from "../alphabetic/alpha-characters";
2
2
 
3
3
  /**
4
4
  * Extracts the _required_ keys in the object's type
@@ -18,7 +18,7 @@ export type OptionalKeys<T extends object> = {
18
18
  * The _keys_ on a given object `T` which have a literal value of `W`.
19
19
  *
20
20
  * Optionally, you may provide a generic `E` to exclude certain keys in
21
- * resultset.
21
+ * result set.
22
22
  * ```ts
23
23
  * // "foo"
24
24
  * type Str = KeysWithValue<{ foo: "hi"; bar: 5 }>;
@@ -1,35 +1,12 @@
1
1
  // #autoindex
2
- // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: c5fbce38
2
+ // #region auto-indexed files
3
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
+ // hash-code: 9dbff34
5
5
 
6
6
  // file exports
7
7
  export * from "./fluent";
8
8
 
9
- // #endregion
9
+ // #endregion auto-indexed files
10
10
 
11
- // This file was created by running: "dd autoindex"; it assumes you have
12
- // the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
13
- //
14
- // By default it assumes that exports are named exports but this can be changed by
15
- // adding a modifier to the '// #autoindex' syntax:
16
- //
17
- // - autoindex:named same as default, exports "named symbols"
18
- // - autoindex:default assumes each file is exporting a default export and
19
- // converts the default export to the name of the file
20
- // - autoindex:offset assumes files export "named symbols" but that each
21
- // file's symbols should be offset by the file's name
22
- //
23
- // You may also exclude certain files or directories by adding it to the
24
- // autoindex command. As an example:
25
- //
26
- // - autoindex:named, exclude: foo,bar,baz
27
- //
28
- // Inversely, if you state a file to be an "orphan" then autoindex files
29
- // below this file will not reference this autoindex file:
30
- //
31
- // - autoindex:named, orphan
32
- //
33
- // All content outside the "// #region" section in this file will be
34
- // preserved in situations where you need to do something paricularly awesome.
35
- // Keep on being awesome.
11
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
12
+ // for more info
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A type utility which looks at a chain for functions and reduces the type
3
+ * to the final `ReturnType` of the chain.
4
+ *
5
+ * ```ts
6
+ * // number
7
+ * type T = FinalReturn<() => (foo: string) => (bar: string) => () => number>;
8
+ * ```
9
+ */
10
+ export type FinalReturn<T extends any> = T extends (...args: any[]) => any
11
+ ? FinalReturn<ReturnType<T>>
12
+ : T;