inferred-types 0.18.4 → 0.19.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.
package/dist/index.d.ts CHANGED
@@ -899,6 +899,11 @@ declare type SnakeCase<S extends string> = string extends S ? string : DashUpper
899
899
  */
900
900
  declare type Get<T, K> = K extends `${infer FK}.${infer L}` ? FK extends keyof T ? Get<T[FK], L> : never : K extends keyof T ? T[K] : never;
901
901
 
902
+ /**
903
+ * Accepts an object with at least one property defined on it
904
+ */
905
+ declare type NotEmptyObject<T extends {}> = ExpandRecursively<Length<UnionToTuple<Keys<T>>> extends 0 ? false : T>;
906
+
902
907
  /**
903
908
  * **ToFluent**
904
909
  *
@@ -1037,7 +1042,7 @@ declare type FirstKeyValue<T extends object> = FirstKey<T> extends keyof T ? T[F
1037
1042
  declare type FirstOfEach<T extends readonly any[][]> = T[number][0] extends T[number][number] ? T[number][0] : never;
1038
1043
 
1039
1044
  /**
1040
- * Typescript utility which recieves `T` as shape which resembles `DictArray<D>`
1045
+ * Typescript utility which receives `T` as shape which resembles `DictArray<D>`
1041
1046
  * and if the type `D` can be inferred it is returned.
1042
1047
  * ```ts
1043
1048
  * // { foo: 1; bar: "hi" }
@@ -1082,6 +1087,19 @@ declare type LastInUnion<U> = UnionToIntersection<U extends unknown ? (x: U) =>
1082
1087
  */
1083
1088
  declare type UnionToTuple<U, Last = LastInUnion<U>> = [U] extends [never] ? [] : [...UnionToTuple<Exclude<U, Last>>, Last];
1084
1089
 
1090
+ /**
1091
+ * Given a dictionary of key/values, where the value is a function, this
1092
+ * type utility will maintain the keys but change the values to whatever
1093
+ * the `ReturnType` of the function was.
1094
+ * ```ts
1095
+ * // { foo: string }
1096
+ * type Test = UnwrapValue<{ foo: (name: string) => name }>
1097
+ * ```
1098
+ */
1099
+ declare type UnwrapValue<T extends Record<string, (...args: any[]) => any>> = {
1100
+ [K in keyof T]: T[K] extends Function ? ReturnType<T[K]> : never;
1101
+ }[keyof T];
1102
+
1085
1103
  declare type ValueFunction<T extends any> = <R extends any>(v: T) => R;
