Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

Hierarchy

Index

Constructors

constructor

Properties

[iterator]

[iterator]: () => Iterator<Field<keyof FieldTypes>, any, undefined>

Type declaration

items

items: Field<keyof FieldTypes>[] & Record<string, Field<keyof FieldTypes>>

Methods

all

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

    Returns Field<keyof FieldTypes>[]

average

  • Alias for the avg() method.

    Type parameters

    • K

    Parameters

    Returns number

avg

  • The avg method returns the average of all items in the collection.

    Type parameters

    • K

    Parameters

    Returns number

chunk

  • The chunk method breaks the collection into multiple, smaller collections of a given size.

    Parameters

    • size: number

    Returns Collection<Field<keyof FieldTypes>[]>

collapse

  • The collapse method collapses a collection of arrays into a single, flat collection.

    Returns Collection<Field<keyof FieldTypes>>

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 Field<keyof FieldTypes> | K, value?: V): boolean
  • The contains method determines whether the collection contains a given item.

    Type parameters

    • K

    • V

    Parameters

    Returns boolean

count

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

    Returns number

crossJoin

  • 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<[Field<keyof FieldTypes>, T]>

dd

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

    Returns void

diff

  • 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

    Returns Collection<Field<keyof FieldTypes>>

diffAssoc

  • diffAssoc<T>(values: T[] | Collection<T>): Collection<Field<keyof FieldTypes>>
  • 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<Field<keyof FieldTypes>>

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

    Parameters

    • object: object

    Returns Collection<K>

dump

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

    Returns FieldCollection<T>

each

every

  • The every method may be used to verify that all elements of a collection pass a given truth test.

    Parameters

    Returns boolean

except

  • The except method returns all items in the collection except for those with the specified keys.

    Type parameters

    • K

    Parameters

    • properties: K[]

    Returns Collection<Field<keyof FieldTypes>>

filter

first

flatMap

  • flatMap<T>(fn: (item: Field<keyof FieldTypes>, 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

    Returns Collection<T>

flatten

  • The flatten method flattens a multi-dimensional collection into a single dimension.

    Parameters

    • Optional depth: number

    Returns Collection<Field<keyof FieldTypes>>

flip

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

    Returns Collection<Field<keyof FieldTypes>>

forPage

  • 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<Field<keyof FieldTypes>>

forget

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

    Type parameters

    • K

    Parameters

    Returns FieldCollection<T>

get

  • The get method returns the item at a given key. If the key does not exist, null is returned.

    Type parameters

    • K

    • V

    Parameters

    Returns Field<keyof FieldTypes>

groupBy

  • The groupBy method groups the collection's items by a given key.

    Type parameters

    • T

    • K

    Parameters

    Returns Collection<T>

has

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

    Type parameters

    • K

    Parameters

    Returns boolean

implode

  • 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

    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<Field<keyof FieldTypes>>

intersectByKeys

  • The intersectByKeys method removes any keys from the original collection that are not present in the given array or collection.

    Type parameters

    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 Field<keyof FieldTypes> | 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

    Returns Collection<T>

keys

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

    Returns Collection<string>

last

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: Field<keyof FieldTypes>, 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

    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

  • The max method returns the maximum value of a given key.

    Parameters

    Returns number

median

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

    Type parameters

    • K

    Parameters

    Returns Field<keyof FieldTypes>

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

  • 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<Field<keyof FieldTypes>>

nth

  • The nth method creates a new collection consisting of every n-th element.

    Parameters

    • n: number
    • Optional offset: number

    Returns Collection<Field<keyof FieldTypes>>

only

  • The only method returns the items in the collection with the specified keys.

    Type parameters

    • K

    Parameters

    • properties: K[]

    Returns Collection<Field<keyof FieldTypes>>

partition

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

  • 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 Field<keyof FieldTypes>

prepend

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

    Type parameters

    • K

    • V

    Parameters

    • value: V
    • Optional key: K

    Returns FieldCollection<T>

pull

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

    Type parameters

    • K

    Parameters

    Returns Field<keyof FieldTypes>

push

put

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

    Type parameters

    • K

    • V

    Parameters

    • key: K
    • value: V

    Returns FieldCollection<T>

random

reduce

  • reduce<T>(fn: (_carry: T, item: Field<keyof FieldTypes>) => 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

    Returns any

reject

  • 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

    Returns Collection<Field<keyof FieldTypes>>

reverse

  • The reverse method reverses the order of the collection's items.

    Returns Collection<Field<keyof FieldTypes>>

search

  • 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

    Returns any

serialize

shift

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

    Returns Field<keyof FieldTypes>

shuffle

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

    Returns FieldCollection<T>

slice

  • The slice method returns a slice of the collection starting at the given index.

    Parameters

    • remove: number
    • Optional limit: number

    Returns Collection<Field<keyof FieldTypes>>

sort

sortBy

  • 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<Field<keyof FieldTypes>>

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

    Parameters

    Returns Collection<Field<keyof FieldTypes>>

sortByDesc

  • 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<Field<keyof FieldTypes>>

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

    Parameters

    Returns Collection<Field<keyof FieldTypes>>

splice

  • 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

    Returns Collection<Field<keyof FieldTypes>>

split

  • The split method breaks a collection into the given number of groups.

    Parameters

    • numberOfGroups: number

    Returns Field<keyof FieldTypes>[]

sum

  • The sum method returns the sum of all items in the collection.

    Type parameters

    • K

    Parameters

    Returns string | number

take

  • 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<Field<keyof FieldTypes>>

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

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

transform

  • 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

  • The unique method returns all of the unique items in the collection.

    Type parameters

    • K

    Parameters

    Returns Collection<Field<keyof FieldTypes>>

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

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

    Type parameters

    • K

    • V

    Parameters

    Returns Collection<Field<keyof FieldTypes>>

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

    Type parameters

    • K

    • V

    Parameters

    Returns Collection<Field<keyof FieldTypes>>

whereIn

  • The whereIn method filters the collection by a given key / value contained within the given array.

    Type parameters

    • K

    • V

    Parameters

    Returns Collection<Field<keyof FieldTypes>>

whereNotIn

  • The whereNotIn method filters the collection by a given key / value not contained within the given array.

    Type parameters

    • K

    • V

    Parameters

    Returns Collection<Field<keyof FieldTypes>>

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

  • 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<[Field<keyof FieldTypes>, T]>