inferred-types 0.25.0 → 0.26.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 +134 -28
- package/dist/index.js +337 -255
- package/dist/index.mjs +332 -252
- package/package.json +1 -1
- package/src/types/functions/LogicFunction.ts +4 -0
- package/src/types/functions/index.ts +1 -0
- package/src/utility/boolean-logic/and.ts +15 -0
- package/src/utility/boolean-logic/filter.ts +268 -0
- package/src/utility/boolean-logic/index.ts +4 -0
- package/src/utility/boolean-logic/not.ts +15 -0
- package/src/utility/boolean-logic/or.ts +15 -0
- package/src/utility/index.ts +1 -1
- package/src/utility/lists/asArray.ts +34 -0
- package/src/utility/lists/index.ts +1 -0
- package/tests/boolean-logic/boolean.spec.ts +21 -0
- package/tests/boolean-logic/filter.spec.ts +52 -0
- package/tests/lists/asArray.test.ts +91 -0
- package/src/utility/map-reduce/filter.ts +0 -35
- package/src/utility/map-reduce/index.ts +0 -12
package/dist/index.d.ts
CHANGED
|
@@ -1192,6 +1192,11 @@ declare type PureFluentApi<TApi extends Record<string, (...args: any[]) => PureF
|
|
|
1192
1192
|
*/
|
|
1193
1193
|
declare type FinalReturn<T extends any> = T extends (...args: any[]) => any ? FinalReturn<ReturnType<T>> : T;
|
|
1194
1194
|
|
|
1195
|
+
/**
|
|
1196
|
+
* A function which returns a boolean value
|
|
1197
|
+
*/
|
|
1198
|
+
declare type LogicFunction<T extends any[]> = (...args: T) => boolean;
|
|
1199
|
+
|
|
1195
1200
|
declare type DictFromKv<T extends readonly Readonly<{
|
|
1196
1201
|
key: string;
|
|
1197
1202
|
value: unknown;
|
|
@@ -1422,6 +1427,116 @@ declare function ruleSet<N extends Narrowable, TState extends Record<keyof TStat
|
|
|
1422
1427
|
|
|
1423
1428
|
declare const api: <N extends Narrowable, TPrivate extends Readonly<Record<any, N>>>(priv: TPrivate) => <TPublic extends object>(pub: TPublic) => () => TPublic;
|
|
1424
1429
|
|
|
1430
|
+
/**
|
|
1431
|
+
* Groups a number of "logic functions" together by combining their results using
|
|
1432
|
+
* the logical **AND** operator.
|
|
1433
|
+
*
|
|
1434
|
+
* **Note:** a "logic function" is any function which returns a boolean
|
|
1435
|
+
*/
|
|
1436
|
+
declare const and: <T extends any[]>(...ops: readonly LogicFunction<T>[]) => LogicFunction<T>;
|
|
1437
|
+
|
|
1438
|
+
/**
|
|
1439
|
+
* Groups a number of "logic functions" together by combining their results using
|
|
1440
|
+
* the logical **OR** operator.
|
|
1441
|
+
*
|
|
1442
|
+
* **Note:** a "logic function" is any function which returns a boolean
|
|
1443
|
+
*/
|
|
1444
|
+
declare const or: <T extends any[]>(...ops: LogicFunction<T>[]) => LogicFunction<T>;
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* Groups a number of "logic functions" together by combining their results using
|
|
1448
|
+
* the logical **NOT** operator.
|
|
1449
|
+
*
|
|
1450
|
+
* **Note:** a "logic function" is any function which returns a boolean
|
|
1451
|
+
*/
|
|
1452
|
+
declare const not: <T extends any[]>(op: LogicFunction<T>) => LogicFunction<T>;
|
|
1453
|
+
|
|
1454
|
+
declare type FilterStarts = {
|
|
1455
|
+
/** one or more string which the value is allowed to start with */
|
|
1456
|
+
startsWith: string | string[];
|
|
1457
|
+
};
|
|
1458
|
+
declare type FilterIs = {
|
|
1459
|
+
/** whether a string _**is**_ of a particular value */
|
|
1460
|
+
is: string | string[];
|
|
1461
|
+
};
|
|
1462
|
+
declare type FilterEnds = {
|
|
1463
|
+
endsWith: string | string[];
|
|
1464
|
+
};
|
|
1465
|
+
declare type FilterContains = {
|
|
1466
|
+
/** whether any of the strings specified are _contained_ in the value */
|
|
1467
|
+
contains: string | string[];
|
|
1468
|
+
};
|
|
1469
|
+
declare type FilterEquals = {
|
|
1470
|
+
/** one or more values which _equal_ the value passed in */
|
|
1471
|
+
equals: number | number[];
|
|
1472
|
+
};
|
|
1473
|
+
declare type FilterNotEqual = {
|
|
1474
|
+
/** one or more values which ALL _do not equal_ the value passed in */
|
|
1475
|
+
notEqual: number | number[];
|
|
1476
|
+
};
|
|
1477
|
+
declare type FilterGreaterThan = {
|
|
1478
|
+
/** the incoming value is greater than this value */
|
|
1479
|
+
greaterThan: number;
|
|
1480
|
+
};
|
|
1481
|
+
declare type FilterLessThan = {
|
|
1482
|
+
/** the incoming value is less than this value */
|
|
1483
|
+
lessThan: number;
|
|
1484
|
+
};
|
|
1485
|
+
declare type StringFilter = FilterIs | FilterStarts | FilterEnds | FilterContains | (FilterStarts & FilterEnds) | (FilterStarts & FilterContains) | (FilterEnds & FilterContains) | (FilterStarts & FilterEnds & FilterContains);
|
|
1486
|
+
declare type NumericFilter = FilterEquals | FilterNotEqual | FilterGreaterThan | FilterLessThan | (FilterEquals & FilterNotEqual) | (FilterEquals & FilterGreaterThan) | (FilterEquals & FilterLessThan) | (FilterNotEqual & FilterGreaterThan) | (FilterNotEqual & FilterLessThan) | (FilterGreaterThan & FilterLessThan) | (FilterEquals & FilterGreaterThan & FilterLessThan) | (FilterNotEqual & FilterGreaterThan & FilterLessThan) | (FilterEquals & FilterNotEqual & FilterGreaterThan & FilterLessThan);
|
|
1487
|
+
declare type FilterDefn = StringFilter | NumericFilter;
|
|
1488
|
+
declare type NotFilter = {
|
|
1489
|
+
/**
|
|
1490
|
+
* **not**
|
|
1491
|
+
*
|
|
1492
|
+
* If you want to build a filter who's conditions being met results in _filtering_
|
|
1493
|
+
* the value rather than accepting it then choose this.
|
|
1494
|
+
*/
|
|
1495
|
+
not: FilterDefn;
|
|
1496
|
+
};
|
|
1497
|
+
declare function isNotFilter(f: FilterDefn | NotFilter): f is NotFilter;
|
|
1498
|
+
declare type UnwrapNot<T extends FilterDefn | NotFilter> = T extends NotFilter ? T["not"] extends StringFilter ? StringFilter : NumericFilter : T;
|
|
1499
|
+
declare function isNumericFilter(filter: FilterDefn): filter is NumericFilter;
|
|
1500
|
+
declare type UndefinedValue<U extends boolean> = true extends U ? "undefined treated as 'true'" : U extends "no-impact" ? "undefined treated in no-impact fashion" : "undefined treated as 'false'";
|
|
1501
|
+
declare type UndefinedTreatment = "undefined treated as 'true'" | "undefined treated as 'false'";
|
|
1502
|
+
declare type LogicalCombinator = "AND" | "OR";
|
|
1503
|
+
/**
|
|
1504
|
+
* **FilterFn**
|
|
1505
|
+
*
|
|
1506
|
+
* A filter function derived from the `filter()` configurator. This function is intended to provide a type-strong _filter_ function which can be used like so:
|
|
1507
|
+
* be used like:
|
|
1508
|
+
* ```ts
|
|
1509
|
+
* const onlyPrivate = filter({ startsWith: "_" });
|
|
1510
|
+
* const privateFiles = files.filter(onlyPrivate);
|
|
1511
|
+
* ```
|
|
1512
|
+
*
|
|
1513
|
+
*/
|
|
1514
|
+
declare type FilterFn<T extends StringFilter | NumericFilter> = T extends StringFilter ? <V extends string | undefined>(input: V) => boolean : <V extends number | undefined>(input: V) => boolean;
|
|
1515
|
+
/**
|
|
1516
|
+
* Defines a logical function for each condition type
|
|
1517
|
+
*/
|
|
1518
|
+
declare type ConditionFilter<T extends StringFilter | NumericFilter> = T extends StringFilter ? (input: string) => boolean : (input: number) => boolean;
|
|
1519
|
+
/**
|
|
1520
|
+
* **filter**
|
|
1521
|
+
*
|
|
1522
|
+
* A higher order helper utility which builds a boolean _filter_ function based on a simple
|
|
1523
|
+
* configuration object. Support either _string_ or _numeric_ filters.
|
|
1524
|
+
*
|
|
1525
|
+
* ```ts
|
|
1526
|
+
* const str = filter({startsWith: ["_", "."], endsWith: ".md"});
|
|
1527
|
+
* const num = filter({ greaterThan: 55, notEqual: [66, 77]});
|
|
1528
|
+
* ```
|
|
1529
|
+
*
|
|
1530
|
+
* All conditions (e.g., `startsWith`, `contains`, `notEqual`, etc.) that a particular filter
|
|
1531
|
+
* is defined as having -- if there is more than one -- will be logically combined using AND
|
|
1532
|
+
* unless specified otherwise in the third parameter.
|
|
1533
|
+
*
|
|
1534
|
+
* How a value of _undefined_ will be treated is stated in the second parameter but defaults
|
|
1535
|
+
* to "no-impact" which means it's `false` when the logicCombinator is OR but defaults
|
|
1536
|
+
* to `true` when the logicCombinator is AND.
|
|
1537
|
+
*/
|
|
1538
|
+
declare const filter: <F extends FilterDefn | NotFilter, U extends boolean | "no-impact", C extends LogicalCombinator>(config: F, logicCombinator?: C, ifUndefined?: U) => FilterFn<UnwrapNot<F>>;
|
|
1539
|
+
|
|
1425
1540
|
/**
|
|
1426
1541
|
* Passing in an array of strings, you are passed back a dictionary with
|
|
1427
1542
|
* all the keys being the strings and values set to `true`.
|
|
@@ -1592,6 +1707,24 @@ declare function kvToDict<K extends string, V extends Narrowable, T extends read
|
|
|
1592
1707
|
value: V;
|
|
1593
1708
|
}>[]>(kvArr: T): DictFromKv<T>;
|
|
1594
1709
|
|
|
1710
|
+
/**
|
|
1711
|
+
* Type utility which converts `undefined[]` to `unknown[]`
|
|
1712
|
+
*/
|
|
1713
|
+
declare type UndefinedArrayIsUnknown<T extends any[]> = undefined[] extends T ? unknown[] : T;
|
|
1714
|
+
declare type AsArray<T, W extends boolean = false> = T extends any[] ? W extends true ? Widen<T> : T : W extends true ? UndefinedArrayIsUnknown<Widen<T>[]> : UndefinedArrayIsUnknown<T[]>;
|
|
1715
|
+
/**
|
|
1716
|
+
* Ensures that any input passed in is passed back as an array:
|
|
1717
|
+
*
|
|
1718
|
+
* - if it was already an array than this just serves as an _identity_ function
|
|
1719
|
+
* - if it was not then it wraps the element into a one element array of the
|
|
1720
|
+
* given type
|
|
1721
|
+
*
|
|
1722
|
+
* Note: by default the _type_ of values will be intentionally widened so that the value "abc"
|
|
1723
|
+
* is of type `string` not the literal `abc`. If you want to keep literal types then
|
|
1724
|
+
* change the optional _widen_ parameter to _false_.
|
|
1725
|
+
*/
|
|
1726
|
+
declare const asArray: <T extends Narrowable, W extends boolean = true>(thing: T, _widen?: W | undefined) => AsArray<T, W>;
|
|
1727
|
+
|
|
1595
1728
|
/**
|
|
1596
1729
|
* Groups an array of data based on the value of a property
|
|
1597
1730
|
* in the objects within the array.
|
|
@@ -1707,33 +1840,6 @@ declare function idTypeGuard<T extends {
|
|
|
1707
1840
|
*/
|
|
1708
1841
|
declare function literal<N extends Narrowable, T extends Record<keyof T, N>>(obj: T): T;
|
|
1709
1842
|
|
|
1710
|
-
declare type Filter<A> = {
|
|
1711
|
-
kind: "Equals";
|
|
1712
|
-
field: keyof A;
|
|
1713
|
-
val: A[keyof A];
|
|
1714
|
-
} | {
|
|
1715
|
-
kind: "Greater";
|
|
1716
|
-
field: keyof A;
|
|
1717
|
-
val: A[keyof A];
|
|
1718
|
-
} | {
|
|
1719
|
-
kind: "Less";
|
|
1720
|
-
field: keyof A;
|
|
1721
|
-
val: A[keyof A];
|
|
1722
|
-
} | {
|
|
1723
|
-
kind: "And";
|
|
1724
|
-
a: Filter<A>;
|
|
1725
|
-
b: Filter<A>;
|
|
1726
|
-
} | {
|
|
1727
|
-
kind: "Or";
|
|
1728
|
-
a: Filter<A>;
|
|
1729
|
-
b: Filter<A>;
|
|
1730
|
-
};
|
|
1731
|
-
declare const equals: <A, K extends keyof A>(field: K, val: A[K]) => Filter<A>;
|
|
1732
|
-
declare const greater: <A, K extends keyof A>(field: K, val: A[K]) => Filter<A>;
|
|
1733
|
-
declare const less: <A, K extends keyof A>(field: K, val: A[K]) => Filter<A>;
|
|
1734
|
-
declare const and: <A>(a: Filter<A>, b: Filter<A>) => Filter<A>;
|
|
1735
|
-
declare const or: <A>(a: Filter<A>, b: Filter<A>) => Filter<A>;
|
|
1736
|
-
|
|
1737
1843
|
declare function Model<N extends string, _R extends {} = {}, _O extends {} = {}>(name: N): {
|
|
1738
1844
|
required<P extends string>(_prop: P): {
|
|
1739
1845
|
required<P_1 extends string>(_prop: P_1): any;
|
|
@@ -1821,4 +1927,4 @@ interface IFluentConfigurator<C> {
|
|
|
1821
1927
|
*/
|
|
1822
1928
|
declare function FluentConfigurator<I>(initial?: I): IFluentConfigurator<{}>;
|
|
1823
1929
|
|
|
1824
|
-
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, DictArrApi, DictArray, DictArrayFilterCallback, DictArrayKv, DictChangeValue, DictFromKv, DictKvTuple, DictPartialApplication, DictPrependWithFn, DictReturnValues, DynamicRule, DynamicRuleSet, Email, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, ExtendsClause, ExtendsNarrowlyClause,
|
|
1930
|
+
export { AllCaps, Alpha, AlphaNumeric, Api, ApiFunction, ApiValue, AppendToDictionary, AppendToObject, ArrConcat, Array$1 as Array, ArrayConverter, AsArray, AssertExtends, Bracket, Break, CamelCase, CapitalizeWords, ClosingBracket, Condition, ConditionFilter, Configurator, Constructor, DashToSnake, DashUppercase, Dasherize, DefinePropertiesApi, DictArrApi, DictArray, DictArrayFilterCallback, DictArrayKv, DictChangeValue, DictFromKv, DictKvTuple, DictPartialApplication, DictPrependWithFn, DictReturnValues, DynamicRule, DynamicRuleSet, Email, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, ExtendsClause, ExtendsNarrowlyClause, FilterContains, FilterDefn, FilterEnds, FilterEquals, FilterFn, FilterGreaterThan, FilterIs, FilterLessThan, FilterNotEqual, FilterStarts, FinalReturn, First, FirstKey, FirstKeyValue, FirstOfEach, FluentConfigurator, FluentFunction, FromDictArray, FunctionType, GeneralDictionary, Get, HasUppercase, IConfigurator, IFluentConfigurator, If, IfExtends, IfExtendsThen, Include, Includes, IsArray, IsBoolean, IsBooleanLiteral, IsCapitalized, IsFalse, IsFunction, IsLiteral, IsNumericLiteral, IsObject, IsString, IsStringLiteral, IsTrue, KebabCase, KeyValue, KeyedRecord, Keys, KeysWithValue, KvFrom, KvTuple, LastInUnion, LeftWhitespace, Length, LogicFunction, LogicalCombinator, LowerAllCaps, LowerAlpha, MapTo, MapToWithFiltering, MaybeFalse, MaybeTrue, Model, Mutable, MutableProps, MutationFunction, MutationIdentity, Narrowable, NonAlpha, NonNumericKeys, NonStringKeys, Not, NotFilter, Numeric, NumericFilter, 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, StringFilter, StringKeys, StringLength, ToFluent, Transformer, Trim, TrimLeft, TrimRight, TupleToUnion, Type, TypeApi, TypeCondition, TypeDefinition, TypeGuard, TypeOptions, UndefinedArrayIsUnknown, UndefinedTreatment, UndefinedValue, UnionToIntersection, UnionToTuple, UniqueDictionary, UniqueForProp, Uniqueness, UnwrapNot, UpperAlpha, ValueTuple, ValueTypeFunc, ValueTypes, Where, WhereNot, Whitespace, Widen, WithNumericKeys, WithStringKeys, WithValue, ZipCode, and, api, arrayToKeyLookup, arrayToObject, asArray, condition, createFnWithProps, createMutationFunction, defineProperties, defineType, dictArr, dictToKv, dictionaryTransform, entries, filter, filterDictArray, fnWithProps, groupBy, idLiteral, idTypeGuard, identity, ifTypeOf, isArray, isBoolean, isFalse, isFunction, isNotFilter, isNull, isNumber, isNumericFilter, isObject, isString, isSymbol, isTrue, isType, isUndefined, keys, kindLiteral, kv, kvToDict, literal, mapTo, mapValues, nameLiteral, not, or, randomString, readonlyFnWithProps, ruleSet, strArrayToDict, type, typeApi, uuid, valueTypes, withValue };
|