Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ModelCollection<T>

Type parameters

Hierarchy

Index

Constructors

Properties

length: number = 0

The length of the collection.

Methods

  • [iterator](): Iterator<T, any, undefined>
  • _allAreObjects(): this is Collection<Record<string, any>>
  • Accepts ModelCollection, array of models, numbers and strings in array format. All other values are discarded. Returns a collection of ids in a string format.

    Parameters

    • values: any

    Returns Collection<string>

  • _throwIfNotModels(iterable?: any): void
  • at(index: number): undefined | T
  • average(key?: string | ((item: T) => any)): number
  • chunkBy<K>(key: K | ((item: T) => PropertyKey)): Record<PropertyKey, Collection<T>>
  • copyWithin(target: number, start: number, end?: number): ModelCollection<T>
  • Only keep one instance of duplicated values in the collection. Optionally find duplicates by key, method name or passed in method. If key is undefined on the model, fall back to model check.

    Type parameters

    • U

    Parameters

    • Optional key: string | ((model: T) => U)

    Returns ModelCollection<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

    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

  • filter(predicate: (value: T, index: number, array: T[]) => boolean, thisArg?: any): ModelCollection<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 ModelCollection<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[]): ModelCollection<T>
  • hasDuplicates(key?: string): boolean
  • includes(model: T): boolean
  • indexOf(searchElement: T, fromIndex?: number): number
  • isEmpty(): boolean
  • isNotEmpty(): boolean
  • join(key?: string | ((item: T) => any), separator?: undefined | string | ((item: T) => any)): 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
  • max(key?: string | ((item: T) => any)): number
  • min(key?: string | ((item: T) => any)): number
  • pluck(properties: string): Collection<any>
  • pluck<Keys>(properties: Keys): Collection<Record<Keys[number], any>>
  • pop(): undefined | T
  • push(...items: T[]): number
  • 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
  • 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

  • splice(start: number, deleteCount: number, ...items: T[]): ModelCollection<T>
  • sum(key?: string | ((item: T) => any)): number
  • toArray(): T[]
  • toJSON(): { elements: R[] }
  • toString(): string
  • unshift(...items: T[]): number
  • values(): IterableIterator<T>
  • _isModel<M>(arg: any): arg is M
  • _isModelArray<M>(array: any): array is M[]
  • isCollection<V>(value: unknown): value is Collection<V>
  • times<ST>(number: number, value: ST | ((index: number) => ST)): Collection<ST>

Generated using TypeDoc