Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

Hierarchy

Index

Constructors

constructor

  • new EntryCollection<T>(entries: IEntry<T>[], meta?: ApiMeta<"list", any>, links?: Partial<Record<"stream" | "self" | "first_page" | "next_page" | "previous_page", string>>): EntryCollection<T>

Properties

[iterator]

[iterator]: () => Iterator<IEntry<T>, any, undefined>

Type declaration

    • (): Iterator<IEntry<T>, any, undefined>
    • Returns Iterator<IEntry<T>, any, undefined>

items

items: IEntry<T>[] & Record<string, IEntry<T>>

Optional Readonly links

links?: Partial<Record<"stream" | "self" | "first_page" | "next_page" | "previous_page", string>>

Optional Readonly meta

meta?: ApiMeta<"list", any>

Methods

all

  • The all method returns the underlying array represented by the collection.

    Returns IEntry<T>[]

average

  • average<K>(key?: K | keyof Entry<T> | keyof IStreams[T]["entries"]): number
  • Alias for the avg() method.

    Type parameters

    • K

    Parameters

    Returns number

avg

  • avg<K>(key?: keyof Entry<T> | keyof IStreams[T]["entries"] | K): number
  • The avg method returns the average of all items in the collection.

    Type parameters

    • K

    Parameters

    Returns number

chunk

  • chunk(size: number): Collection<IEntry<T>[]>
  • The chunk method breaks the collection into multiple, smaller collections of a given size.

    Parameters

    • size: number

    Returns Collection<IEntry<T>[]>

collapse

  • collapse(): Collection<IEntry<T>>
  • The collapse method collapses a collection of arrays into a single, flat collection.

    Returns Collection<IEntry<T>>

combine

  • combine<T, U>(array: U[]): Collection<T>
  • The combine method combines the keys of the collection with the values of another array or collection.

    Type parameters

    • T

    • U

    Parameters

    • array: U[]

    Returns Collection<T>

concat

  • concat<T>(collectionOrArrayOrObject: object | Collection<T> | T[]): any
  • The concat method is used to merge two or more collections/arrays/objects.

    Type parameters

    • T

    Parameters

    • collectionOrArrayOrObject: object | Collection<T> | T[]

    Returns any

contains

  • contains<K, V>(key: Function | keyof Entry<T> | keyof IStreams[T]["entries"] | K, value?: V): boolean
  • The contains method determines whether the collection contains a given item.

    Type parameters

    • K

    • V

    Parameters

    • key: Function | keyof Entry<T> | keyof IStreams[T]["entries"] | K
    • Optional value: V

    Returns boolean

count

  • count(): number
  • The count method returns the total number of items in the collection.

    Returns number

crossJoin

  • crossJoin<T>(values: T[]): Collection<[IEntry<T>, T]>
  • The crossJoin method cross joins the collection with the given array or collection, returning all possible permutations.

    Type parameters

    • T

    Parameters

    • values: T[]

    Returns Collection<[IEntry<T>, T]>

dd

  • dd(): void
  • The dd method will console.log the collection and exit the current process.

    Returns void

diff

  • diff<T>(values: Collection<IEntry<T>> | T[]): Collection<IEntry<T>>
  • The diff method compares the collection against another collection or a plain array based on its values. This method will return the values in the original collection that are not present in the given collection.

    Type parameters

    • T

    Parameters

    • values: Collection<IEntry<T>> | T[]

    Returns Collection<IEntry<T>>

diffAssoc

  • diffAssoc<T>(values: T[] | Collection<T>): Collection<IEntry<T>>
  • The diffAssoc method compares the collection against another collection or a plain object based on its keys and values. This method will return the key / value pairs in the original collection that are not present in the given collection:

    Type parameters

    • T

    Parameters

    • values: T[] | Collection<T>

    Returns Collection<IEntry<T>>

diffKeys

  • diffKeys<K>(object: object): Collection<K>
  • The diffKeys method compares the collection against another collection or a plain object based on its keys. This method will return the key / value pairs in the original collection that are not present in the given collection.

    Type parameters

    • K: string | number | symbol

    Parameters

    • object: object

    Returns Collection<K>

