inferred-types 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/.eslintrc +36 -20
  2. package/.github/workflows/main.yml +34 -0
  3. package/.github/workflows/other.yml +15 -0
  4. package/.vscode/settings.json +10 -2
  5. package/dist/index.d.ts +398 -8541
  6. package/dist/index.js +17 -60
  7. package/dist/index.mjs +8 -48
  8. package/package.json +32 -24
  9. package/src/shared/valueTypes.ts +1 -1
  10. package/src/types/ExpandRecursively.ts +10 -1
  11. package/src/types/SimplifyObject.ts +12 -0
  12. package/src/types/Transformer.ts +1 -1
  13. package/src/types/alphabetic/CamelCase.ts +1 -1
  14. package/src/types/alphabetic/CapFirstAlpha.ts +7 -3
  15. package/src/types/alphabetic/Dasherize.ts +8 -5
  16. package/src/types/alphabetic/KebabCase.ts +1 -1
  17. package/src/types/alphabetic/PascalCase.ts +3 -1
  18. package/src/types/alphabetic/SnakeCase.ts +8 -3
  19. package/src/types/dictionary/DictPartialApplication.ts +30 -0
  20. package/src/types/dictionary/DictPrependWithFn.ts +23 -0
  21. package/src/types/dictionary/DictReturnValues.ts +27 -0
  22. package/src/types/dictionary/RequireProps.ts +15 -0
  23. package/src/types/{type-conversion → dictionary}/SameKeys.ts +0 -0
  24. package/src/types/dictionary/index.ts +8 -3
  25. package/src/types/{props.ts → dictionary/props.ts} +1 -1
  26. package/src/types/functions/FinalReturn.ts +12 -0
  27. package/{on-hold/types → src/types/functions}/index.ts +4 -3
  28. package/src/types/index.ts +4 -3
  29. package/src/types/ruleset-types.ts +3 -3
  30. package/src/types/runtime.ts +18 -18
  31. package/src/types/string-literals/LeftWhitespace.ts +5 -2
  32. package/src/types/string-literals/RightWhitespace.ts +5 -2
  33. package/src/types/tuples/FirstKey.ts +3 -3
  34. package/src/types/tuples/FromDictArray.ts +5 -4
  35. package/src/types/type-conversion/index.ts +2 -5
  36. package/src/utility/api/api.ts +8 -7
  37. package/src/utility/dictionary/dictionaryTransform.ts +5 -4
  38. package/src/utility/dictionary/entries.ts +9 -5
  39. package/src/utility/dictionary/index.ts +2 -3
  40. package/src/utility/dictionary/kv/dictToKv.ts +5 -3
  41. package/src/utility/dictionary/kv/filterDictArray.ts +5 -7
  42. package/src/utility/dictionary/kv/kv.ts +8 -3
  43. package/src/utility/dictionary/kv/kvToDict.ts +3 -2
  44. package/src/utility/dictionary/mapValues.ts +8 -5
  45. package/src/utility/dictionary/strArrayToDict.ts +1 -2
  46. package/src/utility/keys.ts +8 -4
  47. package/src/utility/lists/groupBy.ts +2 -9
  48. package/src/utility/literals/arrayToObject.ts +29 -29
  49. package/src/utility/literals/defineType.ts +6 -6
  50. package/src/utility/literals/identity.ts +5 -2
  51. package/src/utility/literals/literal.ts +3 -3
  52. package/src/utility/ruleset.ts +11 -9
  53. package/src/utility/runtime/condition.ts +1 -1
  54. package/src/utility/runtime/conditions/isFalse.ts +2 -2
  55. package/src/utility/runtime/conditions/isFunction.ts +2 -2
  56. package/src/utility/runtime/conditions/isObject.ts +4 -1
  57. package/src/utility/runtime/conditions/isTrue.ts +1 -1
  58. package/src/utility/runtime/ifTypeOf.ts +1 -1
  59. package/src/utility/runtime/type.ts +3 -1
  60. package/src/utility/runtime/withValue.ts +5 -3
  61. package/src/utility/state/Configurator.ts +2 -2
  62. package/src/utility/state/FluentConfigurator.ts +2 -2
  63. package/src/utility/state/index.ts +2 -3
  64. package/tests/CamelCase-spec.ts +2 -0
  65. package/tests/ExplicitFunction-spec.ts +3 -2
  66. package/tests/IncludeAndRetain-spec.ts +7 -12
  67. package/tests/Includes-spec.ts +2 -0
  68. package/tests/KebabCase-spec.ts +2 -0
  69. package/tests/MutationIdentity-spec.ts +2 -1
  70. package/tests/PascalCase-spec.ts +2 -0
  71. package/tests/Pluralize-spec.ts +2 -0
  72. package/tests/SnakeCase-spec.ts +2 -0
  73. package/tests/Where.spec.ts +9 -10
  74. package/tests/arrayToKeyLookup-spec.ts +5 -5
  75. package/tests/arrayToObject-spec.ts +12 -8
  76. package/tests/constructor.spec.ts +2 -0
  77. package/tests/createFnWithProps.spec.ts +2 -2
  78. package/tests/defineType-spec.ts +17 -11
  79. package/tests/dictionary/DictPartialApplication.test.ts +43 -0
  80. package/tests/dictionary/DictReturnValues.test.ts +32 -0
  81. package/tests/dictionary/Get.spec.ts +5 -3
  82. package/tests/dictionary/PrependValuesWithFunction.ts +34 -0
  83. package/tests/dictionary/RequireProps.test.ts +21 -0
  84. package/tests/dictionaryTransform-spec.ts +3 -3
  85. package/tests/ifTypeOf-spec.ts +31 -20
  86. package/tests/kv/KeyValue-spec.ts +4 -4
  87. package/tests/kv/SameKeys-spec.ts +6 -9
  88. package/tests/kv/dict-to-kv-and-back.spec.ts +5 -4
  89. package/tests/kv/entries-spec.ts +8 -9
  90. package/tests/kv/keys.spec.ts +9 -19
  91. package/tests/kv/kv-spec.ts +4 -4
  92. package/tests/lists/UniqueForProp.spec.ts +3 -1
  93. package/tests/literal-spec.ts +5 -3
  94. package/tests/mapValues-spec.ts +5 -3
  95. package/tests/props-spec.ts +3 -2
  96. package/tests/runtime/condition.spec.ts +2 -1
  97. package/tests/runtime/type.spec.ts +4 -3
  98. package/tests/strArrayToDict-spec.ts +6 -6
  99. package/tests/string-literals/AllCaps.spec.ts +6 -15
  100. package/tests/string-literals/CamelCase.spec.ts +13 -32
  101. package/tests/string-literals/Dasherize.spec.ts +13 -31
  102. package/tests/string-literals/HasUppercase.spec.ts +6 -15
  103. package/tests/string-literals/PascalCase.spec.ts +13 -32
  104. package/tests/string-literals/SnakeCase.spec.ts +13 -32
  105. package/tests/string-literals/whitespace-capture.spec.ts +10 -28
  106. package/tests/tuples/TupleToUnion.spec.ts +3 -1
  107. package/tests/withValue.spec.ts +4 -3
  108. package/tsconfig.json +8 -19
  109. package/vitest.config.ts +13 -0
  110. package/jest.config.ts +0 -20
  111. package/on-hold/Builder/Builder.ts +0 -66
  112. package/on-hold/Builder/BuilderApi.ts +0 -21
  113. package/on-hold/Builder/IdentityToMutationApi.ts +0 -44
  114. package/on-hold/Builder/MutationToFluentApi.ts +0 -60
  115. package/on-hold/Builder/index.ts +0 -35
  116. package/on-hold/tests/Builder-spec.ts +0 -310
  117. package/on-hold/tests/RuleSet-spec.ts +0 -59
  118. package/on-hold/tests/ToFluent-spec.ts +0 -60
  119. package/on-hold/tests/api-spec.ts +0 -73
  120. package/on-hold/tests/data/builder-data.ts +0 -53
  121. package/on-hold/tests/filterDictArray-spec.ts +0 -50
  122. package/on-hold/tests/run-time-spec.ts +0 -44
  123. package/on-hold/type.ts +0 -20
  124. package/on-hold/types/object.ts +0 -19
  125. package/on-hold/types/prop.ts +0 -28
  126. package/on-hold/types/scalar.ts +0 -37
  127. package/src/types/dictionary/NotEmptyObject.ts +0 -9
  128. package/src/types/type-conversion/UnwrapValue.ts +0 -13
  129. package/src/types/type-conversion/WrapValue.ts +0 -15
  130. package/src/utility/dictionary/valuesOfProp.ts +0 -13
  131. package/src/utility/state/KeyStorage.ts +0 -23
