Options
All
  • Public
  • Public/Protected
  • All
Menu

@vangware/micro

Index

Type aliases

ArrayOrIterable

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

Readonly ArrayLike or Iterable alias.

Type parameters

  • Item

    Type of items in the ArrayLike or Iterable.

Entries

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

Array of Entries (Entry type).

Type parameters

  • Source

    Source object to which the entities belong to.

Entry

Entry<Source>: Tuple<string, Readonly<Source[keyof Source]>>

Entity tuple [key, object[key]].

Type parameters

  • Source

    Source object to which the entity belongs to.

Filterer

Filterer<Item>: Mapper<Item, boolean>

Mapper that only returns boolean (used by filtering functions).

Type parameters

  • Item

    Type of the items in the source array.

Grouped

Grouped<Item>: {}

Object with the following shape:

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

Type parameters

  • Item

    Type of the items in the source array.

Type declaration

  • [group: string]: keyof Item[]

Grouper

Grouper<Item>: (item: Readonly<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: Readonly<Item>): string | number
    • Parameters

      • item: Readonly<Item>

      Returns string | number

Mapper

Mapper<Item, Output>: (item: Readonly<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: Readonly<Item>): Output
    • Parameters

      • item: Readonly<Item>

      Returns Output

Nullish

Nullish: null | undefined

Union of null and undefined.

Reducer

