Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asyncjs-util

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asyncjs-util - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

4

package.json

@@ -8,3 +8,3 @@ {

"devDependencies": {
"tap": "14.1.7"
"tap": "14.2.2"
},

@@ -25,3 +25,3 @@ "keywords": [

},
"version": "1.0.0"
"version": "1.1.0"
}
/** Return a specific result of an async/auto process
Omit a cbk and specify reject/resolve if using a Promise
{
[of]: <Property String>
[reject]: <Promise Reject Function>
[resolve]: <Promise Resolve Function>
}

@@ -11,13 +15,17 @@

module.exports = (args, cbk) => {
if (!cbk && !(!!args.reject && !!args.resolve)) {
throw new Error('ExpectedCbkOrPromiseFunctionsToReturnResult');
}
return (err, res) => {
if (!!err) {
return cbk(err);
return !cbk ? args.reject(err) : cbk(err);
}
if (!!args.of) {
return cbk(null, res[args.of]);
return !cbk ? args.resolve(res[args.of]) : cbk(null, res[args.of]);
}
return cbk();
return !cbk ? args.resolve() : cbk();
};
};

@@ -27,7 +27,28 @@ const {test} = require('tap');

test('A callback or promise function is required', ({end, throws}) => {
throws(
() => returnResult({}),
new Error('ExpectedCbkOrPromiseFunctionsToReturnResult')
);
return end();
});
tests.forEach(({args, description, error, expected, result}) => {
return test(description, ({deepEqual, end, equal}) => {
const promise = (err, resolution) => new Promise((resolve, reject) => {
return returnResult({reject, resolve, of: args.of})(err, resolution);
});
return test(description, async ({deepEqual, end, equal, rejects}) => {
// Promise methods
if (!error) {
equal(await promise(null, {foo: result.res}), expected);
} else {
rejects(promise(error), result.err);
}
// Callback methods
return returnResult(args, (err, res) => {
deepEqual(err, error);
equal(res, expected);
deepEqual(err, error, 'Callback returns error');
equal(res, expected, 'Callback returns result');

@@ -34,0 +55,0 @@ return end();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc