Options
All
  • Public
  • Public/Protected
  • All
Menu

@vangware/utils

Index

Type aliases

ArrayOrIterable

ArrayOrIterable<Item>: ArrayLike<Item> | Iterable<Item>

ArrayLike or Iterable alias.

template Item

Type of items in the ArrayLike or Iterable.

Type parameters

  • Item

DecimalTuple

DecimalTuple: readonly [coefficient: number, exponent: number]

2-Tuple to represent decimals [coefficient, exponent]

Entries

Entries<Source>: ReadonlyArray<Entry<Source>>

Array of Entries (Entry type).

template Source

Source object to which the entities belong to.

Type parameters

  • Source

Entry

Entry<Source>: readonly [key: string, value: Source[keyof Source]]

Entity tuple [key, object[key]].

template Source

Source object to which the entity belongs to.

Type parameters

  • Source

Falsy

Falsy: Nullish | "" | 0 | false

Types that evaluates to false in JS.

FilterTuple

FilterTuple<Item, Filtered>: readonly [filteredIn: ReadonlyArray<Filtered>, filteredOut: ReadonlyArray<OptionalExclude<Item, Filtered>>]

Tuple generated by arrayFilterTuple, which contains matching and non matching values.

template Item

Type of the items being filtered.

template Filtered

Type of the matching items.

Type parameters

  • Item

  • Filtered: Item = Item

Filterer

Filterer<Item, Filtered>: GuardedFilterer<Item, Filtered> | UnguardedFilterer<Item>

Filterer function.

template Item

Type of the items in the source array.

template Filtered

Type of filtered items.

Type parameters

  • Item

  • Filtered: Item

Grouped

Grouped<Item>: ImmutableRecord<ReadonlyArray<Item>, string>

Object with the following shape:

{
[groupName]: [...valuesOfGroupName]
}
template Item

Type of the items in the source array.

Type parameters

  • Item

Grouper

Grouper<Item>: (item: Item) => number | string

Type parameters

  • Item

Type declaration

    • (item: Item): number | string
    • Grouper function.

      Parameters

      • item: Item

        Item of the source array.

      Returns number | string

      Group name.

GuardedFilterer

GuardedFilterer<Item, Filtered>: (item: Item) => item is Filtered

Type parameters

  • Item

  • Filtered: Item

Type declaration

    • (item: Item): item is Filtered
    • Guarded filterer function.

      Parameters

      • item: Item

      Returns item is Filtered

ImmutableRecord

ImmutableRecord<Value, Key>: Readonly<Record<Key, Value>>

Readonly Record wrapper.

template Value

Possible values of the given Record.

template Key

Key type of given Record.

Type parameters

  • Value = unknown

  • Key: number | string | symbol = number | string | symbol

Mapper

Mapper<Item, Output>: (item: Item) => Output

Type parameters

  • Item

  • Output

Type declaration

    • (item: Item): Output
    • Mapper function.

      Parameters

      • item: Item

        Item of the source array.

      Returns Output

      Mapped value.

Nullish

Nullish: null | undefined

Union of null and undefined.

OptionalExclude

OptionalExclude<Type, Exclusion>: Exclude<Type, Exclusion> extends never ? Exclusion : Exclude<Type, Exclusion>

Excludes only if it doesn't return never. Fallback to Exclusion.

template Type

Type to apply exclusion on.

template Exclusion

Exclusion object.

Type parameters

  • Type

  • Exclusion

Radix

Radix: 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36

Valid radix values (from 2 to 36).

Reducer

Reducer<Item, Output>: (accumulator: Output) => Mapper<Item, Output>

Type parameters

  • Item

  • Output = ReadonlyArray<Item>

Type declaration

    • (accumulator: Output): Mapper<Item, Output>
    • Reducer function.

      Parameters

      • accumulator: Output

        Reducer accumulator.

      Returns Mapper<Item, Output>

      Mapper with accumulator context.

Sorter

Sorter<Item>: (next: Item) => Mapper<Item, number>

Type parameters

  • Item

Type declaration

    • (next: Item): Mapper<Item, number>
    • Sorter function.

      Parameters

      • next: Item

        Item following the current one.

      Returns Mapper<Item, number>

      Mapped value.

StringReplaceMap

StringReplaceMap: ImmutableRecord<number | string, string>

Object with the following shape:

{
[searchString]: "replacingString"
}

Truthy

Truthy<Actual>: Actual extends Falsy ? never : Actual

Generic type to check if value is not Falsy (evaluates to true in JS).

template Actual

Actual type (if not truthy).

Type parameters

  • Actual = unknown

TypeOf

TypeOf: "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined"

Possible types returned by typeof.

UnguardedFilterer

UnguardedFilterer<Item>: (item: Item) => boolean

Type parameters

  • Item

Type declaration

    • (item: Item): boolean
    • Unguarded filter function.

      Parameters

      • item: Item

      Returns boolean

Functions

Const arrayEvery

  • arrayEvery<Item, Predicated>(predicate: Filterer<Item, Predicated>): (source: readonly Item[]) => source is readonly Predicated[]
  • Curried wrapper for Array.prototype.every.

    example
    const everyNumber = arrayEvery(isNumber);
    everyNumber([0, 1, 2]); // true
    everyNumber([0, 1, "foo", 2]); // false

    Type parameters

    • Item

      Type of items in source array.

    • Predicated

      Type of predicated items.

    Parameters

    • predicate: Filterer<Item, Predicated>

      Function predicate to test every item.

    Returns (source: readonly Item[]) => source is readonly Predicated[]

    Curried function with predicate in context.

      • (source: readonly Item[]): source is readonly Predicated[]
      • Parameters

        • source: readonly Item[]

        Returns source is readonly Predicated[]

