Comparing version 0.1.1 to 0.2.0
module.exports = function cu(fn) { | ||
'use strict'; | ||
var args = [].slice.call(arguments); | ||
if ('function' !== typeof fn) throw new Error('auto-curry: Invalid parameter. First parameter should be a function.'); | ||
@@ -4,0 +6,0 @@ if ('function' === typeof fn && !fn.length) return fn; |
{ | ||
"name": "auto-curry", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Supercharge your functions by giving them the ability to auto-curry", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
@@ -25,3 +22,9 @@ "curry", | ||
}, | ||
"homepage": "https://github.com/zeusdeux/auto-curry" | ||
"homepage": "https://github.com/zeusdeux/auto-curry", | ||
"devDependencies": { | ||
"browserify": "^6.0.2", | ||
"jshint": "^2.5.6", | ||
"mocha": "^1.21.4", | ||
"uglify-js": "^2.4.15" | ||
} | ||
} |
@@ -14,2 +14,11 @@ auto-curry | ||
In `node`, you can just `require('auto-curry')`. | ||
In the browser, you can use `build/auto-curry.min.js` | ||
- with `require.js`, `browserify` etc | ||
- directly by using `window.autoCurry` | ||
##Node | ||
```javascript | ||
@@ -20,16 +29,51 @@ var cu = require('auto-curry'); | ||
}); | ||
var map = cu(function map(list, fn) { | ||
var messWithThis = cu(function(v){ | ||
this.a.push(v); | ||
return ++v; | ||
}); | ||
var map = cu(function map(fn, list) { | ||
var self = arguments[2] ? arguments[2] : this; | ||
try { | ||
return list.map(fn); | ||
return list.map(fn, self); | ||
} | ||
catch (e) { | ||
return [].map.call(list, fn); | ||
return [].map.call(list, fn, self); | ||
} | ||
}); | ||
var x = {a: []}; | ||
console.log(map([1, 2, 3], add(1))); //[2, 3, 4] | ||
console.log(map(add(1), [1, 2, 3])); //[2, 3, 4] | ||
console.log(map(messWithThis, [1,2,3], x)); //[2, 3, 4] | ||
console.log(x.a); //[1, 2, 3] | ||
``` | ||
##Browser | ||
```javascript | ||
var cu = window.autoCurry; //using it off the global | ||
var add = cu(function (a, b) { | ||
return a + b; | ||
}); | ||
var messWithThis = cu(function(v){ | ||
this.a.push(v); | ||
return ++v; | ||
}); | ||
var map = cu(function map(fn, list) { | ||
console.log(arguments[2]); | ||
var self = arguments[2] ? arguments[2] : this; | ||
try { | ||
return list.map(fn, self); | ||
} | ||
catch (e) { | ||
return [].map.call(list, fn, self); | ||
} | ||
}); | ||
var x = {a: []}; | ||
console.log(map(add(1), [1, 2, 3])); //[2, 3, 4] | ||
console.log(map(messWithThis, [1,2,3], x)); //[2, 3, 4] | ||
console.log(x.a); //[1, 2, 3] | ||
``` | ||
#License | ||
[MIT](https://github.com/zeusdeux/auto-curry/blob/master/LICENSE) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
10048
9
113
78
0
4
2