inferred-types 0.19.0 → 0.19.1
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 +9 -1
- package/dist/index.js +18 -0
- package/dist/index.mjs +16 -0
- package/package.json +4 -1
- package/src/types/FunctionType.ts +1 -1
- package/src/utility/createFnWithProps.ts +26 -1
package/dist/index.d.ts
CHANGED
|
@@ -1114,6 +1114,14 @@ declare type WrapValue<T extends {}, F extends ValueFunction<T>> = {
|
|
|
1114
1114
|
};
|
|
1115
1115
|
|
|
1116
1116
|
declare function createFnWithProps<F extends Function, P extends {}>(fn: F, props: P): F & P;
|
|
1117
|
+
/**
|
|
1118
|
+
* Adds a dictionary of key/value pairs to a function.
|
|
1119
|
+
*/
|
|
1120
|
+
declare function fnWithProps<A extends any[], R extends any, P extends {}>(fn: ((...args: A) => R), props: P): ((...args: A) => R) & P;
|
|
1121
|
+
/**
|
|
1122
|
+
* Adds read-only (and narrowly typed) key/value pairs to a function
|
|
1123
|
+
*/
|
|
1124
|
+
declare function readonlyFnWithProps<A extends any[], R extends any, N extends Narrowable, P extends Record<keyof P, N>>(fn: ((...args: A) => R), props: P): ((...args: A) => R) & Readonly<P>;
|
|
1117
1125
|
|
|
1118
1126
|
/**
|
|
1119
1127
|
* Provides the _keys_ of an object with the `keyof T` made explicit.
|
|
@@ -9788,4 +9796,4 @@ declare function KeyStorage(): {
|
|
|
9788
9796
|
done: () => never[];
|
|
9789
9797
|
};
|
|
9790
9798
|
|
|
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 };
|
|
9799
|
+
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, fnWithProps, 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, readonlyFnWithProps, ruleSet, strArrayToDict, type, typeApi, uuid, valueTypes, valuesOfProp, withValue };
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,7 @@ __export(src_exports, {
|
|
|
60
60
|
entries: () => entries,
|
|
61
61
|
equals: () => equals,
|
|
62
62
|
filterDictArray: () => filterDictArray,
|
|
63
|
+
fnWithProps: () => fnWithProps,
|
|
63
64
|
greater: () => greater,
|
|
64
65
|
groupBy: () => groupBy,
|
|
65
66
|
idLiteral: () => idLiteral,
|
|
@@ -89,6 +90,7 @@ __export(src_exports, {
|
|
|
89
90
|
nameLiteral: () => nameLiteral,
|
|
90
91
|
or: () => or,
|
|
91
92
|
randomString: () => randomString,
|
|
93
|
+
readonlyFnWithProps: () => readonlyFnWithProps,
|
|
92
94
|
ruleSet: () => ruleSet,
|
|
93
95
|
strArrayToDict: () => strArrayToDict,
|
|
94
96
|
type: () => type,
|
|
@@ -158,6 +160,20 @@ function createFnWithProps(fn, props) {
|
|
|
158
160
|
return combined;
|
|
159
161
|
})();
|
|
160
162
|
}
|
|
163
|
+
function fnWithProps(fn, props) {
|
|
164
|
+
let combined = fn;
|
|
165
|
+
for (const prop of keys(props)) {
|
|
166
|
+
combined[prop] = props[prop];
|
|
167
|
+
}
|
|
168
|
+
return combined;
|
|
169
|
+
}
|
|
170
|
+
function readonlyFnWithProps(fn, props) {
|
|
171
|
+
let combined = fn;
|
|
172
|
+
for (const prop of keys(props)) {
|
|
173
|
+
combined[prop] = props[prop];
|
|
174
|
+
}
|
|
175
|
+
return combined;
|
|
176
|
+
}
|
|
161
177
|
|
|
162
178
|
// src/utility/ruleset.ts
|
|
163
179
|
function ruleSet(defn) {
|
|
@@ -641,6 +657,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
641
657
|
entries,
|
|
642
658
|
equals,
|
|
643
659
|
filterDictArray,
|
|
660
|
+
fnWithProps,
|
|
644
661
|
greater,
|
|
645
662
|
groupBy,
|
|
646
663
|
idLiteral,
|
|
@@ -670,6 +687,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
670
687
|
nameLiteral,
|
|
671
688
|
or,
|
|
672
689
|
randomString,
|
|
690
|
+
readonlyFnWithProps,
|
|
673
691
|
ruleSet,
|
|
674
692
|
strArrayToDict,
|
|
675
693
|
type,
|
package/dist/index.mjs
CHANGED
|
@@ -77,6 +77,20 @@ function createFnWithProps(fn, props) {
|
|
|
77
77
|
return combined;
|
|
78
78
|
})();
|
|
79
79
|
}
|
|
80
|
+
function fnWithProps(fn, props) {
|
|
81
|
+
let combined = fn;
|
|
82
|
+
for (const prop of keys(props)) {
|
|
83
|
+
combined[prop] = props[prop];
|
|
84
|
+
}
|
|
85
|
+
return combined;
|
|
86
|
+
}
|
|
87
|
+
function readonlyFnWithProps(fn, props) {
|
|
88
|
+
let combined = fn;
|
|
89
|
+
for (const prop of keys(props)) {
|
|
90
|
+
combined[prop] = props[prop];
|
|
91
|
+
}
|
|
92
|
+
return combined;
|
|
93
|
+
}
|
|
80
94
|
|
|
81
95
|
// src/utility/ruleset.ts
|
|
82
96
|
function ruleSet(defn) {
|
|
@@ -558,6 +572,7 @@ export {
|
|
|
558
572
|
entries,
|
|
559
573
|
equals,
|
|
560
574
|
filterDictArray,
|
|
575
|
+
fnWithProps,
|
|
561
576
|
greater,
|
|
562
577
|
groupBy,
|
|
563
578
|
idLiteral,
|
|
@@ -587,6 +602,7 @@ export {
|
|
|
587
602
|
nameLiteral,
|
|
588
603
|
or,
|
|
589
604
|
randomString,
|
|
605
|
+
readonlyFnWithProps,
|
|
590
606
|
ruleSet,
|
|
591
607
|
strArrayToDict,
|
|
592
608
|
type,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inferred-types",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"description": "Functions which provide useful type inference on TS projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ken Snyder<ken@ken.net>",
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"build": "run-s clean autoindex lint build:bundle",
|
|
15
15
|
"build:force": "run-s clean autoindex build:bundle",
|
|
16
16
|
"build:bundle": "npx tsup src/index.ts --dts --format='esm,cjs'",
|
|
17
|
+
"watch": "run-p watch:*",
|
|
18
|
+
"watch:autoindex": "npx dd autoindex --watch",
|
|
19
|
+
"watch:bundle": "npx tsup src/index.ts --dts --format='esm,cjs' --watch",
|
|
17
20
|
"clean": "rimraf dist/**/*",
|
|
18
21
|
"lint": "eslint src/**/*.ts --fix && tsc --noEmit ",
|
|
19
22
|
"lint:full": "eslint src/**/*.ts && eslint test/**/*.ts && tsc --noEmit",
|
|
@@ -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
|
+
}
|