Const arrayFilterIn

  • arrayFilterIn<Item, Filtered>(filterer: Filterer<Item, Filtered>): (source: readonly Item[]) => Filtered[]
  • Takes a positive filterer and applies it to given source array.

    example
    const filterInEven = arrayFilterIn((item: number) => item % 2 === 0);
    const filterOutEmpty = arrayFilterIn((item: string) => item !== "");

    filterInEven([0, 1, 2, 3]); // [0, 2]
    filterOutEmpty(["hello", "", "", "world"]); // ["hello", "world"]

    Type parameters

    • Item

      Type of items in source array.

    • Filtered

      Type of filtered items.

    Parameters

    • filterer: Filterer<Item, Filtered>

      Filterer function.

    Returns (source: readonly Item[]) => Filtered[]

    Curried function with filter set in context.

      • (source: readonly Item[]): Filtered[]
      • Parameters

        • source: readonly Item[]

        Returns Filtered[]

Const arrayFilterOut

  • arrayFilterOut<Item, Filtered>(filterer: Filterer<Item, Filtered>): (source: readonly Item[]) => OptionalExclude<Item, Filtered>[]
  • Takes a negative filterer and applies it to given source array.

    example
    const filterOutEven = arrayFilterOut((item: number) => item % 2 === 0);
    const filterOutEmpty = arrayFilterOut((item: string) => item === "");

    filterOutEven([0, 1, 2, 3]); // [1, 3]
    filterOutEmpty(["hello", "", "", "world"]); // ["hello", "world"]

    Type parameters

    • Item

      Type of items in source array.

    • Filtered

      Type of filtered items.

    Parameters

    • filterer: Filterer<Item, Filtered>

      Filterer out function.

    Returns (source: readonly Item[]) => OptionalExclude<Item, Filtered>[]

    Curried function with filter set in context.

Const arrayFilterTuple

  • arrayFilterTuple<Item, Filtered>(filterer: Filterer<Item, Filtered>): (source: readonly Item[]) => FilterTuple<Item, Filtered>
  • Takes a filterer and applies it to a source array returning a [matching, nonMatching] tuple.

    example
    const filterEvenOdd = arrayFilterTuple((item: number) => item % 2 === 0);

    filterEvenOdd([0, 1, 2, 3]); // [[0, 2], [1, 3]]

    Type parameters

    • Item

      Type of items in source array.

    • Filtered

      Type of filtered items.

    Parameters

    • filterer: Filterer<Item, Filtered>

      Filterer function.

    Returns (source: readonly Item[]) => FilterTuple<Item, Filtered>

    Curried function with filter in context.

      • Parameters

        • source: readonly Item[]

        Returns FilterTuple<Item, Filtered>

Const arrayFlat

  • arrayFlat<Depth>(depth: Depth): <Item>(source: readonly Item[]) => FlatArray<readonly Item[], Depth>[]
  • Curried wrapper for Array.prototype.flat.

    example
    const flatten = arrayFlat(1);
    flatten([["foo", "bar"], [1, 2]]); // ["foo", "bar", 1, 2]

    Type parameters

    • Depth: number

      Recursion depth type.

    Parameters

    • depth: Depth

      The maximum recursion depth.

    Returns <Item>(source: readonly Item[]) => FlatArray<readonly Item[], Depth>[]

    Curried function with depth in context.

      • <Item>(source: readonly Item[]): FlatArray<readonly Item[], Depth>[]
      • Type parameters

        • Item

        Parameters

        • source: readonly Item[]

        Returns FlatArray<readonly Item[], Depth>[]

Const arrayFrom

  • Given an ArrayLike or Iterable, return an array.

    example
    arrayFrom("hello"); // ["h", "e", "l", "l", "o"]
    

    Type parameters

    • Item

      Type of items in source array.

    Parameters

    • source: ArrayOrIterable<Item>

      Source value (must be an ArrayLike or Iterable).

    Returns readonly Item[]

    Frozen array made with given ArrayLike or Iterable.

Const arrayGroup

  • arrayGroup<Item>(grouper: Grouper<Item>): (source: readonly Item[]) => Readonly<Record<string, readonly Item[]>>
  • Takes grouper and applies it to given source array.

    example
    const groupEvenOdd = arrayGroup(
    (item: number) => item % 2 === 0 "even" : "odd"
    );

    groupEvenOdd([0, 1, 2, 3]); // { even: [0, 2], odd: [1, 3] }

    Type parameters

    • Item

      Type of items in source array.

    Parameters

    • grouper: Grouper<Item>

      Grouper function.

    Returns (source: readonly Item[]) => Readonly<Record<string, readonly Item[]>>

    Curried function with grouper in context.

      • (source: readonly Item[]): Readonly<Record<string, readonly Item[]>>
      • Parameters

        • source: readonly Item[]

        Returns Readonly<Record<string, readonly Item[]>>

        Curried function with reducer and initialValue in context.

Const arrayInsert

  • arrayInsert(index: number): <Item>(item: Item) => <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]
  • Takes an index and an item and makes a copy of given source array with that new item in the given index.

    example
    const insertLast = arrayInsert(Infinity);
    const insertFirst = arrayInsert(0);
    const insertValueLast = insertLast("value");
    const insertValueFirst = insertFirst("value");

    insertValueLast([0, 1, 2, 3]); // [0, 1, 2, 3, "value"]
    insertValueFirst([0, 1, 2, 3]); // ["value", 0, 1, 2, 3]

    Parameters

    • index: number

      Index to insert item.

    Returns <Item>(item: Item) => <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]

    Curried function with item in context.

      • <Item>(item: Item): <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]
      • Type parameters

        • Item

        Parameters

        • item: Item

        Returns <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]

          • <SourceItem>(source: readonly SourceItem[]): (Item | SourceItem)[]
          • Type parameters

            • SourceItem = Item

            Parameters

            • source: readonly SourceItem[]

            Returns (Item | SourceItem)[]

            Curried function with index and item in context.