@@ -1,11 +1,16 @@
1
1
  // #autoindex
2
2
  // #region autoindexed files
3
- // index last changed at: 6th Jun, 2022, 03:36 AM ( GMT-7 )
4
- // hash-code: 1f3a5076
3
+ // index last changed at: 7th Jul, 2022, 02:28 PM ( GMT-7 )
4
+ // hash-code: 6e90bc78
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 "./RequireProps";
12
+ export * from "./SameKeys";
13
+ export * from "./props";
9
14
 
10
15
  // #endregion
11
16
 
@@ -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 }>;
@@ -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;
@@ -1,9 +1,10 @@
1
1
  // #autoindex
2
2
  // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: da242834
5
-
3
+ // index last changed at: 6th Jun, 2022, 10:19 AM ( GMT-7 )
4
+ // hash-code: 7fa9afdf
6
5
 
6
+ // file exports
7
+ export * from "./FinalReturn";
7
8
 
8
9
  // #endregion
9
10
 
@@ -1,7 +1,7 @@
1
1
  // #autoindex
2
2
  // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: 7e6e29a0
3
+ // index last changed at: 7th Jul, 2022, 01:15 PM ( GMT-7 )
4
+ // hash-code: f976e182
5
5
 
6
6
  // file exports
7
7
  export * from "./Api";
