Options
All
  • Public
  • Public/Protected
  • All
Menu

@vangware/utils

Index

Type aliases

ArrayOrIterable

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

ArrayLike or Iterable alias.

Type parameters

  • Item

    Type of items in the ArrayLike or Iterable.

DecimalTuple

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

2-Tuple to represent decimals [coefficient, exponent]

Entries

Entries<Source>: readonly Entry<Source>[]

Array of Entries (Entry type).

Type parameters

  • Source

    Source object to which the entities belong to.

Entry

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

Entity tuple [key, object[key]].

Type parameters

  • Source

    Source object to which the entity belongs to.

Falsy

Falsy: false | 0 | "" | Nullish

Types that evaluates to false in JS.

FilterTuple

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

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

Type parameters

  • Item

    Type of the items being filtered.

  • Filtered: Item = Item

    Type of the matching items.

Filterer

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

Filterer function.

Type parameters

  • Item

    Type of the items in the source array.

  • Filtered: Item

    Type of filtered items.

Grouped

Grouped<Item>: ImmutableRecord<readonly Item[], string>

Object with the following shape:

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

Type parameters

  • Item

    Type of the items in the source array.

Grouper

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

Grouper function.

param

Item of the source array.

returns

Group name.

Type parameters

  • Item

    Type of the items in the source array.

Type declaration

    • (item: Item): string | number
    • Parameters

      • item: Item

      Returns string | number

GuardedFilterer

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

Guarded filterer function.

Type parameters

  • Item

    Type of the items in the source array.

  • Filtered: Item

    Type of filtered items.

Type declaration

    • (item: Item): item is Filtered
    • Parameters

      • item: Item

      Returns item is Filtered

ImmutableRecord

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

Readonly Record wrapper.

Type parameters

  • Value = unknown

    Possible values of the given Record.

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

    Key type of given Record.

Mapper

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

Mapper function.

param

Item of the source array.

returns

Mapped value.

Type parameters

  • Item

    Type of the items in the source array.

  • Output

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

Type declaration

    • (item: Item): Output
    • Parameters

      • item: Item

      Returns Output

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.

Type parameters

  • Type

    Type to apply exclusion on.

  • Exclusion

    Exclusion object.

Reducer

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

Reducer function.

param

Reducer accumulator.

returns

Mapper with accumulator context.

Type parameters

  • Item

    Type of the items in the source array.

  • Output = readonly Item[]

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

Type declaration

    • (accumulator: Output): Mapper<Item, Output>
    • Parameters

      • accumulator: Output

      Returns Mapper<Item, Output>

Sorter

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

Sorter function.

param

Item following the current one.

returns

Mapped value.

Type parameters

  • Item

Type declaration

    • (next: Item): Mapper<Item, number>
    • Parameters

      • next: Item

      Returns Mapper<Item, number>

StringReplaceMap

StringReplaceMap: ImmutableRecord<string | number, 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).

Type parameters

  • Actual

    Actual type (if not truthy).

TypeOf

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

Possible types returned by typeof.

UnguardedFilterer

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

Unguarded filter function.

Type parameters

  • Item

    Type of the items in the source array.

Type declaration

    • (item: Item): boolean
    • Parameters

      • item: Item

      Returns boolean

Variables

Const arrayInsertFirst

arrayInsertFirst: (Anonymous function) = arrayInsert(0)

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"]
returns

Curried function with item and index in context.

Const arrayInsertLast

arrayInsertLast: (Anonymous function) = arrayInsert(Infinity)

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"]
returns

Curried function with item and index in context.

Const arrayReplaceFirst

arrayReplaceFirst: (Anonymous function) = arrayReplace(0)

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"]
returns

Curried function with item and index in context.

Const arrayReplaceLast

arrayReplaceLast: (Anonymous function) = arrayReplace(Infinity)

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"]
returns

Curried function with item and index in context.

Const arraySliceTo

arraySliceTo: (Anonymous function) = arraySlice(0)

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]
param

Slice end.

returns

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

Const isBigInt

isBigInt: (Anonymous function) = isType<BigInt>("bigint")

Check if given entity is an instance of BigInt.

Const isBoolean

isBoolean: (Anonymous function) = isType<boolean>("boolean")

Check if given entity is an instance of Boolean.

Const isDate

isDate: (Anonymous function) = instanceOf<Date>(Date)

Check if given entity is an instance of Date.

Const isFunction

isFunction: (Anonymous function) = isType<Function>("function")

Check if given entity is an instance of Function.

Const isNumber

isNumber: (Anonymous function) = isType<number>("number")

Check if entity is an instance of Number.

Const isRegExp

isRegExp: (Anonymous function) = instanceOf<RegExp>(RegExp)

Check if entity is an instance of RegExp.

Const isString

isString: (Anonymous function) = isType<string>("string")

Check if entity is an instance of String.

Const isSymbol

isSymbol: (Anonymous function) = isType<symbol>("symbol")

Check if entity is an instance of Symbol.

Const isUndefined

