Comparing version 0.2.0 to 0.2.1
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.autoCurry=e()}}(function(){return function e(n,r,t){function o(f,u){if(!r[f]){if(!n[f]){var a="function"==typeof require&&require;if(!u&&a)return a(f,!0);if(i)return i(f,!0);var l=new Error("Cannot find module '"+f+"'");throw l.code="MODULE_NOT_FOUND",l}var c=r[f]={exports:{}};n[f][0].call(c.exports,function(e){var r=n[f][1][e];return o(r?r:e)},c,c.exports,e,n,r,t)}return r[f].exports}for(var i="function"==typeof require&&require,f=0;f<t.length;f++)o(t[f]);return o}({1:[function(e,n){n.exports=function r(e){"use strict";var n=[].slice.call(arguments);if("function"!=typeof e)throw new Error("auto-curry: Invalid parameter. First parameter should be a function.");return"function"!=typeof e||e.length?n.length-1>=e.length?e.apply(this,n.slice(1)):function(){var e=n.concat([].slice.call(arguments));return r.apply(this,e)}:e}},{}]},{},[1])(1)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.autoCurry=e()}}(function(){return function e(n,r,t){function o(f,u){if(!r[f]){if(!n[f]){var c="function"==typeof require&&require;if(!u&&c)return c(f,!0);if(i)return i(f,!0);var l=new Error("Cannot find module '"+f+"'");throw l.code="MODULE_NOT_FOUND",l}var a=r[f]={exports:{}};n[f][0].call(a.exports,function(e){var r=n[f][1][e];return o(r?r:e)},a,a.exports,e,n,r,t)}return r[f].exports}for(var i="function"==typeof require&&require,f=0;f<t.length;f++)o(t[f]);return o}({1:[function(e,n,r){n.exports=function e(n){"use strict";var r=[].slice.call(arguments),t=typeof n;if("function"!==t)throw new Error("auto-curry: Invalid parameter. Expected function, received "+t);return n.length<=1?n:r.length-1>=n.length?n.apply(this,r.slice(1)):function(){return e.apply(this,r.concat([].slice.call(arguments)))}}},{}]},{},[1])(1)}); |
16
index.js
module.exports = function cu(fn) { | ||
'use strict'; | ||
var args = [].slice.call(arguments); | ||
'use strict' | ||
if ('function' !== typeof fn) throw new Error('auto-curry: Invalid parameter. First parameter should be a function.'); | ||
if ('function' === typeof fn && !fn.length) return fn; | ||
if (args.length - 1 >= fn.length) return fn.apply(this, args.slice(1)); | ||
var args = [].slice.call(arguments) | ||
var typeOfFn = typeof fn | ||
if ('function' !== typeOfFn) throw new Error('auto-curry: Invalid parameter. Expected function, received ' + typeOfFn) | ||
if (fn.length <= 1) return fn | ||
if (args.length - 1 >= fn.length) return fn.apply(this, args.slice(1)) | ||
return function() { | ||
var tempArgs = args.concat([].slice.call(arguments)); | ||
return cu.apply(this, tempArgs); | ||
return cu.apply(this, args.concat([].slice.call(arguments))) | ||
}; | ||
}; |
{ | ||
"name": "auto-curry", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Supercharge your functions by giving them the ability to auto-curry", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,4 +6,9 @@ auto-curry | ||
#Installation | ||
> Note: | ||
> This library actually uses partial application internally and not currying. So, yes, the name is a misnomer. | ||
> It is the result of my incorrect understanding of the concepts when I wrote the library. | ||
> It is still perfectly usable and is used in production. | ||
# Installation | ||
```javascript | ||
@@ -13,3 +18,3 @@ npm install auto-curry --save | ||
#Usage | ||
# Usage | ||
@@ -23,3 +28,3 @@ In `node`, you can just `require('auto-curry')`. | ||
##Node | ||
## Node | ||
@@ -51,3 +56,4 @@ ```javascript | ||
##Browser | ||
## Browser | ||
```javascript | ||
@@ -79,4 +85,9 @@ var cu = window.autoCurry; //using it off the global | ||
#License | ||
# License | ||
[MIT](https://github.com/zeusdeux/auto-curry/blob/master/LICENSE) | ||
# Changelog | ||
#### `0.2.1` | ||
- Now, if the function passed to `auto-curry` has an arity of one, the function itself is returned. Earlier this was only for zero arity functions. |
@@ -49,2 +49,6 @@ var cu = require('../'); | ||
it('should throw if first argument is not a function', function() { | ||
a.throws(cu.bind(null, 1), /Invalid parameter/); | ||
}); | ||
it('should allow multiple arguments to be passed at a time', function() { | ||
@@ -78,9 +82,15 @@ var sum3 = cu(function(a, b, c) { | ||
it('should return the function if its arity is zero', function() { | ||
it('should return the function if its arity is zero or one', function() { | ||
var fn = function() { | ||
console.log('most useful function EVER!'); | ||
}; | ||
var id = function(x) { | ||
return x; | ||
}; | ||
var curriedFn = cu(fn); | ||
a.strictEqual(curriedFn, fn); | ||
a.strictEqual(curriedFn, fn); | ||
curriedFn = cu(id); | ||
a.strictEqual(curriedFn, id); | ||
}); | ||
@@ -87,0 +97,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
11282
10
154
89