@@ -22,12 +22,12 @@ export * from "./Not";
22
22
  export * from "./Numeric";
23
23
  export * from "./Opaque";
24
24
  export * from "./Retain";
25
+ export * from "./SimplifyObject";
25
26
  export * from "./Transformer";
26
27
  export * from "./TypeGuard";
27
28
  export * from "./Where";
28
29
  export * from "./append-types";
29
30
  export * from "./maybe";
30
- export * from "./props";
31
31
  export * from "./ruleset-types";
32
32
  export * from "./runtime";
33
33
  export * from "./type-testing";
@@ -35,6 +35,7 @@ export * from "./type-testing";
35
35
  export * from "./alphabetic/index";
36
36
  export * from "./dictionary/index";
37
37
  export * from "./fluent/index";
38
+ export * from "./functions/index";
38
39
  export * from "./kv/index";
39
40
  export * from "./lists/index";
40
41
  export * from "./string-literals/index";
@@ -1,6 +1,6 @@
1
- import type { TypeCondition } from "~/utility/runtime/ifTypeOf";
2
- import { OptionalKeys } from "./props";
3
- import { SameKeys } from "./type-conversion/SameKeys";
1
+ import { TypeCondition } from "src/utility/runtime";
2
+ import { OptionalKeys } from "./dictionary/props";
3
+ import { SameKeys } from "./dictionary/SameKeys";
4
4
 
5
5
  /**
6
6
  * **RuleDefinition**
@@ -1,7 +1,7 @@
1
- import { TypeGuard } from "~/types";
2
-
3
1
  // runtime types relate to the types coming out of the runtime utilities
4
2
 
3
+ import { TypeGuard } from "./TypeGuard";
4
+
5
5
  export type RuntimeType<T> = {
6
6
  __kind: "type";
7
7
 
@@ -14,21 +14,21 @@ export type RuntimeProp<P extends Readonly<PropertyKey>, T extends RuntimeType<a
14
14
  key: Readonly<P>;
15
15
  valueType: Readonly<T["type"]>;
16
16
  /**
17
- * Provides the _type_ to the type system when used with `typeof`.
18
- *
19
- * ```ts
20
- * const t = number();
21
- * // number
22
- * type T = typeof t.type;
23
- * ```
24
- *
25
- * **Note:** _the runtime system will get a string equivalent name:_
26
- * ```ts
27
- * const t = number();
28
- * // "number"
29
- * console.log(t.type);
30
- * ```
31
- */
17
+ * Provides the _type_ to the type system when used with `typeof`.
18
+ *
19
+ * ```ts
20
+ * const t = number();
21
+ * // number
22
+ * type T = typeof t.type;
23
+ * ```
24
+ *
25
+ * **Note:** _the runtime system will get a string equivalent name:_
26
+ * ```ts
27
+ * const t = number();
28
+ * // "number"
29
+ * console.log(t.type);
30
+ * ```
31
+ */
32
32
  type: Record<P, T["type"]>;
33
33
  is: TypeGuard<Record<P, T["type"]>>;
34
34
  };
@@ -36,4 +36,4 @@ export type RuntimeProp<P extends Readonly<PropertyKey>, T extends RuntimeType<a
36
36
  export type TypeOptions<T extends Partial<object> = {}> = {
37
37
  /** each type has a default type guard but you can override if you need to be more specific */
38
38
  typeGuard?: TypeGuard<T>;
39
- } & T;
39
+ } & T;
@@ -1,4 +1,5 @@
1
- import type { Replace, TrimLeft } from "~/types";
1
+ import { Replace } from "./Replace";
2
+ import { TrimLeft } from "./TrimLeft";
2
3
 