isUndefined: (Anonymous function) = isType<undefined>("undefined")

Check if given entity is an instance of undefined.

Const stringParseDecimal

stringParseDecimal: (Anonymous function) = stringParseNumber(10)

Parses a string to a decimal value.

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

Source string to be parsed.

returns

Parsed string.

Const stringParseHexadecimal

stringParseHexadecimal: (Anonymous function) = stringParseNumber(16)

Parses a string to a hexadecimal value.

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

Source string to be parsed.

returns

Parsed string.

Functions

Const arrayEvery

  • arrayEvery<Item, Predicated>(predicate: Filterer<Item, Predicated>): (Anonymous function)
  • 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: Item

      Type of predicated items.

    Parameters

    • predicate: Filterer<Item, Predicated>

      Function predicate to test every item.

    Returns (Anonymous function)

    Curried function with predicate in context.

Const arrayFilterIn

  • arrayFilterIn<Item, Filtered>(filterer: Filterer<Item, Filtered>): (Anonymous function)
  • 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: Item

      Type of filtered items.

    Parameters

    • filterer: Filterer<Item, Filtered>

      Filterer function.

    Returns (Anonymous function)

    Curried function with filter set in context.

Const arrayFilterOut

  • arrayFilterOut<Item, Filtered>(filterer: Filterer<Item, Filtered>): (Anonymous function)
  • 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: Item

      Type of filtered items.

    Parameters

    • filterer: Filterer<Item, Filtered>

      Filterer out function.

    Returns (Anonymous function)

    Curried function with filter set in context.

Const arrayFilterTuple

  • arrayFilterTuple<Item, Filtered>(filterer: Filterer<Item, Filtered>): (Anonymous function)
  • 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: Item

      Type of filtered items.

    Parameters

    • filterer: Filterer<Item, Filtered>

      Filterer function.

    Returns (Anonymous function)

    Curried function with filter in context.

Const arrayFlat

  • arrayFlat<Depth>(depth: Depth): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with depth in context.

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 ReadonlyArray<Item>

    Frozen array made with given ArrayLike or Iterable.

Const arrayGroup

  • arrayGroup<Item>(grouper: Grouper<Item>): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with grouper in context.

Const arrayInsert

  • arrayInsert(index: number): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with item in context.

Const arrayJoin

  • arrayJoin(separator: string): (Anonymous function)
  • Curried wrapper for Array.prototype.join.

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

    Parameters

    • separator: string

      Value separator.

    Returns (Anonymous function)

    Curried function with separator in context.

Const arrayMap

  • arrayMap<Item, Output>(mapper: Mapper<Item, Output>): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with mapper in context.

Const arrayReduce

  • arrayReduce<Item, Output>(reducer: Reducer<Item, Output>): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with reducer in context.

Const arrayReplace

  • arrayReplace(index: number): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with 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): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with start in context.

Const arraySliceFrom

  • arraySliceFrom(start: number): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with start in context.

Const arraySome

  • arraySome<Item, Predicated>(predicate: Filterer<Item, Predicated>): (Anonymous function)
  • 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: Item

      Type of predicated items.

    Parameters

    • predicate: Filterer<Item, Predicated>

      Function predicate to test until some item of the type.

    Returns (Anonymous function)

    Curried function with predicate in context.

Const arraySort

  • arraySort<Item>(sorter: Sorter<Item>): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with sorter in context.

Const decimalTupleAdd

  • decimalTupleAdd(addend2: DecimalTuple): (Anonymous function)
  • Takes a addend1 and addend2 and returns the addition of those values.

    example
    const addPoint1 = decimalTupleAdd([1, -1]);
    
    addPoint1([2, -1]); // [3, -1] -> 0.3

    Parameters

    • addend2: DecimalTuple

      Second addend DecimalTuple of the addition.

    Returns (Anonymous function)

    Curried function with addend1 set in context.

Const decimalTupleDivide

  • decimalTupleDivide(__namedParameters: [number, number]): (Anonymous function)
  • Takes a divisor and dividend and returns the division of those values.

    example
    const half = decimalTupleDivide([2, 0]);
    
    half([5, 0]); // [25, -1] -> 2.5

    Parameters

    • __namedParameters: [number, number]

    Returns (Anonymous function)

    Curried function with divisor set in context.

Const decimalTupleMultiply

  • decimalTupleMultiply(__namedParameters: [number, number]): (Anonymous function)
  • Takes a multiplier and multiplicand and returns the multiplication result of those factors.

    example
    const double = decimalTupleMultiply([2, 0]);
    
    double([5, -1]); // [1, 0] -> 1

    Parameters

    • __namedParameters: [number, number]

    Returns (Anonymous function)

    Curried function with multiplier set in context.

Const decimalTupleSubtract

  • decimalTupleSubtract(__namedParameters: [number, number]): (Anonymous function)
  • Takes a subtrahend and minuend and returns the subtraction of those values.

    example
    const subtractPoint1 = decimalTupleSubtract([1, -1]);
    
    subtractPoint1([1, 0]); // [9, -1] -> 0.9

    Parameters

    • __namedParameters: [number, number]

    Returns (Anonymous function)

    Curried function with subtrahend set in context.