Const arrayInsertFirst

  • arrayInsertFirst<Item>(item: Item): <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]
  • Takes an item and inserts it at the beginning of given source array.

    example
    const arrayInsertValueFirst = arrayInsertFirst("value");

    arrayInsertValueFirst([1, 2, 3]); // ["value", 1, 2, 3]
    arrayInsertValueFirst(["foo", "bar"]); // ["value", "foo", "bar"]

    Type parameters

    • Item

    Parameters

    • item: Item

    Returns <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]

    Curried function with item and index in context.

      • <SourceItem>(source: readonly SourceItem[]): (Item | SourceItem)[]
      • Type parameters

        • SourceItem = Item

        Parameters

        • source: readonly SourceItem[]

        Returns (Item | SourceItem)[]

        Curried function with index and item in context.

Const arrayInsertLast

  • arrayInsertLast<Item>(item: Item): <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]
  • Takes an item and inserts it at the end of given source array.

    example
    const arrayInsertValueLast = arrayInsertLast("value");

    arrayInsertValueLast([0, 1, 2, 3]); // [0, 1, 2, 3, "value"]
    arrayInsertValueLast(["foo", "bar"]); // ["foo", "bar", "value"]

    Type parameters

    • Item

    Parameters

    • item: Item

    Returns <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]

    Curried function with item and index in context.

      • <SourceItem>(source: readonly SourceItem[]): (Item | SourceItem)[]
      • Type parameters

        • SourceItem = Item

        Parameters

        • source: readonly SourceItem[]

        Returns (Item | SourceItem)[]

        Curried function with index and item in context.

Const arrayJoin

  • arrayJoin(separator: string): <Item>(source: readonly Item[]) => string
  • Curried wrapper for Array.prototype.join.

    example
    const joinWithSpaces = arrayJoin(" ");
    joinWithSpaces(["foo", "bar"]); // "foo bar"

    Parameters

    • separator: string

      Value separator.

    Returns <Item>(source: readonly Item[]) => string

    Curried function with separator in context.

      • <Item>(source: readonly Item[]): string
      • Type parameters

        • Item

        Parameters

        • source: readonly Item[]

        Returns string

Const arrayMap

  • arrayMap<Item, Output>(mapper: Mapper<Item, Output>): (source: readonly Item[]) => Output[]
  • Takes a mapper function and applies it to given source array.

    example
    const mapDouble = arrayMap((item: number) => item * 2);

    mapDouble([0, 1, 2, 3]); // [0, 2, 4, 6]

    Type parameters

    • Item

      Type of the items in the source array.

    • Output = Item

      Type of the output (same as the input by default).

    Parameters

    • mapper: Mapper<Item, Output>

      Mapper function function.

    Returns (source: readonly Item[]) => Output[]

    Curried function with mapper in context.

      • (source: readonly Item[]): Output[]
      • Parameters

        • source: readonly Item[]

        Returns Output[]

Const arrayReduce

  • arrayReduce<Item, Output>(reducer: Reducer<Item, Output>): (initialValue: Output) => (source: readonly Item[]) => Output
  • Takes a reducer and an initialValue and applies it to source array.

    example
    const sum = arrayReduce<number, number>(total => item => total + item);
    const sumStartingInZero = sum(0);
    const sumStartingInTwo = sum(2);

    sumStartingInZero([1, 2, 3]); // 6
    sumStartingInTwo([1, 2, 3]); // 8

    Type parameters

    • Item

      Type of the items in the source array.

    • Output = readonly Item[]

      Type of the output (an array of Input by default).

    Parameters

    Returns (initialValue: Output) => (source: readonly Item[]) => Output

    Curried function with reducer in context.

      • (initialValue: Output): (source: readonly Item[]) => Output
      • Parameters

        • initialValue: Output

        Returns (source: readonly Item[]) => Output

          • (source: readonly Item[]): Output
          • Parameters

            • source: readonly Item[]

            Returns Output

            Curried function with reducer and initialValue in context.

Const arrayReplace

  • arrayReplace(index: number): <Item>(item: Item) => <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]
  • Takes an index and an item and replaces the source array item in that index with the taken item.

    example
    const replaceLast = arrayReplace(Infinity);
    const replaceFirst = arrayReplace(0);
    const replaceItemLast = replaceLast("replacement");
    const replaceItemFirst = replaceFirst("replacement");

    replaceItemLast([0, 1, 2, 3]); // [0, 1, 2, "replacement"]
    replaceItemFirst([0, 1, 2, 3]); // ["replacement", 1, 2, 3]

    Parameters

    • index: number

      Index to start replace item.

    Returns <Item>(item: Item) => <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]

    Curried function with item in context.

      • <Item>(item: Item): <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]
      • Type parameters

        • Item

        Parameters

        • item: Item

        Returns <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]

          • <SourceItem>(source: readonly SourceItem[]): (Item | SourceItem)[]
          • Type parameters

            • SourceItem = Item

            Parameters

            • source: readonly SourceItem[]

            Returns (Item | SourceItem)[]

            Curried function with index and item in context.

Const arrayReplaceFirst

  • arrayReplaceFirst<Item>(item: Item): <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]
  • Takes an item and replaces the first one with it in the given source array.

    example
    const arrayReplaceValueFirst = arrayReplaceFirst("value");

    arrayReplaceValueFirst([1, 2, 3]); // ["value", 2, 3]
    arrayReplaceValueFirst(["foo", "bar"]); // ["value", "bar"]

    Type parameters

    • Item

    Parameters

    • item: Item

    Returns <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]

    Curried function with item and index in context.

      • <SourceItem>(source: readonly SourceItem[]): (Item | SourceItem)[]
      • Type parameters

        • SourceItem = Item

        Parameters

        • source: readonly SourceItem[]

        Returns (Item | SourceItem)[]

        Curried function with index and item in context.

Const arrayReplaceLast

  • arrayReplaceLast<Item>(item: Item): <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]
  • Takes an item and replaces the last with it in the given source array.

    example
    const arrayReplaceValueLast = arrayReplaceLast("value");

    arrayReplaceValueLast([0, 1, 2, 3]); // [0, 1, 2, "value"]
    arrayReplaceValueLast(["foo", "bar"]); // ["foo", "value"]

    Type parameters

    • Item

    Parameters

    • item: Item

    Returns <SourceItem>(source: readonly SourceItem[]) => (Item | SourceItem)[]

    Curried function with item and index in context.

      • <SourceItem>(source: readonly SourceItem[]): (Item | SourceItem)[]
      • Type parameters

        • SourceItem = Item

        Parameters

        • source: readonly SourceItem[]

        Returns (Item | SourceItem)[]

        Curried function with index and item in context.

