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: T) => any)

    Returns number

  • Chunk the collection by the specified key.

    Type Parameters

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • key: K | ((item: T) => 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.

    Returns

    Parameters

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

    Returns Collection<T>

  • See

    Array.prototype.every

    Returns

    Type Parameters

    Type Parameters

    • S

    Parameters

    • predicate: ((value: T, index: number, array: T[]) => value is S)
        • (value: T, index: number, array: T[]): value is S
        • Parameters

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

          Returns value is S

    • Optional thisArg: any

    Returns this is S[]

  • Parameters

    • predicate: ((value: T, index: number, array: T[]) => unknown)
        • (value: T, index: number, array: T[]): unknown
        • Parameters

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

          Returns unknown

    • Optional thisArg: any

    Returns boolean

  • See

    Array.prototype.filter

    Returns

    Parameters

    • predicate: ((value: T, index: number, array: T[]) => boolean)
        • (value: T, index: number, array: T[]): boolean
        • Parameters

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

          Returns boolean

    • Optional thisArg: any

    Returns Collection<T>

  • See

    Array.prototype.find

    Returns

    Parameters

    • predicate: ((value: T, index: number, obj: T[]) => unknown)
        • (value: T, index: number, obj: T[]): unknown
        • Parameters

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

          Returns unknown

    • Optional thisArg: any

    Returns undefined | T

  • See

    Array.prototype.findIndex

    Returns

    Parameters

    • predicate: ((value: T, index: number, obj: T[]) => unknown)
        • (value: T, index: number, obj: T[]): 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.

    Returns

    Parameters

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

          • item: T
          • index: number

          Returns boolean

    Returns undefined | T

  • See

    Array.prototype.flatMap

    Returns

    Type Parameters

    Type Parameters

    • U

    • This = undefined

    Parameters

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

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

          Returns U | readonly U[]

    • Optional thisArg: This

    Returns Collection<U>

  • Returns

    Parameters

    • callback: ((value: T, index: number, array: T[]) => void)
        • (value: T, index: number, array: T[]): 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: T) => any)

    Returns number[]

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

    Returns

    Parameters

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

    Returns boolean

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

    Returns

    Parameters

    • value: unknown

    Returns boolean

  • See

    Array.prototype.indexOf

    Returns

    Parameters

    • searchElement: T
    • fromIndex: number = 0

    Returns number

  • Assert whether the collection is not empty or is empty. .

    Returns

    Returns boolean

  • See

    Array.prototype.join

    Returns

    Parameters

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

    Returns string

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

    Returns

    Parameters

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

          • item: T
          • index: number

          Returns boolean

    Returns undefined | T

  • See

    Array.prototype.lastIndexOf

    Returns

    Parameters

    • searchElement: T
    • Optional fromIndex: number

    Returns number

  • See

    Array.prototype.map

    Returns

    Type Parameters

    Type Parameters

    • U

    Parameters

    • callback: ((value: T, index: number, array: T[]) => U)
        • (value: T, index: number, array: T[]): 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: T) => any)

    Returns number

  • Get the lowest number in the collection.

    Parameters

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

    Returns number

  • Order the collection by given configurations(s)

    Returns

    Parameters

    • order: T extends Record<PropertyKey, any> ? MaybeArray<Order<T>> : never
    • Rest ...additional: T extends Record<PropertyKey, any> ? Order<T>[] : never

    Returns Collection<T>

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

    Returns

    Parameters

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

    Returns Collection<T>

  • See

    Array.prototype.reduce

    Returns

    Parameters

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

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

          Returns T

    • Optional initialValue: T

    Returns T

  • See

    Array.prototype.reduceRight

    Returns

    Parameters

    • callback: ((previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T)
        • (previousValue: T, currentValue: T, currentIndex: number, array: T[]): 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.

    Returns

    Parameters

    • closure: ((item: T) => boolean)
        • (item: T): 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.

    Returns

    Parameters

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

          • item: T

          Returns boolean

    Returns Collection<T>

  • See

    Array.prototype.some

    Returns

    Parameters

    • predicate: ((value: T, index: number, array: T[]) => unknown)
        • (value: T, index: number, array: T[]): unknown
        • Parameters

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

          Returns unknown

    • Optional thisArg: any

    Returns boolean

  • See

    Array.prototype.sort

    Returns

    Parameters

    • Optional compareFn: ((a: T, b: T) => number)
        • (a: T, b: T): number
        • Parameters

          • a: T
          • b: T

          Returns number

    Returns Collection<T>

  • Get summative of the collection values.

    Parameters

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

    Returns number

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

    Returns

    Parameters

    • closure: ((item: any) => boolean)
        • (item: any): 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.

    Returns

    Parameters

    • closure: ((item: any) => boolean)
        • (item: any): 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.

    Returns

    Parameters

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

    Returns Collection<T>

  • See

    Array.prototype.unshift

    Returns

    Parameters

    • Rest ...items: T[]

    Returns number

  • Asserts whether the given value is an instance of Collection.

    Returns

    Type Parameters

    Type Parameters

    • V

    Parameters

    • value: unknown

    Returns value is Collection<V>

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

    Returns

    Type Parameters

    Type Parameters

    • ST

    Parameters

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

    Returns Collection<ST>

Generated using TypeDoc