array-miner 0.1.0
Search through an array of objects easily and efficiently.
Quick Start
var arrayMiner = ; var data = id: 1 color: 'red' type: 'foo' id: 2 color: 'white' type: 'foo' id: 3 type: 'bar' ; arrayMiner;// [ { id: 1, color: 'red', type: 'foo' },// { id: 2, color: 'white', type: 'foo' } ]
If you plan on searching through the data repeatedly, load it with add
.
arrayMiner;// [ { id: 1, color: 'red', type: 'foo' },// { id: 2, color: 'white', type: 'foo' } ]
For more options and examples, check out the unit tests in test/app.js
or the API.
API
add
Add items as an array or as individual parameters.
arrayMiner; arrayMiner;
clear
Clears out all items previously added.
arrayMinerclear;
count
Returns the length of the current data. You could use .data().length
, but this is faster.
arrayMiner;
data
Returns all the loaded data, dereferenced.
arrayMinerdata;
find
Any object in the array with a matching property value will be returned in the results. Comparison is done with ===
.
arrayMiner;
options
Set or get options. This method is chainable.
// set an optionarrayMineroptions'maxCacheLength' 100; // get an optionarrayMineroptions'maxCacheLength'; // set multiple optionsarrayMineroptions maxCacheLength: 100 dereferenceResults: true; // get all optionsarrayMineroptions;
Option Descriptions
dereferenceResults
Turn dereferencing on/off. When off, queries are faster, but results are returned by reference. By default, dereferencing is false
.
arrayMiner;
cache
Set the number if query results to cache. By default, this is undefined
, which caches everything (until the cache is invalidated by another operation).
arrayMiner;
version
Check the current version.
arrayMinerversion;