1086
1104
  /**
1087
1105
  * **SameKeys**
@@ -9770,4 +9788,4 @@ declare function KeyStorage(): {
9770
9788
  done: () => never[];
9771
9789
  };
9772
9790
 
9773
- 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, DictArray, DictArrayFilterCallback, DictArrayKv, DictFromKv, DictKvTuple, DynamicRule, DynamicRuleSet, Email, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, ExtendsClause, ExtendsNarrowlyClause, Filter, First, FirstKey, FirstKeyValue, FirstOfEach, FluentConfigurator, FluentFunction, FromDictArray, FunctionType, GeneralDictionary, Get, HasUppercase, IConfigurator, IFluentConfigurator, If, IfExtends, IfExtendsThen, Include, Includes, IsArray, IsBoolean, IsCapitalized, IsFalse, IsFunction, IsLiteral, IsObject, IsString, IsTrue, KebabCase, KeyStorage, KeyStorageApi, KeyValue, KeyedRecord, Keys, KeysWithValue, KvFrom, KvTuple, LastInUnion, LeftWhitespace, Length, LowerAllCaps, LowerAlpha, MaybeFalse, MaybeTrue, Model, Mutable, MutationFunction, MutationIdentity, Narrowable, NonAlpha, NonNumericKeys, NonStringKeys, Not, Numeric, NumericKeys, NumericString, ObjectType, Opaque, OpenningBracket, OptionalKeys, OptionalProps, Parenthesis, PascalCase, Pluralize, PrivateKey, PrivateKeys, PublicKeys, Punctuation, PureFluentApi, Replace, RequiredKeys, RequiredProps, Retain, RightWhitespace, RuleDefinition, RuntimeProp, RuntimeType, SameKeys, SecondOfEach, 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, WrapValue, ZipCode, and, api, arrayToKeyLookup, arrayToObject, condition, createFnWithProps, createMutationFunction, defineType, dictToKv, dictionaryTransform, entries, equals, filterDictArray, greater, groupBy, idLiteral, idTypeGuard, identity, ifTypeOf, isArray, isBoolean, isFalse, isFunction, isLiteral, isNull, isNumber, isObject, isString, isSymbol, isTrue, isType, isUndefined, keys, kindLiteral, kv, kvToDict, less, literal, mapValues, nameLiteral, or, randomString, ruleSet, strArrayToDict, type, typeApi, uuid, valueTypes, valuesOfProp, withValue };
9791
+ 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, DictArray, DictArrayFilterCallback, DictArrayKv, DictFromKv, DictKvTuple, DynamicRule, DynamicRuleSet, Email, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, ExtendsClause, ExtendsNarrowlyClause, Filter, First, FirstKey, FirstKeyValue, FirstOfEach, FluentConfigurator, FluentFunction, FromDictArray, FunctionType, GeneralDictionary, Get, HasUppercase, IConfigurator, IFluentConfigurator, If, IfExtends, IfExtendsThen, Include, Includes, IsArray, IsBoolean, IsCapitalized, IsFalse, IsFunction, IsLiteral, IsObject, IsString, IsTrue, KebabCase, KeyStorage, KeyStorageApi, KeyValue, KeyedRecord, Keys, KeysWithValue, KvFrom, KvTuple, LastInUnion, LeftWhitespace, Length, LowerAllCaps, LowerAlpha, MaybeFalse, MaybeTrue, Model, Mutable, MutationFunction, MutationIdentity, Narrowable, NonAlpha, NonNumericKeys, NonStringKeys, Not, NotEmptyObject, Numeric, NumericKeys, NumericString, ObjectType, Opaque, OpenningBracket, OptionalKeys, OptionalProps, Parenthesis, PascalCase, Pluralize, PrivateKey, PrivateKeys, PublicKeys, Punctuation, PureFluentApi, Replace, RequiredKeys, RequiredProps, Retain, RightWhitespace, RuleDefinition, RuntimeProp, RuntimeType, SameKeys, SecondOfEach, SnakeCase, SpecialCharacters, StringDelimiter, StringKeys, StringLength, ToFluent, Transformer, Trim, TrimLeft, TrimRight, TupleToUnion, Type, TypeApi, TypeCondition, TypeDefinition, TypeGuard, TypeOptions, UnionToIntersection, UnionToTuple, UniqueDictionary, UniqueForProp, UnwrapValue, UpperAlpha, ValueTuple, ValueTypeFunc, ValueTypes, Where, WhereNot, Whitespace, WithNumericKeys, WithStringKeys, WithValue, WrapValue, ZipCode, and, api, arrayToKeyLookup, arrayToObject, condition, createFnWithProps, createMutationFunction, defineType, dictToKv, dictionaryTransform, entries, equals, filterDictArray, greater, groupBy, idLiteral, idTypeGuard, identity, ifTypeOf, isArray, isBoolean, isFalse, isFunction, isLiteral, isNull, isNumber, isObject, isString, isSymbol, isTrue, isType, isUndefined, keys, kindLiteral, kv, kvToDict, less, literal, mapValues, nameLiteral, or, randomString, ruleSet, strArrayToDict, type, typeApi, uuid, valueTypes, valuesOfProp, withValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inferred-types",
3
- "version": "0.18.4",
3
+ "version": "0.19.0",
4
4
  "description": "Functions which provide useful type inference on TS projects",
5
5
  "license": "MIT",
6
6
  "author": "Ken Snyder<ken@ken.net>",
@@ -48,4 +48,4 @@
48
48
  "dependencies": {
49
49
  "common-types": "^1.31.0"
50
50
  }
51
- }
51
+ }
@@ -0,0 +1,9 @@
1
+ import { ExpandRecursively } from "../ExpandRecursively";
2
+ import { Keys, Length, UnionToTuple } from "../index";
3
+
4
+ /**
5
+ * Accepts an object with at least one property defined on it
6
+ */
7
+ export type NotEmptyObject<T extends {}> = ExpandRecursively<
8
+ Length<UnionToTuple<Keys<T>>> extends 0 ? false : T
9
+ >;
@@ -1,10 +1,11 @@
1
1
  // #autoindex
2
2
  // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: 47804a72
3
+ // index last changed at: 6th Jun, 2022, 03:36 AM ( GMT-7 )
4
+ // hash-code: 1f3a5076
5
5
 
6
6
  // file exports
7
7
  export * from "./Get";
8
+ export * from "./NotEmptyObject";
8
9
 
9
10
  // #endregion
10
11
 
@@ -2,7 +2,7 @@ import { ExpandRecursively, UnionToIntersection } from "~/types";
2
2
 
3
3
 
4
4
  /**
5
- * Typescript utility which recieves `T` as shape which resembles `DictArray<D>`
5
+ * Typescript utility which receives `T` as shape which resembles `DictArray<D>`
6
6
  * and if the type `D` can be inferred it is returned.
7
7
  * ```ts
8
8
  * // { foo: 1; bar: "hi" }
@@ -0,0 +1,13 @@
1
+
2
+ /**
3
+ * Given a dictionary of key/values, where the value is a function, this
4
+ * type utility will maintain the keys but change the values to whatever
5
+ * the `ReturnType` of the function was.
6
+ * ```ts
7
+ * // { foo: string }
8
+ * type Test = UnwrapValue<{ foo: (name: string) => name }>
9
+ * ```
10
+ */
11
+ export type UnwrapValue<T extends Record<string, (...args: any[]) => any>> = {
12
+ [K in keyof T]: T[K] extends Function ? ReturnType<T[K]> : never;
13
+ }[keyof T];
@@ -1,14 +1,15 @@
1
1
  // #autoindex
2
2
 
3
3
  // #region autoindexed files
4
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
5
- // hash-code: 3c8daf19
4
+ // index last changed at: 6th Jun, 2022, 03:36 AM ( GMT-7 )
5
+ // hash-code: ac142b94
6
6
 
7
7
  // file exports
8
8
  export * from "./SameKeys";
9
9
  export * from "./TupleToUnion";
10
10
  export * from "./UnionToIntersection";
11
11
  export * from "./UnionToTuple";
12
+ export * from "./UnwrapValue";
12
13
  export * from "./WrapValue";
13
14
 
14
15
  // #endregion
@@ -9,4 +9,4 @@ export function createFnWithProps<F extends Function, P extends {}>(fn: F, props
9
9
  }
10
10
  return combined;
11
11
  })() as unknown as F & P;
12
- }
12
+ }