1.0.12 • Published 6 years ago

condjs v1.0.12

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
6 years ago

Build Status npm

Installation

Install the package using npm.

npm install condjs

or use Yarn

yarn add condjs

Usage

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 Condition instance as a argument.

Condition.with(true).and(true).or(c => c.and(true).or(false)).value equals to true && 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')
    });
1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago