Install the package using npm.
npm install condjs
or use Yarn
yarn add condjs
const Condition = require('condjs');
var willBeFalse = Condition.with(true).and(false).value;
var willBeTrue = Condition.with(false).or(true).value;
Condition | Arguments | Returns | Description |
---|---|---|---|
.and | condition: boolean | (c: Condition) => Condition |
Condition |
Logicial && (and) operator |
.or | condition: boolean | (c: Condition) => Condition |
Condition |
Logicial ` |
.set | value: boolean |
Condition |
Sets curent value by given argument |
.then | action: (...args) => {}, ...args |
Condition |
Executes action by given ...args if the value is true |
.else | action: (...args) => {}, ...args |
Condition |
Executes action by given ...args if the value is false |
.value | This is property | boolean |
Returns condition value |
Condition.with(true)
.and(coupon.isActive)
.and(function (c) {
c.or(coupon.limitDate === null)
.or(coupon.limitDate > new Date())
})
.and(function (c) {
c.or(coupon.limitMinPrice === null)
.or(price >= coupon.limitMinPrice);
})
.then(function () {
alert('Coupon applied')
})
.else(function () {
alert('Coupon not available')
});