Const decimalTupleToNumber

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

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

    Parameters

    • __namedParameters: [number, number]

    Returns number

    Number generated from the source coefficient and exponent.

Const equal

  • equal(expected: unknown): (Anonymous function)
  • 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 (Anonymous function)

Const equalArrays

  • equalArrays(compare: (expected: unknown) => (actual: unknown) => boolean): (Anonymous function)
  • 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 (Anonymous function)

Const equalDates

  • equalDates(expected: unknown): (Anonymous function)
  • 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 (Anonymous function)

Const equalObjects

  • equalObjects(compare: (expected: unknown) => (actual: unknown) => boolean): (Anonymous function)
  • 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 (Anonymous function)

Const equalRegExp

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

    Parameters

    • expected: unknown

      Expected value to compare.

    Returns (Anonymous function)

Const equalValues

  • equalValues(expected: unknown): (Anonymous function)
  • 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 (Anonymous function)

Const functionNot

  • functionNot<Argument>(source: (...argument: readonly Argument[]) => boolean): (Anonymous function)
  • 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 (Anonymous function)

    Source function with negated output.

Const instanceOf

  • instanceOf<Expected>(constructor: Function): (Anonymous function)
  • 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: Function

      Constructor used to check.

    Returns (Anonymous function)

    Curried function with constructor in context.

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 isFalsy

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

    Type parameters

    • Actual

      Actual type of the given entity.

    Parameters

    • entity: Actual | Falsy

      Entity to check.

    Returns entity is Falsy

Const isNull

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

    Type parameters

    • Actual = unknown

      Actual type of the entity.

    Parameters

    • entity: Actual | null

      Entity to check.

    Returns entity is null

Const isNullish

  • isNullish<Actual>(entity: Actual | Nullish): entity is Nullish
  • Check if entity is undefined or null.

    Type parameters

    • Actual

      Actual type of the entity.

    Parameters

    • entity: Actual | Nullish

      Entity to check.

    Returns entity is Nullish

Const isObject

  • isObject<Actual>(entity: Actual | ImmutableRecord): entity is ImmutableRecord
  • Check if entity is an instance of Object (null is omitted).

    Type parameters

    • Actual

      Actual type of the entity.

    Parameters

    Returns entity is ImmutableRecord

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

      Actual type of the given entity.

    Parameters

    • entity: Actual

      Entity to check.

    Returns entity is Truthy<Actual>

Const isType

  • isType<Expected>(type: TypeOf): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with type in context.

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): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with addend1 set in context.

Const numberBetween

  • numberBetween(minimum: number): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with minimum set in context.

Const numberBoundary

  • numberBoundary(minimum: number): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with minimum set in context.

Const numberDivide

  • numberDivide(divisor: number): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with divisor set in context.

Const numberFloatToDecimalTuple

  • Takes a source float number and returns a DecimalTuple.

    example
    numberFloatToDecimalTuple(15); // [15, 0]
    numberFloatToDecimalTuple(0.2); // [2, -1]

    Parameters

    • source: number

      Source number to be parsed into a DecimalTuple.

    Returns DecimalTuple

    DecimalTuple [coefficient, exponent].

Const numberMultiply

  • numberMultiply(multiplier: number): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with multiplier set in context.

Const numberSubtract

  • numberSubtract(subtrahend: number): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with subtrahend set in context.

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 numberWithExponentToDecimalTuple

  • numberWithExponentToDecimalTuple(source: number): DecimalTuple
  • Takes a source number with exponent and returns a DecimalTuple.

    example
    numberWithExponentToDecimalTuple(15e20); // [15, 20]
    numberWithExponentToDecimalTuple(1.5e21); // [15, 20]

    Parameters

    • source: number

      Source number to be parsed into a DecimalTuple.

    Returns DecimalTuple

    DecimalTuple [coefficient, exponent].

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 objectMap

  • objectMap<Input, Output>(mapper: Mapper<Entry<Input>, Entry<Output>>): (Anonymous function)
  • 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 (Anonymous function)

    Curried function with mapper in context.

Const stringMapReplace

  • 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

    Returns (Anonymous function)

    Curried function with replaceMap in context.

Const stringMatches

  • stringMatches(__namedParameters: { flags: string; regExp: string }): (Anonymous function)
  • 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: { flags: string; regExp: string }
      • flags: string
      • regExp: string

    Returns (Anonymous function)

    Curried function with regularExpression in context.

Const stringParseNumber

  • stringParseNumber(radix: number): (Anonymous function)
  • Wrapper of parseInt with mandatory radix.

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

    Parameters

    • radix: number

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

    Returns (Anonymous function)

    Curried function with radix in context.

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: { flags: string; regExp: string }): (Anonymous function)
  • 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: { flags: string; regExp: string }
      • flags: string
      • regExp: string

    Returns (Anonymous function)

    Curried function with regularExpression in context.

Generated using TypeDoc