3
4
  /**
4
5
  * Provides the _left_ whitespace of a string
@@ -7,4 +8,6 @@ import type { Replace, TrimLeft } from "~/types";
7
8
  * type T = LeftWhitespace<"\n\t foobar">;
8
9
  * ```
9
10
  */
10
- export type LeftWhitespace<S extends string> = string extends S ? string : Replace<S, TrimLeft<S>, "">;
11
+ export type LeftWhitespace<S extends string> = string extends S
12
+ ? string
13
+ : Replace<S, TrimLeft<S>, "">;
@@ -1,4 +1,5 @@
1
- import type { Replace, TrimRight } from "~/types";
1
+ import { Replace } from "./Replace";
2
+ import { TrimRight } from "./TrimRight";
2
3
 
3
4
  /**
4
5
  * Provides the _left_ whitespace of a string
@@ -7,4 +8,6 @@ import type { Replace, TrimRight } from "~/types";
7
8
  * type T = LeftWhitespace<"\n\t foobar">;
8
9
  * ```
9
10
  */
10
- export type RightWhitespace<S extends string> = string extends S ? string : Replace<S, TrimRight<S>, "">;
11
+ export type RightWhitespace<S extends string> = string extends S
12
+ ? string
13
+ : Replace<S, TrimRight<S>, "">;
@@ -1,10 +1,10 @@
1
- import type { Keys, UnionToTuple } from "~/types";
1
+ import { Keys } from "../Keys";
2
+ import { UnionToTuple } from "../type-conversion/UnionToTuple";
2
3
 
3
4
  /**
4
5
  * Returns the _first_ key in an object.
5
- *
6
+ *
6
7
  * **Note:** key order is not guarenteed so typically this is used
7
8
  * for a key/value pair where only one key is expected
8
9
  */
9
10
  export type FirstKey<T extends object> = UnionToTuple<Keys<T>>[0];
10
-
@@ -1,5 +1,5 @@
1
- import { ExpandRecursively, UnionToIntersection } from "~/types";
2
-
1
+ import { ExpandRecursively } from "../ExpandRecursively";
2
+ import { UnionToIntersection } from "../type-conversion";
3
3
 
4
4
  /**
5
5
  * Typescript utility which receives `T` as shape which resembles `DictArray<D>`
@@ -9,5 +9,6 @@ import { ExpandRecursively, UnionToIntersection } from "~/types";
9
9
  * type Dict = FromDictArray<[["foo", { foo: 1 }], ["bar", { bar: "hi" }]]>;
10
10
  * ```
11
11
  */
12
- export type FromDictArray<T extends [string, Record<string, unknown>][]> =
13
- ExpandRecursively<UnionToIntersection<T[number][1]>>;
12
+ export type FromDictArray<T extends [string, Record<string, unknown>][]> = ExpandRecursively<
13
+ UnionToIntersection<T[number][1]>
14
+ >;
@@ -1,16 +1,13 @@
1
1
  // #autoindex
2
2
 
3
3
  // #region autoindexed files
4
- // index last changed at: 6th Jun, 2022, 03:36 AM ( GMT-7 )
5
- // hash-code: ac142b94
4
+ // index last changed at: 6th Jun, 2022, 10:18 AM ( GMT-7 )
5
+ // hash-code: b346a5f3
6
6
 
7
7
  // file exports
8
- export * from "./SameKeys";
9
8
  export * from "./TupleToUnion";
10
9
  export * from "./UnionToIntersection";
11
10
  export * from "./UnionToTuple";
12
- export * from "./UnwrapValue";
13
- export * from "./WrapValue";
14
11
 
15
12
  // #endregion
16
13
 
@@ -1,9 +1,10 @@
1
- import { Narrowable } from "~/types";
1
+ import { Narrowable } from "src/types/Narrowable";
2
2
 
3
- export const api = <N extends Narrowable, TPrivate extends Readonly<Record<any, N>>>(priv: TPrivate) => <TPublic extends object>(pub: TPublic) => {
4
- const surface = () => pub as TPublic;
5
- surface.prototype.priv = () => priv as TPrivate;
6
-
7
- return surface;
8
- };
3
+ export const api =
4
+ <N extends Narrowable, TPrivate extends Readonly<Record<any, N>>>(priv: TPrivate) =>
5
+ <TPublic extends object>(pub: TPublic) => {
6
+ const surface = () => pub as TPublic;
7
+ surface.prototype.priv = () => priv as TPrivate;
9
8
 
9
+ return surface;
10
+ };
@@ -1,6 +1,8 @@
1
1
  /* eslint-disable no-use-before-define */
