Class: ACollector

ink/collector~ ACollector

new ACollector()

An array based collector

Source:

Extends

Members

difference

Creates an array of array elements not present in the other arrays using strict equality for comparisons, i.e. ===.

Source:

Gets the first n values of the array

Source:

length :integer

Get the size of the collection

Type:
  • integer
Inherited From:
Source:

tail

This method gets all but the first values of array

Source:

Methods

add(item)

Adds to the top of the collection

Parameters:
Name Type Description
item *

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

Source:

all(qu) → {boolean}

Returns true if all items match the query. Aliases as every

Parameters:
Name Type Description
qu object

The query to execute

Inherited From:
Source:
Returns:
Type
boolean

any(qu) → {boolean}

Returns true if any of the items match the query. Aliases as all

Parameters:
Name Type Description
qu object

The query to execute

Inherited From:
Source:
Returns:
Type
boolean

append(item)

Add to the bottom of the list

Parameters:
Name Type Description
item *

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

Source:

at(args)

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

Parameters:
Name Type Description
args indexes

The indexes to use

Source:

compact()

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

Source:

countBy(query, iterator, thisobj) → {object}

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.

Parameters:
Name Type Argument Description
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

Inherited From:
Source:
Returns:
Type
object

each(query, iterator, thisobj)

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.

Parameters:
Name Type Argument Description
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

Inherited From:
Source:

every(qu) → {boolean}

Returns true if all items match the query. Aliases as all

Parameters:
Name Type Description
qu object

The query to execute

Inherited From:
Source:
Returns:
Type
boolean

find(qu) → {array}

Find all records that match a query

Parameters:
Name Type Description
qu object

The query to execute.

Inherited From:
Source:
Returns:

The results

Type
array

findKeys(qu) → {array}

Find all records that match a query and returns the keys for those items. This is similar to module:ink/probe.find but instead of returning records, returns the keys. If obj is an object it will return the hash key. If 'obj' is an array, it will return the index

Parameters:
Name Type Description
qu object

The query to execute.

Inherited From:
Source:
Returns:
Type
array

findOne(qu) → {object}

Returns the first record that matches the query. Aliased as seek.

Parameters:
Name Type Description
qu object

The query to execute.

Inherited From:
Source:
Returns:
Type
object

findOneKey(qu) → {object}

Returns the first record that matches the query and returns its key or index depending on whether obj is an object or array respectively. Aliased as seekKey.

Parameters:
Name Type Description
qu object

The query to execute.

Inherited From:
Source:
Returns:
Type
object

flatten(query, iterator,, thisobj) → {number}

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.

Parameters:
Name Type Argument Description
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

Source:
Returns:
Type
number

groupBy(query, iterator, thisobj) → {object}

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

Parameters:
Name Type Argument Description
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

Inherited From:
Source:
Returns:
Type
object

index(key) → {*}

Gets an items by its index

Parameters:
Name Type Description
key number

The index to get

Source:
Returns:
Type
*

map(query, iterator, thisobj) → {array}

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.

Parameters:
Name Type Argument Description
query object <optional>

A query to evaluate

iterator function

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

thisobj object <optional>

The value of this

Inherited From:
Source:
Returns:
Type
array

max(query, iterator, thisobj) → {number}

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.

Parameters:
Name Type Argument Description
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

Inherited From:
Source:
Returns:
Type
number

min(query, iterator, thisobj) → {number}

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.

Parameters:
Name Type Argument Description
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

Inherited From:
Source:
Returns:
Type
number

pluck(query, property) → {*}

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

Parameters:
Name Type Argument Description
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

Inherited From:
Source:
Returns:
Type
*

push(item)

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

Parameters:
Name Type Description
item *

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

Source:

reduce(query, iterator, accumulator, thisobj) → {*}

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.

Parameters:
Name Type Argument Description
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

Inherited From:
Source:
Returns:
Type
*

remove(qu) → {object|array}

Remove all items in the object/array that match the query

Parameters:
Name Type Description
qu object

The query to execute. See module:ink/probe.queryOperators for the operators you can use.

Inherited From:
Source:
Returns:

The array or object as appropriate without the records.

Type
object | array

shuffle() → {array}

Creates an array of shuffled array values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle.

Inherited From:
Source:
Returns:
Type
array

some(qu) → {boolean}

Returns true if any of the items match the query. Aliases as any

Parameters:
Name Type Description
qu object

The query to execute

Inherited From:
Source:
Returns:
Type
boolean

sortBy(query, iterator, thisobj) → {array}

Returns a sorted copy of the collection.

Parameters:
Name Type Argument Description
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

Inherited From:
Source:
Returns:
Type
array

toArray() → {array}

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

Inherited From:
Source:
Returns:
Type
array

toJSON() → {object}

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

Inherited From:
Source:
Returns:
Type
object

unique(qu) → {array}

Returns the set of unique records that match a query

Parameters:
Name Type Description
qu object

The query to execute.

Inherited From:
Source:
Returns:
Type
array

update(qu, setDocument)

Updates all records in obj that match the query. See module:ink/probe.updateOperators for the operators that are supported.

Parameters:
Name Type Description
qu object

The query which will be used to identify the records to updated

setDocument object

The update operator. See module:ink/probe.updateOperators

Inherited From:
Source:
ink-collector Copyright © 2012-2013 Terry Weiss. All rights reserved.
Documentation generated by JSDoc 3.2.0-dev on Sun Jun 09 2013 11:54:10 GMT-0400 (EDT) using the DocStrap template.