Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • T

Hierarchy

Implements

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

Indexable

[index: number]: T

Collection item.

Index

Constructors

Properties

length: number = 0

The length of the collection.

Methods

  • [iterator](): Iterator<T, any, undefined>
  • The iterator used for looping the collection.

    Returns Iterator<T, any, undefined>

  • _allAreObjects(): this is Collection<Record<string, any>>
  • at(index: number): undefined | T
  • average(key?: string | ((item: T) => any)): number
  • Get the average of values in the collection.

    Parameters

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

    Returns number

  • chunkBy<K>(key: K | ((item: T) => PropertyKey)): Record<PropertyKey, Collection<T>>
  • Chunk the collection by the specified key.

    Type parameters

    • K: string | number | symbol

    Parameters

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

    Returns Record<PropertyKey, Collection<T>>

  • copyWithin(target: number, start: number, end?: number): Collection<T>
  • duplicates(key?: string | ((obj: T) => T)): 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) => T)

    Returns Collection<T>

  • entries(): IterableIterator<[number, T]>
  • every<S>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is S[]
  • every(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean
  • see

    Array.prototype.every

    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

  • fill(value: T, start?: number, end?: number): Collection<T>
  • filter(predicate: (value: T, index: number, array: T[]) => boolean, thisArg?: any): Collection<T>
  • see

    Array.prototype.filter

    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>

  • find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): undefined | T
  • see

    Array.prototype.find

    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

  • findIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number
  • see

    Array.prototype.findIndex

    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

  • first(callback?: (item: T, index: number) => boolean): undefined | T
  • Return the first element in the collection, if callback given the first element that passes the truth test. Otherwise, undefined.

    Parameters

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

          • item: T
          • index: number

          Returns boolean

    Returns undefined | T

  • flatMap<U, This>(callback: (value: T, index: number, array: T[]) => U | readonly U[], thisArg?: This): Collection<U>
  • see

    Array.prototype.flatMap

    Type parameters

    • U

    • This = undefined

    Parameters

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

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

          Returns U | readonly U[]

    • Optional thisArg: This

    Returns Collection<U>

  • forEach(callback: (value: T, index: number, array: T[]) => void, thisArg?: any[]): Collection<T>
  • override

    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>

  • getNumericValues(key?: string | ((item: T) => any)): number[]
  • 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[]

  • hasDuplicates(key?: string | ((obj: T) => T)): boolean
  • Assert whether there are duplicates in the collection based deep equality.

    Parameters

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

    Returns boolean

  • includes(value: unknown): boolean
  • Assert whether the given value is in the collection using deep equality.

    Parameters

    • value: unknown

    Returns boolean

  • indexOf(searchElement: T, fromIndex?: number): number
  • isEmpty(): boolean
  • isNotEmpty(): boolean
  • join(key?: string | ((item: T) => any), separator?: undefined | string | ((item: T) => any)): string
  • see

    Array.prototype.join

    Parameters

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

    Returns string

  • keys(): string[]
  • last(callback?: (item: T, index: number) => boolean): undefined | T
  • Return the last element in the collection, if callback given the last element that passes the truth test. Otherwise undefined.

    Parameters

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

          • item: T
          • index: number

          Returns boolean

    Returns undefined | T

  • lastIndexOf(searchElement: T, fromIndex?: number): number
  • map<U>(callback: (value: T, index: number, array: T[]) => U, thisArg?: any): Collection<U>
  • see

    Array.prototype.map

    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>

  • max(key?: string | ((item: T) => any)): number
  • Get the highest number in the collection.

    Parameters

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

    Returns number

  • min(key?: string | ((item: T) => any)): number
  • Get the lowest number in the collection.

    Parameters

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

    Returns number

  • pad(length: number, value?: T | (() => T)): Collection<T>
  • 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>

  • pluck(properties: string): Collection<any>
  • pluck<Keys>(properties: Keys): Collection<Record<Keys[number], any>>
  • pop(): undefined | T
  • push(...items: T[]): number
  • random(count?: number): undefined | Collection<T> | T
  • reduce(callback: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T
  • see

    Array.prototype.reduce

    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

  • reduceRight(callback: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T
  • see

    Array.prototype.reduceRight

    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

  • shift(): undefined | T
  • skipUntil(closure: (item: T) => boolean): Collection<T>
  • Skip items in the collection until the given closure with the current item resolves to false.

    Parameters

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

          • item: T

          Returns boolean

    Returns Collection<T>

  • skipWhile(closure: (item: T) => boolean): Collection<T>
  • Skip items in the collection while the given closure with the current item resolves to true.

    Parameters

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

          • item: T

          Returns boolean

    Returns Collection<T>

  • slice(start?: number, end?: number): Collection<T>
  • some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean
  • see

    Array.prototype.some

    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

  • sort(compareFn?: (a: T, b: T) => number): Collection<T>
  • splice(start: number, deleteCount: number, ...items: T[]): Collection<T>
  • sum(key?: string | ((item: T) => any)): number
  • Get summative of the collection values.

    Parameters

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

    Returns number

  • takeUntil(closure: (item: any) => boolean): Collection<T>
  • Take items in the collection until the given closure with the current item resolves to false.

    Parameters

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

          • item: any

          Returns boolean

    Returns Collection<T>

  • takeWhile(closure: (item: any) => boolean): Collection<T>
  • Take items in the collection while the given closure with the current item resolves to true.

    Parameters

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

          • item: any

          Returns boolean

    Returns Collection<T>

  • toArray(): T[]
  • toJSON(): { elements: any[] }
  • toString(): string
  • unique(key?: string | ((obj: T) => T)): Collection<T>
  • 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) => T)

    Returns Collection<T>

  • unshift(...items: T[]): number
  • values(): IterableIterator<T>
  • isCollection<V>(value: unknown): value is Collection<V>
  • times<ST>(number: number, value: ST | ((index: number) => ST)): Collection<ST>
  • Create a new collection from the evaluated callback or value the given number of times.

    Type parameters

    • ST

    Parameters

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

    Returns Collection<ST>

Generated using TypeDoc