New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

cfy

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

cfy - npm Package Compare versions

Comparing version
1.0.10
to
1.0.12
+1
-17
examples/example_node.js
var {
yfy_node,
cfy_node,
ycall_node,
cfy,
} = require('./index'); // require('ycall')
} = require('../index'); // require('cfy')

@@ -23,9 +22,2 @@ var cfy_node_example = cfy_node(function*() {

var ycall_node_example = cfy_node(function*() {
var result = yield ycall_node(add_async_node, 5, 1); // 6
return result;
});
ycall_node_example(function(err, x) { console.log(x) }); // 6
var yfy_node_example = cfy_node(function*() {

@@ -51,9 +43,1 @@ var result = yield yfy_node(add_async_node)(5, 1); // 6

yfy_node_example_with_arguments(2, 7, function(err, x) { console.log(x) }); // 15
var ycall_node_example_with_arguments = cfy_node(function*(a, b) {
var result = yield ycall_node(add_async_node, 5, 1); // 6
return result + a + b;
});
ycall_node_example_with_arguments(2, 7, function(err, x) { console.log(x) }); // 15
var {
yfy,
cfy,
ycall,
} = require('./index'); // require('ycall')
yfy_multi,
} = require('../index'); // require('cfy')

@@ -22,9 +22,2 @@ var cfy_example = cfy(function*() {

var ycall_example = cfy(function*() {
var result = yield ycall(add_async, 5, 1); // 6
return result;
});
ycall_example(function(x) { console.log(x) }); // 6
var yfy_example = cfy(function*() {

@@ -43,9 +36,2 @@ var result = yield yfy(add_async)(5, 1); // 6

var ycall_example_with_arguments = cfy(function*(a, b) {
var result = yield ycall(add_async, 5, 1); // 6
return result + a + b;
});
ycall_example_with_arguments(2, 7, function(x) { console.log(x) }); // 15
var yfy_example_with_arguments = cfy(function*(a, b) {

@@ -58,16 +44,9 @@ var result = yield yfy(add_async)(5, 1); // 6

var ycall_example_multiarg_callback = cfy(function*() {
var [result, result2, result3] = yield ycall(addone_multiarg_callback_async, 5); // result=6, result2='foo', result3='bar'
var yfy_multi_example = cfy(function*() {
var [result, result2, result3] = yield yfy_multi(addone_multiarg_callback_async)(5); // result=6, result2='foo', result3='bar'
return [result, result2, result3];
});
ycall_example_multiarg_callback(function(x) { console.log(x) }); // [6, 'foo', 'bar']
yfy_multi_example(function(x) { console.log(x) }); // [6, 'foo', 'bar']
var yfy_example_multiarg_callback = cfy(function*() {
var [result, result2, result3] = yield yfy(addone_multiarg_callback_async)(5); // result=6, result2='foo', result3='bar'
return [result, result2, result3];
});
yfy_example_multiarg_callback(function(x) { console.log(x) }); // [6, 'foo', 'bar']
var sleep = cfy(function*(time) {

@@ -74,0 +53,0 @@ function sleep_base(msecs, callback) {

+103
-42
// Generated by LiveScript 1.5.0
(function(){
var co, denodeify, unthenify, yfy, yfy_node, cfy, cfy_node, ycall, ycall_node, out$ = typeof exports != 'undefined' && exports || this, slice$ = [].slice;
var co, unthenify, yfy, yfy_node, yfy_multi, yfy_multi_node, cfy, cfy_node, out$ = typeof exports != 'undefined' && exports || this, slice$ = [].slice;
co = require('co');
denodeify = require('denodeify');
unthenify = require('unthenify');
out$.yfy = yfy = function(f){
return denodeify(f, function(){
var res, res$, i$, to$;
return function(){
var functionArguments, res$, i$, to$, self;
res$ = [];

@@ -14,27 +13,106 @@ for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {

}
res = res$;
if (res.length === 1) {
return [null, res[0]];
} else {
return [null, slice$.call(res)];
}
});
functionArguments = res$;
self = this;
return new Promise(function(resolve, reject){
var callbackFunction;
callbackFunction = function(){
var args, res$, i$, to$;
res$ = [];
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
res$.push(arguments[i$]);
}
args = res$;
return resolve(args[0]);
};
functionArguments.push(callbackFunction);
return f.apply(self, functionArguments);
});
};
};
out$.yfy_node = yfy_node = function(f){
return denodeify(f, function(err){
var res, res$, i$, to$;
return function(){
var functionArguments, res$, i$, to$, self;
res$ = [];
for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
res$.push(arguments[i$]);
}
res = res$;
if (res.length === 1) {
return [err, res[0]];
} else {
return [err, slice$.call(res)];
functionArguments = res$;
self = this;
return new Promise(function(resolve, reject){
var callbackFunction;
callbackFunction = function(){
var args, res$, i$, to$, err;
res$ = [];
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
res$.push(arguments[i$]);
}
args = res$;
err = args[0];
if (err) {
return reject(err);
}
return resolve(args[1]);
};
functionArguments.push(callbackFunction);
return f.apply(self, functionArguments);
});
};
};
out$.yfy_multi = yfy_multi = function(f){
return function(){
var functionArguments, res$, i$, to$, self;
res$ = [];
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
res$.push(arguments[i$]);
}
});
functionArguments = res$;
self = this;
return new Promise(function(resolve, reject){
var callbackFunction;
callbackFunction = function(){
var args, res$, i$, to$;
res$ = [];
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
res$.push(arguments[i$]);
}
args = res$;
return resolve(args);
};
functionArguments.push(callbackFunction);
return f.apply(self, functionArguments);
});
};
};
out$.yfy_multi_node = yfy_multi_node = function(f){
return function(){
var functionArguments, res$, i$, to$, self;
res$ = [];
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
res$.push(arguments[i$]);
}
functionArguments = res$;
self = this;
return new Promise(function(resolve, reject){
var callbackFunction;
callbackFunction = function(){
var args, res$, i$, to$, err;
res$ = [];
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
res$.push(arguments[i$]);
}
args = res$;
err = args[0];
if (err) {
return reject(err);
}
return resolve(args.slice(1));
};
functionArguments.push(callbackFunction);
return f.apply(self, functionArguments);
});
};
};
out$.cfy = cfy = function(f){
var wrapped;
var num_args, wrapped;
num_args = f.length;
wrapped = co.wrap(f);

@@ -48,3 +126,3 @@ return function(){

args = res$; callback = arguments[i$];
if (typeof callback === 'function') {
if (args.length === num_args && typeof callback === 'function') {
return wrapped.bind(this).apply(null, args).then(callback, function(err){

@@ -59,3 +137,4 @@ return console.log(err);

out$.cfy_node = cfy_node = function(f){
var wrapped, wrapped_cb;
var num_args, wrapped, wrapped_cb;
num_args = f.length;
wrapped = co.wrap(f);

@@ -70,3 +149,3 @@ wrapped_cb = unthenify(wrapped);

args = res$; callback = arguments[i$];
if (typeof callback === 'function') {
if (args.length === num_args && typeof callback === 'function') {
return wrapped_cb.bind(this).apply(null, slice$.call(args).concat([callback]));

@@ -78,20 +157,2 @@ } else {

};
out$.ycall = ycall = function(f){
var args, res$, i$, to$;
res$ = [];
for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
res$.push(arguments[i$]);
}
args = res$;
return yfy(f).apply(null, args);
};
out$.ycall_node = ycall_node = function(f){
var args, res$, i$, to$;
res$ = [];
for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
res$.push(arguments[i$]);
}
args = res$;
return yfy_node(f).apply(null, args);
};
}).call(this);
{
"name": "cfy",
"version": "1.0.10",
"version": "1.0.12",
"description": "Use generators and yield to write regular callback-based functions",

@@ -15,4 +15,3 @@ "main": "index.js",

"cfy",
"yfy",
"ycall"
"yfy"
],

@@ -34,3 +33,2 @@ "scripts": {

"co": "^4.6.0",
"denodeify": "^1.2.1",
"unthenify": "^1.0.2"

@@ -37,0 +35,0 @@ },

+19
-29

@@ -25,3 +25,3 @@ # cfy - CallbackiFY

```javascript
var {cfy, cfy_node, ycall, ycall_node, yfy, yfy_node} = require('cfy');
var {cfy, cfy_node, yfy, yfy_node} = require('cfy');
```

@@ -120,3 +120,3 @@

`yfy` transforms a callback-style function into a promise which can be yielded within a generator.
`yfy` transforms a callback-style function into a promise which can be yielded within a generator. If the callback has multiple results, only the first one will be output. (Use `yfy_multi` if you need all the results).

@@ -140,3 +140,3 @@ ```javascript

`yfy_node` transforms a nodeback-style function into a promise which can be yielded within a generator.
`yfy_node` transforms a nodeback-style function into a promise which can be yielded within a generator. If the callback has multiple results, only the first one will be output (the error parameter will not be included). (Use `yfy_multi_node` if you need all the results).

@@ -158,38 +158,24 @@ ```javascript

### ycall
### yfy_multi
`ycall` is a shorthand that calls `yfy` on a callback-based function and calls it with the remaining parameters. So `ycall(func, x, y)` is equivalent to `yfy(func)(x, y)`
`yfy_multi` transforms a callback-style function into a promise which can be yielded within a generator. The promise will resolve to an array containing all the arguments to the callback function.
```javascript
function add_async(x, y, callback) {
setTimeout(function() {
callback(x + y);
}, 1000);
}
var yfy_multi_example = yfy_multi(function(x, callback) {
callback(x + 1, x + 2);
})
var ycall_example_with_arguments = cfy(function*(a, b) {
var result = yield ycall(add_async, 5, 1); // 6
return result + a + b;
});
ycall_example_with_arguments(2, 7, function(x) { console.log(x) }); // 15
yfy_multi_example(2).then(function(x) {console.log(x)}); // [3, 4]
```
### ycall_node
### yfy_multi_node
`ycall_node` is a shorthand that calls `yfy_node` on a nodeback-based function and calls it with the remaining parameters. So `ycall_node(func, x, y)` is equivalent to `yfy_node(func)(x, y)`
`yfy_multi_node` transforms a nodeback-style function into a promise which can be yielded within a generator. The promise will resolve to an array containing all the arguments to the callback function, except the first one (error parameter).
```javascript
function add_async_node(x, y, nodeback) {
setTimeout(function() {
nodeback(null, x + 1);
}, 1000);
}
var yfy_multi_node_example = yfy_multi_node(function(x, callback) {
callback(null, x + 1, x + 2);
})
var ycall_node_example_with_arguments = cfy_node(function*(a, b) {
var result = yield ycall_node(add_async_node, 5, 1); // 6
return result + a + b;
});
ycall_node_example_with_arguments(2, 7, function(err, x) { console.log(x) }); // 15
yfy_multi_node_example(2).then(function(x) {console.log(x)}); // [3, 4]
```

@@ -201,2 +187,6 @@

## Limitations
Note that `cfy` will return a promise if you are using it with functions that take variable numbers of arguments. This is because it is not possible to distinguish whether the last argument is intended to be used as a callback or another argument.
## License

@@ -203,0 +193,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet