inferred-types 0.19.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 (133) 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 +403 -8538
  6. package/dist/index.js +35 -60
  7. package/dist/index.mjs +24 -48
  8. package/package.json +34 -23
  9. package/src/shared/valueTypes.ts +1 -1
  10. package/src/types/ExpandRecursively.ts +10 -1
  11. package/src/types/FunctionType.ts +1 -1
  12. package/src/types/SimplifyObject.ts +12 -0
  13. package/src/types/Transformer.ts +1 -1
  14. package/src/types/alphabetic/CamelCase.ts +1 -1
  15. package/src/types/alphabetic/CapFirstAlpha.ts +7 -3
  16. package/src/types/alphabetic/Dasherize.ts +8 -5
  17. package/src/types/alphabetic/KebabCase.ts +1 -1
  18. package/src/types/alphabetic/PascalCase.ts +3 -1
  19. package/src/types/alphabetic/SnakeCase.ts +8 -3
  20. package/src/types/dictionary/DictPartialApplication.ts +30 -0
  21. package/src/types/dictionary/DictPrependWithFn.ts +23 -0
  22. package/src/types/dictionary/DictReturnValues.ts +27 -0
  23. package/src/types/dictionary/RequireProps.ts +15 -0
  24. package/src/types/{type-conversion → dictionary}/SameKeys.ts +0 -0
  25. package/src/types/dictionary/index.ts +8 -3
  26. package/src/types/{props.ts → dictionary/props.ts} +1 -1
  27. package/src/types/functions/FinalReturn.ts +12 -0
  28. package/{on-hold/types → src/types/functions}/index.ts +4 -3
  29. package/src/types/index.ts +4 -3
  30. package/src/types/ruleset-types.ts +3 -3
  31. package/src/types/runtime.ts +18 -18
  32. package/src/types/string-literals/LeftWhitespace.ts +5 -2
  33. package/src/types/string-literals/RightWhitespace.ts +5 -2
  34. package/src/types/tuples/FirstKey.ts +3 -3
  35. package/src/types/tuples/FromDictArray.ts +5 -4
  36. package/src/types/type-conversion/index.ts +2 -5
  37. package/src/utility/api/api.ts +8 -7
  38. package/src/utility/createFnWithProps.ts +26 -1
  39. package/src/utility/dictionary/dictionaryTransform.ts +5 -4
  40. package/src/utility/dictionary/entries.ts +9 -5
  41. package/src/utility/dictionary/index.ts +2 -3
  42. package/src/utility/dictionary/kv/dictToKv.ts +5 -3
  43. package/src/utility/dictionary/kv/filterDictArray.ts +5 -7
  44. package/src/utility/dictionary/kv/kv.ts +8 -3
  45. package/src/utility/dictionary/kv/kvToDict.ts +3 -2
  46. package/src/utility/dictionary/mapValues.ts +8 -5
  47. package/src/utility/dictionary/strArrayToDict.ts +1 -2
  48. package/src/utility/keys.ts +8 -4
  49. package/src/utility/lists/groupBy.ts +2 -9
  50. package/src/utility/literals/arrayToObject.ts +29 -29
  51. package/src/utility/literals/defineType.ts +6 -6
  52. package/src/utility/literals/identity.ts +5 -2
  53. package/src/utility/literals/literal.ts +3 -3
  54. package/src/utility/ruleset.ts +11 -9
  55. package/src/utility/runtime/condition.ts +1 -1
  56. package/src/utility/runtime/conditions/isFalse.ts +2 -2
  57. package/src/utility/runtime/conditions/isFunction.ts +2 -2
  58. package/src/utility/runtime/conditions/isObject.ts +4 -1
  59. package/src/utility/runtime/conditions/isTrue.ts +1 -1
  60. package/src/utility/runtime/ifTypeOf.ts +1 -1
  61. package/src/utility/runtime/type.ts +3 -1
  62. package/src/utility/runtime/withValue.ts +5 -3
  63. package/src/utility/state/Configurator.ts +2 -2
  64. package/src/utility/state/FluentConfigurator.ts +2 -2
  65. package/src/utility/state/index.ts +2 -3
  66. package/tests/CamelCase-spec.ts +2 -0
  67. package/tests/ExplicitFunction-spec.ts +3 -2
  68. package/tests/IncludeAndRetain-spec.ts +7 -12
  69. package/tests/Includes-spec.ts +2 -0
  70. package/tests/KebabCase-spec.ts +2 -0
  71. package/tests/MutationIdentity-spec.ts +2 -1
  72. package/tests/PascalCase-spec.ts +2 -0
  73. package/tests/Pluralize-spec.ts +2 -0
  74. package/tests/SnakeCase-spec.ts +2 -0
  75. package/tests/Where.spec.ts +9 -10
  76. package/tests/arrayToKeyLookup-spec.ts +5 -5
  77. package/tests/arrayToObject-spec.ts +12 -8
  78. package/tests/constructor.spec.ts +2 -0
  79. package/tests/createFnWithProps.spec.ts +2 -2
  80. package/tests/defineType-spec.ts +17 -11
  81. package/tests/dictionary/DictPartialApplication.test.ts +43 -0
  82. package/tests/dictionary/DictReturnValues.test.ts +32 -0
  83. package/tests/dictionary/Get.spec.ts +5 -3
  84. package/tests/dictionary/PrependValuesWithFunction.ts +34 -0
  85. package/tests/dictionary/RequireProps.test.ts +21 -0
  86. package/tests/dictionaryTransform-spec.ts +3 -3
  87. package/tests/ifTypeOf-spec.ts +31 -20
  88. package/tests/kv/KeyValue-spec.ts +4 -4
  89. package/tests/kv/SameKeys-spec.ts +6 -9
  90. package/tests/kv/dict-to-kv-and-back.spec.ts +5 -4
  91. package/tests/kv/entries-spec.ts +8 -9
  92. package/tests/kv/keys.spec.ts +9 -19
  93. package/tests/kv/kv-spec.ts +4 -4
  94. package/tests/lists/UniqueForProp.spec.ts +3 -1
  95. package/tests/literal-spec.ts +5 -3
  96. package/tests/mapValues-spec.ts +5 -3
  97. package/tests/props-spec.ts +3 -2
  98. package/tests/runtime/condition.spec.ts +2 -1
  99. package/tests/runtime/type.spec.ts +4 -3
  100. package/tests/strArrayToDict-spec.ts +6 -6
  101. package/tests/string-literals/AllCaps.spec.ts +6 -15
  102. package/tests/string-literals/CamelCase.spec.ts +13 -32
  103. package/tests/string-literals/Dasherize.spec.ts +13 -31
  104. package/tests/string-literals/HasUppercase.spec.ts +6 -15
  105. package/tests/string-literals/PascalCase.spec.ts +13 -32
  106. package/tests/string-literals/SnakeCase.spec.ts +13 -32
  107. package/tests/string-literals/whitespace-capture.spec.ts +10 -28
  108. package/tests/tuples/TupleToUnion.spec.ts +3 -1
  109. package/tests/withValue.spec.ts +4 -3
  110. package/tsconfig.json +8 -19
  111. package/vitest.config.ts +13 -0
  112. package/jest.config.ts +0 -20
  113. package/on-hold/Builder/Builder.ts +0 -66
  114. package/on-hold/Builder/BuilderApi.ts +0 -21
  115. package/on-hold/Builder/IdentityToMutationApi.ts +0 -44
  116. package/on-hold/Builder/MutationToFluentApi.ts +0 -60
  117. package/on-hold/Builder/index.ts +0 -35
  118. package/on-hold/tests/Builder-spec.ts +0 -310
  119. package/on-hold/tests/RuleSet-spec.ts +0 -59
  120. package/on-hold/tests/ToFluent-spec.ts +0 -60
  121. package/on-hold/tests/api-spec.ts +0 -73
  122. package/on-hold/tests/data/builder-data.ts +0 -53
  123. package/on-hold/tests/filterDictArray-spec.ts +0 -50
  124. package/on-hold/tests/run-time-spec.ts +0 -44
  125. package/on-hold/type.ts +0 -20
  126. package/on-hold/types/object.ts +0 -19
  127. package/on-hold/types/prop.ts +0 -28
  128. package/on-hold/types/scalar.ts +0 -37
  129. package/src/types/dictionary/NotEmptyObject.ts +0 -9
  130. package/src/types/type-conversion/UnwrapValue.ts +0 -13
  131. package/src/types/type-conversion/WrapValue.ts +0 -15
  132. package/src/utility/dictionary/valuesOfProp.ts +0 -13
  133. package/src/utility/state/KeyStorage.ts +0 -23
