Class ModelCollection<T>

Type Parameters

Hierarchy

Constructors

Properties

length: number = 0

The length of the collection.

Methods

  • Protected

    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.

    Returns

    Parameters

    • values: any

    Returns Collection<string>

  • Protected

    Throw error if not every item is a Model.

    Parameters

    • Optional iterable: any

    Returns void

  • 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 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.

    Returns

    Type Parameters

    Type Parameters

    • U

    Parameters

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

    Returns ModelCollection<T>

  • See

    Array.prototype.every

    Returns

    Type Parameters

    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

  • 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 ModelCollection<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 ModelCollection<T>

  • 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

  • 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

  • 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

  • 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

  • Get summative of the collection values.

    Parameters

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

    Returns number

  • Protected

    Check whether the given argument is (probably) model or not.

    Returns

    Type Parameters

    Type Parameters

    Parameters

    • arg: any

    Returns arg is M

  • Protected

    Determine if the given array is a Model array.

    Returns

    Type Parameters

    Type Parameters

    Parameters

    • array: any

    Returns array is M[]

  • 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