dump

  • The dump method outputs the results at that moment and then continues processing.

    Returns EntryCollection<T>

each

  • The each method iterates over the items in the collection and passes each item to a callback.

    Parameters

    • fn: (item: IEntry<T>) => void
        • Parameters

          Returns void

    • Optional index: number
    • Optional items: IEntry<T>[]

    Returns EntryCollection<T>

every

  • every(fn: (item: IEntry<T>) => boolean): boolean
  • The every method may be used to verify that all elements of a collection pass a given truth test.

    Parameters

    • fn: (item: IEntry<T>) => boolean
        • Parameters

          Returns boolean

    Returns boolean

except

  • except<K>(properties: K[]): Collection<IEntry<T>>
  • The except method returns all items in the collection except for those with the specified keys.

    Type parameters

    • K

    Parameters

    • properties: K[]

    Returns Collection<IEntry<T>>

filter

  • filter(fn: (item: IEntry<T>) => boolean): Collection<IEntry<T>>
  • filter(fn: (item: IEntry<T>, key?: any) => boolean): Collection<IEntry<T>>
  • The filter method filters the collection using the given callback, keeping only those items that pass a given truth test.

    Parameters

    • fn: (item: IEntry<T>) => boolean
        • Parameters

          Returns boolean

    Returns Collection<IEntry<T>>

  • Parameters

    • fn: (item: IEntry<T>, key?: any) => boolean
        • (item: IEntry<T>, key?: any): boolean
        • Parameters

          • item: IEntry<T>
          • Optional key: any

          Returns boolean

    Returns Collection<IEntry<T>>

first

  • first<V>(fn?: (item: IEntry<T>) => boolean, defaultValue?: (...any: any[]) => IEntry<T> | V): IEntry<T>
  • The first method returns the first element in the collection that passes a given truth test.

    Type parameters

    • V

    Parameters

    • Optional fn: (item: IEntry<T>) => boolean
        • Parameters

          Returns boolean

    • Optional defaultValue: (...any: any[]) => IEntry<T> | V
        • (...any: any[]): IEntry<T> | V
        • Parameters

          • Rest ...any: any[]

          Returns IEntry<T> | V

    Returns IEntry<T>

flatMap

  • flatMap<T>(fn: (item: IEntry<T>, key: any) => T): Collection<T>
  • The flatMap method iterates through the collection and passes each value to the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items. Then, the array is flattened by a level.

    Type parameters

    • T

    Parameters

    • fn: (item: IEntry<T>, key: any) => T
        • (item: IEntry<T>, key: any): T
        • Parameters

          Returns T

    Returns Collection<T>

flatten

  • flatten(depth?: number): Collection<IEntry<T>>
  • The flatten method flattens a multi-dimensional collection into a single dimension.

    Parameters

    • Optional depth: number

    Returns Collection<IEntry<T>>

flip

  • The flip method swaps the collection's keys with their corresponding values.

    Returns Collection<IEntry<T>>

forPage

  • forPage(page: number, chunk: number): Collection<IEntry<T>>
  • The forPage method returns a new collection containing the items that would be present on a given page number. The method accepts the page number as its first argument and the number of items to show per page as its second argument.

    Parameters

    • page: number
    • chunk: number

    Returns Collection<IEntry<T>>

forget

  • The forget method removes an item from the collection by its key.

    Type parameters

    • K

    Parameters

    Returns EntryCollection<T>

get

  • get<K, V>(key: keyof Entry<T> | keyof IStreams[T]["entries"] | K, defaultValue?: (...any: any[]) => IEntry<T> | V): IEntry<T>
  • The get method returns the item at a given key. If the key does not exist, null is returned.

    Type parameters

    • K

    • V

    Parameters

    • key: keyof Entry<T> | keyof IStreams[T]["entries"] | K
    • Optional defaultValue: (...any: any[]) => IEntry<T> | V
        • (...any: any[]): IEntry<T> | V
        • Parameters

          • Rest ...any: any[]

          Returns IEntry<T> | V

    Returns IEntry<T>