Const arrayReverse

  • arrayReverse<Item>(source: readonly Item[]): Item[]
  • Takes a source array and reverse the order of its items.

    example
    arrayReverse([0, 1, 2, 3]); // [3, 2, 1, 0]
    

    Type parameters

    • Item

      Type of the items in the source array.

    Parameters

    • source: readonly Item[]

      Source array to be reversed.

    Returns Item[]

    Copy of source with values in reversed order.

Const arraySlice

  • arraySlice(start: number): (end: number) => <Item>(source: readonly Item[]) => Item[]
  • Takes a start and end and applies a slice to source array from given start to given end.

    example
    const sliceFrom1 = arraySlice(1);
    const sliceFrom1To3 = sliceFrom1(3);

    sliceFrom1To3([0, 1, 2, 3]); // [1, 2]

    Parameters

    • start: number

      Slice start.

    Returns (end: number) => <Item>(source: readonly Item[]) => Item[]

    Curried function with start in context.

      • (end: number): <Item>(source: readonly Item[]) => Item[]
      • Parameters

        • end: number

        Returns <Item>(source: readonly Item[]) => Item[]

          • <Item>(source: readonly Item[]): Item[]
          • Type parameters

            • Item

            Parameters

            • source: readonly Item[]

            Returns Item[]

            Curried function with start in context.

Const arraySliceFrom

  • arraySliceFrom(start: number): <Item>(source: readonly Item[]) => Item[]
  • Takes a start and applies a slice to source array from given start to the end of the source.

    example
    const sliceFrom1 = arraySliceFrom(1);

    sliceFrom1([0, 1, 2, 3]); // [1, 2, 3]

    Parameters

    • start: number

      Slice start.

    Returns <Item>(source: readonly Item[]) => Item[]

    Curried function with start in context.

      • <Item>(source: readonly Item[]): Item[]
      • Type parameters

        • Item

        Parameters

        • source: readonly Item[]

        Returns Item[]

        Curried function with start in context.

Const arraySliceTo

  • arraySliceTo(end: number): <Item>(source: readonly Item[]) => Item[]
  • Takes an end and applies a slice to source array from the start of the source to the given end.

    example
    const sliceTo2 = arraySliceTo(2);

    sliceTo2([0, 1, 2, 3]); // [0, 1, 2]

    Parameters

    • end: number

      Slice end.

    Returns <Item>(source: readonly Item[]) => Item[]

    Curried function with end in context (start set to 0).

      • <Item>(source: readonly Item[]): Item[]
      • Type parameters

        • Item

        Parameters

        • source: readonly Item[]

        Returns Item[]

        Curried function with start in context.

Const arraySome

  • arraySome<Item, Predicated>(predicate: Filterer<Item, Predicated>): (source: readonly Item[]) => source is readonly (Item | Predicated)[]
  • Curried wrapper for Array.prototype.some.

    example
    const someNumber = arraySome(isNumber);
    someNumber([0, 1, 2]); // true
    someNumber([0, 1, "foo", 2]); // true
    someNumber(["foo", "bar"]); // false

    Type parameters

    • Item

      Type of items in source array.

    • Predicated

      Type of predicated items.

    Parameters

    • predicate: Filterer<Item, Predicated>

      Function predicate to test until some item of the type.

    Returns (source: readonly Item[]) => source is readonly (Item | Predicated)[]

    Curried function with predicate in context.

      • (source: readonly Item[]): source is readonly (Item | Predicated)[]
      • Parameters

        • source: readonly Item[]

        Returns source is readonly (Item | Predicated)[]

Const arraySort

  • arraySort<Item>(sorter: Sorter<Item>): (source: readonly Item[]) => Item[]
  • Takes a sorter function and applies it to given source array.

    example
    const sortNumbers = arraySort(
    (next: number) => (item: number) => next - item
    );

    sortNumbers([3, 0, 2, 1]); // [0, 1, 2, 3]

    Type parameters

    • Item

      Type of the items in the source array.

    Parameters

    • sorter: Sorter<Item>

      Sorter function function.

    Returns (source: readonly Item[]) => Item[]

    Curried function with sorter in context.

      • (source: readonly Item[]): Item[]
      • Parameters

        • source: readonly Item[]

        Returns Item[]

Const decimalTupleAdd

Const decimalTupleDivide

Const decimalTupleMultiply

Const decimalTupleSubtract

Const decimalTupleToNumber

  • decimalTupleToNumber(__namedParameters: DecimalTuple): number
  • Takes a source DecimalTuple [coefficient, exponent] and returns a number.

    example
    decimalTupleToNumber([3141592653589793, -15]); // 3.141592653589793
    decimalTupleToNumber([5, 3]); // 5000

    Parameters

    Returns number

    Number generated from the source coefficient and exponent.

Const equal

  • equal(expected: unknown): (actual: unknown) => boolean
  • Given and expected value and an actual value, returns true if those values are deeply equal, or false if not.

    example
    const equalTo2 = equal(2);
    const equalToObject = equal({ foo: "bar" });

    equalTo2(2); // true
    equalTo2(5); // false
    equalToObject({ foo: "bar" }); // true
    equalToObject({ bar: "baz" }); // false

    Parameters

    • expected: unknown

      Expected value to compare.

    Returns (actual: unknown) => boolean

      • (actual: unknown): boolean
      • Parameters

        • actual: unknown

        Returns boolean

