js-criteria
A criteria library on json , javascript map object.
Motivation
Aims to be a complete solution for query on json and javascript map objects. All coded with ES6 syntax.
What's inside
- Webpack for all development (server,hotload etc.) and build (package, optimize, etc.) needs.
- Babel for writing codes with ES6 syntax and transpiling them browser compatible codes.
- ESLint for protecting our nice formatted codes.
- Flow for type checking.
- Karma for running tests.
- Chai for asserting test errors.
- Isparta for ES6 code coverage.
- Istanbul for code coveragereporting.
Quick Start
Install and Usage
Go to your project folder
npm install js-criteria --save
You can import this project in 2 ways.
- Partial import. For ex.
import Criteria from "js-criteria/lib/api/Criteria";
All-in-one, minified, optimized single js. For ex. TODO: example coming soon.
- Example Data
[
{
id: "1",
name: "Luffy",
surname: "Monkey D."
},
{
id: "2",
name: "Zoro",
surname: "Roronoa"
},
{
id: "3",
name: "Nami",
surname: ""
},
];
- Create Criteria to query on list of data
const criteria = new Criteria(dataList);
- add Restrictions
criteria.add(Restrictions.like("name", "%a%"));
criteria.add(Restrictions.gt("id", 1));
- setFirstResult
criteria.setMaxResults(3);
- setMaxResults
criteria.setMaxResults(3);
add Order (sorting)
criteria.addOrder(Order.asc("name"));
get result list
const list = criteria.list();
How to contribute
Clone and run npm install
. This will install both run-time project dependencies and developer tools listed
in package.json file.
How to Build for Production
If you need just to build the app (without running a dev server), simply run:
$ npm run-script build
How to run Unit Tests.
$ npm test