conditionalize
v0.0.8
Published
A library of conditions builder and validator
Downloads
5
Maintainers
Readme
A library of conditions builder and validator.
Conditionalize based on idea & codes from sequelize Querying Where. And targets node.js and the browser.
Browser Support
| | | | | | --- | --- | --- | --- | --- | :---: | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | :x: |
Installation
Package manager
Using npm:
$ npm install conditionalize
Using yarn:
$ yarn add conditionalize
Using pnpm:
$ pnpm add conditionalize
You can import the library using import
or require
approach:
// ES6
import Conditionalize from 'conditionalize';
const { Op } = Conditionalize;
const instance = new Conditionalize();
console.log(instance.check());
If you use require
, only default export is available:
// CommonJS
const Conditionalize = require('conditionalize');
const instance = new Conditionalize();
console.log(instance.check());
Examples
Basic
import Conditionalize from 'conditionalize';
const instance = new Conditionalize();
instance.check();
// => true
Constructor With options
Name | Type | Default | Description -|-|-|- dataSource | object | - | Input data that needs to check where | object | - | Logical comparisons(and/or/not .etc) operatorsMap | object | - | The map of operators operatorsAliases | object | - | The alias of operators
import Conditionalize from 'conditionalize';
const { Op } = Conditionalize;
const instance = new Conditionalize({
dataSource: {
authorId: 20,
rank: 2
},
where: {
authorId: {
[Op.gte]: 22
}
}
});
instance.check();
// => false
API
@TODO
Tests
Tests are using jest, to run the tests use:
$ npm run test
Coverage
Jest output coverage files to coverage
directory.
$ npm run coverage
License
This software is released under the terms of the MIT license.