0.0.4 • Published 6 years ago

@mestl/guardjs v0.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
6 years ago

#Guardjs It is a liblary, which implement guard for javascript. It allows to add any condition and use it in one line in a different way.

##Using To use this library, you just need to require it by requirejs:

var guard = require('guardjs');

or using ES6 imports:

import guard from 'guardjs';

After that you may do any checks with predefined conditions:

var str = "Example string";

var result = guard.is.string.and.not.empty(str);

Also you can throw errors when condition is incorrect:

var str = "";

guard.throwIf.string.and.not.empty(str, "Invalid arguments", Exception);

##Way to extend You can fork this repository or change code in download package. To add new conditions, you just need to add it to guardIs.js or guardThrowIf.js like in example:

class GuardIs {
    get undefined() {
        return createCheck(this, item => {
            return item === undefined;
        });
    }
    ...
    get myCustomCheck() {
        return createCheck(this, item => {
            return _.isNumber(item) && item === 2;
        });
    }
}

And just use it:

var a = 2;
var b = "";

if(guard.is.myCustomCheck(a)) {
    //should executed
}

if(guard.is.myCustomCheck(a) && guard.is.myCustomCheck(b)) {
    //should not executed
}
0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago