@webshrine/stdtyp
Advanced tools
Comparing version 0.0.11 to 0.0.12
{ | ||
"name": "@webshrine/stdtyp", | ||
"type": "module", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "repository": { |
import type { IterateParameters } from '.' | ||
import type { AnyArray, AnyArrayOptional, AnyObject } from '..' | ||
/** @category Utilities */ | ||
type ConcatTwoArrays<A extends AnyArray, B extends AnyArrayOptional> = B extends AnyArray ? [...A, ...B] : A | ||
@@ -9,2 +10,3 @@ | ||
* matches any types of functions if generics wasn't defined | ||
* @category Utilities | ||
*/ | ||
@@ -23,6 +25,12 @@ export type Fn< | ||
/** Any function without parameters */ | ||
/** | ||
* Any function without parameters | ||
* @category Utilities | ||
*/ | ||
export type FnNullary<Result = void> = Fn<undefined, Result> | ||
/** Any function with parameters */ | ||
/** | ||
* Any function with parameters | ||
* @category Utilities | ||
*/ | ||
export type FnParametrized< | ||
@@ -33,2 +41,3 @@ Parameters extends AnyArray = AnyArray, | ||
/** @category Utilities */ | ||
export type FnMethod< | ||
@@ -40,2 +49,3 @@ Context, | ||
/** @category Utilities */ | ||
export type FnMethodPipe< | ||
@@ -52,3 +62,6 @@ Context, | ||
/** Any async function */ | ||
/** | ||
* Any async function | ||
* @category Utilities | ||
*/ | ||
export type FnAsync< | ||
@@ -60,20 +73,42 @@ Parameters extends AnyArrayOptional = AnyArrayOptional, | ||
/** Any async function without parameters */ | ||
/** | ||
* Any async function without parameters | ||
* @category Utilities | ||
*/ | ||
export type FnAsyncNullary<Result = void> = FnAsync<undefined, Result> | ||
/** @category Utilities */ | ||
export type FnAsyncProcedure<Parameters extends AnyArrayOptional = AnyArrayOptional> = FnAsync<Parameters, void> | ||
/** @category Utilities */ | ||
export type FnAsyncPredicate<Parameters extends AnyArrayOptional = AnyArrayOptional> = FnAsync<Parameters, boolean> | ||
/** Any function without result */ | ||
/** | ||
* Any function without result | ||
* @category Utilities | ||
*/ | ||
export type FnProcedure<Parameters extends AnyArrayOptional = AnyArrayOptional> = Fn<Parameters, void> | ||
/** Any function with boolean result */ | ||
/** | ||
* Any function with boolean result | ||
* @category Utilities | ||
*/ | ||
export type FnPredicate<Parameters extends AnyArrayOptional = AnyArrayOptional> = Fn<Parameters, boolean> | ||
/** Binary function that returns boolean */ | ||
/** | ||
* Binary function that returns boolean | ||
* @category Utilities | ||
*/ | ||
export type FnMatch<A = any, B = A> = FnPredicate<[a: A, b: B]> | ||
/** Comparison function that returns `-1 | 0 | 1` as result */ | ||
/** | ||
* Comparison function that returns `-1 | 0 | 1` as result | ||
* @category Utilities | ||
*/ | ||
export type FnCompare<Value = any> = FnParametrized<[a: Value, b: Value], -1 | 0 | 1> | ||
/** Transforming function */ | ||
/** | ||
* Transforming function | ||
* @category Utilities | ||
*/ | ||
export type FnTransform< | ||
@@ -85,3 +120,6 @@ Input = any, | ||
/** Summarizer funcConcatTwoArrays */ | ||
/** | ||
* Summarizer funcConcatTwoArrays | ||
* @category Utilities | ||
*/ | ||
export type FnReduce<Input = any, Result = any> = FnParametrized<[a: Input, b: Input], Result> | ||
@@ -92,2 +130,3 @@ | ||
* If `Id` wasn't provided, returns universal iterate function type | ||
* @category Utilities | ||
*/ | ||
@@ -100,5 +139,9 @@ export type FnIterate< | ||
/** Iteration function of `times*` utils */ | ||
/** | ||
* Iteration function of `times*` utils | ||
* @category Utilities | ||
*/ | ||
export type FnIterateTimes<Result = void> = (number: number, index: number, count: number) => Result | ||
/** @category Utilities */ | ||
export type FnIterateDeep< | ||
@@ -116,15 +159,30 @@ Item = any, | ||
/** Procedure iteration function */ | ||
/** | ||
* Procedure iteration function | ||
* @category Utilities | ||
*/ | ||
export type FnProcedureIterate<Item = any, Id extends PropertyKey = PropertyKey> = FnIterate<Item, Id, void> | ||
/** Predicate iteration function */ | ||
/** | ||
* Predicate iteration function | ||
* @category Utilities | ||
*/ | ||
export type FnPredicateIterate<Item = any, Id extends PropertyKey = PropertyKey> = FnIterate<Item, Id, boolean> | ||
/** Transform iteration function */ | ||
/** | ||
* Transform iteration function | ||
* @category Utilities | ||
*/ | ||
export type FnTransformIterate<Input = any, Id extends PropertyKey = PropertyKey, Output = Input> = FnIterate<Input, Id, Output> | ||
/** Reduce iteration function */ | ||
/** | ||
* Reduce iteration function | ||
* @category Utilities | ||
*/ | ||
export type FnReduceIterate<Item = any, Id extends PropertyKey = PropertyKey, Result = any> = Fn<[previousValue: Result | undefined, ...IterateParameters<Item, Id>], Result> | ||
/** Wrapper function */ | ||
/** | ||
* Wrapper function | ||
* @category Utilities | ||
*/ | ||
export type FnWrapper< | ||
@@ -154,6 +212,12 @@ F extends Fn = Fn, | ||
/** Guard function */ | ||
/** | ||
* Guard function | ||
* @category Utilities | ||
*/ | ||
export type FnGuard<Target> = (value: any) => value is Target | ||
/** Formatter function */ | ||
/** | ||
* Formatter function | ||
* @category Utilities | ||
*/ | ||
export type FnFormat<Input, Output> = FnTransform<Readonly<Input>, Output | null> |
import type { FnNullary } from '.' | ||
/** Allows `T` to be `T` or `null` */ | ||
/** | ||
* Allows `T` to be `T` or `null` | ||
* @category Utilities | ||
*/ | ||
export type Nullable<T> = T | null | ||
/** Allows `T` to be `T` or `Promise<T>` */ | ||
/** | ||
* Allows `T` to be `T` or `Promise<T>` | ||
* @category Utilities | ||
*/ | ||
export type MaybePromise<T> = T | Promise<T> | ||
/** Allows `T` to be `T` or `() => T` */ | ||
/** | ||
* Allows `T` to be `T` or `() => T` | ||
* @category Utilities | ||
*/ | ||
export type MaybeReturned<T> = T | FnNullary<T> | ||
/** Allows `T` to be `T` or `T[]` */ | ||
/** | ||
* Allows `T` to be `T` or `T[]` | ||
* @category Utilities | ||
*/ | ||
export type MaybeArray<T> = T | T[] | ||
@@ -22,2 +34,3 @@ | ||
* const literal2: MaybeSomeLiterals = 'other literal' // still ok and IDE can suggest source literals | ||
* @category Utilities | ||
*/ | ||
@@ -24,0 +37,0 @@ export type MaybeLiteral<T extends PropertyKey> = T | (string & {}) |
import type { AnyArrayOptional, AnyObject, CollectionKey, Decrement } from '..' | ||
/** @category Utilities */ | ||
export type Collection< | ||
@@ -11,2 +12,3 @@ Item = any, | ||
* If `Id` wasn't provided, returns universal iterate parameters | ||
* @category Utilities | ||
*/ | ||
@@ -19,2 +21,3 @@ export type IterateParameters< | ||
/** @category Utilities */ | ||
export type Constructor< | ||
@@ -26,2 +29,4 @@ Instance = any, | ||
: { new(): Instance } | ||
/** @category Utilities */ | ||
export type NullaryConstructor<Instance> = Constructor<Instance> | ||
@@ -33,4 +38,6 @@ | ||
/** @category Utilities */ | ||
type IfString<Value, Then = Value, Else = never> = Value extends string ? Then : Else | ||
/** @category Utilities */ | ||
type StringifyKey<K extends PropertyKey> = K extends string | ||
@@ -43,6 +50,10 @@ ? K | ||
* Instead of `keyof T`, returns only strings and stringified numbers | ||
* @category Utilities | ||
*/ | ||
export type Keys<T extends AnyObject> = StringifyKey<keyof T> | ||
/** The same as `Keys<T>`, but recursively for all nested objects */ | ||
/** | ||
* The same as `Keys<T>`, but recursively for all nested objects | ||
* @category Utilities | ||
*/ | ||
export type KeysDeep<T extends Collection, Depth extends number = 20> = Depth extends -1 | ||
@@ -56,2 +67,3 @@ ? never | ||
/** @category Utilities */ | ||
type OmitDeepRecursor<T, K extends string> = | ||
@@ -64,4 +76,6 @@ T extends ReadonlyArray<infer I> | ||
/** @category Utilities */ | ||
export type OmitDeep<T extends Collection, K extends string> = OmitDeepRecursor<T, K> | ||
/** @category Utilities */ | ||
type PickDeepRecursor<T, K extends string> = | ||
@@ -74,4 +88,6 @@ T extends ReadonlyArray<infer I> | ||
/** @category Utilities */ | ||
export type PickDeep<T extends Collection, K extends string> = PickDeepRecursor<T, K> | ||
/** @category Utilities */ | ||
export type Paths<T extends AnyObject> = { | ||
@@ -90,2 +106,3 @@ [K in keyof T]: K extends string | ||
/** @category Utilities */ | ||
export type Split<T extends string, Separator extends string> = | ||
@@ -92,0 +109,0 @@ string extends T ? string[] : |
16273
508