Const equalArrays

  • equalArrays(compare: (expected: unknown) => (actual: unknown) => boolean): (expected: unknown) => (actual: unknown) => boolean
  • Given a compare function, an expected value and an actual value, returns true if those values are equal based on the compare output, or false if not.

    example
    const compare = actual => expected => actual === expected;
    const equalToArray = equalArrays(compare)(["foo", "bar"]);

    equalToArray(["foo", "bar"]); // true
    equalToArray(["bar", "foo"]); // false

    Parameters

    • compare: (expected: unknown) => (actual: unknown) => boolean

      Comparison function.

        • (expected: unknown): (actual: unknown) => boolean
        • Parameters

          • expected: unknown

          Returns (actual: unknown) => boolean

            • (actual: unknown): boolean
            • Parameters

              • actual: unknown

              Returns boolean

    Returns (expected: unknown) => (actual: unknown) => boolean

      • (expected: unknown): (actual: unknown) => boolean
      • Parameters

        • expected: unknown

        Returns (actual: unknown) => boolean

          • (actual: unknown): boolean
          • Parameters

            • actual: unknown

            Returns boolean

Const equalDates

  • equalDates(expected: unknown): (actual: unknown) => boolean
  • Given and expected value and an actual value, returns true if those values are dates and equal, or false if not.

    example
    const equalToDate = equalDates(new Date(0));

    equalToDate(new Date(0)); // true
    equalToDate(new Date(1)); // false

    Parameters

    • expected: unknown

      Expected value to compare.

    Returns (actual: unknown) => boolean

      • (actual: unknown): boolean
      • Parameters

        • actual: unknown

        Returns boolean

Const equalObjects

  • equalObjects(compare: (expected: unknown) => (actual: unknown) => boolean): (expected: unknown) => (actual: unknown) => boolean
  • Given a compare function, an expected value and an actual value, returns true if those values are equal based on the compare output, or false if not.

    example
    const compare = actual => expected => actual === expected;
    const equalToObject = equalObjects(compare)({ foo: "bar" });

    equalToObject({ foo: "bar" }); // true
    equalToObject({ bar: "baz" }); // false

    Parameters

    • compare: (expected: unknown) => (actual: unknown) => boolean

      Comparison function.

        • (expected: unknown): (actual: unknown) => boolean
        • Parameters

          • expected: unknown

          Returns (actual: unknown) => boolean

            • (actual: unknown): boolean
            • Parameters

              • actual: unknown

              Returns boolean

    Returns (expected: unknown) => (actual: unknown) => boolean

      • (expected: unknown): (actual: unknown) => boolean
      • Parameters

        • expected: unknown

        Returns (actual: unknown) => boolean

          • (actual: unknown): boolean
          • Parameters

            • actual: unknown

            Returns boolean

Const equalRegExp

  • equalRegExp(expected: unknown): (actual: unknown) => boolean
  • Given and expected value and an actual value, returns true if those values are regular expressions and equal, or false if not.

    example
    const equalToRegExp = equalRegExp(new RegExp(/./gu));

    equalToRegExp(new RegExp(/./gu)); // true
    equalToRegExp(new RegExp(/foo/gu)); // false

    Parameters

    • expected: unknown

      Expected value to compare.

    Returns (actual: unknown) => boolean

      • (actual: unknown): boolean
      • Parameters

        • actual: unknown

        Returns boolean

Const equalValues

  • equalValues(expected: unknown): (actual: unknown) => boolean
  • Given and expected value and an actual value, returns true if those values are equal, or false if not.

    example
    const equalTo2 = equalValues(2);

    equalTo2(2); // true
    equalTo2(8); // false

    Parameters

    • expected: unknown

      Expected value to compare.

    Returns (actual: unknown) => boolean

      • (actual: unknown): boolean
      • Parameters

        • actual: unknown

        Returns boolean

Const functionNot

  • functionNot<Argument>(source: (...argument: readonly Argument[]) => boolean): (...argument: readonly Argument[]) => boolean
  • Takes a source function and returns a copy with negated output.

    example
    const isPositive = (value: number) => value >= 0;
    const isNegative = functionNot(isPositive);

    isPositive(1); // true
    isNegative(1); // false

    Type parameters

    • Argument = unknown

      Argument type of the given function

    Parameters

    • source: (...argument: readonly Argument[]) => boolean

      Source function which output will be negated.

        • (...argument: readonly Argument[]): boolean
        • Parameters

          • Rest ...argument: readonly Argument[]

          Returns boolean

    Returns (...argument: readonly Argument[]) => boolean

    Source function with negated output.

      • (...argument: readonly Argument[]): boolean
      • Parameters

        • Rest ...argument: readonly Argument[]

        Returns boolean

Const instanceOf

  • instanceOf<Expected>(constructor: new (..._arguments: readonly never[]) => unknown): <Actual>(entity: Expected | Actual) => entity is Expected
  • Takes a constructor and checks if given entity is an instance of it.

    example
    const isInstanceOfArray = instanceOf(Array)

    isInstanceOfArray([]); // true
    isInstanceOfArray({}); // false

    Type parameters

    • Expected = unknown

      Expected type.

    Parameters

    • constructor: new (..._arguments: readonly never[]) => unknown

      Constructor used to check.

        • new (..._arguments: readonly never[]): unknown
        • Parameters

          • Rest ..._arguments: readonly never[]

          Returns unknown

    Returns <Actual>(entity: Expected | Actual) => entity is Expected

    Curried function with constructor in context.

      • <Actual>(entity: Expected | Actual): entity is Expected
      • Type parameters

        • Actual = unknown

        Parameters

        • entity: Expected | Actual

        Returns entity is Expected

Const isArray

  • isArray<Actual, Item>(entity: Actual | readonly Item[]): entity is readonly Item[]
  • Check if given entity is an instance of Array.

    Type parameters

    • Actual = unknown

      Actual type of the given entity.

    • Item = unknown

      Type of items in given entity.

    Parameters

    • entity: Actual | readonly Item[]

      Entity to check.

    Returns entity is readonly Item[]

Const isBigInt

  • isBigInt<Actual>(entity: BigInt | Actual): entity is BigInt
  • Check if given entity is an instance of BigInt.

    Type parameters

    • Actual = unknown

    Parameters

    • entity: BigInt | Actual

    Returns entity is BigInt

