Skip to content

Utils Reference

Coverage License NPM Version Open Issues Size

⚒️ Lou’s TypeScript curried functional utils.

Usage

📦 Node

Install @lou.codes/utils as a dependency:

Terminal window
1
pnpm add @lou.codes/utils
2
# or
3
npm install @lou.codes/utils
4
# or
5
yarn add @lou.codes/utils

Import it and use it:

1
import { get } from "@lou.codes/utils";
2
3
get("foo")({ foo: "bar" }); // "bar"

🦕 Deno

Import @lou.codes/utils using the npm: prefix, and use it directly:

1
import { get } from "npm:@lou.codes/utils";
2
3
get("foo")({ foo: "bar" }); // "bar"

🌎 Browser

Import @lou.codes/utils using esm.sh, and use it directly:

1
<script type="module">
2
import { get } from "https://esm.sh/@lou.codes/utils";
3
4
get("foo")({ foo: "bar" }); // "bar"
5
</script>

Classes

bind

bind<Context>(context): <Method>(method: Method) => Method

Bounds the given context to the given method.

Type parameters

Name
Context

Parameters

NameType
contextContext

Returns

fn

Curried function with context in context.

▸ <Method>(method): Method

Type parameters
NameType
Methodextends Function
Parameters
NameType
methodMethod
Returns

Method

Example

1
const bindConsole = bind(console);
2
const log = bindConsole(console.log);
3
4
log("Hello world!"); // Logs "Hello world!" without context errors.

View source


construct

construct<Constructor>(constructor): (…constructorArguments: ConstructorParameters<Constructor>) => Unbound<InstanceType<Constructor>>

Creates a new instance of the given constructor with the given arguments. This also binds all functions to the instance.

Type parameters

NameType
Constructorextends Class<never>

Parameters

NameType
constructorConstructor

Returns

fn

Curried function with constructor in context.

▸ (...constructorArguments): Unbound<InstanceType<Constructor>>

Parameters
NameType
...constructorArgumentsConstructorParameters<Constructor>
Returns

Unbound<InstanceType<Constructor>>

Example

1
const constructDate = construct(Date);
2
const { getTime } = constructDate(); // Works because all methods are binded.

View source


constructArray

constructArray<Item>(length): Object

Functional alias for new Array().

Type parameters

Name
Item

Parameters

NameType
lengthnumber

Returns

Object

