Facetor
- 🔍 Facetor - NPM module to filter a list of objects by its fields. Useful for e-commerce style catalog pages.
- Version 2.x.x has arrived! with some major breaking changes
USAGE
- Facetor has two steps: - Build Index, by specifying array of Items to filter and the Items' filterable fields. - Build Results, from array of field.values to return, and array of attributes returned for each field.
Prep - Load the module
Let's load the module
- On Node.js / CommonJS:
- in terminal:
npm install facetor
- in node:
var Facetor = require('facetor')
- in terminal:
- On the browser - html:
- in html head tag: - BigInteger.js:
<script src="//example.com/biginteger.js"></script>
- Facetor.js:<script src="//example.com/facetor.js"></script>
- in html head tag: - BigInteger.js:
- AMD is also supported.
Step 1
Build Index, by specifying array of Items to filter and the Items' filterable fields.
- EX: Here, we want to make the fields "style" and "category" available for filtering later:
var catalogFacetor = separator: "|" ;catalogFacetor;
Step 2
Build Results, from array of field.values, and array of attributes returned for each field.
- Values in the same parent fields use "OR" binary logic, while fields use "AND" logic.
- EX: Here, we want to only get "style.rural" and "category.oranges" items.
var result = catalogFacetor;
- Results in
Import and Export
Allows building of index ahead of time to save cpu and memory.
- Export current index
var indexJSON = catalogFacetor;
- Import index from json object
var newCatalogFacetor = ;newCatalogFacetor; // exported from abovevar results = newCatalogFacetor;// same results as step 2