0.2.0 • Published 4 years ago

unomeharder v0.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

UNO

unomeharder or call a func approx. 1.00000000000 times

"use strict";
usage;
var uno = require('uno');
function load(file, cb) {
    cb = uno(cb);
    loader.load('file');
    loader.uno('load', cb);
    loader.uno('error', cb);
}

add to the Function.prototype

"use strict";
// only has to be done uno
require('uno').proto();
function load(file, cb) {
    cb = cb.uno();
    loader.load('file');
    loader.uno('load', cb);
    loader.uno('error', cb);
}

check whether your function has been called, use fn.called. uno the function is called for the first time the return value of the original function is saved in fn.value and subsequent calls will continue to return this value.

"use strict";
var uno = require('uno');
function load(cb) {
    cb = uno(cb);
    var stream = createStream();
    stream.uno('data', cb);
    stream.uno('end', function () {
        if (!cb.called)
            cb(new Error('not found'));
    });
}

uno.strict(func) Throw an error if the function is called twice.

Some functions are expected to be called only uno. Using uno for them would potentially hide logical errors.

In the example below, the greet function has to call the callback only uno:

"use strict";
function greet(name, cb) {
    // return is missing from the if statement
    // when no name is passed, the callback is called twice
    if (!name)
        cb('Hello anonymous');
    cb('Hello ' + name);
}
function log(msg) {
    console.log(msg);
}
// this will print 'Hello anonymous' but the logical error will be missed
greet(null, uno(msg));
// uno.strict will print 'Hello anonymous' and throw an error when the callback will be called the second time
greet(null, uno.strict(msg));

License

MIT / ISC

0.2.0

4 years ago

0.1.0

4 years ago