Descripción

An object and array collector

Detalles

Clases


new CollectorBase()


new OCollector()


new ACollector()

Métodos


<inner> add( key, item )

Descripción

Adds an item to the collection

Parámetros
Nombre Tipo Descripción
key *

The key to use for the item being added.

item *

The item to add to the collection. The item is not iterated so that you could add bundled items to the collection


<inner> each( [ query ], iterator [, thisobj ] )

Descripción

Iterate over each item in the collection, or a subset that matches a query. This supports two signatures:
.each(query, function) and .each(function). If you pass in a query, only the items that match the query
are iterated over.

Parámetros
Nombre Tipo Atributos Descripción
query object <optional>

A query to evaluate

iterator function

Function to execute against each item in the collection

thisobj object <optional>

The value of this


<inner> toArray() → {array}

Descripción

Returns the collection as an array. If it is already an array, it just returns that.

Returns

<inner> toJSON() → {object}

Descripción

Supports conversion to a JSON string or for passing over the wire

Returns

<inner> map( [ query ], iterator [, thisobj ] )

Descripción

Maps the contents to an array by iterating over it and transforming it. You supply the iterator. Supports two signatures:
.map(query, function) and .map(function). If you pass in a query, only the items that match the query
are iterated over.

Parámetros
Nombre Tipo Atributos Descripción
query object <optional>

A query to evaluate

iterator function

Function to execute against each item in the collection

thisobj object <optional>

The value of this


<inner> reduce( [ query ], iterator [, accumulator [, thisobj ] ] ) → {*}

Descripción

Reduces a collection to a value which is the accumulated result of running each element in the collection through the
callback, where each successive callback execution consumes the return value of the previous execution. If accumulator
is not passed, the first element of the collection will be used as the initial accumulator value.
are iterated over.

Parámetros
Nombre Tipo Atributos Descripción
query object <optional>

A query to evaluate

iterator function

The function that will be executed in each item in the collection

accumulator * <optional>

Initial value of the accumulator.

thisobj object <optional>

The value of this

Returns

<inner> countBy( [ query ], iterator [, thisobj ] ) → {object}

Descripción

Creates an object composed of keys returned from running each element
of the collection through the given callback. The corresponding value of each key
is the number of times the key was returned by the callback.

Parámetros
Nombre Tipo Atributos Descripción
query object <optional>

A query to evaluate. If you pass in a query, only the items that match the query
are iterated over.

iterator function
thisobj object <optional>

The value of this

Returns

<inner> groupBy( [ query ], iterator [, thisobj ] ) → {object}

Descripción

Creates an object composed of keys returned from running each element of the collection through the callback.
The corresponding value of each key is an array of elements passed to callback that returned the key.
The callback is invoked with three arguments: (value, index|key, collection).

Parámetros
Nombre Tipo Atributos Descripción
query object <optional>

A query to evaluate . If you pass in a query, only the items that match the query
are iterated over.

iterator function
thisobj object <optional>

The value of this

Returns

<inner> pluck( [ query ], property ) → {*}

Descripción

Reduce the collection to a single value. Supports two signatures:
.pluck(query, function) and .pluck(function)

Parámetros
Nombre Tipo Atributos Descripción
query object <optional>

The query to evaluate. If you pass in a query, only the items that match the query
are iterated over.

property string

The property that will be 'plucked' from the contents of the collection

Returns

<inner> sortBy( [ query ], iterator [, thisobj ] ) → {array}

Descripción

Returns a sorted copy of the collection.

Parámetros
Nombre Tipo Atributos Descripción
query object <optional>

The query to evaluate. If you pass in a query, only the items that match the query
are iterated over.

iterator function
thisobj object <optional>

The value of this

Returns

<inner> max( [ query ], iterator [, thisobj ] ) → {number}

Descripción

Retrieves the maximum value of an array. If callback is passed,
it will be executed for each value in the array to generate the criterion by which the value is ranked.

Parámetros
Nombre Tipo Atributos Descripción
query object <optional>

A query to evaluate . If you pass in a query, only the items that match the query
are iterated over.

iterator function
thisobj object <optional>

The value of this

Returns

<inner> min( [ query ], iterator [, thisobj ] ) → {number}

Descripción

Retrieves the minimum value of an array. If callback is passed,
it will be executed for each value in the array to generate the criterion by which the value is ranked.

Parámetros
Nombre Tipo Atributos Descripción
query object <optional>

A query to evaluate . If you pass in a query, only the items that match the query
are iterated over.

iterator function
thisobj object <optional>

The value of this

Returns

<inner> destroy()

Descripción

Destructor called when the object is destroyed.


<inner> key( key ) → {*}

Descripción

Get a record by key

Parámetros
Nombre Tipo Descripción
key *

The key of the record to get

Returns

<inner> add( item )

Descripción

Adds to the top of the collection

Parámetros
Nombre Tipo Descripción
item *

The item to add to the collection. Only one item at a time can be added


<inner> append( item )

Descripción

Add to the bottom of the list

Parámetros
Nombre Tipo Descripción
item *

The item to add to the collection. Only one item at a time can be added


<inner> push( item )

Descripción

Add an item to the top of the list. This is identical to add, but is provided for stack semantics

Parámetros
Nombre Tipo Descripción
item *

The item to add to the collection. Only one item at a time can be added


<inner> compact()

Descripción

Modifies the collection with all falsey values of array removed. The values false, null, 0, "", undefined and NaN are all falsey.


<inner> at( args )

Descripción

Creates an array of elements from the specified indexes, or keys, of the collection. Indexes may be specified as
individual arguments or as arrays of indexes

Parámetros
Nombre Tipo Descripción
args indexes

The indexes to use


<inner> flatten( [ query ], iterator, [, thisobj ] ) → {number}

Descripción

Flattens a nested array (the nesting can be to any depth). If isShallow is truthy, array will only be flattened a single level.
If callback is passed, each element of array is passed through a callback before flattening.

Parámetros
Nombre Tipo Atributos Descripción
query object <optional>

A query to evaluate . If you pass in a query, only the items that match the query
are iterated over.

iterator, function
thisobj object <optional>

The value of this

Returns

<inner> index( key ) → {*}

Descripción

Gets an items by its index

Parámetros
Nombre Tipo Descripción
key number

The index to get

Returns

<static> collect( obj ) → {ACollector|OCollector}

Descripción

Collect an object

Parámetros
Nombre Tipo Descripción
obj array | object

What to collect

Returns