1.0.12 • Published 6 years ago
condjs v1.0.12
Installation
Install the package using npm.
npm install condjsor use Yarn
yarn add condjsUsage
const Condition = require('condjs');
var willBeFalse = Condition.with(true).and(false).value;
var willBeTrue = Condition.with(false).or(true).value;Methods
.and(condition)\
.or(condition) - Logicial && (and) and || (or) operations
.set(condition) - Sets current value (.or(...).value) to given condition's value
What is condition?\ Condition is a boolean or function that accepts a new
Conditioninstance as a argument.
Condition.with(true).and(true).or(c => c.and(true).or(false)).valueequals totrue && true || (true || false).
.then(action, ...args) - Action will be called with given args if the condition value is true
.else(action, ...args) - Action will be called with given args if the condition value is false
Example
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')
});