@@ -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,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,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,3 +1,4 @@
1
+ import { Narrowable } from "../types/Narrowable";
1
2
  import { keys } from "./keys";
2
3
 
3
4
  export function createFnWithProps<F extends Function, P extends {}>(fn: F, props: P) {
@@ -9,4 +10,28 @@ export function createFnWithProps<F extends Function, P extends {}>(fn: F, props
9
10
  }
10
11
  return combined;
11
12
  })() as unknown as F & P;
12
- }
13
+ }
14
+
15
+ /**
16
+ * Adds a dictionary of key/value pairs to a function.
17
+ */
18
+ export function fnWithProps<A extends any[], R extends any, P extends {}>(fn: ((...args: A) => R), props: P) {
19
+ // eslint-disable-next-line prefer-const
20
+ let combined: any = fn;
21
+ for (const prop of keys(props)) {
22
+ combined[prop] = props[prop];
23
+ }
24
+ return combined as ((...args: A) => R) & P;
25
+ }
26
+
27
+ /**
28
+ * Adds read-only (and narrowly typed) key/value pairs to a function
29
+ */
30
+ export function readonlyFnWithProps<A extends any[], R extends any, N extends Narrowable, P extends Record<keyof P, N>>(fn: ((...args: A) => R), props: P) {
31
+ // eslint-disable-next-line prefer-const
32
+ let combined: any = fn;
33
+ for (const prop of keys(props)) {
34
+ combined[prop] = props[prop];
35
+ }
36
+ return combined as ((...args: A) => R) & Readonly<P>;
37
+ }
@@ -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
  }