Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Patterns of function calls.
npm i execon --save
# or
bower i execon --save
var exec = require('execon');
Check is parameter is function, if it's - executes it with given parameters
Was:
function(callback, p1, p2, pN) {
if (typeof callback === 'function')
callback(p1, p2, pN);
}
Now
function(callback, p1, p2, pN) {
exec(callback, p1, p2, pN);
}
or just
exec.ret(callback, p1, p2, pN);
Conditional execution one of two functions
Preconditions:
function one() {
console.log(1);
}
function two(callback) {
setTimeout(callback, 1000);
}
Before:
if (2 > 3)
one();
else
two(one);
After:
exec.if(2 > 3, one, two);
if a you need a couple async operation do same work, and then call callback, this function for you.
Node.js example.
var fs = require('fs'),
Util = require('execon');
exec.parallel([
function(callback) {
fs.readFile('file1', callback);
},
function(callback) {
fs.readFile('file2', callback);
}
], function(error, data1, data2) {
if (error)
console.log(error)
else
console.log(data1, data2);
});
Vanilla js example.
var ONE_SECOND = 1000,
TWO_SECONDS = 2000,
func = function(time, str, callback) {
setTimeout(function() {
console.log(str);
callback(null, str);
}, time);
},
func1 = func.bind(null, TWO_SECONDS, 'first'),
func2 = func.bind(null, ONE_SECOND, 'second');
exec.parallel([func1, func2], function(error, str1, str2) {
console.log(str1, str2);
});
executes functions one-by-one
function one(callback){
setTimeout(function() {
console.log(1)
callback();
}, 1000);
}
function two(callback) {
console.log(2);
callback();
}
exec.series([one, two], function(error) {
console.log(error || 'done');
});
MIT
FAQs
Patterns of function calls
The npm package execon receives a total of 1,173 weekly downloads. As such, execon popularity was classified as popular.
We found that execon demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.