Const isBoolean

  • isBoolean<Actual>(entity: boolean | Actual): entity is boolean
  • Check if given entity is an instance of Boolean.

    Type parameters

    • Actual = unknown

    Parameters

    • entity: boolean | Actual

    Returns entity is boolean

Const isDate

  • isDate<Actual>(entity: Date | Actual): entity is Date
  • Check if given entity is an instance of Date.

    Type parameters

    • Actual = unknown

    Parameters

    • entity: Date | Actual

    Returns entity is Date

Const isFalsy

  • isFalsy<Actual>(entity: Actual | Falsy): entity is Falsy
  • Check if given entity is falsy (0, NaN, "", false, or nullish).

    Type parameters

    • Actual = unknown

      Actual type of the given entity.

    Parameters

    • entity: Actual | Falsy

      Entity to check.

    Returns entity is Falsy

Const isFunction

  • isFunction<Actual>(entity: Function | Actual): entity is Function
  • Check if given entity is an instance of Function.

    Type parameters

    • Actual = unknown

    Parameters

    • entity: Function | Actual

    Returns entity is Function

Const isNull

  • isNull<Actual>(entity: null | Actual): entity is null
  • Check if entity is null.

    Type parameters

    • Actual = unknown

      Actual type of the entity.

    Parameters

    • entity: null | Actual

      Entity to check.

    Returns entity is null

Const isNullish

  • Check if entity is undefined or null.

    Type parameters

    • Actual = unknown

      Actual type of the entity.

    Parameters

    • entity: Nullish | Actual

      Entity to check.

    Returns entity is Nullish

Const isNumber

  • isNumber<Actual>(entity: number | Actual): entity is number
  • Check if entity is an instance of Number.

    Type parameters

    • Actual = unknown

    Parameters

    • entity: number | Actual

    Returns entity is number

Const isObject

  • isObject<Actual>(entity: Actual | Readonly<Record<string | number | symbol, unknown>>): entity is Readonly<Record<string | number | symbol, unknown>>
  • Check if entity is an instance of Object (null is omitted).

    Type parameters

    • Actual = unknown

      Actual type of the entity.

    Parameters

    • entity: Actual | Readonly<Record<string | number | symbol, unknown>>

      Entity to check.

    Returns entity is Readonly<Record<string | number | symbol, unknown>>

Const isPromise

  • isPromise<PromiseValue, Actual>(entity: Actual | Promise<PromiseValue>): entity is Promise<PromiseValue>
  • Check if entity value is an instance of Promise.

    Type parameters

    • PromiseValue = unknown

      Value of the promise.

    • Actual = unknown

      Actual type of the entity.

    Parameters

    • entity: Actual | Promise<PromiseValue>

      Entity to check.

    Returns entity is Promise<PromiseValue>

Const isRegExp

  • isRegExp<Actual>(entity: RegExp | Actual): entity is RegExp
  • Check if entity is an instance of RegExp.

    Type parameters

    • Actual = unknown

    Parameters

    • entity: RegExp | Actual

    Returns entity is RegExp

Const isString

  • isString<Actual>(entity: string | Actual): entity is string
  • Check if entity is an instance of String.

    Type parameters

    • Actual = unknown

    Parameters

    • entity: string | Actual

    Returns entity is string

Const isSymbol

  • isSymbol<Actual>(entity: symbol | Actual): entity is symbol
  • Check if entity is an instance of Symbol.

    Type parameters

    • Actual = unknown

    Parameters

    • entity: symbol | Actual

    Returns entity is symbol

Const isTruthy

  • isTruthy<Actual>(entity: Actual): entity is Truthy<Actual>
  • Check if given entity is truthy (so not 0, NaN, "", false, or nullish).

    Type parameters

    • Actual = unknown

      Actual type of the given entity.

    Parameters

    • entity: Actual

      Entity to check.

    Returns entity is Truthy<Actual>

Const isType

  • isType<Expected>(type: TypeOf): <Actual>(entity: Expected | Actual) => entity is Expected
  • Takes a type string and checks if given entity is of that typeof.

    example
    const isTypeString = typeOf<string>("string");

    isTypeString("value"); // true
    isTypeString(1); // false

    Type parameters

    • Expected = unknown

      Expected type.

    Parameters

    • type: TypeOf

      Type to check (from typeof).

    Returns <Actual>(entity: Expected | Actual) => entity is Expected

    Curried function with type in context.

      • <Actual>(entity: Expected | Actual): entity is Expected
      • Type parameters

        • Actual = unknown

        Parameters

        • entity: Expected | Actual

        Returns entity is Expected

Const isUndefined

  • isUndefined<Actual>(entity: undefined | Actual): entity is undefined
  • Check if given entity is an instance of undefined.

    Type parameters

    • Actual = unknown

    Parameters

    • entity: undefined | Actual

    Returns entity is undefined

Const jsonParsePromise

  • jsonParsePromise<Output>(text: string): Promise<Output>
  • Takes a JSON string and parses it safely using a Promise.

    example
    jsonParsePromise("invalid")
    .then(console.log)
    .catch(console.error); // error
    jsonParsePromise("{}")
    .then(console.log)
    .catch(console.error); // log

    Type parameters

    • Output = unknown

      Expected type if the parse is successful.

    Parameters

    • text: string

      String value to parse.

    Returns Promise<Output>

    Promise which resolves to an object of type Output.

Const jsonStringifyPromise

  • jsonStringifyPromise<Source>(source: Source): Promise<string>
  • Takes an object and stringify to JSON safely using a Promise.

    example
    jsonStringifyPromise(circular)
    .then(console.log)
    .catch(console.error); // error
    jsonStringifyPromise({})
    .then(console.log)
    .catch(console.error); // log

    Type parameters

    • Source

      Type of source object.

    Parameters

    • source: Source

      Source object.

    Returns Promise<string>

    Promise which resolves to a string or rejects with errors.