groupBy

  • groupBy<T, K>(key: keyof Entry<T> | keyof IStreams[T]["entries"] | K | ((item: IEntry<T>, index?: number) => K)): Collection<T>
  • The groupBy method groups the collection's items by a given key.

    Type parameters

    • T

    • K

    Parameters

    • key: keyof Entry<T> | keyof IStreams[T]["entries"] | K | ((item: IEntry<T>, index?: number) => K)

    Returns Collection<T>

has

  • The has method determines if one or more keys exists in the collection.

    Type parameters

    • K

    Parameters

    Returns boolean

implode

  • implode<K>(key: keyof Entry<T> | keyof IStreams[T]["entries"] | K, glue?: string): string
  • The implode method joins the items in a collection. Its arguments depend on the type of items in the collection.

    If the collection contains arrays or objects, you should pass the key of the attributes you wish to join, and the "glue" string you wish to place between the values.

    Type parameters

    • K

    Parameters

    • key: keyof Entry<T> | keyof IStreams[T]["entries"] | K
    • Optional glue: string

    Returns string

intersect

  • The intersect method removes any values from the original collection that are not present in the given array or collection. The resulting collection will preserve the original collection's keys.

    Parameters

    Returns Collection<IEntry<T>>

intersectByKeys

  • intersectByKeys<K>(values: IEntry<T> | Collection<IEntry<T>>): Collection<K>
  • The intersectByKeys method removes any keys from the original collection that are not present in the given array or collection.

    Type parameters

    • K: string | number | symbol

    Parameters

    Returns Collection<K>

isEmpty

  • isEmpty(): boolean
  • The isEmpty method returns true if the collection is empty; otherwise, false is returned.

    Returns boolean

isNotEmpty

  • isNotEmpty(): boolean
  • The isNotEmpty method returns true if the collection is not empty; otherwise, false is returned.

    Returns boolean

keyBy

  • keyBy<T, K>(key: Function | keyof Entry<T> | keyof IStreams[T]["entries"] | K): Collection<T>
  • The keyBy method keys the collection by the given key. If multiple items have the same key, only the last one will appear in the new collection.

    Type parameters

    • T

    • K

    Parameters

    • key: Function | keyof Entry<T> | keyof IStreams[T]["entries"] | K

    Returns Collection<T>

keys

  • keys(): Collection<string>
  • The keys method returns all of the collection's keys.

    Returns Collection<string>

last

  • The last method returns the last element in the collection that passes a given truth test.

    Parameters

    • Optional fn: (item: IEntry<T>) => boolean
        • Parameters

          Returns boolean

    Returns IEntry<T>

macro

  • macro(name: string, fn: Function): void
  • The macro method lets you register custom methods.

    Parameters

    • name: string
    • fn: Function

    Returns void

map

  • map<T>(fn: (item: IEntry<T>, index: any) => T): Collection<T>
  • The map method iterates through the collection and passes each value to the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items.

    Type parameters

    • T

    Parameters

    • fn: (item: IEntry<T>, index: any) => T
        • (item: IEntry<T>, index: any): T
        • Parameters

          Returns T

    Returns Collection<T>

mapInto

  • mapInto<T>(ClassName: T): Collection<T>
  • The mapInto method iterates through the collection and instantiates the given class with each element as a constructor.

    Type parameters

    • T: Function

    Parameters

    • ClassName: T

    Returns Collection<T>

mapToGroups

  • mapToGroups(fn: Function): Collection<any>
  • The mapToGroups method iterates through the collection and passes each value to the given callback.

    Parameters

    • fn: Function

    Returns Collection<any>

mapWithKeys

  • mapWithKeys<T>(fn: Function): Collection<T>
  • The mapWithKeys method iterates through the collection and passes each value to the given callback. The callback should return an array where the first element represents the key and the second element represents the value pair.

    Type parameters

    • T

    Parameters

    • fn: Function

    Returns Collection<T>

max

  • max(key?: string | keyof IStreams[T]["entries"]): number
  • The max method returns the maximum value of a given key.

    Parameters

    • Optional key: string | keyof IStreams[T]["entries"]

    Returns number

median

  • The median method returns the median value of a given key.

    Type parameters

    • K

    Parameters

    Returns IEntry<T>

