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

chickencurry

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chickencurry - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

lib/countDefinedItems.js

62

index.js

@@ -1,47 +0,8 @@

var slice = Array.prototype.slice,
var merge = require('./lib/merge'),
countDefinedItems = require('./lib/countDefinedItems'),
slice = Array.prototype.slice,
__;
function forEach(arr, fn) {
for (var i = 0; i < arr.length; i++) {
fn(i, arr[i]);
}
}
function map(arr, fn) {
var newArr = [];
forEach(arr, function(key, item) {
newArr.push(fn(key, item));
});
return newArr;
}
function mergeArguments(args, curryArgs) {
var mergedArgs = [];
mergedArgs = map(curryArgs, function(key, item) {
if (item === __) {
return args.shift();
} else {
return item;
}
});
return mergedArgs.concat(args);
}
function countArgs(args) {
var count = 0;
forEach(args, function(key, item) {
if (item !== __) {
count = count + 1;
}
});
return count;
}
function recurry(fn, curryArgs) {
function curry(fn, curryArgs) {
return function() {

@@ -51,7 +12,12 @@ var args = slice.call(arguments),

if (fn.length <= countArgs(curryArgs.concat(args))) {
mergedArgs = mergeArguments(args, curryArgs);
if (fn.length <= countDefinedItems(curryArgs.concat(args))) {
mergedArgs = merge(args, curryArgs);
return fn.apply(null, mergedArgs);
} else {
return recurry(fn, curryArgs.concat(args));
mergedArgs = curryArgs.concat(args);
if (fn.length >= mergedArgs.length) {
return curry(fn, mergedArgs);
} else {
return curry(fn, merge(args, curryArgs));
}
}

@@ -61,8 +27,8 @@ };

module.exports = function curry(fn) {
module.exports = function(fn) {
var args = slice.call(arguments, 1);
return recurry(fn, args);
return curry(fn, args);
};
module.exports.__ = __;
{
"name": "chickencurry",
"version": "1.0.1",
"version": "1.0.2",
"description": "Add some chicken curry to your functions",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -71,2 +71,3 @@ var curry = require('./index.js'),

it('should wrap the function if no argument to curry is passed', function() {
var __ = curry.__;
var addCurry = curry(add);

@@ -78,16 +79,42 @@ var joinCurry = curry(join);

expect(addCurry(1)).to.be.a('function');
expect(addCurry(1, 2)).to.equal(3);
expect(addCurry(1)(2)).to.equal(3);
expect(addCurry(__, 2)(1)).to.equal(3);
expect(addCurry(__)(2)(1)).to.equal(3);
expect(addCurry(2, __)(1)).to.equal(3);
expect(addCurry(2)(__)(1)).to.equal(3);
expect(joinCurry).to.be.a('function');
expect(joinCurry('_')).to.be.a('function');
expect(joinCurry('_', '_')).to.be.a('function');
expect(joinCurry('_','_', 'chicken')).to.equal('_chicken_');
expect(joinCurry('_')('_')).to.be.a('function');
expect(joinCurry('_','_')('chicken')).to.equal('_chicken_');
expect(joinCurry).to.be.a('function');
expect(joinCurry('_')('_')('chicken')).to.equal('_chicken_');
expect(joinCurry('_', '_', 'chicken')).to.equal('_chicken_');
expect(joinCurry('_')('_', 'fish')).to.equal('_fish_');
expect(joinCurry(__)).to.be.a('function');
expect(joinCurry(__, '_')).to.be.a('function');
expect(joinCurry(__,'_', 'chicken')).to.be.a('function');
expect(joinCurry(__,'_', 'chicken')('_')).to.equal('_chicken_');
expect(joinCurry(__)('_')).to.be.a('function');
expect(joinCurry(__,'_')('chicken')).to.be.a('function');
expect(joinCurry(__,'_')('chicken')('$')).to.equal('$chicken_');
expect(joinCurry(curry.__,'_')('_', 'chicken')).to.equal('_chicken_');
expect(joinCurry('_', curry.__)('-', 'chicken')).to.equal('_chicken-');
expect(joinCurry(curry.__)('.')('curry')('.')).to.equal('.curry.');
expect(joinCurry(curry.__)('.')('curry')('$')).to.equal('$curry.');
expect(joinCurry('_', curry.__, 'chicken')('-')).to.equal('_chicken-');
expect(joinCurry(curry.__, '_', 'chicken')('-')).to.equal('-chicken_');
expect(joinDot('.')('chicken')).to.equal('.chicken.');
expect(joinDot('.', 'chicken')).to.equal('.chicken.');
expect(joinDot('$', 'chicken')).to.equal('.chicken$');
expect(joinDot('$')('chicken')).to.equal('.chicken$');
expect(joinDot(__, 'chicken')('$')).to.equal('.chicken$');
expect(joinDot(__)('chicken')('$')).to.equal('.chicken$');
expect(joinDot('$', __)('chicken')).to.equal('.chicken$');
expect(joinDot('$')(__)('chicken')).to.equal('.chicken$');
expect(joinDot(__, __)('$', 'chicken')).to.equal('.chicken$');
expect(joinDot(__, __)('$')('chicken')).to.equal('.chicken$');
expect(joinDot(__)(__)('$', 'chicken')).to.equal('.chicken$');
expect(joinDot(__)(__)('$')('chicken')).to.equal('.chicken$');
});

@@ -94,0 +121,0 @@

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