Socket
Socket
Sign inDemoInstall

thunkify-wrap

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thunkify-wrap - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

test/methods.js

6

History.md
n.n.n / 2014-02-28
==================
* support methods
* fix test in 0.10
0.0.2 / 2014-02-28

@@ -3,0 +9,0 @@ ==================

36

index.js

@@ -10,6 +10,13 @@ /**!

* Expose `thunkify()`.
* @param {Function | Object} input
* @param {Object} [ctx]
* @param {Array} [methods]
* @return {Function}
* @api public
*/
module.exports = function (input, ctx) {
module.exports = function (input, ctx, methods) {
var type = typeof input;
// thunkify function
if (type === 'function') {

@@ -19,9 +26,22 @@ return thunkify(input, ctx);

ctx = ctx === undefined ? input : ctx;
// thunkify object
if (type === 'object') {
for (var key in input) {
if (typeof input[key] === 'function') {
input[key] = thunkify(input[key], ctx);
if (Array.isArray(ctx)) {
methods = ctx;
ctx = input;
}
ctx = ctx === undefined ? input : ctx;
if (methods && methods.length) {
methods.forEach(function (method) {
input[method] = thunkify(input[method], ctx);
});
} else {
// thunkify all methods in input
for (var key in input) {
if (typeof input[key] === 'function') {
input[key] = thunkify(input[key], ctx);
}
}
}
return input;

@@ -37,3 +57,3 @@ }

* @param {Function} fn
* @param {Object} ctx
* @param {Object} [ctx]
* @return {Function}

@@ -50,3 +70,3 @@ * @api public

args.push(function(){
args.push(function () {
results = arguments;

@@ -62,3 +82,3 @@

return function(fn){
return function (fn) {
cb = fn;

@@ -65,0 +85,0 @@

{
"name": "thunkify-wrap",
"version": "0.0.2",
"version": "0.0.3",
"repository": "dead-horse/node-thunkify-wrap",

@@ -16,6 +16,5 @@ "description": "Turn callbacks, arrays, generators, generator functions, and promises into a thunk",

"mocha": "*",
"should": "*",
"co": "^3.0.4"
"should": "*"
},
"license": "MIT"
}

@@ -74,4 +74,17 @@

### methods
by pass `methods` list, support only thunkify a part of methods in an object.
```
exports.create3 = function (a, b) {
var cal = new Cal(a, b);
thunkify(cal, cal, ['plus']);
// or
thunkify(cal, ['plus']);
};
```
# License
MIT
var co = require('co');
var assert = require('assert');

@@ -13,7 +12,9 @@ var thunkify = require('..');

cal1.minus = thunkify(cal1.minus, cal1);
co(function *() {
assert((yield cal1.plus) === 4);
assert((yield cal1.minus) === 2);
done();
})();
cal1.plus()(function (err, res) {
assert(res === 4);
cal1.minus()(function (err, res) {
assert(res === 2);
done();
});
});
});

@@ -26,9 +27,11 @@ });

cal2 = thunkify(cal2);
co(function *() {
assert((yield cal2.plus) === 3);
assert((yield cal2.minus) === 1);
done();
})();
cal2.plus()(function (err, res) {
assert(res === 3);
cal2.minus()(function (err, res) {
assert(res === 1);
done();
});
});
});
});
});
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