merge

  • merge<T>(objectOrArray: object | T[]): Collection<T>
  • The merge method merges the given object into the original collection. If a key in the given object matches a key in the original collection, the given objects value will overwrite the value in the original collection.

    Type parameters

    • T

    Parameters

    • objectOrArray: object | T[]

    Returns Collection<T>

min

  • min<K>(key?: keyof Entry<T> | keyof IStreams[T]["entries"] | K): number
  • The min method returns the minimum value of a given key.

    Type parameters

    • K

    Parameters

    Returns number

mode

  • The mode method returns the mode value of a given key.

    Type parameters

    • K

    Parameters

    Returns Collection<IEntry<T>>

nth

  • nth(n: number, offset?: number): Collection<IEntry<T>>
  • The nth method creates a new collection consisting of every n-th element.

    Parameters

    • n: number
    • Optional offset: number

    Returns Collection<IEntry<T>>

only

  • only<K>(properties: K[]): Collection<IEntry<T>>
  • The only method returns the items in the collection with the specified keys.

    Type parameters

    • K

    Parameters

    • properties: K[]

    Returns Collection<IEntry<T>>

partition

  • The partition method may be combined with destructuring to separate elements that pass a given truth test from those that do not.

    Parameters

    • fn: (item: IEntry<T>) => boolean
        • Parameters

          Returns boolean

    Returns [IEntry<T>[], IEntry<T>[]]

pipe

  • pipe<U>(fn: (...any: any[]) => U): U
  • The pipe method passes the collection to the given callback and returns the result.

    Type parameters

    • U

    Parameters

    • fn: (...any: any[]) => U
        • (...any: any[]): U
        • Parameters

          • Rest ...any: any[]

          Returns U

    Returns U

pluck

  • pluck<T, K, V>(value: keyof Entry<T> | keyof IStreams[T]["entries"] | V, key?: keyof Entry<T> | keyof IStreams[T]["entries"] | K): Collection<T>
  • The pluck method retrieves all of the values for a given key.

    Type parameters

    • T

    • K

    • V

    Parameters

    Returns Collection<T>

pop

  • The pop method removes and returns the last item from the collection.

    Returns IEntry<T>

prepend

  • The prepend method adds an item to the beginning of the collection.

    Type parameters

    • K

    • V

    Parameters

    • value: V
    • Optional key: K

    Returns EntryCollection<T>

pull

  • The pull method removes and returns an item from the collection by its key.

    Type parameters

    • K

    Parameters

    Returns IEntry<T>

push

  • The push method appends an item to the end of the collection.

    Parameters

    Returns EntryCollection<T>

put

  • The put method sets the given key and value in the collection.

    Type parameters

    • K

    • V

    Parameters

    • key: K
    • value: V

    Returns EntryCollection<T>

random

  • The random method returns a random item from the collection.

    Parameters

    • Optional length: number

    Returns EntryCollection<T> | IEntry<T>

reduce

  • reduce<T>(fn: (_carry: T, item: IEntry<T>) => T, carry?: T): any
  • The reduce method reduces the collection to a single value, passing the result of each iteration into the subsequent iteration.

    Type parameters

    • T

    Parameters

    • fn: (_carry: T, item: IEntry<T>) => T
        • (_carry: T, item: IEntry<T>): T
        • Parameters

          Returns T

    • Optional carry: T

    Returns any

reject

  • reject(fn: (item: IEntry<T>) => boolean): Collection<IEntry<T>>
  • The reject method filters the collection using the given callback. The callback should return true if the item should be removed from the resulting collection.

    Parameters

    • fn: (item: IEntry<T>) => boolean
        • Parameters

          Returns boolean

    Returns Collection<IEntry<T>>

reverse

  • reverse(): Collection<IEntry<T>>
  • The reverse method reverses the order of the collection's items.

    Returns Collection<IEntry<T>>

search

  • search(valueOrFunction: IEntry<T> | ((value: IEntry<T>, key: number) => boolean), strict?: boolean): any
  • The search method searches the collection for the given value and returns its key if found. If the item is not found, false is returned.

    Parameters

    • valueOrFunction: IEntry<T> | ((value: IEntry<T>, key: number) => boolean)
    • Optional strict: boolean

    Returns any