NameTypeDescription
[unscopables]{ [unscopables]?: boolean ; length?: boolean ; [iterator]?: { valueOf: () => boolean } ; at?: { valueOf: () => boolean } ; concat?: { valueOf: () => boolean } ; entries?: { valueOf: () => boolean } ; every?: { valueOf: () => boolean } ; filter?: { valueOf: () => boolean } ; find?: { valueOf: () => boolean } ; findIndex?: { valueOf: () => boolean } ; findLast?: { valueOf: () => boolean } ; findLastIndex?: { valueOf: () => boolean } ; flat?: { valueOf: () => boolean } ; flatMap?: { valueOf: () => boolean } ; forEach?: { valueOf: () => boolean } ; includes?: { valueOf: () => boolean } ; indexOf?: { valueOf: () => boolean } ; join?: { valueOf: () => boolean } ; keys?: { valueOf: () => boolean } ; lastIndexOf?: { valueOf: () => boolean } ; map?: { valueOf: () => boolean } ; reduce?: { valueOf: () => boolean } ; reduceRight?: { valueOf: () => boolean } ; slice?: { valueOf: () => boolean } ; some?: { valueOf: () => boolean } ; toLocaleString?: { valueOf: () => boolean } ; toReversed?: { valueOf: () => boolean } ; toSorted?: { valueOf: () => boolean } ; toSpliced?: { valueOf: () => boolean } ; toString?: { valueOf: () => boolean } ; values?: { valueOf: () => boolean } ; with?: { valueOf: () => boolean } }Is an object whose properties have the value ‘true’ when they will be absent when used in a ‘with’ statement.
[unscopables].[unscopables] (optional)booleanIs an object whose properties have the value ‘true’ when they will be absent when used in a ‘with’ statement.
[unscopables].length (optional)booleanGets the length of the array. This is a number one higher than the highest element defined in an array.
[unscopables].[iterator] (optional)[object Object]-
[unscopables].at (optional)[object Object]-
[unscopables].concat (optional)[object Object]-
[unscopables].entries (optional)[object Object]-
[unscopables].every (optional)[object Object]-
[unscopables].filter (optional)[object Object]-
[unscopables].find (optional)[object Object]-
[unscopables].findIndex (optional)[object Object]-
[unscopables].findLast (optional)[object Object]-
[unscopables].findLastIndex (optional)[object Object]-
[unscopables].flat (optional)[object Object]-
[unscopables].flatMap (optional)[object Object]-
[unscopables].forEach (optional)[object Object]-
[unscopables].includes (optional)[object Object]-
[unscopables].indexOf (optional)[object Object]-
[unscopables].join (optional)[object Object]-
[unscopables].keys (optional)[object Object]-
[unscopables].lastIndexOf (optional)[object Object]-
[unscopables].map (optional)[object Object]-
[unscopables].reduce (optional)[object Object]-
[unscopables].reduceRight (optional)[object Object]-
[unscopables].slice (optional)[object Object]-
[unscopables].some (optional)[object Object]-
[unscopables].toLocaleString (optional)[object Object]-
[unscopables].toReversed (optional)[object Object]-
[unscopables].toSorted (optional)[object Object]-
[unscopables].toSpliced (optional)[object Object]-
[unscopables].toString (optional)[object Object]-
[unscopables].values (optional)[object Object]-
[unscopables].with (optional)[object Object]-
lengthnumberGets the length of the array. This is a number one higher than the highest element defined in an array.
[iterator](this: void, …methodArguments: []) => IterableIterator<Item>-
at(this: void, …methodArguments: [index: number]) => undefined | Item-
concat(this: void, …methodArguments: (Item | ConcatArray<Item>)[]) => Item[]-
entries(this: void, …methodArguments: []) => IterableIterator<[number, Item]>-
every(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => boolean-
filter(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => Item[]-
find(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => undefined | Item-
findIndex(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => number-
findLast(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => undefined | Item-
findLastIndex(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => number-
flat(this: void, …methodArguments: [depth?: number]) => unknown[]-
flatMap(this: void, …methodArguments: [callback: Function, thisArg?: unknown]) => unknown[]-
forEach(this: void, …methodArguments: [callbackfn: Function, thisArg?: any]) => void-
includes(this: void, …methodArguments: [searchElement: Item, fromIndex?: number]) => boolean-
indexOf(this: void, …methodArguments: [searchElement: Item, fromIndex?: number]) => number-
join(this: void, …methodArguments: [separator?: string]) => string-
keys(this: void, …methodArguments: []) => IterableIterator<number>-
lastIndexOf(this: void, …methodArguments: [searchElement: Item, fromIndex?: number]) => number-
map(this: void, …methodArguments: [callbackfn: Function, thisArg?: any]) => unknown[]-
reduce(this: void, …methodArguments: [callbackfn: Function, initialValue: unknown]) => unknown-
reduceRight(this: void, …methodArguments: [callbackfn: Function, initialValue: unknown]) => unknown-
slice(this: void, …methodArguments: [start?: number, end?: number]) => Item[]-
some(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => boolean-
toLocaleString(this: void, …methodArguments: []) => string-
toReversed(this: void, …methodArguments: []) => Item[]-
toSorted(this: void, …methodArguments: [compareFn?: Function]) => Item[]-
toSpliced(this: void, …methodArguments: [start: number, deleteCount?: number]) => Item[]-
toString(this: void, …methodArguments: []) => string-
values(this: void, …methodArguments: []) => IterableIterator<Item>-
with(this: void, …methodArguments: [index: number, value: Item]) => Item[]-

View source

constructArray<Items>(...items): Object

Functional alias for new Array().

Type parameters

NameType
Itemsextends ReadOnlyArray

Parameters

NameType
...itemsItems

Returns

Object

NameTypeDescription
[unscopables]{ [unscopables]?: boolean ; length?: boolean ; [iterator]?: { valueOf: () => boolean } ; at?: { valueOf: () => boolean } ; concat?: { valueOf: () => boolean } ; entries?: { valueOf: () => boolean } ; every?: { valueOf: () => boolean } ; filter?: { valueOf: () => boolean } ; find?: { valueOf: () => boolean } ; findIndex?: { valueOf: () => boolean } ; findLast?: { valueOf: () => boolean } ; findLastIndex?: { valueOf: () => boolean } ; flat?: { valueOf: () => boolean } ; flatMap?: { valueOf: () => boolean } ; forEach?: { valueOf: () => boolean } ; includes?: { valueOf: () => boolean } ; indexOf?: { valueOf: () => boolean } ; join?: { valueOf: () => boolean } ; keys?: { valueOf: () => boolean } ; lastIndexOf?: { valueOf: () => boolean } ; map?: { valueOf: () => boolean } ; reduce?: { valueOf: () => boolean } ; reduceRight?: { valueOf: () => boolean } ; slice?: { valueOf: () => boolean } ; some?: { valueOf: () => boolean } ; toLocaleString?: { valueOf: () => boolean } ; toReversed?: { valueOf: () => boolean } ; toSorted?: { valueOf: () => boolean } ; toSpliced?: { valueOf: () => boolean } ; toString?: { valueOf: () => boolean } ; values?: { valueOf: () => boolean } ; with?: { valueOf: () => boolean } }Is an object whose properties have the value ‘true’ when they will be absent when used in a ‘with’ statement.
[unscopables].[unscopables] (optional)booleanIs an object whose properties have the value ‘true’ when they will be absent when used in a ‘with’ statement.
[unscopables].length (optional)booleanGets the length of the array. This is a number one higher than the highest element defined in an array.
[unscopables].[iterator] (optional)[object Object]-
[unscopables].at (optional)[object Object]-
[unscopables].concat (optional)[object Object]-
[unscopables].entries (optional)[object Object]-
[unscopables].every (optional)[object Object]-
[unscopables].filter (optional)[object Object]-
[unscopables].find (optional)[object Object]-
[unscopables].findIndex (optional)[object Object]-
[unscopables].findLast (optional)[object Object]-
[unscopables].findLastIndex (optional)[object Object]-
[unscopables].flat (optional)[object Object]-
[unscopables].flatMap (optional)[object Object]-
[unscopables].forEach (optional)[object Object]-
[unscopables].includes (optional)[object Object]-
[unscopables].indexOf (optional)[object Object]-
[unscopables].join (optional)[object Object]-
[unscopables].keys (optional)[object Object]-
[unscopables].lastIndexOf (optional)[object Object]-
[unscopables].map (optional)[object Object]-
[unscopables].reduce (optional)[object Object]-
[unscopables].reduceRight (optional)[object Object]-
[unscopables].slice (optional)[object Object]-
[unscopables].some (optional)[object Object]-
[unscopables].toLocaleString (optional)[object Object]-
[unscopables].toReversed (optional)[object Object]-
[unscopables].toSorted (optional)[object Object]-
[unscopables].toSpliced (optional)[object Object]-
[unscopables].toString (optional)[object Object]-
[unscopables].values (optional)[object Object]-
[unscopables].with (optional)[object Object]-
lengthnumberGets the length of the array. This is a number one higher than the highest element defined in an array.
[iterator](this: void, …methodArguments: []) => IterableIterator<Items[number]>-
at(this: void, …methodArguments: [index: number]) => undefined | Items[number]-
concat(this: void, …methodArguments: (Items[number] | ConcatArray<Items[number]>)[]) => Items[number][]-
entries(this: void, …methodArguments: []) => IterableIterator<[number, Items[number]]>-
every(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => boolean-
filter(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => Items[number][]-
find(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => undefined | Items[number]-
findIndex(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => number-
findLast(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => undefined | Items[number]-
findLastIndex(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => number-
flat(this: void, …methodArguments: [depth?: number]) => unknown[]-
flatMap(this: void, …methodArguments: [callback: Function, thisArg?: unknown]) => unknown[]-
forEach(this: void, …methodArguments: [callbackfn: Function, thisArg?: any]) => void-
includes(this: void, …methodArguments: [searchElement: Items[number], fromIndex?: number]) => boolean-
indexOf(this: void, …methodArguments: [searchElement: Items[number], fromIndex?: number]) => number-
join(this: void, …methodArguments: [separator?: string]) => string-
keys(this: void, …methodArguments: []) => IterableIterator<number>-
lastIndexOf(this: void, …methodArguments: [searchElement: Items[number], fromIndex?: number]) => number-
map(this: void, …methodArguments: [callbackfn: Function, thisArg?: any]) => unknown[]-
reduce(this: void, …methodArguments: [callbackfn: Function, initialValue: unknown]) => unknown-
reduceRight(this: void, …methodArguments: [callbackfn: Function, initialValue: unknown]) => unknown-
slice(this: void, …methodArguments: [start?: number, end?: number]) => Items[number][]-
some(this: void, …methodArguments: [predicate: Function, thisArg?: any]) => boolean-
toLocaleString(this: void, …methodArguments: []) => string-
toReversed(this: void, …methodArguments: []) => Items[number][]-
toSorted(this: void, …methodArguments: [compareFn?: Function]) => Items[number][]-
toSpliced(this: void, …methodArguments: [start: number, deleteCount?: number]) => Items[number][]-
toString(this: void, …methodArguments: []) => string-
values(this: void, …methodArguments: []) => IterableIterator<Items[number]>-
with(this: void, …methodArguments: [index: number, value: Items[number]]) => Items[number][]-

View source


constructDataView

constructDataView(...constructorArguments): Object

Functional alias for new DataView().

Parameters

NameType
...constructorArguments[buffer: ArrayBufferLike & Object, byteOffset?: number, byteLength?: number]

Returns

Object

NameType
[toStringTag]string
bufferArrayBuffer
byteLengthnumber
byteOffsetnumber
getBigInt64(this: void, …methodArguments: [byteOffset: number, littleEndian?: boolean]) => bigint
getBigUint64(this: void, …methodArguments: [byteOffset: number, littleEndian?: boolean]) => bigint
getFloat32(this: void, …methodArguments: [byteOffset: number, littleEndian?: boolean]) => number
getFloat64(this: void, …methodArguments: [byteOffset: number, littleEndian?: boolean]) => number
getInt16(this: void, …methodArguments: [byteOffset: number, littleEndian?: boolean]) => number
getInt32(this: void, …methodArguments: [byteOffset: number, littleEndian?: boolean]) => number
getInt8(this: void, …methodArguments: [byteOffset: number]) => number
getUint16(this: void, …methodArguments: [byteOffset: number, littleEndian?: boolean]) => number
getUint32(this: void, …methodArguments: [byteOffset: number, littleEndian?: boolean]) => number
getUint8(this: void, …methodArguments: [byteOffset: number]) => number
setBigInt64(this: void, …methodArguments: [byteOffset: number, value: bigint, littleEndian?: boolean]) => void
setBigUint64(this: void, …methodArguments: [byteOffset: number, value: bigint, littleEndian?: boolean]) => void
setFloat32(this: void, …methodArguments: [byteOffset: number, value: number, littleEndian?: boolean]) => void
setFloat64(this: void, …methodArguments: [byteOffset: number, value: number, littleEndian?: boolean]) => void
setInt16(this: void, …methodArguments: [byteOffset: number, value: number, littleEndian?: boolean]) => void
setInt32(this: void, …methodArguments: [byteOffset: number, value: number, littleEndian?: boolean]) => void
setInt8(this: void, …methodArguments: [byteOffset: number, value: number]) => void
setUint16(this: void, …methodArguments: [byteOffset: number, value: number, littleEndian?: boolean]) => void
setUint32(this: void, …methodArguments: [byteOffset: number, value: number, littleEndian?: boolean]) => void
setUint8(this: void, …methodArguments: [byteOffset: number, value: number]) => void

View source


constructDate

constructDate(date?): Object

Functional alias for new Date().

Parameters

NameType
date (optional)string | number | Readonly<Date>

Returns

Object

NameType
getVarDate(this: void, …methodArguments: []) => VarDate
[toPrimitive](this: void, …methodArguments: [hint: string]) => string | number
getDate(this: void, …methodArguments: []) => number
getDay(this: void, …methodArguments: []) => number
getFullYear(this: void, …methodArguments: []) => number
getHours(this: void, …methodArguments: []) => number
getMilliseconds(this: void, …methodArguments: []) => number
getMinutes(this: void, …methodArguments: []) => number
getMonth(this: void, …methodArguments: []) => number
getSeconds(this: void, …methodArguments: []) => number
getTime(this: void, …methodArguments: []) => number
getTimezoneOffset(this: void, …methodArguments: []) => number
getUTCDate(this: void, …methodArguments: []) => number
getUTCDay(this: void, …methodArguments: []) => number
getUTCFullYear(this: void, …methodArguments: []) => number
getUTCHours(this: void, …methodArguments: []) => number
getUTCMilliseconds(this: void, …methodArguments: []) => number
getUTCMinutes(this: void, …methodArguments: []) => number
getUTCMonth(this: void, …methodArguments: []) => number
getUTCSeconds(this: void, …methodArguments: []) => number
setDate(this: void, …methodArguments: [date: number]) => number
setFullYear(this: void, …methodArguments: [year: number, month?: number, date?: number]) => number
setHours(this: void, …methodArguments: [hours: number, min?: number, sec?: number, ms?: number]) => number
setMilliseconds(this: void, …methodArguments: [ms: number]) => number
setMinutes(this: void, …methodArguments: [min: number, sec?: number, ms?: number]) => number
setMonth(this: void, …methodArguments: [month: number, date?: number]) => number
setSeconds(this: void, …methodArguments: [sec: number, ms?: number]) => number
setTime(this: void, …methodArguments: [time: number]) => number
setUTCDate(this: void, …methodArguments: [date: number]) => number
setUTCFullYear(this: void, …methodArguments: [year: number, month?: number, date?: number]) => number
setUTCHours(this: void, …methodArguments: [hours: number, min?: number, sec?: number, ms?: number]) => number
setUTCMilliseconds(this: void, …methodArguments: [ms: number]) => number
setUTCMinutes(this: void, …methodArguments: [min: number, sec?: number, ms?: number]) => number
setUTCMonth(this: void, …methodArguments: [month: number, date?: number]) => number
setUTCSeconds(this: void, …methodArguments: [sec: number, ms?: number]) => number
toDateString(this: void, …methodArguments: []) => string
toISOString(this: void, …methodArguments: []) => string
toJSON(this: void, …methodArguments: [key?: any]) => string
toLocaleDateString(this: void, …methodArguments: [locales?: LocalesArgument, options?: DateTimeFormatOptions]) => string
toLocaleString(this: void, …methodArguments: [locales?: LocalesArgument, options?: DateTimeFormatOptions]) => string
toLocaleTimeString(this: void, …methodArguments: [locales?: LocalesArgument, options?: DateTimeFormatOptions]) => string
toString(this: void, …methodArguments: []) => string
toTimeString(this: void, …methodArguments: []) => string
toUTCString(this: void, …methodArguments: []) => string
valueOf(this: void, …methodArguments: []) => number

View source


constructError

constructError(...constructorArguments): Object

Functional alias for new Error().

Parameters

NameType
...constructorArguments[message?: string, options?: ErrorOptions]

Returns

Object

NameType
cause (optional)unknown
messagestring
namestring
stack (optional)string

View source


constructIntlCollator

constructIntlCollator(...constructorArguments): Object

Functional alias for new Intl.Collator(), which enables language-sensitive string comparison.

Parameters

NameType
...constructorArguments[locales?: LocalesArgument, options?: CollatorOptions]

Returns

Object

NameType
compare(this: void, …methodArguments: [x: string, y: string]) => number
resolvedOptions(this: void, …methodArguments: []) => ResolvedCollatorOptions

See

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator

View source


constructIntlDateTimeFormat

constructIntlDateTimeFormat(...constructorArguments): Object

Functional alias for new Intl.DateTimeFormat(), which enables language-sensitive date and time formatting.

Parameters

NameType
...constructorArguments[locales?: LocalesArgument, options?: DateTimeFormatOptions]

Returns

Object

NameType
format(this: void, …methodArguments: [date?: number | Date]) => string
formatRange(this: void, …methodArguments: [startDate: number | bigint | Date, endDate: number | bigint | Date]) => string
formatRangeToParts(this: void, …methodArguments: [startDate: number | bigint | Date, endDate: number | bigint | Date]) => DateTimeRangeFormatPart[]
formatToParts(this: void, …methodArguments: [date?: number | Date]) => DateTimeFormatPart[]
resolvedOptions(this: void, …methodArguments: []) => ResolvedDateTimeFormatOptions

See

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat

View source


constructIntlLocale

constructIntlLocale(tag, options?): Object

Functional alias for new Intl.Locale(), which represents a Unicode locale identifier.

Parameters

NameType
tagReadonly<Locale | LocaleIdentifier>
options (optional)Readonly<LocaleOptions>

Returns

Object

NameTypeDescription
baseNamestringA string containing the language, and the script and region if available.
calendar (optional)stringThe part of the Locale that indicates the locale’s calendar era.
caseFirst (optional)LocaleCollationCaseFirstFlag that defines whether case is taken into account for the locale’s collation rules.
collation (optional)stringThe collation type used for sorting
hourCycle (optional)LocaleHourCycleKeyThe time keeping format convention used by the locale.
languagestringThe primary language subtag associated with the locale.
numberingSystem (optional)stringThe numeral system used by the locale.
numeric (optional)booleanFlag that defines whether the locale has special collation handling for numeric characters.
region (optional)stringThe region of the world (usually a country) associated with the locale. Possible values are region codes as defined by ISO 3166-1.
script (optional)stringThe script used for writing the particular language used in the locale. Possible values are script codes as defined by ISO 15924.
maximize(this: void, …methodArguments: []) => Locale-
minimize(this: void, …methodArguments: []) => Locale-
toString(this: void, …methodArguments: []) => string-

See

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale

View source


constructIntlNumberFormat

constructIntlNumberFormat(...constructorArguments): Object

Functional alias for new Intl.NumberFormat(), which enables language-sensitive number formatting.

Parameters

NameType
...constructorArguments[locales?: LocalesArgument, options?: NumberFormatOptions]

Returns

Object

NameType
format(this: void, …methodArguments: [value: number | bigint]) => string
formatRange(this: void, …methodArguments: [start: number | bigint, end: number | bigint]) => string
formatRangeToParts(this: void, …methodArguments: [start: number | bigint, end: number | bigint]) => NumberRangeFormatPart[]
formatToParts(this: void, …methodArguments: [number?: number | bigint]) => NumberFormatPart[]
resolvedOptions(this: void, …methodArguments: []) => ResolvedNumberFormatOptions

See

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

View source


constructIntlPluralRules

constructIntlPluralRules(...constructorArguments): Object

Functional alias for new Intl.PluralRules(), which enables plural-sensitive formatting and plural-related language rules.

Parameters

NameType
...constructorArguments[locales?: LocalesArgument, options?: PluralRulesOptions]

Returns

Object

NameType
resolvedOptions(this: void, …methodArguments: []) => ResolvedPluralRulesOptions
select(this: void, …methodArguments: [n: number]) => LDMLPluralRule

See

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules

View source


constructIntlRelativeTimeFormat

constructIntlRelativeTimeFormat(...constructorArguments): Object

Functional alias for new Intl.RelativeTimeFormat(), which enables language-sensitive relative time formatting.

Parameters

NameType
...constructorArguments[locales?: LocalesArgument, options?: RelativeTimeFormatOptions]

Returns

Object

NameType
format(this: void, …methodArguments: [value: number, unit: RelativeTimeFormatUnit]) => string
formatToParts(this: void, …methodArguments: [value: number, unit: RelativeTimeFormatUnit]) => RelativeTimeFormatPart[]
resolvedOptions(this: void, …methodArguments: []) => ResolvedRelativeTimeFormatOptions

See

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat

View source


constructMap

constructMap<Key, Value>(iterable?): Object

Functional alias for new Map().

Type parameters

Name
Key
Value

Parameters

NameType
iterable (optional)Iterable<readonly [Key, Value]>

Returns

Object

NameTypeDescription
[toStringTag]string-
sizenumber
[iterator](this: void, …methodArguments: []) => IterableIterator<[Key, Value]>-
clear(this: void, …methodArguments: []) => void-
delete(this: void, …methodArguments: [key: Key]) => boolean-
entries(this: void, …methodArguments: []) => IterableIterator<[Key, Value]>-
forEach(this: void, …methodArguments: [callbackfn: Function, thisArg?: any]) => void-
get(this: void, …methodArguments: [key: Key]) => undefined | Value-
has(this: void, …methodArguments: [key: Key]) => boolean-
keys(this: void, …methodArguments: []) => IterableIterator<Key>-
set(this: void, …methodArguments: [key: Key, value: Value]) => Map<Key, Value>-
values(this: void, …methodArguments: []) => IterableIterator<Value>-

View source


constructPromise

constructPromise<Value>(executor): Object

Functional alias for new Promise().

Type parameters

Name
Value

Parameters

NameType
executor(resolve: (value: Value) => void, reject: (reason?: unknown) => void) => void

Returns

Object

NameTypeDescription
catch<RejectedValue>(this: void, onrejected?: Unary<unknown, RejectedValue | PromiseLike<RejectedValue>>) => Promise<Value | RejectedValue>-
then<ResolvedValue, RejectedValue>(this: void, onResolved?: Unary<Value, ResolvedValue | PromiseLike<ResolvedValue>>, onRejected?: Unary<unknown, RejectedValue | PromiseLike<RejectedValue>>) => Promise<ResolvedValue | RejectedValue>-

View source


constructProxy

constructProxy<Target>(target, handler): Unbound<Target>

Functional alias for new Proxy().

Type parameters

NameType
Targetextends object

Parameters

NameType
targetTarget
handlerProxyHandler<Target>

Returns

Unbound<Target>

View source


constructRangeError

constructRangeError(...constructorArguments): Object

Functional alias for new RangeError().

Parameters

NameType
...constructorArguments[message?: string, options?: ErrorOptions]

Returns

Object

NameType
cause (optional)unknown
messagestring
namestring
stack (optional)string

View source


constructReferenceError

constructReferenceError(...constructorArguments): Object

Functional alias for new ReferenceError().

Parameters

NameType
...constructorArguments[message?: string, options?: ErrorOptions]

Returns

Object

NameType
cause (optional)unknown
messagestring
namestring
stack (optional)string

View source


constructRegExp

constructRegExp(...constructorArguments): Object

Functional alias for new RegExp().

Parameters

NameType
...constructorArguments[pattern: string | RegExp, flags?: string]

Returns

Object

NameTypeDescription
dotAllbooleanReturns a Boolean value indicating the state of the dotAll flag (s) used with a regular expression. Default is false. Read-only.
flagsstringReturns 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.
globalbooleanReturns a Boolean value indicating the state of the global flag (g) used with a regular expression. Default is false. Read-only.
hasIndicesbooleanReturns a Boolean value indicating the state of the hasIndices flag (d) used with with a regular expression. Default is false. Read-only.
ignoreCasebooleanReturns a Boolean value indicating the state of the ignoreCase flag (i) used with a regular expression. Default is false. Read-only.
lastIndexnumber-
multilinebooleanReturns a Boolean value indicating the state of the multiline flag (m) used with a regular expression. Default is false. Read-only.
sourcestringReturns 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.
stickybooleanReturns a Boolean value indicating the state of the sticky flag (y) used with a regular expression. Default is false. Read-only.
unicodebooleanReturns a Boolean value indicating the state of the Unicode flag (u) used with a regular expression. Default is false. Read-only.
[matchAll](this: void, …methodArguments: [str: string]) => IterableIterator<RegExpMatchArray>-
[match](this: void, …methodArguments: [string: string]) => null | RegExpMatchArray-
[replace](this: void, …methodArguments: [string: string, replacer: Function]) => string-
[search](this: void, …methodArguments: [string: string]) => number-
[split](this: void, …methodArguments: [string: string, limit?: number]) => string[]-
compile(this: void, …methodArguments: [pattern: string, flags?: string]) => RegExp-
exec(this: void, …methodArguments: [string: string]) => null | RegExpExecArray-
test(this: void, …methodArguments: [string: string]) => boolean-

View source


constructSet

constructSet<Value>(iterable?): Object

Functional alias for new Set().

Type parameters

Name
Value

Parameters

NameType
iterable (optional)Iterable<Value>

Returns

Object

NameTypeDescription
[toStringTag]string-
sizenumber
[iterator](this: void, …methodArguments: []) => IterableIterator<Value>-
add(this: void, …methodArguments: [value: Value]) => Set<Value>-
clear(this: void, …methodArguments: []) => void-
delete(this: void, …methodArguments: [value: Value]) => boolean-
entries(this: void, …methodArguments: []) => IterableIterator<[Value, Value]>-
forEach(this: void, …methodArguments: [callbackfn: Function, thisArg?: any]) => void-
has(this: void, …methodArguments: [value: Value]) => boolean-
keys(this: void, …methodArguments: []) => IterableIterator<Value>-
values(this: void, …methodArguments: []) => IterableIterator<Value>-

View source


constructSyntaxError

constructSyntaxError(...constructorArguments): Object

Functional alias for new SyntaxError().

Parameters

NameType
...constructorArguments[message?: string, options?: ErrorOptions]

Returns

Object

NameType
cause (optional)unknown
messagestring
namestring
stack (optional)string

View source


constructTextEncoder

constructTextEncoder(...constructorArguments): Object

Functional alias for new TextEncoder().

Parameters

NameType
...constructorArguments[]

Returns

Object

NameTypeDescription
encodingstringReturns “utf-8”. MDN Reference
encode(this: void, …methodArguments: [input?: string]) => Uint8Array-
encodeInto(this: void, …methodArguments: [source: string, destination: Uint8Array]) => TextEncoderEncodeIntoResult-

View source


constructTypeError

constructTypeError(...constructorArguments): Object

Functional alias for new TypeError().

Parameters

NameType
...constructorArguments[message?: string, options?: ErrorOptions]

Returns

Object

NameType
cause (optional)unknown
messagestring
namestring
stack (optional)string

View source


constructURIError

constructURIError(...constructorArguments): Object

Functional alias for new URIError().

Parameters

NameType
...constructorArguments[message?: string, options?: ErrorOptions]

Returns

Object

NameType
cause (optional)unknown
messagestring
namestring
stack (optional)string

View source


constructWeakMap

constructWeakMap<Key, Value>(iterable?): Object

Functional alias for new WeakMap().

Type parameters

NameType
Keyextends object
ValueValue

Parameters

NameType
iterable (optional)Iterable<readonly [Key, Value]>

Returns

Object

NameType
[toStringTag]string
delete(this: void, …methodArguments: [key: Key]) => boolean
get(this: void, …methodArguments: [key: Key]) => undefined | Value
has(this: void, …methodArguments: [key: Key]) => boolean
set(this: void, …methodArguments: [key: Key, value: Value]) => WeakMap<Key, Value>

View source


constructWeakSet

constructWeakSet<Value>(iterable?): Object

Functional alias for new WeakSet().

Type parameters

NameType
Valueextends object

Parameters

NameType
iterable (optional)Iterable<Value>

Returns

Object

NameType
[toStringTag]string
add(this: void, …methodArguments: [value: Value]) => WeakSet<Value>
delete(this: void, …methodArguments: [value: Value]) => boolean
has(this: void, …methodArguments: [value: Value]) => boolean

View source

Common

toString

toString<Input>(input): Input extends Strigifiable ? `${Input<Input>}` : Input extends { toString: () => string } ? ReturnType<Input<Input>["toString"]> : string

Parses given value to string.

Type parameters

NameType
Inputextends Strigifiable | { toString: () => string }

Parameters

NameType
inputInput

Returns

Input extends Strigifiable ? `${Input<Input>}` : Input extends { toString: () => string } ? ReturnType<Input<Input>["toString"]> : string

stringified value.

Example

1
toString(10); // "10"
2
toString({}); // "[object Object]"
3
toString({ toString: _ => "test" }); // "test"

View source

Conditions

when

when<Value, Predicated>(predicate): <TrueOutput>(truthyHandler: Unary<Predicated & Value, TrueOutput>) => <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: Value) => TrueOutput | FalseOutput

Curried conditional (like a functional ternary).

Type parameters

NameType
ValueValue
Predicatednever

Parameters

NameTypeDescription
predicateSingle<Predicated> extends Single<never> ? Filter<Value> : Predicate<Value, Predicated>Predicate to check value against.

Returns

fn

Curried function with predicate in context.

▸ <TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: Value) => TrueOutput | FalseOutput

Type parameters
Name
TrueOutput
Parameters
NameType
truthyHandlerUnary<Predicated & Value, TrueOutput>
Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: Value) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputValue extends Predicated ? Value<Value> : Predicated
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueValue
Returns

TrueOutput | FalseOutput

Example

1
const isEven = (value: number) => value % 2 === 0;
2
const whenIsEven = when(isEven);
3
const double = (value: number) => value * 2;
4
const doubleWhenEven = whenIsEven(double);
5
const triple = (value: number) => value * 3;
6
const tripleWhenOdd = whenIsEven(triple);
7
8
tripleWhenOdd(2); // 4
9
tripleWhenOdd(3); // 9

View source


whenFalsy

whenFalsy<Value, Predicated>(predicate): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: Value) => Predicated & Value | FalseOutput

Like when, but when is falsy the value is returned as is.

Type parameters

NameType
ValueValue
Predicatednever

Parameters

NameTypeDescription
predicateSingle<Predicated> extends Single<never> ? Filter<Value> : Predicate<Value, Predicated>Predicate to check value against.

Returns

fn

Curried function with predicate in context.

▸ <FalseInput, FalseOutput>(falsyHandler): (value: Value) => Predicated & Value | FalseOutput

Type parameters
NameType
FalseInputValue extends Predicated ? Value<Value> : Predicated
FalseOutputPredicated & Value
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): Predicated & Value | FalseOutput

Parameters
NameType
valueValue
Returns

Predicated & Value | FalseOutput

Example

1
const isEven = (value: number) => value % 2 === 0;
2
const whenIsOdd = whenFalsy(isEven);
3
const double = (value: number) => value * 2;
4
const doubleWhenOdd = whenIsOdd(double);
5
6
doubleWhenOdd(2); // 2
7
doubleWhenOdd(3); // 6

View source


whenIsArray

whenIsArray<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is an Array.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<ReadOnlyArray<unknown>, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputReadOnlyArray<unknown>
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsAsyncIterable

whenIsAsyncIterable<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is an AsyncIterable.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<Readonly<AsyncIterable<unknown>>, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputReadonly<AsyncIterable<unknown>>
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsBigInt

whenIsBigInt<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a BigInt.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<bigint, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputbigint
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsBoolean

whenIsBoolean<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a Boolean.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<boolean, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputboolean
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsDate

whenIsDate<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a Date.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<Date, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputDate
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsFalsy

whenIsFalsy<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a Falsy value.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<Falsy, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputFalsy
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsFunction

whenIsFunction<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a Function.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<Function, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputFunction
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsIsomorphicIterable

whenIsIsomorphicIterable<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is an AsynchronousIterable.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<IsomorphicIterable<unknown>, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputIsomorphicIterable<unknown>
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsIterable

whenIsIterable<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is an Iterable.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<Readonly<Iterable<unknown>>, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputReadonly<Iterable<unknown>>
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsNull

whenIsNull<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is null.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<null, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputnull
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsNullish

whenIsNullish<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a Nullish value.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<Nullish, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputNullish
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsNumber

whenIsNumber<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a Number.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<number, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputnumber
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsObject

whenIsObject<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is an Object.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<object, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputobject
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsPromise

whenIsPromise<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a Promise.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<Promise<unknown>, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputPromise<unknown>
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsPropertyKey

whenIsPropertyKey<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a PropertyKey.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<PropertyKey, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputPropertyKey
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsPrototypeOfObject

whenIsPrototypeOfObject<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: object) => TrueOutput | FalseOutput

Conditional handler for when something has an Object prototype.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<never, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: object) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputnever
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueobject
Returns

TrueOutput | FalseOutput

View source


whenIsRegExp

whenIsRegExp<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a RegExp.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<RegExp, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputRegExp
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsSafeInteger

whenIsSafeInteger<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: number) => TrueOutput | FalseOutput

Conditional handler for when a number is a SafeInteger.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<never, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: number) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputnever
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valuenumber
Returns

TrueOutput | FalseOutput

View source


whenIsString

whenIsString<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a String.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<string, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputstring
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsSymbol

whenIsSymbol<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a Symbol.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<symbol, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputsymbol
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsTruthy

whenIsTruthy<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is a Truthy value.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<Readonly<unknown>, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputReadonly<unknown>
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenIsUndefined

whenIsUndefined<TrueOutput>(truthyHandler): <FalseInput, FalseOutput>(falsyHandler: Unary<FalseInput, FalseOutput>) => (value: unknown) => TrueOutput | FalseOutput

Conditional handler for when something is undefined.

Type parameters

Name
TrueOutput

Parameters

NameType
truthyHandlerUnary<undefined, TrueOutput>

Returns

fn

▸ <FalseInput, FalseOutput>(falsyHandler): (value: unknown) => TrueOutput | FalseOutput

Type parameters
NameType
FalseInputundefined
FalseOutputTrueOutput
Parameters
NameType
falsyHandlerUnary<FalseInput, FalseOutput>
Returns

fn

▸ (value): TrueOutput | FalseOutput

Parameters
NameType
valueunknown
Returns

TrueOutput | FalseOutput

View source


whenTruthy

whenTruthy<Value, Predicated>(predicate): <Output>(truthyHandler: Unary<Predicated & Value, Output>) => (value: Value) => Value | Output

Like when, but when is falsy the value is returned as is.

Type parameters

NameType
ValueValue
Predicatednever

Parameters

NameTypeDescription
predicateSingle<Predicated> extends Single<never> ? Filter<Value> : Predicate<Value, Predicated>Predicate to check value against.

Returns

fn

Curried function with predicate in context.

▸ <Output>(truthyHandler): (value: Value) => Value | Output

Type parameters
Name
Output
Parameters
NameType
truthyHandlerUnary<Predicated & Value, Output>
Returns

fn

▸ (value): Value | Output

Parameters
NameType
valueValue
Returns

Value | Output

Example

1
const isEven = (value: number) => value % 2 === 0;
2
const whenIsEven = whenTruthy(isEven);
3
const double = (value: number) => value * 2;
4
const doubleWhenEven = whenIsEven(double);
5
6
doubleWhenEven(2); // 4
7
doubleWhenEven(3); // 3

View source

Functions

always

always<Input>(input): () => Input

Returns a function that always returns the same value.

Type parameters

Name
Input

Parameters

NameType
inputInput

Returns

fn

Function that always return the given value.

▸ (): Input

Returns

Input

Example

1
const alwaysFoo = always("foo");
2
const fillWithFoo = map(alwaysFoo);
3
4
fillWithFoo([0, 1, 2]); // ["foo", "foo", "foo"]

View source


applyTo

applyTo<Input>(input): <Output>(unary: Unary<Input, Output>) => Output

Takes a value and applies a function to it.

Type parameters

Name
Input

Parameters

NameType
inputInput

Returns

fn

Function that expects a function that will receive the input.

▸ <Output>(unary): Output

Type parameters
Name
Output
Parameters
NameType
unaryUnary<Input, Output>
Returns

Output

Example

1
const applyTo10 = applyTo(10);
2
3
applyTo10((value: number) => value * 2); // 20
4
applyTo10((value: number) => value / 2); // 5

View source


entryKey

entryKey<InputEntry>(entry): EntryKey<InputEntry>

Get key of an Entry.

Type parameters

NameType
InputEntryextends Entry

Parameters

NameTypeDescription
entryInputEntryEntry to get key from.

Returns

EntryKey<InputEntry>

Key of an Entry.

Example

1
entryKey(["key", "value"]); // "key"

View source


entryValue

entryValue<InputEntry>(entry): EntryValue<InputEntry>

Get value of an Entry.

Type parameters

NameType
InputEntryextends Entry

Parameters

NameTypeDescription
entryInputEntryEntry to get vale from.

Returns

EntryValue<InputEntry>

Value of an Entry.

Example

1
entryKey(["key", "value"]); // "value"

View source


flip

flip<UnaryToFlip>(unary): (…secondArgument: Parameters<UnaryOutput<UnaryToFlip>>) => (…firstArgument: Parameters<UnaryToFlip>) => UnaryOutput<UnaryOutput<UnaryToFlip>>

Flips arguments of a curried function.

Type parameters

NameType
UnaryToFlipextends Unary<never, Unary<never, unknown>>

Parameters

NameType
unaryUnaryToFlip

Returns

fn

Curried function with unary in context.

▸ (...secondArgument): (…firstArgument: Parameters<UnaryToFlip>) => UnaryOutput<UnaryOutput<UnaryToFlip>>

Parameters
NameType
...secondArgumentParameters<UnaryOutput<UnaryToFlip>>
Returns

fn

▸ (...firstArgument): UnaryOutput<UnaryOutput<UnaryToFlip>>

Parameters
NameType
...firstArgumentParameters<UnaryToFlip>
Returns

UnaryOutput<UnaryOutput<UnaryToFlip>>

Example

1
const concat = (first: string) => (second: string) => `${first}${second}`;
2
const flippedConcat = flip(concat);
3
4
flippedConcat("1")("2"); // "21"

View source


identity

identity<Input>(input): Input

Identity function.

Type parameters

Name
Input

Parameters

NameType
inputInput

Returns

Input

Same value given.

Example

1
identity("foo"); // "foo"

View source


memoize

memoize<MemoizedFunction>(unary): MemoizedFunction

Memoize function return values for expensive operations.

Type parameters

NameType
MemoizedFunctionextends Unary<never, unknown>

Parameters

NameTypeDescription
unaryMemoizedFunctionFunction to memoize.

Returns

MemoizedFunction

Curried function with unary in context.

Example

1
const expensiveOperation = (value: number) => value * 2;
2
const memoizedOperation = memoize(expensiveOperation);
3
4
memoizedOperation(2); // 4
5
memoizedOperation(2); // 4 (cached)

View source


negate

negate<Item, Predicated>(predicate): Single<Predicated> extends Single<never> ? Unary<Item, boolean> : Predicate<Item, Exclude<Item, Predicated>>

Takes a function and returns a copy with negated output.

Type parameters

NameType
ItemItem
Predicatednever

Parameters

NameTypeDescription
predicateSingle<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

1
const isPositive = (value: number) => value >= 0;
2
const isNegative = not(isPositive);
3
4
isPositive(1); // true
5
isNegative(1); // false

View source


once

once<OnceFunction>(unary): (value: UnaryInput<OnceFunction>) => UnaryOutput<OnceFunction> | UnaryOutput<OnceFunction>

Runs a function once, and after that returns always the same value.

Type parameters

NameType
OnceFunctionextends Unary<never, unknown>

Parameters

NameTypeDescription
unaryOnceFunctionFunction to run once.

Returns

fn

Curried function with unary in context.

▸ (value): UnaryOutput<OnceFunction> | UnaryOutput<OnceFunction>

Parameters
NameType
valueUnaryInput<OnceFunction>
Returns

UnaryOutput<OnceFunction> | UnaryOutput<OnceFunction>

Example

1
const expensiveOperation = (value: number) => value * 2;
2
const onceOperation = once(expensiveOperation);
3
4
onceOperation(2); // 4
5
onceOperation(3); // 4 (cached)

View source


tap

tap<Input>(tapper): <Tapped>(tapped: Tapped) => Tapped

Tap into a value before calling a function.

Type parameters

Name
Input

Parameters

NameTypeDescription
tapperUnary<Input, unknown>Tapper function to be called with the value.

Returns

fn

Curried function with tapper in context.

▸ <Tapped>(tapped): Tapped

Type parameters
NameType
Tappedextends Unary<Input, unknown>
Parameters
NameType
tappedTapped
Returns

Tapped

Example

1
const log = tap(console.log);
2
const double = (value: number) => value * 2;
3
const doubleAndLog = log(double);
4
5
doubleAndLog(2); // 4 (returns and logs 4)

View source


thunk

thunk<Input, Output>(unary): (input: Input) => () => Output

Delayed evaluation function.

Type parameters

Name
Input
Output

Parameters

NameType
unaryUnary<Input, Output>

Returns

fn

Function that will run the given function when called.

▸ (input): () => Output

Parameters
NameType
inputInput
Returns

fn

▸ (): Output

Returns

Output

Example

1
const always = thunk(id);
2
const alwaysFoo = always("foo");
3
alwaysFoo(); // "foo"

View source

Numbers

cryptoNumber

cryptoNumber(seed): Promise<number>

Generates number using SubtleCrypto#digest and the given seed.

⚠️ IMPORTANT: This only works in secure contexts (HTTPS/Node).

Parameters

NameTypeDescription
seedstring | NumericSeed to be used to generate random numbers.

Returns

Promise<number>

Pseudo-random number from seed.

Example

1
const seededRandom1 = await random("some seed");
2
const seededRandom2 = await random("some seed");
3
4
seededRandom1 === seededRandom2; // true because it has the same seed

See

View source

Objects

awaitableHandler

awaitableHandler<Value, Output>(handler): <AwaitableValue>(awaitable: AwaitableValue) => AwaitableValue extends Promise<Value> ? Promise<Output> : Output

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

Name
Value
Output

Parameters

NameTypeDescription
handler(awaitable: Value) => OutputHandler function to be called with the value.

Returns

fn

Curried function with handler in context.

▸ <AwaitableValue>(awaitable): AwaitableValue extends Promise<Value> ? Promise<Output> : Output

Type parameters
Name
AwaitableValue
Parameters
NameType
awaitableAwaitableValue
Returns

AwaitableValue extends Promise<Value> ? Promise<Output> : Output

Example

1
const double = maybePromiseHandler((value: number) => value * 2);
2
3
double(2); // 4
4
double(Promise.resolve(2)); // Promise<4>

View source


get

get<Key>(key): <Source>(object: Source) => Source[Key & keyof Source]

Get the value of a property in an object.

Type parameters

NameType
Keyextends PropertyKey

Parameters

NameType
keyKey

Returns

fn

Curried function with key in context.

▸ <Source>(object): Source[Key & keyof Source]

Type parameters
NameType
Sourceextends Readonly<Record<Key, unknown>>
Parameters
NameType
objectSource
Returns

Source[Key & keyof Source]

Example

1
const getFoo = get("foo");
2
3
getFoo({ foo: "bar" }); // "bar"
4
getFoo({}); // undefined

View source


intercept

intercept<Interceptions>(interceptions): <Target>(target: Target) => keyof Target extends keyof Interceptions ? Omit<Target, keyof Interceptions> : Target & { readonly [Property in string | number | symbol]: ReturnType<Interceptions[Property]> }

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

NameType
Interceptionsextends Readonly<Record<PropertyKey, <ProxiedObject>(target: ProxiedObject) => unknown>>

Parameters

NameTypeDescription
interceptionsInterceptionsDictionary property -> handler.

Returns

fn

Curried function with interceptions in context.

▸ <Target>(target): keyof Target extends keyof Interceptions ? Omit<Target, keyof Interceptions> : Target & { readonly [Property in string | number | symbol]: ReturnType<Interceptions[Property]> }

Type parameters
NameType
Targetextends object
Parameters
NameType
targetTarget
Returns

keyof Target extends keyof Interceptions ? Omit<Target, keyof Interceptions> : Target & { readonly [Property in string | number | symbol]: ReturnType<Interceptions[Property]> }

Example

1
const test = { foo: "foo" };
2
const barIntercept = intercept({ foo: () => "bar" });
3
4
const interceptedTest = barIntercept(test);
5
interceptedTest.foo; // "bar"
6
test.foo; // "foo"

View source


mutate

mutate<Update>(update): <Target>(target: Target) => Target & Update

Function to encapsulate object mutations.

⚠️ IMPORTANT: Try to avoid this util, use intercept instead.

Type parameters

NameType
Updateextends object

Parameters

NameTypeDescription
updateUpdateUpdate to apply to given target.

Returns

fn

Curried function with update in context.

▸ <Target>(target): Target & Update

Type parameters
NameType
Targetextends object
Parameters
NameType
targetTarget
Returns

Target & Update

Example

1
const state = { a: 1 };
2
mutate(set("a")(2))(state);
3
console.log(state); // { a: 2 }

View source


omit

omit<Properties>(...properties): <Source>(object: Source) => Omit<Source, Properties[number]>

Omits given properties from an object.

Type parameters

NameType
Propertiesextends ReadOnlyArray<PropertyKey>

Parameters

NameTypeDescription
...propertiesPropertiesProperties to omit.

Returns

fn

Curried function with properties in context.

▸ <Source>(object): Omit<Source, Properties[number]>

Type parameters
NameType
Sourceextends Readonly<Record<PropertyKey, unknown>>
Parameters
NameType
objectSource
Returns

Omit<Source, Properties[number]>

Example

1
const object = { a: 1, b: 2, c: 3 };
2
const omitAC = omit("a", "c");
3
const result = omitAC(object); // { b: 2 }

View source


pick

pick<Properties>(...properties): <Source>(object: Source) => Pick<Source, Properties[number]>

Picks given properties from an object.

Type parameters

NameType
Propertiesextends ReadOnlyArray<PropertyKey>

Parameters

NameTypeDescription
...propertiesPropertiesProperties to pick.

Returns

fn

Curried function with properties in context.

▸ <Source>(object): Pick<Source, Properties[number]>

Type parameters
NameType
Sourceextends Readonly<Record<PropertyKey, unknown>>
Parameters
NameType
objectSource
Returns

Pick<Source, Properties[number]>

Example

1
const object = { a: 1, b: 2, c: 3 };
2
const pickAC = pick("a", "c");
3
const result = pickAC(object); // { a: 1, c: 3 }

View source


set

set<Key>(key): <Value>(value: Value) => <Source>(object: Source) => Omit<Source, Key> & Readonly<Record<Key, Value>>

Set the value of a property in an object (read only).

Type parameters

NameType
Keyextends PropertyKey

Parameters

NameType
keyKey

Returns

fn

Curried function with key in context.

▸ <Value>(value): <Source>(object: Source) => Omit<Source, Key> & Readonly<Record<Key, Value>>

Type parameters
Name
Value
Parameters
NameType
valueValue
Returns

fn

▸ <Source>(object): Omit<Source, Key> & Readonly<Record<Key, Value>>

Type parameters
NameType
Sourceextends object
Parameters
NameType
objectSource
Returns

Omit<Source, Key> & Readonly<Record<Key, Value>>

Example

1
const setFoo = set("foo");
2
3
setFoo("baz")({ foo: "bar" }); // { foo: "baz" }
4
setFoo("baz")({ bar: "foo" }); // { bar: "foo", foo: "baz" }
5
setFoo("baz")({}); // { foo: "baz" }

View source

Promises

otherwise

otherwise<Output>(handler): <PromisedValue>(promise: Promise<PromisedValue>) => Promise<Output | PromisedValue>

Sets a promise catch handler.

Type parameters

Name
Output

Parameters

NameType
handlerUnary<unknown, Output | PromiseLike<Output>>

Returns

fn

Curried function with handler set in context.

▸ <PromisedValue>(promise): Promise<Output | PromisedValue>

Type parameters
Name
PromisedValue
Parameters
NameType
promisePromise<PromisedValue>
Returns

Promise<Output | PromisedValue>

Example

1
const otherwiseLog = otherwise(console.error);
2
3
otherwiseLog(fetch("/api")); // Logs on error.

View source


then

then<HandlerInput, Output>(handler): <PromiseInstance>(promise: PromiseInstance) => Promise<Output>

Sets a promise then handler.

Type parameters

Name
HandlerInput
Output

Parameters

NameType
handlerUnary<HandlerInput, Output | PromiseLike<Output>>

Returns

fn

Curried function with handler set in context.

▸ <PromiseInstance>(promise): Promise<Output>

Type parameters
NameType
PromiseInstanceextends Promise<HandlerInput>
Parameters
NameType
promisePromiseInstance
Returns

Promise<Output>

Example

1
const thenJson = then((response: Response) => response.json());
2
3
thenJson(fetch("/api")); // Parsed response

View source