Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

themisir/condjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

APIs

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

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')
    });

About

Boolean builder library ✔❌

Resources

Stars

Watchers

Forks

Packages

No packages published