inferred-types 0.23.0 → 0.23.2

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.
package/dist/index.d.ts CHANGED
@@ -1438,6 +1438,24 @@ declare function entries<N extends Narrowable, T extends Record<string, N>, I ex
1438
1438
  */
1439
1439
  declare function mapValues<N extends Narrowable, T extends Record<string, N>, V>(obj: T, valueMapper: (k: T[keyof T]) => V): { [K in keyof T]: V; };
1440
1440
 
1441
+ /**
1442
+ * **mapTo**
1443
+ *
1444
+ * A utility function which maps one dictionary structure `I` to another `O`; where:
1445
+ *
1446
+ * - `I` maps to `O[ ]` so this allows a cardinality of 0:M
1447
+ * - In other words ... values from `I` can be filtered, translated 1:1 or split into multiple outputs
1448
+ * - Type constrains laid out by `I` and `O` will be enforced by type system
1449
+ *
1450
+ * ```ts
1451
+ * type I = { title: string; color: string; products: Product[] };
1452
+ * type O = { title: string; count: number };
1453
+ * const summarize: mapTo<I,O>()
1454
+ * .map();
1455
+ * ```
1456
+ */
1457
+ declare const mapTo: <I extends {}, O extends {}>(cb: MapTo<I, O>) => (source: I) => O[];
1458
+
1441
1459
  /**
1442
1460
  * converts an array of strings `["a", "b", "c"]` into a more type friendly
1443
1461
  * dictionary of the type `{ a: true, b: true, c: true }`
@@ -1451,7 +1469,9 @@ declare function strArrayToDict<T extends readonly string[]>(...strings: T): Exp
1451
1469
  * const arr = dictToKv({ id: 123, foo: "bar" });
1452
1470
  * ```
1453
1471
  */
