refine
Refine is a lightweight, extensible object query tool for JavaScript.
Refine offers:
- A fluent, easy-to-read API
- Custom-defined filters
- Simplicity
Example
var refine = ;var select = refineselect;var order = ; var entities = orderentities; var customerInfo = ; console;// { customerId: 'pj123', name: 'Peter Joseph' }
Installation
$ npm install refine
Usage
refine.select(collection)
select
takes an array as the collection
parameter and returns a Query
object for chaining.
Query#where(property)
Query#where
creates a Filter
object, with property
as the property name to use when running a filter on the query. This method returns the newly created Filter
object.
Filter#equals(val)
Executes an equality comparison filter using the provided val
string. Returns an Array.
Filter#contains(val)
Executes a contains filter using the provided val
string. Returns an Array.
Custom Filters
Custom filters can be assigned using refine.Filter.prototype
.
Define this.action
inside the filter to generate the filtered array.
Example of a custom filter:
var refine = ; refineFilterprototype { this { return collection; }; return refineQuery;};
Custom filter in action:
var select = select; var informational = ; console; /*{ class: 'info customer', rel: 'http://x.io/rels/customer', properties: { customerId: 'pj123', name: 'Peter Joseph' }, links: [ { rel: 'self', href: 'http://api.x.io/customers/pj123' } ] }*/
License
MIT/X11