Utils Reference
⚒️ Lou’s Code TypeScript curried functional utils.
Usage
📦 Node
Install @lou.codes/utils
as a dependency:
Import it and use it:
🦕 Deno
Import @lou.codes/utils
using the npm:
prefix, and use it directly:
🌎 Browser
Import @lou.codes/utils
using esm.sh, and use it directly:
Useful links
- 📝 Documentation: TypeDoc generated documentation.
- ⏳ Changelog: List of changes between versions.
- ✅ Tests Coverage: Coveralls page with tests coverage.
Classes
bind()
Bounds the given context to the given method.
Type parameters
Type parameter |
---|
Context |
Parameters
Parameter | Type |
---|---|
context | Context |
Returns
Function
Curried function with context
in context.
Type parameters
Type parameter |
---|
Method extends Function |
Parameters
Parameter | Type |
---|---|
method | Method |
Returns
Method
Example
construct()
Creates a new instance of the given constructor with the given arguments. This also binds all functions to the instance.
Type parameters
Type parameter |
---|
Constructor extends Class <never > |
Parameters
Parameter | Type |
---|---|
constructor | Constructor |
Returns
Function
Curried function with constructor
in context.
Parameters
Parameter | Type |
---|---|
…constructorArguments | ConstructorParameters <Constructor > |
Returns
Unbound
<InstanceType
<Constructor
>>
Example
constructArray()
constructArray(length)
Functional alias for new Array()
.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type |
---|---|
length | number |
Returns
object
Member | Type | Description |
---|---|---|
[unscopables] | object | Is an object whose properties have the value ‘true’ when they will be absent when used in a ‘with’ statement. |
[unscopables].[unscopables] | boolean | Is an object whose properties have the value ‘true’ when they will be absent when used in a ‘with’ statement. |
[unscopables].length | boolean | Gets the length of the array. This is a number one higher than the highest element defined in an array. |
[unscopables].[iterator] | - | |
[unscopables].at | - | |
[unscopables].concat | - | |
[unscopables].entries | - | |
[unscopables].every | - | |
[unscopables].filter | - | |
[unscopables].find | - | |
[unscopables].findIndex | - | |
[unscopables].findLast | - | |
[unscopables].findLastIndex | - | |
[unscopables].flat | - | |
[unscopables].flatMap | - | |
[unscopables].forEach | - | |
[unscopables].includes | - | |
[unscopables].indexOf | - | |
[unscopables].join | - | |
[unscopables].keys | - | |
[unscopables].lastIndexOf | - | |
[unscopables].map | - | |
[unscopables].reduce | - | |
[unscopables].reduceRight | - | |
[unscopables].slice | - | |
[unscopables].some | - | |
[unscopables].toLocaleString | - | |
[unscopables].toReversed | - | |
[unscopables].toSorted | - | |
[unscopables].toSpliced | - | |
[unscopables].toString | - | |
[unscopables].values | - | |
[unscopables].with | - | |
length | number | Gets the length of the array. This is a number one higher than the highest element defined in an array. |
[iterator] | IterableIterator <Item > | - |
at | undefined | Item | - |
concat | Item [] | - |
entries | IterableIterator <[number , Item ]> | - |
every | boolean | - |
filter | Item [] | - |
find | undefined | Item | - |
findIndex | number | - |
findLast | undefined | Item | - |
findLastIndex | number | - |
flat | unknown [] | - |
flatMap | unknown [] | - |
forEach | void | - |
includes | boolean | - |
indexOf | number | - |
join | string | - |
keys | IterableIterator <number > | - |
lastIndexOf | number | - |
map | unknown [] | - |
reduce | unknown | - |
reduceRight | unknown | - |
slice | Item [] | - |
some | boolean | - |
toLocaleString | string | - |
toReversed | Item [] | - |
toSorted | Item [] | - |
toSpliced | Item [] | - |
toString | string | - |
values | IterableIterator <Item > | - |
with | Item [] | - |
constructArray(items)
Functional alias for new Array()
.
Type parameters
Type parameter |
---|
Items extends ReadOnlyArray |
Parameters
Parameter | Type |
---|---|
…items | Items |
Returns
object
Member | Type | Description |
---|---|---|
[unscopables] | object | Is an object whose properties have the value ‘true’ when they will be absent when used in a ‘with’ statement. |
[unscopables].[unscopables] | boolean | Is an object whose properties have the value ‘true’ when they will be absent when used in a ‘with’ statement. |
[unscopables].length | boolean | Gets the length of the array. This is a number one higher than the highest element defined in an array. |
[unscopables].[iterator] | - | |
[unscopables].at | - | |
[unscopables].concat | - | |
[unscopables].entries | - | |
[unscopables].every | - | |
[unscopables].filter | - | |
[unscopables].find | - | |
[unscopables].findIndex | - | |
[unscopables].findLast | - | |
[unscopables].findLastIndex | - | |
[unscopables].flat | - | |
[unscopables].flatMap | - | |
[unscopables].forEach | - | |
[unscopables].includes | - | |
[unscopables].indexOf | - | |
[unscopables].join | - | |
[unscopables].keys | - | |
[unscopables].lastIndexOf | - | |
[unscopables].map | - | |
[unscopables].reduce | - | |
[unscopables].reduceRight | - | |
[unscopables].slice | - | |
[unscopables].some | - | |
[unscopables].toLocaleString | - | |
[unscopables].toReversed | - | |
[unscopables].toSorted | - | |
[unscopables].toSpliced | - | |
[unscopables].toString | - | |
[unscopables].values | - | |
[unscopables].with | - | |
length | number | Gets the length of the array. This is a number one higher than the highest element defined in an array. |
[iterator] | IterableIterator <Items [number ]> | - |
at | undefined | Items [number ] | - |
concat | Items [number ][] | - |
entries | IterableIterator <[number , Items [number ]]> | - |
every | boolean | - |
filter | Items [number ][] | - |
find | undefined | Items [number ] | - |
findIndex | number | - |
findLast | undefined | Items [number ] | - |
findLastIndex | number | - |
flat | unknown [] | - |
flatMap | unknown [] | - |
forEach | void | - |
includes | boolean | - |
indexOf | number | - |
join | string | - |
keys | IterableIterator <number > | - |
lastIndexOf | number | - |
map | unknown [] | - |
reduce | unknown | - |
reduceRight | unknown | - |
slice | Items [number ][] | - |
some | boolean | - |
toLocaleString | string | - |
toReversed | Items [number ][] | - |
toSorted | Items [number ][] | - |
toSpliced | Items [number ][] | - |
toString | string | - |
values | IterableIterator <Items [number ]> | - |
with | Items [number ][] | - |
constructDataView()
Functional alias for new DataView()
.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [ArrayBufferLike & object , number , number ] |
Returns
object
Member | Type |
---|---|
[toStringTag] | string |
buffer | ArrayBuffer |
byteLength | number |
byteOffset | number |
getBigInt64 | bigint |
getBigUint64 | bigint |
getFloat32 | number |
getFloat64 | number |
getInt16 | number |
getInt32 | number |
getInt8 | number |
getUint16 | number |
getUint32 | number |
getUint8 | number |
setBigInt64 | void |
setBigUint64 | void |
setFloat32 | void |
setFloat64 | void |
setInt16 | void |
setInt32 | void |
setInt8 | void |
setUint16 | void |
setUint32 | void |
setUint8 | void |
constructDate()
Functional alias for new Date()
.
Parameters
Parameter | Type |
---|---|
date ? | string | number | Readonly <Date > |
Returns
object
Member | Type |
---|---|
getVarDate | (this : void , …methodArguments : []) => VarDate |
[toPrimitive] | string | number |
getDate | number |
getDay | number |
getFullYear | number |
getHours | number |
getMilliseconds | number |
getMinutes | number |
getMonth | number |
getSeconds | number |
getTime | number |
getTimezoneOffset | number |
getUTCDate | number |
getUTCDay | number |
getUTCFullYear | number |
getUTCHours | number |
getUTCMilliseconds | number |
getUTCMinutes | number |
getUTCMonth | number |
getUTCSeconds | number |
setDate | number |
setFullYear | number |
setHours | number |
setMilliseconds | number |
setMinutes | number |
setMonth | number |
setSeconds | number |
setTime | number |
setUTCDate | number |
setUTCFullYear | number |
setUTCHours | number |
setUTCMilliseconds | number |
setUTCMinutes | number |
setUTCMonth | number |
setUTCSeconds | number |
toDateString | string |
toISOString | string |
toJSON | string |
toLocaleDateString | string |
toLocaleString | string |
toLocaleTimeString | string |
toString | string |
toTimeString | string |
toUTCString | string |
valueOf | number |
constructError()
Functional alias for new Error()
.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [string , ErrorOptions ] |
Returns
object
Member | Type |
---|---|
cause | unknown |
message | string |
name | string |
stack | string |
constructIntlCollator()
Functional alias for new Intl.Collator()
, which enables language-sensitive
string comparison.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [LocalesArgument , CollatorOptions ] |
Returns
object
Member | Type |
---|---|
compare | number |
resolvedOptions | ResolvedCollatorOptions |
See
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator
constructIntlDateTimeFormat()
Functional alias for new Intl.DateTimeFormat()
, which enables
language-sensitive date and time formatting.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [LocalesArgument , DateTimeFormatOptions ] |
Returns
object
Member | Type |
---|---|
format | string |
formatRange | string |
formatRangeToParts | DateTimeRangeFormatPart [] |
formatToParts | DateTimeFormatPart [] |
resolvedOptions | ResolvedDateTimeFormatOptions |
See
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
constructIntlLocale()
Functional alias for new Intl.Locale()
, which represents a Unicode locale
identifier.
Parameters
Parameter | Type |
---|---|
tag | Readonly <Locale | LocaleIdentifier > |
options ? | Readonly <LocaleOptions > |
Returns
object
Member | Type | Description |
---|---|---|
baseName | string | A string containing the language, and the script and region if available. |
calendar | string | The part of the Locale that indicates the locale’s calendar era. |
caseFirst | LocaleCollationCaseFirst | Flag that defines whether case is taken into account for the locale’s collation rules. |
collation | string | The collation type used for sorting |
hourCycle | LocaleHourCycleKey | The time keeping format convention used by the locale. |
language | string | The primary language subtag associated with the locale. |
numberingSystem | string | The numeral system used by the locale. |
numeric | boolean | Flag that defines whether the locale has special collation handling for numeric characters. |
region | string | The region of the world (usually a country) associated with the locale. Possible values are region codes as defined by ISO 3166-1. |
script | string | The script used for writing the particular language used in the locale. Possible values are script codes as defined by ISO 15924. |
maximize | Locale | - |
minimize | Locale | - |
toString | string | - |
See
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale
constructIntlNumberFormat()
Functional alias for new Intl.NumberFormat()
, which enables language-sensitive
number formatting.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [LocalesArgument , NumberFormatOptions ] |
Returns
object
Member | Type |
---|---|
format | string |
formatRange | string |
formatRangeToParts | NumberRangeFormatPart [] |
formatToParts | NumberFormatPart [] |
resolvedOptions | ResolvedNumberFormatOptions |
See
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
constructIntlPluralRules()
Functional alias for new Intl.PluralRules()
, which enables plural-sensitive
formatting and plural-related language rules.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [LocalesArgument , PluralRulesOptions ] |
Returns
object
Member | Type |
---|---|
resolvedOptions | ResolvedPluralRulesOptions |
select | LDMLPluralRule |
See
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules
constructIntlRelativeTimeFormat()
Functional alias for new Intl.RelativeTimeFormat()
, which enables
language-sensitive relative time formatting.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [LocalesArgument , RelativeTimeFormatOptions ] |
Returns
object
Member | Type |
---|---|
format | string |
formatToParts | RelativeTimeFormatPart [] |
resolvedOptions | ResolvedRelativeTimeFormatOptions |
See
constructMap()
Functional alias for new Map()
.
Type parameters
Type parameter |
---|
Key |
Value |
Parameters
Parameter | Type |
---|---|
iterable ? | Iterable <readonly [Key , Value ]> |
Returns
object
Member | Type | Description |
---|---|---|
[toStringTag] | string | - |
size | number | |
[iterator] | IterableIterator <[Key , Value ]> | - |
clear | void | - |
delete | boolean | - |
entries | IterableIterator <[Key , Value ]> | - |
forEach | void | - |
get | undefined | Value | - |
has | boolean | - |
keys | IterableIterator <Key > | - |
set | Map <Key , Value > | - |
values | IterableIterator <Value > | - |
constructPromise()
Functional alias for new Promise()
.
Type parameters
Type parameter |
---|
Value |
Parameters
Parameter | Type |
---|---|
executor | (resolve : (value : Value ) => void , reject : (reason ?: unknown ) => void ) => void |
Returns
object
Member | Type | Description |
---|---|---|
catch | <RejectedValue >(this : void , onrejected ?: Unary <unknown , RejectedValue | PromiseLike <RejectedValue >>) => Promise <Value | RejectedValue > | See Promise#then |
then | <ResolvedValue , RejectedValue >(this : void , onResolved ?: Unary <Value , ResolvedValue | PromiseLike <ResolvedValue >>, onRejected ?: Unary <unknown , RejectedValue | PromiseLike <RejectedValue >>) => Promise <ResolvedValue | RejectedValue > | See Promise#then |
constructProxy()
Functional alias for new Proxy()
.
Type parameters
Type parameter |
---|
Target extends object |
Parameters
Parameter | Type |
---|---|
target | Target |
handler | ProxyHandler <Target > |
Returns
Unbound
<Target
>
constructRangeError()
Functional alias for new RangeError()
.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [string , ErrorOptions ] |
Returns
object
Member | Type |
---|---|
cause | unknown |
message | string |
name | string |
stack | string |
constructReferenceError()
Functional alias for new ReferenceError()
.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [string , ErrorOptions ] |
Returns
object
Member | Type |
---|---|
cause | unknown |
message | string |
name | string |
stack | string |
constructRegExp()
Functional alias for new RegExp()
.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [string | RegExp , string ] |
Returns
object
Member | Type | Description |
---|---|---|
dotAll | boolean | Returns a Boolean value indicating the state of the dotAll flag (s) used with a regular expression. Default is false. Read-only. |
flags | string | Returns a string indicating the flags of the regular expression in question. This field is read-only. The characters in this string are sequenced and concatenated in the following order: - “g” for global - “i” for ignoreCase - “m” for multiline - “u” for unicode - “y” for sticky If no flags are set, the value is the empty string. |
global | boolean | Returns a Boolean value indicating the state of the global flag (g) used with a regular expression. Default is false. Read-only. |
hasIndices | boolean | Returns a Boolean value indicating the state of the hasIndices flag (d) used with with a regular expression. Default is false. Read-only. |
ignoreCase | boolean | Returns a Boolean value indicating the state of the ignoreCase flag (i) used with a regular expression. Default is false. Read-only. |
lastIndex | number | - |
multiline | boolean | Returns a Boolean value indicating the state of the multiline flag (m) used with a regular expression. Default is false. Read-only. |
source | string | Returns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal. |
sticky | boolean | Returns a Boolean value indicating the state of the sticky flag (y) used with a regular expression. Default is false. Read-only. |
unicode | boolean | Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular expression. Default is false. Read-only. |
[matchAll] | IterableIterator <RegExpMatchArray > | - |
[match] | null | RegExpMatchArray | - |
[replace] | string | - |
[search] | number | - |
[split] | string [] | - |
compile | RegExp | - |
exec | null | RegExpExecArray | - |
test | boolean | - |
constructSet()
Functional alias for new Set()
.
Type parameters
Type parameter |
---|
Value |
Parameters
Parameter | Type |
---|---|
iterable ? | Iterable <Value > |
Returns
object
Member | Type | Description |
---|---|---|
[toStringTag] | string | - |
size | number | |
[iterator] | IterableIterator <Value > | - |
add | Set <Value > | - |
clear | void | - |
delete | boolean | - |
entries | IterableIterator <[Value , Value ]> | - |
forEach | void | - |
has | boolean | - |
keys | IterableIterator <Value > | - |
values | IterableIterator <Value > | - |
constructSyntaxError()
Functional alias for new SyntaxError()
.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [string , ErrorOptions ] |
Returns
object
Member | Type |
---|---|
cause | unknown |
message | string |
name | string |
stack | string |
constructTextEncoder()
Functional alias for new TextEncoder()
.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [] |
Returns
object
Member | Type | Description |
---|---|---|
encoding | string | Returns “utf-8”. MDN Reference |
encode | Uint8Array | - |
encodeInto | TextEncoderEncodeIntoResult | - |
constructTypeError()
Functional alias for new TypeError()
.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [string , ErrorOptions ] |
Returns
object
Member | Type |
---|---|
cause | unknown |
message | string |
name | string |
stack | string |
constructURIError()
Functional alias for new URIError()
.
Parameters
Parameter | Type |
---|---|
…constructorArguments | [string , ErrorOptions ] |
Returns
object
Member | Type |
---|---|
cause | unknown |
message | string |
name | string |
stack | string |
constructWeakMap()
Functional alias for new WeakMap()
.
Type parameters
Type parameter |
---|
Key extends object |
Value |
Parameters
Parameter | Type |
---|---|
iterable ? | Iterable <readonly [Key , Value ]> |
Returns
object
Member | Type |
---|---|
[toStringTag] | string |
delete | boolean |
get | undefined | Value |
has | boolean |
set | WeakMap <Key , Value > |
constructWeakSet()
Functional alias for new WeakSet()
.
Type parameters
Type parameter |
---|
Value extends object |
Parameters
Parameter | Type |
---|---|
iterable ? | Iterable <Value > |
Returns
object
Member | Type |
---|---|
[toStringTag] | string |
add | WeakSet <Value > |
delete | boolean |
has | boolean |
Common
toString()
Parses given value to string.
Type parameters
Type parameter |
---|
Input extends Strigifiable | object |
Parameters
Parameter | Type |
---|---|
input | Input |
Returns
Input
extends Strigifiable
? `${Input<Input>}` : Input
extends
object
? ReturnType
<Input
<Input
>["toString"
]> : string
stringified value.
Example
Conditions
when()
Curried conditional (like a functional ternary).
Type parameters
Type parameter | Value |
---|---|
Value | - |
Predicated | never |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Single <Predicated > extends Single <never > ? Filter <Value > : Predicate <Value , Predicated > | Predicate to check value against. |
Returns
Function
Curried function with predicate
in context.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <Predicated & Value , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | Value extends Predicated ? Value <Value > : Predicated |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | Value |
Returns
TrueOutput
| FalseOutput
Example
whenFalsy()
Like when
, but when is falsy the value is returned as is.
Type parameters
Type parameter | Value |
---|---|
Value | - |
Predicated | never |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Single <Predicated > extends Single <never > ? Filter <Value > : Predicate <Value , Predicated > | Predicate to check value against. |
Returns
Function
Curried function with predicate
in context.
Type parameters
Type parameter | Value |
---|---|
FalseInput | Value extends Predicated ? Value <Value > : Predicated |
FalseOutput | Predicated & Value |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | Value |
Returns
Predicated
& Value
| FalseOutput
Example
whenIsArray()
Conditional handler for when something is an Array
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <ReadOnlyArray <unknown >, TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | ReadOnlyArray <unknown > |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsAsyncIterable()
Conditional handler for when something is an AsyncIterable
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <Readonly <AsyncIterable <unknown >>, TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | Readonly <AsyncIterable <unknown >> |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsBigInt()
Conditional handler for when something is a BigInt
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <bigint , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | bigint |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsBoolean()
Conditional handler for when something is a Boolean
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <boolean , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | boolean |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsDate()
Conditional handler for when something is a Date
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <Date , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | Date |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsFalsy()
Conditional handler for when something is a Falsy
value.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <Falsy , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | Falsy |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsFunction()
Conditional handler for when something is a Function
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <Function , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | Function |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsIsomorphicIterable()
Conditional handler for when something is an AsynchronousIterable
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <IsomorphicIterable <unknown >, TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | IsomorphicIterable <unknown > |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsIterable()
Conditional handler for when something is an Iterable
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <Readonly <Iterable <unknown >>, TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | Readonly <Iterable <unknown >> |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsNull()
Conditional handler for when something is null
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <null , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | null |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsNullish()
Conditional handler for when something is a Nullish
value.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <Nullish , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | Nullish |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsNumber()
Conditional handler for when something is a Number
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <number , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | number |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsObject()
Conditional handler for when something is an Object
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <object , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | object |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsPromise()
Conditional handler for when something is a Promise
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <Promise <unknown >, TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | Promise <unknown > |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsPropertyKey()
Conditional handler for when something is a PropertyKey
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <PropertyKey , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | PropertyKey |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsPrototypeOfObject()
Conditional handler for when something has an Object
prototype.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <never , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | never |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | object |
Returns
TrueOutput
| FalseOutput
whenIsRegExp()
Conditional handler for when something is a RegExp
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <RegExp , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | RegExp |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsSafeInteger()
Conditional handler for when a number is a SafeInteger
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <never , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | never |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | number |
Returns
TrueOutput
| FalseOutput
whenIsString()
Conditional handler for when something is a String
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <string , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | string |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsSymbol()
Conditional handler for when something is a Symbol
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <symbol , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | symbol |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsTruthy()
Conditional handler for when something is a Truthy
value.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <Readonly <unknown >, TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | Readonly <unknown > |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenIsUndefined()
Conditional handler for when something is undefined
.
Type parameters
Type parameter |
---|
TrueOutput |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <undefined , TrueOutput > |
Returns
Function
Type parameters
Type parameter | Value |
---|---|
FalseInput | undefined |
FalseOutput | TrueOutput |
Parameters
Parameter | Type |
---|---|
falsyHandler | Unary <FalseInput , FalseOutput > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
TrueOutput
| FalseOutput
whenTruthy()
Like when
, but when is falsy the value is returned as is.
Type parameters
Type parameter | Value |
---|---|
Value | - |
Predicated | never |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Single <Predicated > extends Single <never > ? Filter <Value > : Predicate <Value , Predicated > | Predicate to check value against. |
Returns
Function
Curried function with predicate
in context.
Type parameters
Type parameter |
---|
Output |
Parameters
Parameter | Type |
---|---|
truthyHandler | Unary <Predicated & Value , Output > |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | Value |
Returns
Value
| Output
Example
Functions
always()
Returns a function that always returns the same value.
Type parameters
Type parameter |
---|
Input |
Parameters
Parameter | Type |
---|---|
input | Input |
Returns
Function
Function that always return the given value.
Returns
Input
Example
applyTo()
Takes a value and applies a function to it.
Type parameters
Type parameter |
---|
Input |
Parameters
Parameter | Type |
---|---|
input | Input |
Returns
Function
Function that expects a function that will receive the input
.
Type parameters
Type parameter |
---|
Output |
Parameters
Parameter | Type |
---|---|
unary | Unary <Input , Output > |
Returns
Output
Example
entryKey()
Get key of an Entry
.
Type parameters
Type parameter |
---|
InputEntry extends Entry |
Parameters
Parameter | Type | Description |
---|---|---|
entry | InputEntry | Entry to get key from. |
Returns
EntryKey
<InputEntry
>
Key of an Entry
.
Example
entryValue()
Get value of an Entry
.
Type parameters
Type parameter |
---|
InputEntry extends Entry |
Parameters
Parameter | Type | Description |
---|---|---|
entry | InputEntry | Entry to get vale from. |
Returns
EntryValue
<InputEntry
>
Value of an Entry
.
Example
flip()
Flips arguments of a curried function.
Type parameters
Type parameter |
---|
UnaryToFlip extends Unary <never , Unary <never , unknown >> |
Parameters
Parameter | Type |
---|---|
unary | UnaryToFlip |
Returns
Function
Curried function with unary
in context.
Parameters
Parameter | Type |
---|---|
…secondArgument | Parameters <UnaryOutput <UnaryToFlip >> |
Returns
Function
Parameters
Parameter | Type |
---|---|
…firstArgument | Parameters <UnaryToFlip > |
Returns
UnaryOutput
<UnaryOutput
<UnaryToFlip
>>
Example
identity()
Identity function.
Type parameters
Type parameter |
---|
Input |
Parameters
Parameter | Type |
---|---|
input | Input |
Returns
Input
Same value given.
Example
memoize()
Memoize function return values for expensive operations.
Type parameters
Type parameter |
---|
MemoizedFunction extends Unary <never , unknown > |
Parameters
Parameter | Type | Description |
---|---|---|
unary | MemoizedFunction | Function to memoize. |
Returns
MemoizedFunction
Curried function with unary
in context.
Example
negate()
Takes a function and returns a copy with negated output.
Type parameters
Type parameter | Value |
---|---|
Item | - |
Predicated | never |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Single <Predicated > extends Single <never > ? Filter <Item > : Predicate <Item , Predicated > | Function to be negated. |
Returns
Single
<Predicated
> extends Single
<never
> ? Unary
<Item
,
boolean
> : Predicate
<Item
, Exclude
<Item
, Predicated
>>
Source function with negated output.
Example
once()
Runs a function once, and after that returns always the same value.
Type parameters
Type parameter |
---|
OnceFunction extends Unary <never , unknown > |
Parameters
Parameter | Type | Description |
---|---|---|
unary | OnceFunction | Function to run once. |
Returns
Function
Curried function with unary
in context.
Parameters
Parameter | Type |
---|---|
value | UnaryInput <OnceFunction > |
Returns
UnaryOutput
<OnceFunction
> | UnaryOutput
<OnceFunction
>
Example
tap()
Tap into a value before calling a function.
Type parameters
Type parameter |
---|
Input |
Parameters
Parameter | Type | Description |
---|---|---|
tapper | Unary <Input , unknown > | Tapper function to be called with the value. |
Returns
Function
Curried function with tapper
in context.
Type parameters
Type parameter |
---|
Tapped extends Unary <Input , unknown > |
Parameters
Parameter | Type |
---|---|
tapped | Tapped |
Returns
Tapped
Example
thunk()
Delayed evaluation function.
Type parameters
Type parameter |
---|
Input |
Output |
Parameters
Parameter | Type |
---|---|
unary | Unary <Input , Output > |
Returns
Function
Function that will run the given function when called.
Parameters
Parameter | Type |
---|---|
input | Input |
Returns
Function
Returns
Output
Example
Numbers
cryptoNumber()
Generates number
using SubtleCrypto#digest
and the given seed.
⚠️ IMPORTANT: This only works in secure contexts (HTTPS/Node).
Parameters
Parameter | Type | Description |
---|---|---|
seed | string | Numeric | Seed to be used to generate random numbers. |
Returns
Promise
<number
>
Pseudo-random number from seed.
Example
See
Objects
awaitableHandler()
If the given value is a promise, the handler
is called when is resolved,
otherwise the handler is called directly with the value.
Type parameters
Type parameter |
---|
Value |
Output |
Parameters
Parameter | Type | Description |
---|---|---|
handler | (awaitable : Value ) => Output | Handler function to be called with the value. |
Returns
Function
Curried function with handler
in context.
Type parameters
Type parameter |
---|
AwaitableValue |
Parameters
Parameter | Type |
---|---|
awaitable | AwaitableValue |
Returns
AwaitableValue
extends Promise
<Value
> ? Promise
<Output
> :
Output
Example
get()
Get the value of a property in an object.
Type parameters
Type parameter |
---|
Key extends PropertyKey |
Parameters
Parameter | Type |
---|---|
key | Key |
Returns
Function
Curried function with key
in context.
Type parameters
Type parameter |
---|
Source extends Readonly <Record <Key , unknown >> |
Parameters
Parameter | Type |
---|---|
object | Source |
Returns
Source
[Key
& keyof Source
]
Example
intercept()
Function that takes a dictionary property -> getter
and uses said getter in
the matching property of the object by returning a proxy to it.
Type parameters
Type parameter |
---|
Interceptions extends Readonly <Record <PropertyKey , <ProxiedObject >(target : ProxiedObject ) => unknown >> |
Parameters
Parameter | Type | Description |
---|---|---|
interceptions | Interceptions | Dictionary property -> handler . |
Returns
Function
Curried function with interceptions
in context.
Type parameters
Type parameter |
---|
Target extends object |
Parameters
Parameter | Type |
---|---|
target | Target |
Returns
keyof Target
extends keyof Interceptions
? Omit
<Target
, keyof
Interceptions
> : Target
& { readonly [Property in string | number |
symbol]: ReturnType<Interceptions[Property]> }
Example
mutate()
Function to encapsulate object mutations.
⚠️ IMPORTANT: Try to avoid this util, use intercept instead.
Type parameters
Type parameter |
---|
Update extends object |
Parameters
Parameter | Type | Description |
---|---|---|
update | Update | Update to apply to given target. |
Returns
Function
Curried function with update
in context.
Type parameters
Type parameter |
---|
Target extends object |
Parameters
Parameter | Type |
---|---|
target | Target |
Returns
Target
& Update
Example
omit()
Omits given properties from an object.
Type parameters
Type parameter |
---|
Properties extends ReadOnlyArray <PropertyKey > |
Parameters
Parameter | Type | Description |
---|---|---|
…properties | Properties | Properties to omit. |
Returns
Function
Curried function with properties
in context.
Type parameters
Type parameter |
---|
Source extends Readonly <Record <PropertyKey , unknown >> |
Parameters
Parameter | Type |
---|---|
object | Source |
Returns
Omit
<Source
, Properties
[number
]>
Example
pick()
Picks given properties from an object.
Type parameters
Type parameter |
---|
Properties extends ReadOnlyArray <PropertyKey > |
Parameters
Parameter | Type | Description |
---|---|---|
…properties | Properties | Properties to pick. |
Returns
Function
Curried function with properties
in context.
Type parameters
Type parameter |
---|
Source extends Readonly <Record <PropertyKey , unknown >> |
Parameters
Parameter | Type |
---|---|
object | Source |
Returns
Pick
<Source
, Properties
[number
]>
Example
set()
Set the value of a property in an object (read only).
Type parameters
Type parameter |
---|
Key extends PropertyKey |
Parameters
Parameter | Type |
---|---|
key | Key |
Returns
Function
Curried function with key
in context.
Type parameters
Type parameter |
---|
Value |
Parameters
Parameter | Type |
---|---|
value | Value |
Returns
Function
Type parameters
Type parameter |
---|
Source extends object |
Parameters
Parameter | Type |
---|---|
object | Source |
Returns
Omit
<Source
, Key
> & Readonly
<Record
<Key
, Value
>>
Example
Promises
otherwise()
Sets a promise catch
handler.
Type parameters
Type parameter |
---|
Output |
Parameters
Parameter | Type |
---|---|
handler | Unary <unknown , Output | PromiseLike <Output >> |
Returns
Function
Curried function with handler
set in context.
Type parameters
Type parameter |
---|
PromisedValue |
Parameters
Parameter | Type |
---|---|
promise | Promise <PromisedValue > |
Returns
Promise
<Output
| PromisedValue
>
Example
then()
Sets a promise then
handler.
Type parameters
Type parameter |
---|
HandlerInput |
Output |
Parameters
Parameter | Type |
---|---|
handler | Unary <HandlerInput , Output | PromiseLike <Output >> |
Returns
Function
Curried function with handler
set in context.
Type parameters
Type parameter |
---|
PromiseInstance extends Promise <HandlerInput > |
Parameters
Parameter | Type |
---|---|
promise | PromiseInstance |
Returns
Promise
<Output
>