
Research
/Security News
DuckDB npm Account Compromised in Continuing Supply Chain Attack
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Another control-flow library for node with little style changes and tweaks.
MIT license
Just as every other node.js package, just install it via npm.
npm install scoop
scoop looks and feels more or less like all the other control-flow libraries, some facts:
I really liked step for it's simplicity but it was also not perfectly what I wanted.
From 'examples/simple.js':
scoop(
function readFile(ctx) {
// read the file and store the result in ctx['data']
fs.readFile('test.json', 'utf8', this('data'));
},
function toJSON(ctx) {
// read ctx['data'], transform it and save the result into ctx['json']
ctx['json'] = JSON.parse(ctx['data']);
})( // please note this line
function finalize(err, ctx) {
// test if there was any error
if (err) throw err;
// show that ctx['json'] is populated with the expected result
console.log(ctx['json']['test']);
}
);
The sample should be easy enough to get the main idea behind scoop. Whenever you call 'this' a callback is generated which excepts the usual callback style ('function (err, result)'). The argument used on 'this' is used as the 'key' for the result in the 'context'.
The context may be changed and read everytime you want and is never touched by scoop except for result population. You may also save the result of the first scoop call to specify a finailzer later.
From 'examples/sametick.js':
function correctCallback(callback) {
process.nextTick(function() {
callback(null, 'foo');
});
}
function brokenCallback(callback) {
callback(null, 'bar');
}
scoop(
function first(ctx) {
correctCallback(this('correct'));
},
function second(ctx) {
brokenCallback(this('broken'));
})(
function finalize(err, ctx) {
if (err) throw err;
console.log(ctx);
}
);
The passed functions have to return before every callback may be called. Scoop enforces that callbacks are not called in the same tick by throwing an Error if this happens.
From 'examples/multiple.js':
scoop(
function readFile(ctx) {
fs.readFile('test.json', 'utf8', this('data'));
fs.readFile('test.json', 'utf8', this('data'));
},
function toJSON(ctx) {
ctx['json'] = [];
for (i in ctx['data']) {
ctx['json'].push(JSON.parse(ctx['data'][i]));
}
})(
function finalize(err, ctx) {
if (err) throw err;
console.log(ctx['json']);
}
);
If a key is used multiple times the results are automatically stored in an array where the order is equal to the initial call order.
From 'examples/forcearray.js':
scoop(
function readFile(ctx) {
fs.readFile('test.json', 'utf8', this(['data']));
},
function toJSON(ctx) {
ctx['json'] = JSON.parse(ctx['data'][0]);
})(
function finalize(err, ctx) {
if (err) throw err;
console.log(ctx['json']);
}
);
You may also force the Array creation by passing the desired key within an array. This tells scoop to create an array as the result regardless of the number of results.
From 'examples/nested.js':
function readFiles(files, callback) {
scoop(
function read(ctx) {
for (i in files) {
fs.readFile(files[i], 'utf8', this(['data']));
}
})(
function finalize(err, ctx) {
if (err) {
callback(err);
} else {
callback(null, ctx['data']);
}
}
);
}
scoop(
function readFile(ctx) {
fs.readFile('test.json', 'utf8', this('data'));
readFiles(['simple.js', 'multiple.js', 'forcearray.js'], this('data'));
},
function toJSON(ctx) {
ctx['json'] = JSON.parse(ctx['data'][0]);
})(
function finalize(err, ctx) {
if (err) throw err;
console.log(ctx['data'][0]);
console.log(ctx['data'][1].length);
}
);
This example is combination of all the other samples with the addition of nesting. Please note that you aren't forced to use only one key for all the results you are expecting. Just use as many as you need.
FAQs
Just another control-flow library which is a little bit different.
We found that scoop 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.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.