Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

Const arrayIfy

  • arrayIfy<T, R>(input: T | Readonly<T>): R[]
  • description

    Convert an object to an array. Can be an instance of a class or anything really.

    example

    import { arrayIfy } from 'tyvn'; const data: Set = new Set(); data.add('hello'); data.add('world'); arrayIfy<Set, string>(data); // ['hello', 'world']

    Type parameters

    • T: Iterable<unknown, T>

    • R

    Parameters

    • input: T | Readonly<T>

      Input to arrayify

    Returns R[]

Const filterMap

  • filterMap<T, R>(arr: T[], filter: FilterFn<T, R>): R[]
  • description

    Filter and map merged into one function.

    example

    filterMap<string, string>(['a', 'th', 'is', 'wi', 'll', 'display'], (accept, deny, value) => { if(value.length == 2) { return accept(value); } else return deny(); }) // ['th', 'is', 'wi', 'll']

    Type parameters

    • T

    • R

    Parameters

    • arr: T[]

      The array input. Must be an array of T.

    • filter: FilterFn<T, R>

      The filter function.

    Returns R[]

Const limitArray

  • limitArray<R>(arr: R[], length: number): R[][]
  • description

    Create sub arrays depending on the max length of them and the input array.

    example

    const data: Set = new Set(); data.add('hello'); data.add('world'); limitArray(arrayIfy<Set, string>(data), 1) // [['hello'], ['world']]

    Type parameters

    • R

    Parameters

    • arr: R[]

      The input array to (chunk) slice

    • length: number

      The max length of each sub-array

    Returns R[][]

Const limitArrayify

  • limitArrayify<T, R>(input: T | Readonly<T>, length: number): R[][]
  • description

    A convenience functions. Combines arrayIfy and limitArray

    example

    const data: Set = new Set(); data.add('hello'); data.add('world'); limitArrayify<Set, string>(data, 1); // [['hello'], ['world']]

    Type parameters

    • T: Iterable<unknown, T>

    • R

    Parameters

    • input: T | Readonly<T>

      The array of input. Has to be either a readonly version or a instanceof T.

    • length: number

      The max length of each sub array

    Returns R[][]

Const removeAll

  • removeAll<T>(arr: T[], value: T): T[]
  • description

    Remove all elements from an array that are equal to the value supplied

    example

    removeAll(['hello', 'world', 'hello'], 'hello'); // ['world'];

    Type parameters

    • T

    Parameters

    • arr: T[]

      The array inputted. Must be an array of T

    • value: T

      The value to remove. Must be the same typeof T

    Returns T[]

Const takeUntil

  • takeUntil<T>(arr: T[], until: UntilFn<T>): T[]
  • description

    Take elements from an array until a specified function returns false.

    example

    takeUntil(['hello', 'world', 'this', 'will', 'not', 'be', 'displayed'], (value: string, index: number) => index < 2); // ['hello', 'world'];

    Type parameters

    • T

    Parameters

    • arr: T[]

      The array inputted. Must be an array of T

    • until: UntilFn<T>

      The until function, same parameters that map returns. Must return a boolean.

    Returns T[]

Const waitUntil

  • waitUntil<T>(arr: T[], until: UntilFn<T>): T[]
  • description

    Take elements from an array until a specified function returns true.

    example

    waitUntil(['hello', 'world', 'this', 'will', 'not', 'be', 'displayed'], (value: string, index: number) => index > 2); // ['hello', 'world', 'this'];

    Type parameters

    • T

    Parameters

    • arr: T[]

      The array inputted. Must be an array of T

    • until: UntilFn<T>

      The until function, same parameters that map returns. Must return a boolean.

    Returns T[]

Legend

  • Interface
  • Interface with type parameter
  • Function with type parameter

Generated using TypeDoc, the 2/8/2021 at 8:46:57 AM