Reducer<Item, Output>: (accumulator: Readonly<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

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

Type declaration

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

      • accumulator: Readonly<Output>

      Returns Mapper<Item, Output>

StringReplaceMap

StringReplaceMap: {}

Object with the following shape:

{
    [searchString]: "replacingString"
}

Type declaration

  • [match: string]: string | number

Tuple

Tuple<Item1, Item2>: keyof [Item1, Item2]

2-Tuple [Item1, Item2]

Type parameters

  • Item1

    First item type.

  • Item2

    Second item item type (Same as Item1 by default).

TypeOf

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

Possible types returned by typeof.

Variables

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.

Functions

Const between

  • between(minimum: number): (Anonymous function)
  • Takes a minimum and maximum and returns a boolean if source number is between them.

    example
    const between0 = between(0);
    const between0And10 = between0(10);
    
    between0And10(5); // 5 because is inside the between10)
    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 boundary

  • boundary(minimum: number): (Anonymous function)
  • Takes a minimum and maximum and applies them to a given source number.

    example
    const boundaryFrom0 = boundary(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 entries

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

    example
    entries({ key: "value" }); // [["key", "value"]]
    entries({ 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 filterIn

  • filterIn<Item>(filterer: Filterer<Item>): (Anonymous function)
  • Takes a positive filterer and applies it to given source array.

    example
    const filterInEven = filterIn<number>(item => item % 2 === 0);
    const filterOutEmpty = filterIn<string>(item => item !== "");
    
    filterInEven([0, 1, 2, 3]); // [0, 2]
    filterOutEmpty(["hello", "", "", "world"]); // ["hello", "world"]

    Type parameters

    • Item

      Type of items in source array.

    Parameters

    • filterer: Filterer<Item>

      Filterer function.

    Returns (Anonymous function)

    Curried function with filter set in context.

Const filterOut

  • filterOut<Item>(filterer: Filterer<Item>): (Anonymous function)
  • Takes a negative filterer and applies it to given source array.

    example
    const filterOutEven = filterOut<number>(item => item % 2 === 0);
    const filterOutEmpty = filterOut<string>(item => item === "");
    
    filterOutEven([0, 1, 2, 3]); // [1, 3]
    filterOutEmpty(["hello", "", "", "world"]); // ["hello", "world"]

    Type parameters

    • Item

      Type of items in source array.

    Parameters

    • filterer: Filterer<Item>

      Filterer out function.

    Returns (Anonymous function)

    Curried function with filter set in context.

Const filterTuple

  • filterTuple<Item>(filterer: Filterer<Item>): (Anonymous function)
  • Takes a filterer and applies it to a source array returning a [matching, nonMatching] tuple.

    example
    const filterTupleEvenOdd = filterTuple<number>(item => item % 2 === 0);
    
    filterTupleEventOdd([0, 1, 2, 3]); // [[0, 2], [1, 3]]

    Type parameters

    • Item

      Type of items in source array.

    Parameters

    • filterer: Filterer<Item>

      Filterer function.

    Returns (Anonymous function)

    Curried function with filter in context.

Const from

  • Given an ArrayLike or Iterable, return an array.

    example
    from("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 keyof Item[]

    Frozen array made with given ArrayLike or Iterable.

Const fromEntries

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

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

    Type parameters

    • Expected

      Expected object type.

    Parameters

    • source: Entries<Expected>

      Source entries array.

    Returns {}

    Object resulting of given entries.

Const group

  • group<Item>(grouper: Grouper<Item>): (Anonymous function)
  • Takes grouper and applies it to given source array.

    example
    const evenOddGroup = group<number>(
        item => item % 2 === 0 "even" : "odd"
    );
    
    evenOddGroup([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 insert

  • insert<Item>(item: Item): (Anonymous function)
  • Takes an item and an index and makes a copy of given source array with that new item in the given index.

    example
    const insertItem = insert("new");
    const insertItemLast = insertItem(Infinity);
    const insertItemFirst = insertItem(0);
    const insertItemSecond = insertItem(1);
    
    insertItemLast([0, 1, 2, 3]); // [0, 1, 2, 3, "new"]
    insertItemFirst([0, 1, 2, 3]); // ["new", 0, 1, 2, 3]
    insertItemSecond([0, 1, 2, 3]); // [0, "new", 1, 2, 3]

    Type parameters

    • Item

      Type of items to insert in source array.

    Parameters

    • item: Item

      Item to be inserted.

    Returns (Anonymous function)

    Curried function with item in context.

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

      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 | keyof Item[]): entity is keyof Item[]
  • Check if given entity is an instance of Array.

    Type parameters

    • Actual

      Actual type of the given entity.

    • Item

      Type of items in given entity.

    Parameters

    • entity: Actual | keyof Item[]

      Entity to check.

    Returns entity is keyof Item[]

Const isNull

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

    Type parameters

    • Actual

      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 | object): entity is object
  • Check if entity is an instance of Object (null is omitted).

    Type parameters

    • Actual

      Actual type of the entity.

    Parameters

    • entity: Actual | object

      Entity to check.

    Returns entity is object

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

      Value of the promise.

    • Actual

      Actual type of the entity.

    Parameters

    • entity: Actual | Promise<PromiseValue>

      Entity to check.

    Returns entity is Promise<PromiseValue>

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

      Expected type.

    Parameters

    • type: TypeOf

      Type to check (from typeof).

    Returns (Anonymous function)

    Curried function with type in context.

Const map

  • map<Item, Output>(mapper: Mapper<Item, Output>): (Anonymous function)
  • Takes a mapper function and applies it to given source array.

    example
    const mapDouble = map<number>(item => item * 2);
    
    mapDouble([0, 1, 2, 3]); // [0, 2, 4, 6]

    Type parameters

    • Item

      Type of the items in the source array.

    • Output

      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 mapReplace

  • Takes StringReplaceMap object and makes a regex map replace of given 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 not

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

    example
    const isPositive = (value: number) => value >= 0;
    const isNegative = not(isPositive);
    
    isPositive(1); // true
    isNegative(1); // false

    Type parameters

    • Argument

      Argument type of the given function

    Parameters

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

      Source function which output will be negated.

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

          • Rest ...argument: keyof Argument[]

          Returns boolean

    Returns (Anonymous function)

    Source function with negated output.

Const parsePromise

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

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

    Type parameters

    • Output

      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 push

  • push<Item>(item: Item): (Anonymous function)
  • Takes an item and pushes it into the end of given source array.

    example
    const pushFour = push(4);
    
    pushFour([0, 1, 2, 3]); // [0, 1, 2, 3, 4]
    pushFour(["value"]); // ["value", 4]

    Type parameters

    • Item

      Type of items to be inserted into source array.

    Parameters

    • item: Item

      Item to be inserted.

    Returns (Anonymous function)

    Curried function with item and index in context.

Const reduce

  • reduce<Item, Output>(reducer: Reducer<Item, Output>): (Anonymous function)
  • Takes a reducer and an initialValue and applies it to source array.

    example
    const sum = reduce<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

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

    Parameters

    Returns (Anonymous function)

    Curried function with reducer in context.

Const replace

  • replace<Item>(item: Item): (Anonymous function)
  • Takes an item and an index and replaces the source array item in that index with the taken item.

    example
    const replaceWithReplacement = replace("replacement");
    const replaceItemLast = replaceWithReplacement(Infinity);
    const replaceItemFirst = replaceWithReplacement(0);
    const replaceItemSecond = replaceWithReplacement(1);
    
    replaceItemLast([0, 1, 2, 3]); // [0, 1, 2, "replacement"]
    replaceItemFirst([0, 1, 2, 3]); // ["replacement", 1, 2, 3]
    replaceItemSecond([0, 1, 2, 3]); // [0, "replacement", 2, 3]

    Type parameters

    • Item

      Type of the item to be inserted.

    Parameters

    • item: Item

      Replacing item.

    Returns (Anonymous function)

    Curried function with item in context.

Const slice

  • slice(start: number): (Anonymous function)
  • Takes a start and and end and applies a slice to given source array.

    example
    const sliceFrom1 = slice(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 stringifyPromise

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

    example
    stringifyPromise(circular).then(console.log).catch(console.error); // error
    stringifyPromise({}).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 unshift

  • unshift<Item>(item: Item): (Anonymous function)
  • Takes an item and pushes it into the beginning of given source array.

    example
    const unshiftZero = unshift(0);
    
    unshiftZero([1, 2, 3]); // [0, 1, 2, 3]
    unshiftZero(["value"]); // [0, "value"]

    Type parameters

    • Item

      Type of items to be inserted into source array.

    Parameters

    • item: Item

      Item to be inserted.

    Returns (Anonymous function)

    Curried function with item and index in context.

Generated using TypeDoc