shift

  • The shift method removes and returns the first item from the collection.

    Returns IEntry<T>

shuffle

  • The shuffle method randomly shuffles the items in the collection.

    Returns EntryCollection<T>

slice

  • slice(remove: number, limit?: number): Collection<IEntry<T>>
  • The slice method returns a slice of the collection starting at the given index.

    Parameters

    • remove: number
    • Optional limit: number

    Returns Collection<IEntry<T>>

sort

  • The sort method sorts the collection.

    Parameters

    Returns Collection<IEntry<T>>

sortBy

  • sortBy<V>(value: V): Collection<IEntry<T>>
  • sortBy(fn: (item: IEntry<T>) => number): Collection<IEntry<T>>
  • The sortBy method sorts the collection by the given key. The sorted collection keeps the original array keys.

    Type parameters

    • V

    Parameters

    • value: V

    Returns Collection<IEntry<T>>

  • The sortBy method sorts the collection by the given callback. The sorted collection keeps the original array keys.

    Parameters

    • fn: (item: IEntry<T>) => number
        • Parameters

          Returns number

    Returns Collection<IEntry<T>>

sortByDesc

  • sortByDesc<V>(value: V): Collection<IEntry<T>>
  • sortByDesc(fn: (item: IEntry<T>) => number): Collection<IEntry<T>>
  • This method has the same signature as the sortBy method, but will sort the collection in the opposite order.

    Type parameters

    • V

    Parameters

    • value: V

    Returns Collection<IEntry<T>>

  • This method has the same signature as the sortBy method, but will sort the collection in the opposite order.

    Parameters

    • fn: (item: IEntry<T>) => number
        • Parameters

          Returns number

    Returns Collection<IEntry<T>>

splice

  • splice(index: number, limit: number, replace?: IEntry<T>[]): Collection<IEntry<T>>
  • The splice method removes and returns a slice of items starting at the specified index. You may pass a second argument to limit the size of the resulting chunk.

    Parameters

    • index: number
    • limit: number
    • Optional replace: IEntry<T>[]

    Returns Collection<IEntry<T>>

split

  • split(numberOfGroups: number): IEntry<T>[]
  • The split method breaks a collection into the given number of groups.

    Parameters

    • numberOfGroups: number

    Returns IEntry<T>[]

sum

  • sum<K>(key?: keyof Entry<T> | keyof IStreams[T]["entries"] | K | ((item: IEntry<T>) => string | number)): string | number
  • The sum method returns the sum of all items in the collection.

    Type parameters

    • K

    Parameters

    • Optional key: keyof Entry<T> | keyof IStreams[T]["entries"] | K | ((item: IEntry<T>) => string | number)

    Returns string | number

take

  • take(length: number): Collection<IEntry<T>>
  • The take method returns a new collection with the specified number of items: You may also pass a negative integer to take the specified amount of items from the end of the collection.

    Parameters

    • length: number

    Returns Collection<IEntry<T>>

tap

  • The tap method passes the collection to the given callback, allowing you to "tap" into the collection at a specific point and do something with the items while not affecting the collection itself.

    Parameters

    • fn: (collection: Collection<IEntry<T>>) => void
        • (collection: Collection<IEntry<T>>): void
        • Parameters

          • collection: Collection<IEntry<T>>

          Returns void

    Returns EntryCollection<T>

times

  • times<T>(times: number, fn: (time: number) => T): T[]
  • The times method creates a new collection by invoking the callback a given amount of times.

    Type parameters

    • T

    Parameters

    • times: number
    • fn: (time: number) => T
        • (time: number): T
        • Parameters

          • time: number

          Returns T

    Returns T[]

toArray

  • toArray<T>(): T[]
  • The toArray method converts the collection into a plain array. If the collection is an object, an array containing the values will be returned.

    Type parameters

    • T

    Returns T[]

toJson

  • toJson(): string
  • The toJson method converts the collection into JSON string.

    Returns string

toObject

  • toObject(): Record<string, IEntry<T>>

