conditionalize
v0.0.9
Published
A library of conditions builder and validator
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 conditionalizeUsing yarn:
$ yarn add conditionalizeUsing pnpm:
$ pnpm add conditionalizeYou 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();
// => trueConstructor 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();
// => falseAPI
@TODO
Tests
Tests are using jest, to run the tests use:
$ npm run testCoverage
Jest output coverage files to coverage directory.
$ npm run coverageLicense
This software is released under the terms of the MIT license.