Const numberAdd

  • numberAdd(addend2: number): (addend1: number) => number
  • Takes a addend1 and addend2 and returns the precise addition of those values (uses DecimalTuple internally).

    example
    const addPoint1 = numberAdd(0.1);

    addPoint1(0.2); // 0.3

    Parameters

    • addend2: number

      Second addend of the addition.

    Returns (addend1: number) => number

    Curried function with addend1 set in context.

      • (addend1: number): number
      • Parameters

        • addend1: number

        Returns number

Const numberBetween

  • numberBetween(minimum: number): (maximum: number) => (source: number) => boolean
  • Takes a minimum and maximum and returns a boolean if source number is between them.

    example
    const between0 = numberBetween(0);
    const between0And10 = between0(10);

    between0And10(5); // 5 because is inside the range (0-10).
    between0And10(-1); // 0 because it was lower than the minimum (0).
    between0And10(11); // 10 because it was higher than the maximum (10).

    Parameters

    • minimum: number

      Minimum boundary.

    Returns (maximum: number) => (source: number) => boolean

    Curried function with minimum set in context.

      • (maximum: number): (source: number) => boolean
      • Parameters

        • maximum: number

        Returns (source: number) => boolean

          • (source: number): boolean
          • Parameters

            • source: number

            Returns boolean

            Curried function with minimum and maximum set in context.

Const numberBoundary

  • numberBoundary(minimum: number): (maximum: number) => (source: number) => number
  • Takes a minimum and maximum and applies them to a given source number.

    example
    const boundaryFrom0 = numberBoundary(0);
    const boundaryFrom0To10 = boundaryFrom0(10);

    boundaryFrom0To10(5); // 5 because is inside the boundary (0-10)
    boundaryFrom0To10(-1); // 0 because it was lower than the minimum (0).
    boundaryFrom0To10(11); // 10 because it was higher than the maximum (10).

    Parameters

    • minimum: number

      Minimum boundary.

    Returns (maximum: number) => (source: number) => number

    Curried function with minimum set in context.

      • (maximum: number): (source: number) => number
      • Parameters

        • maximum: number

        Returns (source: number) => number

          • (source: number): number
          • Parameters

            • source: number

            Returns number

            Curried function with minimum and maximum set in context.

Const numberDivide

  • numberDivide(divisor: number): (dividend: number) => number
  • Takes a divisor and dividend and returns the precise division of those values (uses DecimalTuple internally).

    example
    const half = numberDivide(2);

    half(5); // 2.5

    Parameters

    • divisor: number

      Divisor of the division.

    Returns (dividend: number) => number

    Curried function with divisor set in context.

      • (dividend: number): number
      • Parameters

        • dividend: number

        Returns number

Const numberMultiply

  • numberMultiply(multiplier: number): (multiplicand: number) => number
  • Takes a multiplier and multiplicand and returns the precise multiplication of those factors (uses DecimalTuple internally).

    example
    const double = numberMultiply(2);

    double(0.5); // 1

    Parameters

    • multiplier: number

      Multiplier of the multiplication.

    Returns (multiplicand: number) => number

    Curried function with multiplier set in context.

      • (multiplicand: number): number
      • Parameters

        • multiplicand: number

        Returns number

Const numberSubtract

  • numberSubtract(subtrahend: number): (minuend: number) => number
  • Takes a subtrahend and minuend and returns the precise subtraction of those values (uses DecimalTuple internally).

    example
    const subtractPoint1 = numberSubtract(0.1);

    subtractPoint1(1); // 0.9

    Parameters

    • subtrahend: number

      Subtrahend of the subtraction.

    Returns (minuend: number) => number

    Curried function with subtrahend set in context.

      • (minuend: number): number
      • Parameters

        • minuend: number

        Returns number

Const numberToDecimalTuple

  • Takes a source number and returns a DecimalTuple [coefficient, exponent].

    example
    numberToDecimalTuple(Math.PI); // [3141592653589793, -15]
    numberToDecimalTuple(5000); // [5, 3]

    Parameters

    • source: number

      Source number to be parsed into a DecimalTuple.

    Returns DecimalTuple

    DecimalTuple [coefficient, exponent].

Const numberToString

  • numberToString(radix: Radix): (source: number) => string
  • Wrapper of Number.prototype.toString with mandatory radix.

    example
    numberToString(10)(10); // "10"
    numberToString(16)(16); // "10"
    numberToString(2)(2); // "10"

    Parameters

    • radix: Radix

      A value between 2 and 36 that specifies the base of the number.

    Returns (source: number) => string

    Curried function with radix in context.

      • (source: number): string
      • Parameters

        • source: number

        Returns string

Const numberToStringDecimal

  • numberToStringDecimal(source: number): string
  • Parses a number to a decimal string.

    example
    numberToStringDecimal(10); // "10"
    numberToStringDecimal(0x10); // "16"

    Parameters

    • source: number

      Source number to be stringified

    Returns string

    Stringified number.

Const numberToStringHexadecimal

  • numberToStringHexadecimal(source: number): string
  • Parses a number to a hexadecimal string.

    example
    numberToStringHexadecimal(16); // "10"
    numberToStringHexadecimal(0x10); // "10"

    Parameters

    • source: number

      Source number to be stringified.

    Returns string

    Stringified number.

Const objectEntries

  • objectEntries<Source>(source: Source): Entries<Source>
  • Takes a source object and returns an entries array.

    example
    objectEntries({ key: "value" }); // [["key", "value"]]
    objectEntries({ foo: "bar", number: 1 }); // [["foo", "bar"], ["number", 1]]

    Type parameters

    • Source

      Source object type.

    Parameters

    • source: Source

      Source object.

    Returns Entries<Source>

    Array of entries of the given source object.

Const objectFromEntries

  • objectFromEntries<Expected>(source: Entries<Expected>): Expected
  • Takes a source entries array and returns an object.

    example
    objectFromEntries([["key", "value"]]); // { key: "value" }
    objectFromEntries([
    ["foo", "bar"],
    ["number", 1]
    ]); // { foo: "bar", number: 1 }

    Type parameters

    • Expected

      Expected object type.

    Parameters

    • source: Entries<Expected>

      Source entries array.

    Returns Expected

    Object resulting of given entries.

