blodash

0.0.14 • Public • Published

bLodash

Build Status We don't lie about our coverage

Why does this library exist? It's the satirical edition of the absolutely legendary library that is lodash.

the one true god

Using blodash allows you to liberate your code from nasty issues with using any sort of native features and tries to take all of the guesswork out of whether something truly exists or not. To put it simply, it's the last and only library you will ever need from hereon out.

Don't be fooled about using built in features of Javascript. You might not know when those features are going to be ripped out from under you and change. So you need a reliable callback based solution.

bLodash extensions

Native#If

Evaluates your function or boolean and will decide to call your callback if it evaluates to true. If boolean evaluates as false an exception (b_.E.FalseIf) is thrown.

b_.if( function|boolean, callback );

Native#Else

Evaluates your if expression and catches the false exception and returns undefined.

b_.else( function|boolean, callback );

Native#Switch

Evaluates your switch and catches any exception that may be thrown in your case statements. Throws an exception only if no statement is found with your value(default case).

//Where switched value is known at creation
b_.switch( function|value );

//When switch statement isn't known until later
b_.switch( function|value, callback );

b_.switch( ... )
    .eval( value, defaultCase );

Native#TryCatch

    b_.try(function(){
        throw new Error()
    })
        .catch(Error, function(){
            return true;
        })
        .exec();

bLodash Example

Simple if

var a = true;
var value = b_.if( a, function(){
    return 'if-true';
});

console.log(value);
// if-true

Exception Safe If:

Note, there is no way to return a value from an else. You must have a functional callback to be able to get values out of an else.


b_.else(function() {
    b_.if(function() {
        return b_.else(function() {
            b_.if(value, function() {
                cb(b_.null);
            });
        }) === undefined;
    });

    cb(b_.true);
});

Functional Switch:

Never have to worry about native switch again

    b_.switch('case1')
        .case('case0', function(){
            iLoveBlodash();
            return null; //Equivalent to break
        })
        .case('case1', function(){
            lodashIsRevolutionary();
            return null;
        });

var _switch = b_.switch();

for(var i = 0; i < 50; i++)
    _switch.case(i, function(){ console.log(i); });

_switch.eval(5);
// 5 6 7 8 9 10 11 ...

Try/Catch:

Never guess about what error is thrown again

    b_.try(function(){
        this.object.does.not.work
    })
        .catch(ReferenceError, function(){
            return true;
        })
        .catch(Error, function(){
            return null
        })
        .exec();

    try {
        this.object.does.not.work
    } catch(e) {
        if(e instanceof ReferenceError){
            return true;
        } else {
            return null;
        }
    }

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.140latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.140
0.0.130
0.0.120
0.0.110
0.0.100
0.0.90
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10
0.0.01

Package Sidebar

Install

npm i blodash

Weekly Downloads

1

Version

0.0.14

License

MIT

Unpacked Size

341 kB

Total Files

11

Last publish

Collaborators

  • sieabah