2
- import { keys } from "~/utility/keys";
3
- import { SameKeys, Transformer } from "~/types";
2
+
3
+ import { SameKeys } from "src/types/dictionary";
4
+ import { Transformer } from "src/types/Transformer";
5
+ import { keys } from "../keys";
4
6
 
5
7
  /**
6
8
  * Takes a dictionary of type `I` and converts it to a dictionary of type `O` where
@@ -13,9 +15,8 @@ export function dictionaryTransform<I extends object, O extends SameKeys<I>>(
13
15
  input: I,
14
16
  transform: Transformer<I, O>
15
17
  ) {
16
-
17
18
  return keys(input).reduce((acc, i) => {
18
19
  const key = i as string & keyof I;
19
- return {...acc, [key]: transform(input, key)};
20
+ return { ...acc, [key]: transform(input, key) };
20
21
  }, {} as O);
21
22
  }
@@ -1,10 +1,11 @@
1
- import { KeyValue, Narrowable } from "~/types";
1
+ import { KeyValue } from "src/types/kv";
2
+ import { Narrowable } from "src/types/Narrowable";
2
3
  import { keys } from "../keys";
3
4
 
4
5
  /**
5
6
  * **entries**
6
7
  *
7
- * Provides an _interable_ over the passed in dictionary object where each iteration
8
+ * Provides an _iterable_ over the passed in dictionary object where each iteration
8
9
  * provides a tuple of `[ key, value ]` which preserve type literals.
9
10
  *
10
11
  * For example:
@@ -14,8 +15,11 @@ import { keys } from "../keys";
14
15
  * for (const [k, v] of entries(obj)) { ... }
15
16
  * ```
16
17
  */