Const objectGetProperty

  • objectGetProperty<Property>(property: Property): <Source>(source: Source) => Source[Property]
  • Get value of given property for given source object.

    example
    const getFoo = objectGet("foo");
    getFoo({ foo: 1 }); // 1
    getFoo({ bar: 1 }); // undefined

    Type parameters

    • Property: string | number | symbol

      Type of the property.

    Parameters

    • property: Property

      Name of property.

    Returns <Source>(source: Source) => Source[Property]

    Curried function with property in context.

      • <Source>(source: Source): Source[Property]
      • Type parameters

        • Source: Record<string | number | symbol, unknown>

        Parameters

        • source: Source

        Returns Source[Property]

Const objectMap

  • objectMap<Input, Output>(mapper: Mapper<Entry<Input>, Entry<Output>>): (source: Input) => Output
  • Takes a mapper function and applies it to given source object using objectEntries and objectFromEntries.

    example
    const mapDouble = objectMap(([key, value]) => [key, value * 2]);

    mapDouble({ a: 0, b: 1, c: 2, d: 3 }); // { a: 0, b: 2, c: 4, d: 6 }

    Type parameters

    • Input

      Type of the input object.

    • Output = Input

      Type of the output object.

    Parameters

    Returns (source: Input) => Output

    Curried function with mapper in context.

      • (source: Input): Output
      • Parameters

        • source: Input

        Returns Output

Const objectSetProperty

  • objectSetProperty<Property>(property: Property): <Value>(value: Value) => <Source>(source: Source) => Omit<Source, Property> & { readonly [ P in string | number | symbol]: Value }
  • Set value of given property in given source object.

    example
    const setFoo = objectSet("foo")("bar");
    setFoo({ foo: 1 }); // { foo: "bar" }
    setFoo({ bar: 1 }); // { bar: 1, foo: "bar" }

    Type parameters

    • Property: string | number | symbol

      Type of the property.

    Parameters

    • property: Property

      Name of property.

    Returns <Value>(value: Value) => <Source>(source: Source) => Omit<Source, Property> & { readonly [ P in string | number | symbol]: Value }

    Curried function with property in context.

      • <Value>(value: Value): <Source>(source: Source) => Omit<Source, Property> & { readonly [ P in string | number | symbol]: Value }
      • Type parameters

        • Value

        Parameters

        • value: Value

        Returns <Source>(source: Source) => Omit<Source, Property> & { readonly [ P in string | number | symbol]: Value }

          • <Source>(source: Source): Omit<Source, Property> & { readonly [ P in string | number | symbol]: Value }
          • Type parameters

            • Source: Record<string | number | symbol, unknown>

            Parameters

            • source: Source

            Returns Omit<Source, Property> & { readonly [ P in string | number | symbol]: Value }

Const stringMapReplace

  • stringMapReplace(replaceMap: Readonly<Record<string, string | number>>): (source: string) => string
  • Takes StringReplaceMap object and runs a replaceAll of given object keys with it's values in the source string.

    example
    const leet = stringMapReplace({
    a: 4,
    e: 3,
    i: 1,
    o: 0
    });

    leet("hello there!"); // "h3ll0 th3r3!"

    Parameters

    • replaceMap: Readonly<Record<string, string | number>>

      Replace map for the string.

    Returns (source: string) => string

    Curried function with replaceMap in context.

      • (source: string): string
      • Parameters

        • source: string

        Returns string

Const stringMatches

  • stringMatches(__namedParameters: Readonly<RegExp>): (source: string) => RegExpMatchArray
  • Takes a regular expression and a string and returns a RegExpMatchArray.

    example
    const matchesNumbers = stringTest(/\d/gu);
    onlyHasNumbers("1234"); // ["1", "2", "3", "4"]
    onlyHasNumbers("nope"); // []

    Parameters

    • __namedParameters: Readonly<RegExp>

    Returns (source: string) => RegExpMatchArray

    Curried function with regularExpression in context.

      • (source: string): RegExpMatchArray
      • Parameters

        • source: string

        Returns RegExpMatchArray

Const stringParseDecimal

  • stringParseDecimal(source: string): number
  • Parses a string to a decimal value.

    example
    stringParseDecimal("10"); // 10
    stringParseDecimal("0x10"); // 10

    Parameters

    • source: string

      Source string to be parsed.

    Returns number

    Parsed string.

Const stringParseHexadecimal

  • stringParseHexadecimal(source: string): number
  • Parses a string to a hexadecimal value.

    example
    stringParseHexadecimal("10"); // 16 (0x10)
    stringParseHexadecimal("0x10"); // 16 (0x10)

    Parameters

    • source: string

      Source string to be parsed.

    Returns number

    Parsed string.

Const stringParseNumber

  • stringParseNumber(radix: Radix): (source: string) => number
  • Wrapper of parseInt with mandatory radix.

    example
    stringParseNumber(10)("10"); // 10
    stringParseNumber(16)("10"); // 16 (0x10)
    stringParseNumber(2)("10"); // 2

    Parameters

    • radix: Radix

      A value between 2 and 36 that specifies the base of the number.

    Returns (source: string) => number

    Curried function with radix in context.

      • (source: string): number
      • Parameters

        • source: string

        Returns number

Const stringReverse

  • stringReverse(source: string): string
  • Takes a source string and returns that string reversed.

    example
    const oof = stringReverse("foo"); // off === "oof"
    const rab = stringReverse("bar"); // rab === "rab"

    Parameters

    • source: string

      String to be reversed.

    Returns string

    Reversed string.

Const stringTest

  • stringTest(__namedParameters: Readonly<RegExp>): (source: string) => boolean
  • Takes a regular expression and a string and returns true if it matches.

    example
    const onlyHasNumbers = stringTest(/^\d+$/gu);
    onlyHasNumbers("1234"); // true
    onlyHasNumbers("nope"); // false

    Parameters

    • __namedParameters: Readonly<RegExp>

    Returns (source: string) => boolean

    Curried function with regularExpression in context.

      • (source: string): boolean
      • Parameters

        • source: string

        Returns boolean