transform

  • transform<T>(fn: (item: IEntry<T>) => T): Collection<T>
  • The transform method iterates over the collection and calls the given callback with each item in the collection. The items in the collection will be replaced by the values returned by the callback.

    Type parameters

    • T

    Parameters

    Returns Collection<T>

union

  • union<T>(object: Object): Collection<T>
  • The union method adds the given array to the collection. If the given array contains keys that are already in the original collection, the original collection's values will be preferred.

    Type parameters

    • T

    Parameters

    • object: Object

    Returns Collection<T>

unique

  • unique<K>(key?: Function | keyof Entry<T> | keyof IStreams[T]["entries"] | K): Collection<IEntry<T>>
  • The unique method returns all of the unique items in the collection.

    Type parameters

    • K

    Parameters

    • Optional key: Function | keyof Entry<T> | keyof IStreams[T]["entries"] | K

    Returns Collection<IEntry<T>>

unless

  • unless(value: boolean, fn: () => any, defaultFn: () => any): void
  • The unless method will execute the given callback when the first argument given to the method evaluates to false.

    Parameters

    • value: boolean
    • fn: () => any
        • (): any
        • Returns any

    • defaultFn: () => any
        • (): any
        • Returns any

    Returns void

unwrap

  • unwrap<T>(value: T[] | Collection<T>): T[]
  • The unwrap method will unwrap the given collection.

    Type parameters

    • T

    Parameters

    • value: T[] | Collection<T>

    Returns T[]

values

  • values<T>(): Collection<T>
  • The values method returns a new collection with the keys reset to consecutive integers.

    Type parameters

    • T

    Returns Collection<T>

when

  • when(condition: boolean, fn: () => any, defaultFn: () => any): void
  • The when method will execute the given callback when the first argument given to the method evaluates to true.

    Parameters

    • condition: boolean
    • fn: () => any
        • (): any
        • Returns any

    • defaultFn: () => any
        • (): any
        • Returns any

    Returns void

where

  • where<K, V>(key: keyof Entry<T> | keyof IStreams[T]["entries"] | K, value: V): Collection<IEntry<T>>
  • where<K, V>(key: keyof Entry<T> | keyof IStreams[T]["entries"] | K, operator: Operator, value: V): Collection<IEntry<T>>
  • The where method filters the collection by a given key / value pair.

    Type parameters

    • K

    • V

    Parameters

    Returns Collection<IEntry<T>>

  • The where method filters the collection by a given key / value pair.

    Type parameters

    • K

    • V

    Parameters

    • key: keyof Entry<T> | keyof IStreams[T]["entries"] | K
    • operator: Operator
    • value: V

    Returns Collection<IEntry<T>>

whereIn

  • whereIn<K, V>(key: keyof Entry<T> | keyof IStreams[T]["entries"] | K, values: V[]): Collection<IEntry<T>>
  • The whereIn method filters the collection by a given key / value contained within the given array.

    Type parameters

    • K

    • V

    Parameters

    • key: keyof Entry<T> | keyof IStreams[T]["entries"] | K
    • values: V[]

    Returns Collection<IEntry<T>>

whereNotIn

  • whereNotIn<K, V>(key: keyof Entry<T> | keyof IStreams[T]["entries"] | K, values: V[]): Collection<IEntry<T>>
  • The whereNotIn method filters the collection by a given key / value not contained within the given array.

    Type parameters

    • K

    • V

    Parameters

    • key: keyof Entry<T> | keyof IStreams[T]["entries"] | K
    • values: V[]

    Returns Collection<IEntry<T>>

wrap

  • wrap<T>(value: T | T[] | Collection<T>): Collection<T>
  • The wrap method will wrap the given value in a collection.

    Type parameters

    • T

    Parameters

    • value: T | T[] | Collection<T>

    Returns Collection<T>

zip

  • zip<T>(array: T[]): Collection<[IEntry<T>, T]>
  • The zip method merges together the values of the given array with the values of the original collection at the corresponding index.

    Type parameters

    • T

    Parameters

    • array: T[]

    Returns Collection<[IEntry<T>, T]>

Static fromResponse