1454
- declare function dictToKv<N extends Narrowable, T extends Record<string, N>, U extends boolean>(obj: T, _makeTuple?: U): U extends true ? UnionToTuple<(Mutable<T> extends infer T_1 extends object ? { [K in keyof T_1]: {
1472
+ declare function dictToKv<N extends Narrowable, T extends {
1473
+ [key: string]: N;
1474
+ }, U extends boolean>(obj: T, _makeTuple?: U): U extends true ? UnionToTuple<(Mutable<T> extends infer T_1 extends object ? { [K in keyof T_1]: {
1455
1475
  key: K;
1456
1476
  value: Mutable<T>[K];
1457
1477
  }; } : never)[keyof T], LastInUnion<(Mutable<T> extends infer T_1 extends object ? { [K in keyof T_1]: {
@@ -1721,4 +1741,4 @@ interface IFluentConfigurator<C> {
1721
1741
  */
1722
1742
  declare function FluentConfigurator<I>(initial?: I): IFluentConfigurator<{}>;
1723
1743
 
1724
- export { AllCaps, Alpha, AlphaNumeric, Api, ApiFunction, ApiValue, AppendToDictionary, AppendToObject, ArrConcat, Array$1 as Array, ArrayConverter, AssertExtends, Bracket, Break, CamelCase, CapitalizeWords, ClosingBracket, Condition, Configurator, Constructor, DashToSnake, DashUppercase, Dasherize, DefinePropertiesApi, DictArray, DictArrayFilterCallback, DictArrayKv, DictChangeValue, DictFromKv, DictKvTuple, DictPartialApplication, DictPrependWithFn, DictReturnValues, DynamicRule, DynamicRuleSet, Email, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, ExtendsClause, ExtendsNarrowlyClause, Filter, FinalReturn, First, FirstKey, FirstKeyValue, FirstOfEach, FluentConfigurator, FluentFunction, FromDictArray, FunctionType, GeneralDictionary, Get, HasUppercase, IConfigurator, IFluentConfigurator, If, IfExtends, IfExtendsThen, Include, Includes, IsArray, IsBoolean, IsCapitalized, IsFalse, IsFunction, IsObject, IsString, IsTrue, KebabCase, KeyValue, KeyedRecord, Keys, KeysWithValue, KvFrom, KvTuple, LastInUnion, LeftWhitespace, Length, LowerAllCaps, LowerAlpha, MapTo, MaybeFalse, MaybeTrue, Model, Mutable, MutableProps, MutationFunction, MutationIdentity, Narrowable, NonAlpha, NonNumericKeys, NonStringKeys, Not, Numeric, NumericKeys, NumericString, ObjectType, Opaque, OpeningBracket, OptionalKeys, OptionalProps, Parenthesis, PascalCase, Pluralize, PrivateKey, PrivateKeys, PublicKeys, Punctuation, PureFluentApi, Replace, RequireProps, RequiredKeys, RequiredProps, Retain, RightWhitespace, RuleDefinition, RuntimeProp, RuntimeType, SameKeys, SecondOfEach, SimplifyObject, SnakeCase, SpecialCharacters, StringDelimiter, StringKeys, StringLength, ToFluent, Transformer, Trim, TrimLeft, TrimRight, TupleToUnion, Type, TypeApi, TypeCondition, TypeDefinition, TypeGuard, TypeOptions, UnionToIntersection, UnionToTuple, UniqueDictionary, UniqueForProp, UpperAlpha, ValueTuple, ValueTypeFunc, ValueTypes, Where, WhereNot, Whitespace, WithNumericKeys, WithStringKeys, WithValue, ZipCode, and, api, arrayToKeyLookup, arrayToObject, condition, createFnWithProps, createMutationFunction, defineProperties, defineType, dictToKv, dictionaryTransform, entries, equals, filterDictArray, fnWithProps, greater, groupBy, idLiteral, idTypeGuard, identity, ifTypeOf, isArray, isBoolean, isFalse, isFunction, isNull, isNumber, isObject, isString, isSymbol, isTrue, isType, isUndefined, keys, kindLiteral, kv, kvToDict, less, literal, mapValues, nameLiteral, or, randomString, readonlyFnWithProps, ruleSet, strArrayToDict, type, typeApi, uuid, valueTypes, withValue };
1744
+ export { AllCaps, Alpha, AlphaNumeric, Api, ApiFunction, ApiValue, AppendToDictionary, AppendToObject, ArrConcat, Array$1 as Array, ArrayConverter, AssertExtends, Bracket, Break, CamelCase, CapitalizeWords, ClosingBracket, Condition, Configurator, Constructor, DashToSnake, DashUppercase, Dasherize, DefinePropertiesApi, DictArray, DictArrayFilterCallback, DictArrayKv, DictChangeValue, DictFromKv, DictKvTuple, DictPartialApplication, DictPrependWithFn, DictReturnValues, DynamicRule, DynamicRuleSet, Email, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, ExtendsClause, ExtendsNarrowlyClause, Filter, FinalReturn, First, FirstKey, FirstKeyValue, FirstOfEach, FluentConfigurator, FluentFunction, FromDictArray, FunctionType, GeneralDictionary, Get, HasUppercase, IConfigurator, IFluentConfigurator, If, IfExtends, IfExtendsThen, Include, Includes, IsArray, IsBoolean, IsCapitalized, IsFalse, IsFunction, IsObject, IsString, IsTrue, KebabCase, KeyValue, KeyedRecord, Keys, KeysWithValue, KvFrom, KvTuple, LastInUnion, LeftWhitespace, Length, LowerAllCaps, LowerAlpha, MapTo, MaybeFalse, MaybeTrue, Model, Mutable, MutableProps, MutationFunction, MutationIdentity, Narrowable, NonAlpha, NonNumericKeys, NonStringKeys, Not, Numeric, NumericKeys, NumericString, ObjectType, Opaque, OpeningBracket, OptionalKeys, OptionalProps, Parenthesis, PascalCase, Pluralize, PrivateKey, PrivateKeys, PublicKeys, Punctuation, PureFluentApi, Replace, RequireProps, RequiredKeys, RequiredProps, Retain, RightWhitespace, RuleDefinition, RuntimeProp, RuntimeType, SameKeys, SecondOfEach, SimplifyObject, SnakeCase, SpecialCharacters, StringDelimiter, StringKeys, StringLength, ToFluent, Transformer, Trim, TrimLeft, TrimRight, TupleToUnion, Type, TypeApi, TypeCondition, TypeDefinition, TypeGuard, TypeOptions, UnionToIntersection, UnionToTuple, UniqueDictionary, UniqueForProp, UpperAlpha, ValueTuple, ValueTypeFunc, ValueTypes, Where, WhereNot, Whitespace, WithNumericKeys, WithStringKeys, WithValue, ZipCode, and, api, arrayToKeyLookup, arrayToObject, condition, createFnWithProps, createMutationFunction, defineProperties, defineType, dictToKv, dictionaryTransform, entries, equals, filterDictArray, fnWithProps, greater, groupBy, idLiteral, idTypeGuard, identity, ifTypeOf, isArray, isBoolean, isFalse, isFunction, isNull, isNumber, isObject, isString, isSymbol, isTrue, isType, isUndefined, keys, kindLiteral, kv, kvToDict, less, literal, mapTo, mapValues, nameLiteral, or, randomString, readonlyFnWithProps, ruleSet, strArrayToDict, type, typeApi, uuid, valueTypes, withValue };
package/dist/index.js CHANGED
@@ -64,6 +64,7 @@ __export(src_exports, {
64
64
  kvToDict: () => kvToDict,
65
65
  less: () => less,
66
66
  literal: () => literal,
67
+ mapTo: () => mapTo,
67
68
  mapValues: () => mapValues,
68
69
  nameLiteral: () => nameLiteral,
69
70
  or: () => or,
@@ -221,6 +222,9 @@ function mapValues(obj, valueMapper) {
221
222
  );
222
223
  }
223
224
 
225
+ // src/utility/dictionary/mapTo.ts
226
+ var mapTo = (cb) => (source) => cb(source);
227
+
224
228
  // src/utility/dictionary/strArrayToDict.ts
225
229
  function strArrayToDict(...strings) {
226
230
  return strings.reduce((acc, str) => {
@@ -665,6 +669,7 @@ function withValue(td) {
665
669
  kvToDict,
666
670
  less,
667
671
  literal,
672
+ mapTo,
668
673
  mapValues,
669
674
  nameLiteral,
670
675
  or,
package/dist/index.mjs CHANGED
@@ -140,6 +140,9 @@ function mapValues(obj, valueMapper) {
140
140
  );
141
141
  }
142
142
 
143
+ // src/utility/dictionary/mapTo.ts
144
+ var mapTo = (cb) => (source) => cb(source);
145
+
143
146
  // src/utility/dictionary/strArrayToDict.ts
144
147
  function strArrayToDict(...strings) {
145
148
  return strings.reduce((acc, str) => {
@@ -583,6 +586,7 @@ export {
583
586
  kvToDict,
584
587
  less,
585
588
  literal,
589
+ mapTo,
586
590
  mapValues,
587
591
  nameLiteral,
588
592
  or,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inferred-types",
3
- "version": "0.23.0",
3
+ "version": "0.23.2",
4
4
  "description": "Functions which provide useful type inference on TS projects",
5
5
  "license": "MIT",
6
6
  "author": "Ken Snyder<ken@ken.net>",
@@ -9,6 +9,7 @@ export * from "./defineProperties";
9
9
  export * from "./dictionaryTransform";
10
10
  export * from "./entries";
11
11
  export * from "./mapValues";
12
+ export * from "./mapTo";
12
13
  export * from "./strArrayToDict";
13
14
  // directory exports
14
15
  export * from "./kv/index";
@@ -11,7 +11,7 @@ import { keys } from "src/utility/keys";
11
11
  * const arr = dictToKv({ id: 123, foo: "bar" });
12
12
  * ```
13
13
  */
14
- export function dictToKv<N extends Narrowable, T extends Record<string, N>, U extends boolean>(
14
+ export function dictToKv<N extends Narrowable, T extends { [key: string]: N }, U extends boolean>(
15
15
  obj: T,
16
16
  _makeTuple: U = false as U
17
17
  ) {