17
- export function entries<N extends Narrowable, T extends Record<string, N>, I extends KeyValue<T, keyof T>>(obj: T) {
18
-
18
+ export function entries<
19
+ N extends Narrowable,
20
+ T extends Record<string, N>,
21
+ I extends KeyValue<T, keyof T>
22
+ >(obj: T) {
19
23
  const iterable = {
20
24
  *[Symbol.iterator]() {
21
25
  for (const k of keys(obj)) {
@@ -26,4 +30,4 @@ export function entries<N extends Narrowable, T extends Record<string, N>, I ext
26
30
  };
27
31
 
28
32
  return iterable;
29
- }
33
+ }
@@ -1,7 +1,7 @@
1
1
  // #autoindex
2
2
  // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: c3587066
3
+ // index last changed at: 7th Jul, 2022, 01:47 PM ( GMT-7 )
4
+ // hash-code: dd2bf50a
5
5
 
6
6
  // file exports
7
7
  export * from "./arrayToKeyLookup";
@@ -9,7 +9,6 @@ export * from "./dictionaryTransform";
9
9
  export * from "./entries";
10
10
  export * from "./mapValues";
11
11
  export * from "./strArrayToDict";
12
- export * from "./valuesOfProp";
13
12
  // directory exports
14
13
  export * from "./kv/index";
15
14
 
@@ -1,6 +1,8 @@
1
- import { Mutable, Narrowable, UnionToTuple } from "~/types";
2
- import { KvFrom } from "~/types/kv/KvFrom";
3
- import { keys } from "~/utility/keys";
1
+ import { KvFrom } from "src/types/kv";
2
+ import { Mutable } from "src/types/Mutable";
3
+ import { Narrowable } from "src/types/Narrowable";
4
+ import { UnionToTuple } from "src/types/type-conversion";
5
+ import { keys } from "src/utility/keys";
4
6
 
5
7
  /**
6
8
  * Converts a dictionary object into an array of dictionaries with `key` and `value` properties
@@ -1,5 +1,5 @@
1
- import type { DictArray, DictArrayFilterCallback } from "~/types";
2
- import { Configurator, IConfigurator } from "~/utility/state";
1
+ import { DictArray, DictArrayFilterCallback } from "src/types/tuples";
2
+ import { Configurator, IConfigurator } from "src/utility/state";
3
3
 
4
4
  export interface Array<T> {
5
5
  filter<U extends T>(pred: (a: T) => a is U): U[];
@@ -11,12 +11,11 @@ export interface Array<T> {
11
11
  */
12
12
  export function filterDictArray<
13
13
  T extends object,
14
- C extends DictArrayFilterCallback<keyof T, T, true | false>,
15
- >(dictArr: DictArray<T>, cb: C) {
16
-
14
+ C extends DictArrayFilterCallback<keyof T, T, true | false>
15
+ >(dictArr: DictArray<T>, cb: C) {
17
16
  const state: IConfigurator = Configurator();
18
17
 
19
- const updated = dictArr.filter(i => {
18
+ const updated = dictArr.filter((i) => {
20
19
  const [k, v] = i;
21
20
  const keep = cb(k, v);
22
21
  if (!keep) {
@@ -30,4 +29,3 @@ export function filterDictArray<
30
29
  type ExcludedKeys = "";
31
30
  return updated as unknown as DictArray<Omit<T, ExcludedKeys>>;
32
31
  }
33
-
@@ -1,13 +1,18 @@
1
- import { ExpandRecursively, Narrowable } from "~/types";
1
+ import { ExpandRecursively } from "src/types/ExpandRecursively";
2
+ import { Narrowable } from "src/types/Narrowable";
2
3
 
3
4
  /**
4
5
  * Build a key-value pair where both _key_ and _value_ are inferred. This
5
6
  * includes ensuring that the _key_ is a type literal not just a "string".
6
7
  *
7
8
  * > note: the value will be inferred but if you need to constrain it
8
- * > to a narrower type then both inferrences will break and you should
9
+ * > to a narrower type then both inferences will break and you should
9
10
  * > instead use `KV2` to get this capability.
10
11
  */
11
- export function kv<K extends string, N extends Narrowable, V extends Record<any, N> | boolean | number | string | null | undefined>(key: K, value: V) {
12
+ export function kv<
13
+ K extends string,
14
+ N extends Narrowable,
15
+ V extends Record<any, N> | boolean | number | string | null | undefined
16
+ >(key: K, value: V) {
12
17
  return { [key]: value } as ExpandRecursively<Record<K, V>>;
13
18
  }
@@ -1,5 +1,6 @@
1
- import { Mutable, Narrowable } from "~/types";
2
- import { DictFromKv } from "~/types/kv";
1
+ import { DictFromKv } from "src/types/kv";
2
+ import { Mutable } from "src/types/Mutable";
3
+ import { Narrowable } from "src/types/Narrowable";
3
4
 
4
5
  /**
5
6
  * Converts an array of dictionaries with `key` and `value` properties to a singular dictionary.
@@ -1,20 +1,23 @@
1
- import { Narrowable } from "~/types";
1
+ import { Narrowable } from "src/types/Narrowable";
2
2
  import { entries } from "./entries";
3
3
 
4
4
  /**
5
5
  * **mapValues**
6
- *
6
+ *
7
7
  * Maps over a dictionary, preserving the keys but allowing the values to be mutated.
8
- *
8
+ *
9
9
  * ```ts
10
10
  * const colors = { red: 4, blue: 2, green: 3 };
11
11
  * // { red: 8, blue: 4, green: 6 }
12
12
  * const twoX = mapValues(colors, v => v * 2);
13
13
  * ```
14
14
  */
15
- export function mapValues<N extends Narrowable, T extends Record<string, N>, V>(obj: T, valueMapper: (k: T[keyof T]) => V) {
15
+ export function mapValues<N extends Narrowable, T extends Record<string, N>, V>(
16
+ obj: T,
17
+ valueMapper: (k: T[keyof T]) => V
18
+ ) {
16
19
  return Object.fromEntries(
17
20
  // TODO: fix the type error with v and valueMapper
18
21
  [...entries(obj)].map(([k, v]) => [k, valueMapper(v as any)])
19
22
  ) as { [K in keyof T]: V };
20
- }
23
+ }
@@ -1,5 +1,4 @@
1
- import { ExpandRecursively } from "~/types/ExpandRecursively";
2
-
1
+ import { ExpandRecursively } from "src/types/ExpandRecursively";
3
2
 
4
3
  /**
5
4
  * converts an array of strings `["a", "b", "c"]` into a more type friendly
@@ -1,12 +1,16 @@
1
- import { Keys, Length } from "~/types";
1
+ import { Keys } from "src/types/Keys";
2
+ import { Length } from "src/types/Length";
2
3
 
3
4
  /**
4
5
  * Provides the _keys_ of an object with the `keyof T` made explicit.
5
6
  */
6
7
  export function keys<T extends {}, W extends readonly string[]>(obj: T, ...without: W) {
7
- const v = without.length > 0
8
- ? Object.keys(obj).filter(k => !without.includes(k)) as unknown as Array<Exclude<keyof T, Keys<W>>>
9
- : Object.keys(obj) as unknown as Array<keyof T>;
8
+ const v =
9
+ without.length > 0
10
+ ? (Object.keys(obj).filter((k) => !without.includes(k)) as unknown as Array<
11
+ Exclude<keyof T, Keys<W>>
12
+ >)
13
+ : (Object.keys(obj) as unknown as Array<keyof T>);
10
14
 
11
15
  return v as unknown as Length<W> extends 0 ? Array<keyof T> : Array<Exclude<keyof T, Keys<W>>>;
12
16
  }
@@ -1,5 +1,4 @@
1
- import { Narrowable } from "~/types";
2
- // import { UniqueForProp } from "~/types/lists/UniqueForProp";
1
+ import { Narrowable } from "src/types/Narrowable";
3
2
 
4
3
  /**
5
4
  * Groups an array of data based on the value of a property
@@ -11,12 +10,6 @@ import { Narrowable } from "~/types";
11
10
  *
12
11
  * @ignore not implemented
13
12
  */
14
- export function groupBy<T extends Record<string, Narrowable>, K extends keyof T & string>(
15
- _data: Readonly<T[]>
16
- ) {
13
+ export function groupBy<T extends Record<string, Narrowable>>(_data: Readonly<T[]>) {
17
14
  throw new Error("not implemented");
18
- return (_groupBy: K) => {
19
- // type _GroupedBy = UniqueForProp<typeof data, K>;
20
- // const _output = {} as Record<GroupedBy, Narrowable>;
21
- };
22
15
  }
@@ -1,22 +1,28 @@
1
- import { Narrowable } from "~/types/Narrowable";
2
-
1
+ import { Narrowable } from "src/types/Narrowable";
3
2
 
4
3
  /**
5
4
  * **UniqueDictionary**
6
- *
5
+ *
7
6
  * A dictionary converted by `arrayToObject()` which expects each key `S` to have a only a
8
7
  * single/unique value.
9
8
  */
10
- export type UniqueDictionary<S extends PropertyKey, N extends Narrowable, T extends Record<keyof T, N> & Record<S, any>> = { [V in T as V[S]]: V };
9
+ export type UniqueDictionary<
10
+ S extends PropertyKey,
11
+ N extends Narrowable,
12
+ T extends Record<keyof T, N> & Record<S, any>
13
+ > = { [V in T as V[S]]: V };
11
14
 
12
15
  /**
13
16
  * **GeneralDictionary**
14
- *
17
+ *
15
18
  * A dictionary converted by `arrayToObject()` which expects each key `S` to have an
16
19
  * array of values.
17
20
  */
18
- export type GeneralDictionary<S extends PropertyKey, N extends Narrowable, T extends Record<keyof T, N> & Record<S, any>> = { [V in T as V[S]]: V[] };
19
-
21
+ export type GeneralDictionary<
22
+ S extends PropertyKey,
23
+ N extends Narrowable,
24
+ T extends Record<keyof T, N> & Record<S, any>
25
+ > = { [V in T as V[S]]: V[] };
20
26
 
21
27
  export type ArrayConverter<S extends PropertyKey, U extends boolean> =
22
28
  /**
@@ -28,45 +34,40 @@ export type ArrayConverter<S extends PropertyKey, U extends boolean> =
28
34
  arr: readonly T[]
29
35
  ) => true extends U ? UniqueDictionary<S, N, T> : GeneralDictionary<S, N, T>;
30
36
 
31
-
32
37
  /**
33
38
  * Converts an array of objects into a dictionary by picking a property name contained
34
39
  * by all objects and using that as the key to the dictionary.
35
- *
40
+ *
36
41
  * ```ts
37
- * const arr = [
42
+ * const arr = [
38
43
  * { kind: "color", favorite: "blue", likes: 100 },
39
44
  * { kind: "song", favorite: "some song", likes: 25 }
40
45
  * ];
41
46
  * const dict = arrayToObject("kind")(arr);
42
47
  * ```
43
- *
48
+ *
44
49
  * This will produce a dictionary with keys of `color` and `song`.
45
50
  */
46
- export function arrayToObject<
47
- S extends PropertyKey,
48
- U extends boolean
49
- >(prop: S, unique?: U) {
51
+ export function arrayToObject<S extends PropertyKey, U extends boolean>(prop: S, unique?: U) {
50
52
  type X = true extends U ? true : false;
51
53
  /**
52
54
  * **arrayToObject** - partially applied
53
- *
55
+ *
54
56
  * pass in an array of objects to complete application of arrayToObject()
55
57
  */
56
- const transform: ArrayConverter<S, X> = <N extends Narrowable, T extends Record<keyof T, N> & Record<S, any>>(
58
+ const transform: ArrayConverter<S, X> = <
59
+ N extends Narrowable,
60
+ T extends Record<keyof T, N> & Record<S, any>
61
+ >(
57
62
  arr: readonly T[]
58
63
  ): true extends X ? UniqueDictionary<S, N, T> : GeneralDictionary<S, N, T> => {
59
-
60
- const result = unique !== false
61
- ? arr.reduce(
62
- (acc, v) => ({ ...acc, [v[prop]]: v }), {} as UniqueDictionary<S, N, T>
63
- )
64
- : arr.reduce(
65
- (acc, v) => {
66
- const existing = acc[v[prop] as T[S]] || [];
67
- return { ...acc, [v[prop]]: [...existing, v] };
68
- }, {} as GeneralDictionary<S, N, T>
69
- );
64
+ const result =
65
+ unique !== false
66
+ ? arr.reduce((acc, v) => ({ ...acc, [v[prop]]: v }), {} as UniqueDictionary<S, N, T>)
67
+ : arr.reduce((acc, v) => {
68
+ const existing = acc[v[prop] as T[S]] || [];
69
+ return { ...acc, [v[prop]]: [...existing, v] };
70
+ }, {} as GeneralDictionary<S, N, T>);
70
71
 
71
72
  // type cast based on `U`
72
73
  return result as true extends X ? UniqueDictionary<S, N, T> : GeneralDictionary<S, N, T>;
@@ -75,4 +76,3 @@ export function arrayToObject<
75
76
  return transform;
76
77
  // return converter(prop, unique);
77
78
  }
78
-
@@ -1,15 +1,15 @@
1
- import { ExpandRecursively, Narrowable } from "~/types";
1
+ import { ExpandRecursively } from "src/types/ExpandRecursively";
2
+ import { Narrowable } from "src/types/Narrowable";
2
3
 
3
4
  /**
4
5
  * Build a _type_ from two run-time dictionaries.
5
- *
6
+ *
6
7
  * 1. The _first_ -- which is optional -- is interpreted as a _literal_ type definition
7
8
  * 2. The _second_ dictionary is interpreted as a "wide" definition of prop types
8
9
  */
9
- export function defineType<
10
- N extends Narrowable,
11
- TLiteral extends Record<string, N>
12
- >(literal: TLiteral = {} as TLiteral) {
10
+ export function defineType<N extends Narrowable, TLiteral extends Record<string, N>>(
11
+ literal: TLiteral = {} as TLiteral
12
+ ) {
13
13
  /**
14
14
  * Add any key/value pairs which you want to have _wide_ types associated;
15
15
  * literal types are defined already and stated above.
@@ -1,4 +1,5 @@
1
- import { Narrowable } from "~/types/Narrowable";
1
+ import { Narrowable } from "src/types/Narrowable";
2
+
2
3
  /**
3
4
  * An identity function for any type, with the goal of preserving literal type information
4
5
  * whereever possible.
@@ -6,4 +7,6 @@ import { Narrowable } from "~/types/Narrowable";
6
7
  export const identity = <
7
8
  N extends Narrowable,
8
9
  T extends Record<any, N> | number | string | boolean | symbol | undefined | null
9
- >(v: T) => v;
10
+ >(
11
+ v: T
12
+ ) => v;
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-use-before-define */
2
2
 
3
- import { Narrowable } from "~/types";
3
+ import { Narrowable } from "src/types/Narrowable";
4
4
 
5
5
  /**
6
6
  * Takes an object as input --which has an `id` property and returns it as the same
@@ -39,8 +39,8 @@ export function idTypeGuard<T extends { id: I }, I extends PropertyKey>(
39
39
  /**
40
40
  * Takes an object as input and infers the narrow literal types of the property
41
41
  * values on the object.
42
- *
43
- * > Note: this addresses this [a known TS gap](https://github.com/microsoft/TypeScript/issues/30680).
42
+ *
43
+ * > Note: this addresses this [a known TS gap](https://github.com/microsoft/TypeScript/issues/30680).
44
44
  * > Hopefully at some point this will be addressed in the language.
45
45
  */
46
46
  export function literal<N extends Narrowable, T extends Record<keyof T, N>>(obj: T) {