Class: CollectorBase

ink/collector~ CollectorBase

new CollectorBase()

A collector

Source:

Members

length :integer

Get the size of the collection

Type:
  • integer
Source:

Methods

add(key, item)

Adds an item to the collection

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

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

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

Source:
Returns:
Type
boolean

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

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

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

Source:
Returns:
Type
boolean

find(qu) → {array}

Find all records that match a query

Parameters:
Name Type Description
qu object

The query to execute.

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.

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.

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.

Source:
Returns:
Type
object

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

Source:
Returns:
Type
object

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

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

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

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

Source:
Returns:
Type
*

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

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.

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.

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

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

Source:
Returns:
Type
array

toArray() → {array}

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

Source:
Returns:
Type
array

toJSON() → {object}

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

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.

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

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.