Class Collection<T>

Type Parameters

  • T

Hierarchy

Implements

  • default
  • default<T>
  • Iterable<T>
  • ArrayLike<T>

Indexable

[index: number]: T

Constructors

Properties

length: number = 0

The length of the collection.

Methods

  • The iterator used for looping the collection.

    Returns Iterator<T, any, undefined>

  • Get the average of values in the collection.

    Parameters

    • Optional key: string | ((item) => any)

    Returns number

  • Chunk the collection by the specified key.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • key: K | ((item) => PropertyKey)

    Returns Record<PropertyKey, Collection<T>>

  • Only keep the duplicated values in the collection. Optionally if all items are object compare by the given key or function.

    Parameters

    • Optional key: string | ((obj) => T)

    Returns Collection<T>

  • See

    Array.prototype.every

    Type Parameters

    • S

    Parameters

    • predicate: ((value, index, array) => value is S)
        • (value, index, array): value is S
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns value is S

    • Optional thisArg: any

    Returns this is S[]

  • Parameters

    • predicate: ((value, index, array) => unknown)
        • (value, index, array): unknown
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns unknown

    • Optional thisArg: any

    Returns boolean

  • See

    Array.prototype.filter

    Parameters

    • predicate: ((value, index, array) => boolean)
        • (value, index, array): boolean
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns boolean

    • Optional thisArg: any

    Returns Collection<T>

  • See

    Array.prototype.find

    Parameters

    • predicate: ((value, index, obj) => unknown)
        • (value, index, obj): unknown
        • Parameters

          • value: T
          • index: number
          • obj: T[]

          Returns unknown

    • Optional thisArg: any

    Returns undefined | T

  • See

    Array.prototype.findIndex

    Parameters

    • predicate: ((value, index, obj) => unknown)
        • (value, index, obj): unknown
        • Parameters

          • value: T
          • index: number
          • obj: T[]

          Returns unknown

    • Optional thisArg: any

    Returns number

  • Return the first element in the collection, if callback given the first element that passes the truth test. Otherwise, undefined.

    Parameters

    • Optional callback: ((item, index) => boolean)
        • (item, index): boolean
        • Parameters

          • item: T
          • index: number

          Returns boolean

    Returns undefined | T

  • See

    Array.prototype.flatMap

    Type Parameters

    • U

    • This = undefined

    Parameters

    • callback: ((this, value, index, array) => U | readonly U[])
        • (this, value, index, array): U | readonly U[]
        • Parameters

          • this: This
          • value: T
          • index: number
          • array: T[]

          Returns U | readonly U[]

    • Optional thisArg: This

    Returns Collection<U>

  • Parameters

    • callback: ((value, index, array) => void)
        • (value, index, array): void
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns void

    • Optional thisArg: any[]

    Returns Collection<T>

  • Private

    The getter that returns the numeric values based on the given key or the getter function.

    Parameters

    • Optional key: string | ((item) => any)

    Returns number[]

  • Assert whether there are duplicates in the collection based deep equality.

    Parameters

    • Optional key: string | ((obj) => T)

    Returns boolean

  • Assert whether the given value is in the collection using deep equality.

    Parameters

    • value: unknown

    Returns boolean

  • See

    Array.prototype.indexOf

    Parameters

    • searchElement: T
    • fromIndex: number = 0

    Returns number

  • See

    Array.prototype.join

    Parameters

    • Optional key: string | ((item) => any)
    • separator: undefined | string | ((item) => any) = key

    Returns string

  • Return the last element in the collection, if callback given the last element that passes the truth test. Otherwise, undefined.

    Parameters

    • Optional callback: ((item, index) => boolean)
        • (item, index): boolean
        • Parameters

          • item: T
          • index: number

          Returns boolean

    Returns undefined | T

  • See

    Array.prototype.lastIndexOf

    Parameters

    • searchElement: T
    • Optional fromIndex: number

    Returns number

  • See

    Array.prototype.map

    Type Parameters

    • U

    Parameters

    • callback: ((value, index, array) => U)
        • (value, index, array): U
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns U

    • Optional thisArg: any

    Returns Collection<U>

  • Get the highest number in the collection.

    Parameters

    • Optional key: string | ((item) => any)

    Returns number

  • Get the lowest number in the collection.

    Parameters

    • Optional key: string | ((item) => any)

    Returns number

  • Pad collection to the specified length with a value. Negative length will pad the beginning of the collection.

    Parameters

    • length: number
    • Optional value: T | (() => T)

    Returns Collection<T>

  • See

    Array.prototype.reduce

    Parameters

    • callback: ((previousValue, currentValue, currentIndex, array) => T)
        • (previousValue, currentValue, currentIndex, array): T
        • Parameters

          • previousValue: T
          • currentValue: T
          • currentIndex: number
          • array: T[]

          Returns T

    • Optional initialValue: T

    Returns T

  • See

    Array.prototype.reduceRight

    Parameters

    • callback: ((previousValue, currentValue, currentIndex, array) => T)
        • (previousValue, currentValue, currentIndex, array): T
        • Parameters

          • previousValue: T
          • currentValue: T
          • currentIndex: number
          • array: T[]

          Returns T

    • Optional initialValue: T

    Returns T

  • Skip items in the collection until the given closure with the current item resolves to false.

    Parameters

    • closure: ((item) => boolean)
        • (item): boolean
        • Parameters

          • item: T

          Returns boolean

    Returns Collection<T>

  • Skip items in the collection while the given closure with the current item resolves to true.

    Parameters

    • closure: ((item) => boolean)
        • (item): boolean
        • Parameters

          • item: T

          Returns boolean

    Returns Collection<T>

  • See

    Array.prototype.some

    Parameters

    • predicate: ((value, index, array) => unknown)
        • (value, index, array): unknown
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns unknown

    • Optional thisArg: any

    Returns boolean

  • Get summative of the collection values.

    Parameters

    • Optional key: string | ((item) => any)

    Returns number

  • Take items in the collection until the given closure with the current item resolves to false.

    Parameters

    • closure: ((item) => boolean)
        • (item): boolean
        • Parameters

          • item: any

          Returns boolean

    Returns Collection<T>

  • Take items in the collection while the given closure with the current item resolves to true.

    Parameters

    • closure: ((item) => boolean)
        • (item): boolean
        • Parameters

          • item: any

          Returns boolean

    Returns Collection<T>

  • Inherit Doc

    Returns {
        elements: any[];
    }

    • elements: any[]
  • De-duplicate the collection. Optionally find duplicates by key or the return value of a method called with the element.

    Parameters

    • Optional key: string | ((obj) => T)

    Returns Collection<T>

  • Call a callback on the collection unless the first argument is Boolean(true) or a closure called with the collection resolving to a value converted to boolean.

    Parameters

    Returns Collection<T>

  • Call a callback on the collection when the first argument is Boolean(true) or a closure called with the collection resolving to a value converted to boolean.

    Parameters

    Returns Collection<T>

  • Create a new collection from the evaluated callback or value the given number of times.

    Type Parameters

    • ST

    Parameters

    • number: number
    • value: ST | ((index) => ST)

    Returns Collection<ST>

Generated using TypeDoc