Socket
Socket
Sign inDemoInstall

cmd.js

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmd.js - npm Package Compare versions

Comparing version 0.1.8 to 0.2.0

src/lib/do.js

2

package.json
{
"name": "cmd.js",
"version": "0.1.8",
"version": "0.2.0",
"description": "A chainable utility toolkit for JavaScript.",

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

@@ -289,2 +289,41 @@ # cmd.js

## Tutorial
Let's start with some data:
```js
var products = [
{name: 'apple', type: 'fruit', q: 5, price: 1.99},
{name: 'pear', type: 'fruit', q: 3, price: 2.59},
{name: 'carrot', type: 'vegetable', q: 7, price: 0.59}
];
```
How many products are there in total? Luckily, `.sum` takes an array and returns a single number:
```js
cmd.get('q').sum.with(products);
// 15
```
How many apples are there? Use `.raw` to get just the first result unwrapped:
```js
cmd.filter(cmd.get('name').equals('apple')).get('q').raw(products);
// 5
How many fruits are there? Use `.filter` and `.sum` together:
```js
cmd.filter(cmd.get('type').equals('fruit')).get('q').sum.with(products);
// 8
```
What is the total extended cost of all items?
```js
cmd.do(cmd.get('q'), cmd.get('price')).map.product.sum.call('toFixed', 2).with(products);
// '21.85'
```
## Developer Notes

@@ -291,0 +330,0 @@

/**
* Command: new Command(function () { ... })
* Command
* @author Nate Ferrero

@@ -11,6 +11,23 @@ */

/**
* Helper to merge array arguments
*/
var merge = function (args) {
var _args = [];
Array.prototype.forEach.call(args, function (arg) {
if (Array.isArray(arg)) {
Array.prototype.push.apply(_args, arg);
}
else {
_args.push(arg);
}
});
return _args;
};
/**
* Command class
*/
var Command = function (context) {
this.context = context;
var Command = function (_fn, name) {
this.fn = _fn ? _fn.bind(this) : null;
this.name = name;
};

@@ -28,3 +45,3 @@

'call', 'case', 'clone', 'compare', 'count',
'default', 'divide',
'default', 'divide', 'do',
'equals', 'exists', 'extend',

@@ -99,27 +116,16 @@ 'filter', 'format',

var valsLoader = function (args) {
var getVals = self.args(name, 'vals', function (vals) {
return fn(args, vals);
});
/**
* To syntax to avoid merging array values, just use raw values
*/
getVals.__defineGetter__('to', function () {
return function rawValsLoader() {
return fn.call(null, args, Array.prototype.slice.call(arguments));
};
});
/**
* Map to operate on multiple value sets
*/
getVals.__defineGetter__('map', function () {
return function mappedValsLoader() {
return Array.prototype.map.call(arguments, function (x) {
return getVals.apply(null, x);
return self.vals(name, function (vals) {
if (!Array.isArray(vals)) {
vals = [vals];
}
if (self._map) {
return vals.map(function (val) {
if (!Array.isArray(val)) {
val = [val];
}
return fn(args, val);
});
}
return fn(args, vals);
});
return getVals;
};

@@ -138,15 +144,6 @@

*/
var argsLoader = self.args(name, 'args', function (args) {
var argsLoader = self.args(name, function (args) {
return valsLoader(args);
});
/**
* To syntax to avoid merging array arguments, just use raw arguments
*/
argsLoader.__defineGetter__('to', function () {
return function rawArgsLoader() {
return valsLoader(Array.prototype.slice.call(arguments));
};
})
if (typeof plugin.argSets === 'object' && plugin.argSets) {

@@ -182,29 +179,22 @@ Object.keys(plugin.argSets).forEach(function (key) {

var valsLoader = function (args) {
var getVals = self.args(name, 'vals', function (vals) {
return vals.map(function (val) {
return self.vals(name, function (vals) {
var eachFn = function (val) {
if (self._map) {
if (!Array.isArray(val)) {
val = [val];
}
return val.map(function (v) {
if (!Array.isArray(v)) {
v = [v];
}
return fn(args, v);
});
}
return fn(args, val);
});
});
/**
* To syntax to avoid merging array values, just use raw values
*/
getVals.__defineGetter__('to', function () {
return function rawValsLoader() {
return Array.prototype.map.call(arguments, fn.bind(null, args));
};
});
/**
* Map to operate on multiple value sets
*/
getVals.__defineGetter__('map', function () {
return function mappedValsLoader() {
return Array.prototype.map.call(arguments, function (x) {
return getVals.apply(null, Array.isArray(x) ? x : [x]);
});
if (!Array.isArray(vals)) {
return eachFn(vals);
}
return vals.map(eachFn);
});
return getVals;
};

@@ -223,15 +213,6 @@

*/
var argsLoader = self.args(name, 'args', function (args) {
var argsLoader = self.args(name, function (args) {
return valsLoader(args);
});
/**
* To syntax to avoid merging array arguments, just use raw arguments
*/
argsLoader.__defineGetter__('to', function () {
return function rawArgsLoader() {
return valsLoader(Array.prototype.slice.call(arguments));
};
});
if (typeof plugin.argSets === 'object' && plugin.argSets) {

@@ -261,49 +242,98 @@ Object.keys(plugin.argSets).forEach(function (key) {

});
return cmd[name];
};
/**
* Command.args()
* @author Nate Ferrero
* Command.with
*/
Command.prototype.args = function argsWrapper(name, purpose, done) {
Command.prototype.with = function () {
if (!this.fn) {
throw new Error('Inappropriate place to call .with()')
}
var args = function args() {
var _args = [];
Array.prototype.forEach.call(arguments, function (arg) {
if (Array.isArray(arg)) {
Array.prototype.push.apply(_args, arg);
/**
* Merge multiple subsets of arguments
*/
if (this._map) {
var self = this;
return Array.prototype.map.call(arguments, function (args) {
if (!Array.isArray(args)) {
args = [args];
}
else {
_args.push(arg);
}
return self.args('with', self.fn).apply(self, args);
});
return done(_args);
}
return this.args('with', this.fn).apply(null, Array.prototype.slice.call(arguments));
};
/**
* Command.to
*/
Command.prototype.to = function () {
if (!this.fn) {
throw new Error('Inappropriate place to call .to()')
}
return this.fn(Array.prototype.slice.call(arguments));
};
/**
* Command.raw
*/
Command.prototype.__defineGetter__('raw', function () {
var self = this;
return function (value) {
if (!self.fn) {
throw new Error('Inappropriate place to call .raw()')
}
return self.fn(Array.isArray(value) ? value : [value])[0];
};
});
/**
* Command.map
*/
Command.prototype.__defineGetter__('map', function () {
this._map = true;
return this;
});
/**
* Command.args()
* @author Nate Ferrero
*/
Command.prototype.args = function argsWrapper(name, done) {
var args = function args() {
return done(merge(arguments));
};
args.$name = name;
args.$purpose = purpose;
if (purpose === 'vals') {
args.__defineGetter__('and', function () {
return new Command(args);
});
/**
* Get the first result unwrapped
*/
args.raw = function (first) {
return args(first).shift();
/**
* Skip argument merging with .to()
*/
args.__defineGetter__('to', function () {
return function unmergedArgs() {
return done(Array.prototype.slice.call(arguments));
};
});
if (this.context) {
var context = this.context;
return cmd.args(name, 'vals', function (vals) {
return args.apply(null, context(vals));
});
}
}
return args;
};
/**
* Command.vals()
* @author Nate Ferrero
*/
Command.prototype.vals = function valsWrapper(name, done) {
var last = this.fn;
return new Command(function (args) {
if (last) {
args = last(args);
}
return done(args);
}, name);
};
var cmd = new Command();

@@ -310,0 +340,0 @@

@@ -18,3 +18,3 @@ (function () {

var direction = 1;
var local = cmd.clone(args);
var local = cmd.clone.with(args);

@@ -21,0 +21,0 @@ if (local && local.length && typeof local[0] === 'number') {

@@ -19,5 +19,5 @@ var cmd = require('../src/cmd');

it('returns the sum of arguments plus each value', function () {
expect(cmd.add(1, 2, 3)(4, 40, 400)).to.deep.equal([10, 46, 406]);
expect(cmd.add(1, 2, 3).with(4, 40, 400)).to.deep.equal([10, 46, 406]);
});
});

@@ -15,9 +15,9 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.alert).to.be.a('function');
expect(cmd.alert).to.be.an('object');
});
it('returns [undefined]', function () {
expect(cmd.alert('Test Alert')).to.deep.equal([undefined]);
expect(cmd.alert.with('Test Alert')).to.deep.equal([undefined]);
});
});

@@ -19,9 +19,9 @@ var cmd = require('../src/cmd');

it('invokes the specified method on each value with given arguments', function () {
expect(cmd.call('toPrecision', 3)(1, 10, 100)).to.deep.equal(['1.00', '10.0', '100']);
expect(cmd.call('toPrecision', 3).with(1, 10, 100)).to.deep.equal(['1.00', '10.0', '100']);
});
it('respects the positioning of cmd.it within the given arguments', function () {
expect(cmd.call(Math.pow, 2, cmd.it)(1, 2, 3)).to.deep.equal([2, 4, 8]);
expect(cmd.call(Math.pow, cmd.it, 2)(1, 2, 3)).to.deep.equal([1, 4, 9]);
expect(cmd.call(Math.pow, 2, cmd.it).with(1, 2, 3)).to.deep.equal([2, 4, 8]);
expect(cmd.call(Math.pow, cmd.it, 2).with(1, 2, 3)).to.deep.equal([1, 4, 9]);
});
});

@@ -21,7 +21,7 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.case.lower).to.be.a('function');
expect(cmd.case.lower).to.be.an('object');
});
it('returns the lowercase value', function () {
expect(cmd.case.lower('A normal looking sentence.')).to.deep.equal(['a normal looking sentence.']);
expect(cmd.case.lower.with('A normal looking sentence.')).to.deep.equal(['a normal looking sentence.']);
});

@@ -33,7 +33,7 @@ });

it('is a function', function () {
expect(cmd.case.title).to.be.a('function');
expect(cmd.case.title).to.be.an('object');
});
it('returns the titlecase value', function () {
expect(cmd.case.title('A normal looking sentence.')).to.deep.equal(['A Normal Looking Sentence.']);
expect(cmd.case.title.with('A normal looking sentence.')).to.deep.equal(['A Normal Looking Sentence.']);
});

@@ -45,9 +45,9 @@ });

it('is a function', function () {
expect(cmd.case.upper).to.be.a('function');
expect(cmd.case.upper).to.be.an('object');
});
it('returns the uppercase value', function () {
expect(cmd.case.upper('A normal looking sentence.')).to.deep.equal(['A NORMAL LOOKING SENTENCE.']);
expect(cmd.case.upper.with('A normal looking sentence.')).to.deep.equal(['A NORMAL LOOKING SENTENCE.']);
});
});
});

@@ -15,3 +15,3 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.clone).to.be.a('function');
expect(cmd.clone).to.be.an('object');
});

@@ -18,0 +18,0 @@

@@ -15,7 +15,7 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.count).to.be.a('function');
expect(cmd.count).to.be.an('object');
});
it('counts the number of values given', function () {
var num = cmd.count(1, [2, 3, 4], 5, [6]);
var num = cmd.count.with(1, [2, 3, 4], 5, [6]);
expect(num).to.equal(6);

@@ -22,0 +22,0 @@ });

@@ -19,5 +19,5 @@ var cmd = require('../src/cmd');

it('returns the default arg in place of null or undefined', function () {
expect(cmd.default(9)(1, null, 3)).to.deep.equal([1, 9, 3]);
expect(cmd.default(9).with(1, null, 3)).to.deep.equal([1, 9, 3]);
});
});

@@ -19,5 +19,5 @@ var cmd = require('../src/cmd');

it('returns the sum of arguments plus each value', function () {
expect(cmd.divide(1, 2, 3)(6, 60, 600)).to.deep.equal([1, 10, 100]);
expect(cmd.divide(1, 2, 3).with(6, 60, 600)).to.deep.equal([1, 10, 100]);
});
});

@@ -19,13 +19,13 @@ var cmd = require('../src/cmd');

it('returns true for equal values', function () {
expect(cmd.equals(100)(100)).to.deep.equal([true]);
expect(cmd.equals(100).with(100)).to.deep.equal([true]);
});
it('returns false for different objects', function () {
expect(cmd.equals({})({})).to.deep.equal([false]);
expect(cmd.equals({}).with({})).to.deep.equal([false]);
});
it('returns false for different arrays', function () {
expect(cmd.equals([[]])([[]])).to.deep.equal([false]);
expect(cmd.equals([[]]).with([[]])).to.deep.equal([false]);
});
});

@@ -15,3 +15,3 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.exists).to.be.a('function');
expect(cmd.exists).to.be.an('object');
});

@@ -22,7 +22,7 @@

it('undefined', function () {
expect(cmd.exists(undefined)).to.deep.equal([false]);
expect(cmd.exists.with(undefined)).to.deep.equal([false]);
});
it('null', function () {
expect(cmd.exists(null)).to.deep.equal([false]);
expect(cmd.exists.with(null)).to.deep.equal([false]);
});

@@ -35,19 +35,19 @@

it('0', function () {
expect(cmd.exists(0)).to.deep.equal([true]);
expect(cmd.exists.with(0)).to.deep.equal([true]);
});
it('false', function () {
expect(cmd.exists(false)).to.deep.equal([true]);
expect(cmd.exists.with(false)).to.deep.equal([true]);
});
it('true', function () {
expect(cmd.exists(true)).to.deep.equal([true]);
expect(cmd.exists.with(true)).to.deep.equal([true]);
});
it('""', function () {
expect(cmd.exists("")).to.deep.equal([true]);
expect(cmd.exists.with("")).to.deep.equal([true]);
});
it('{}', function () {
expect(cmd.exists({})).to.deep.equal([true]);
expect(cmd.exists.with({})).to.deep.equal([true]);
});

@@ -54,0 +54,0 @@

@@ -20,11 +20,11 @@ var cmd = require('../src/cmd');

var obj = {};
expect(cmd.extend()(obj)[0]).to.equal(obj);
expect(cmd.extend().with(obj)[0]).to.equal(obj);
});
it('returns an empty array when no values provided', function () {
expect(cmd.extend({a: 1}, {b: 2})()).to.deep.equal([]);
expect(cmd.extend({a: 1}, {b: 2}).with()).to.deep.equal([]);
});
it('extends a single value with an argument', function () {
expect(cmd.extend({a: 1})({x: 2})).to.deep.equal([
expect(cmd.extend({a: 1}).with({x: 2})).to.deep.equal([
{a: 1, x: 2}

@@ -35,3 +35,3 @@ ]);

it('extends each argument provided', function () {
expect(cmd.extend({a: 1}, {b: 2})({x: 3})).to.deep.equal([
expect(cmd.extend({a: 1}, {b: 2}).with({x: 3})).to.deep.equal([
{a: 1, b: 2, x: 3}

@@ -42,3 +42,3 @@ ]);

it('extends each value provided', function () {
expect(cmd.extend({a: 1})({x: 2}, {y: 3})).to.deep.equal([
expect(cmd.extend({a: 1}).with({x: 2}, {y: 3})).to.deep.equal([
{a: 1, x: 2},

@@ -50,3 +50,3 @@ {a: 1, y: 3}

it('extends each argument and value provided', function () {
expect(cmd.extend({a: 1}, {b: 2})({x: 3}, {y: 4})).to.deep.equal([
expect(cmd.extend({a: 1}, {b: 2}).with({x: 3}, {y: 4})).to.deep.equal([
{a: 1, b: 2, x: 3},

@@ -53,0 +53,0 @@ {a: 1, b: 2, y: 4}

@@ -21,3 +21,3 @@ var cmd = require('../src/cmd');

return x % 2 == 0;
})(0, 1, 2, 3, 4)).to.deep.equal([0, 2, 4]);
}).with(0, 1, 2, 3, 4)).to.deep.equal([0, 2, 4]);
});

@@ -30,5 +30,5 @@

return x !== 2;
})(0, 1, 2, 3, 4)).to.deep.equal([0, 4]);
}).with(0, 1, 2, 3, 4)).to.deep.equal([0, 4]);
});
});

@@ -19,3 +19,3 @@ var cmd = require('../src/cmd');

it('formats values', function () {
expect(cmd.format('One is {} and two is {}')(1, 2)).to.deep.equal([
expect(cmd.format('One is {} and two is {}').with(1, 2)).to.deep.equal([
'One is 1 and two is 2'

@@ -26,3 +26,3 @@ ]);

it('formats values with multiple args', function () {
expect(cmd.format('One is {} and two is {}', '{} + {} = {}')(1, 2, 3)).to.deep.equal([
expect(cmd.format('One is {} and two is {}', '{} + {} = {}').with(1, 2, 3)).to.deep.equal([
'One is 1 and two is 2',

@@ -29,0 +29,0 @@ '1 + 2 = 3'

@@ -19,3 +19,3 @@ var cmd = require('../src/cmd');

it('get gets values', function () {
expect(cmd.get('a')({a: 1}, {a: 2}, {a: 3})).to.deep.equal([
expect(cmd.get('a').with({a: 1}, {a: 2}, {a: 3})).to.deep.equal([
1, 2, 3

@@ -26,3 +26,3 @@ ]);

it('get gets deep values', function () {
expect(cmd.get('a', 'b', 'c')({a: {b: {c: 1}}}, {a: {b: {c: 2}}}, {a: {b: {c: 3}}})).to.deep.equal([
expect(cmd.get('a', 'b', 'c').with({a: {b: {c: 1}}}, {a: {b: {c: 2}}}, {a: {b: {c: 3}}})).to.deep.equal([
1, 2, 3

@@ -33,3 +33,3 @@ ]);

it('get gets undefined when no values', function () {
expect(cmd.get('a', 'b', 'c')({a: {b: {}}}, {a: {}}, {})).to.deep.equal([
expect(cmd.get('a', 'b', 'c').with({a: {b: {}}}, {a: {}}, {})).to.deep.equal([
undefined, undefined, undefined

@@ -36,0 +36,0 @@ ]);

@@ -19,3 +19,3 @@ var cmd = require('../src/cmd');

it('groups values into buckets of a particular size', function () {
expect(cmd.group(2)(1, 2, 3, 4)).to.deep.equal([
expect(cmd.group(2).with(1, 2, 3, 4)).to.deep.equal([
[1, 2], [3, 4]

@@ -28,3 +28,3 @@ ]);

return x > 2;
})(1, 2, 3, 4)).to.deep.equal([
}).with(1, 2, 3, 4)).to.deep.equal([
[1, 2], [3, 4]

@@ -31,0 +31,0 @@ ]);

@@ -19,3 +19,3 @@ var cmd = require('../src/cmd');

it('has returns true for valid properties', function () {
expect(cmd.has('a')({a: 1})).to.deep.equal([
expect(cmd.has('a').with({a: 1})).to.deep.equal([
true

@@ -26,3 +26,3 @@ ]);

it('has returns false for invalid properties', function () {
expect(cmd.has('b')({a: 1})).to.deep.equal([
expect(cmd.has('b').with({a: 1})).to.deep.equal([
false

@@ -33,3 +33,3 @@ ]);

it('has returns true for deep valid properties', function () {
expect(cmd.has('a', 'length')({a: 'something'}, {b: 'something'})).to.deep.equal([
expect(cmd.has('a', 'length').with({a: 'something'}, {b: 'something'})).to.deep.equal([
true, false

@@ -36,0 +36,0 @@ ]);

@@ -19,3 +19,3 @@ var cmd = require('../src/cmd');

it('joins values', function () {
expect(cmd.join('::')(0, 1, 2, 3, 4)).to.deep.equal([
expect(cmd.join('::').with(0, 1, 2, 3, 4)).to.deep.equal([
'0::1::2::3::4'

@@ -26,3 +26,3 @@ ]);

it('joins values with multiple args', function () {
expect(cmd.join('::', ', ')(0, 1, 2, 3, 4)).to.deep.equal([
expect(cmd.join('::', ', ').with(0, 1, 2, 3, 4)).to.deep.equal([
'0::1::2::3::4',

@@ -29,0 +29,0 @@ '0, 1, 2, 3, 4'

@@ -24,8 +24,8 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.log).to.be.a('function');
expect(cmd.log).to.be.an('object');
});
it('log logs values', function () {
cmd.log('log1', 'log2');
cmd.log('log3', 'log4');
cmd.log.with('log1', 'log2');
cmd.log.with('log3', 'log4');

@@ -32,0 +32,0 @@ expect(cmd.$logInterface.logs).to.deep.equal([

@@ -30,3 +30,3 @@ var cmd = require('../src/cmd');

return x.toUpperCase();
})('a', 'b', 'c');
}).with('a', 'b', 'c');

@@ -33,0 +33,0 @@ expect(cmd.$loggerInterface.logs).to.deep.equal([

@@ -28,9 +28,9 @@ var cmd = require('../src/cmd');

it('matches based on value', function () {
expect(msgMatch(5)).to.deep.equal(['You have five messages']);
expect(msgMatch.with(5)).to.deep.equal(['You have five messages']);
});
it('returns default when no match', function () {
expect(msgMatch('failure')).to.deep.equal(['Unknown']);
expect(msgMatch.with('failure')).to.deep.equal(['Unknown']);
});
});

@@ -15,9 +15,9 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.max).to.be.a('function');
expect(cmd.max).to.be.an('object');
});
it('returns the max value', function () {
expect(cmd.max(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(10);
expect(cmd.max.with(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(10);
});
});

@@ -15,9 +15,9 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.min).to.be.a('function');
expect(cmd.min).to.be.an('object');
});
it('returns the min value', function () {
expect(cmd.min(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(1);
expect(cmd.min.with(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(1);
});
});

@@ -32,3 +32,3 @@ var cmd = require('../src/cmd');

it('works when no arguments are given', function () {
expect(cmd.add()()).to.deep.equal([]);
expect(cmd.add().with()).to.deep.equal([]);
});

@@ -38,11 +38,11 @@

expect(
cmd.add(1)() ).to.deep.equal([]);
cmd.add(1).with() ).to.deep.equal([]);
expect(
cmd.add(1, 2, 3)() ).to.deep.equal([]);
cmd.add(1, 2, 3).with() ).to.deep.equal([]);
expect(
cmd.add(1, [2, 3])() ).to.deep.equal([]);
cmd.add(1, [2, 3]).with() ).to.deep.equal([]);
expect(
cmd.add([1, 2, 3])() ).to.deep.equal([]);
cmd.add([1, 2, 3]).with() ).to.deep.equal([]);
expect(
cmd.add([1], [2], [3])() ).to.deep.equal([]);
cmd.add([1], [2], [3]).with() ).to.deep.equal([]);
});

@@ -52,11 +52,11 @@

expect(
cmd.add()(1) ).to.deep.equal([1]);
cmd.add().with(1) ).to.deep.equal([1]);
expect(
cmd.add()(1, 2, 3) ).to.deep.equal([1, 2, 3]);
cmd.add().with(1, 2, 3) ).to.deep.equal([1, 2, 3]);
expect(
cmd.add()(1, [2, 3]) ).to.deep.equal([1, 2, 3]);
cmd.add().with(1, [2, 3]) ).to.deep.equal([1, 2, 3]);
expect(
cmd.add()([1, 2, 3]) ).to.deep.equal([1, 2, 3]);
cmd.add().with([1, 2, 3]) ).to.deep.equal([1, 2, 3]);
expect(
cmd.add()([1], [2], [3]) ).to.deep.equal([1, 2, 3]);
cmd.add().with([1], [2], [3]) ).to.deep.equal([1, 2, 3]);
});

@@ -66,11 +66,11 @@

expect(
cmd.add(1)(1) ).to.deep.equal([2]);
cmd.add(1).with(1) ).to.deep.equal([2]);
expect(
cmd.add(1, 2, 3)(1, 2, 3) ).to.deep.equal([7, 8, 9]);
cmd.add(1, 2, 3).with(1, 2, 3) ).to.deep.equal([7, 8, 9]);
expect(
cmd.add(1, [2, 3])(1, [2, 3]) ).to.deep.equal([7, 8, 9]);
cmd.add(1, [2, 3]).with(1, [2, 3]) ).to.deep.equal([7, 8, 9]);
expect(
cmd.add([1, 2, 3])([1, 2, 3]) ).to.deep.equal([7, 8, 9]);
cmd.add([1, 2, 3]).with([1, 2, 3]) ).to.deep.equal([7, 8, 9]);
expect(
cmd.add([1], [2], [3])([1], [2], [3]) ).to.deep.equal([7, 8, 9]);
cmd.add([1], [2], [3]).with([1], [2], [3]) ).to.deep.equal([7, 8, 9]);
});

@@ -80,3 +80,3 @@

expect(
cmd.add.to([1], [2], [3])([100], [200], [300])
cmd.add.to([1], [2], [3]).with([100], [200], [300])
).to.deep.equal(['100123', '200123', '300123']);

@@ -99,3 +99,3 @@ });

expect(
cmd.add(1, 2, 3).map([100], [200], [300])
cmd.add(1, 2, 3).map.with([100], [200], [300])
).to.deep.equal([[106], [206], [306]]);

@@ -121,7 +121,7 @@ });

it('called "add123"', function () {
expect(cmd.add123).to.be.a('function');
expect(cmd.add123).to.be.an('object');
});
it('works when no values are given', function () {
expect(cmd.add123()).to.deep.equal([]);
expect(cmd.add123.with()).to.deep.equal([]);
});

@@ -131,11 +131,11 @@

expect(
cmd.add123(1) ).to.deep.equal([7]);
cmd.add123.with(1) ).to.deep.equal([7]);
expect(
cmd.add123(1, 2, 3) ).to.deep.equal([7, 8, 9]);
cmd.add123.with(1, 2, 3) ).to.deep.equal([7, 8, 9]);
expect(
cmd.add123(1, [2, 3]) ).to.deep.equal([7, 8, 9]);
cmd.add123.with(1, [2, 3]) ).to.deep.equal([7, 8, 9]);
expect(
cmd.add123([1, 2, 3]) ).to.deep.equal([7, 8, 9]);
cmd.add123.with([1, 2, 3]) ).to.deep.equal([7, 8, 9]);
expect(
cmd.add123([1], [2], [3]) ).to.deep.equal([7, 8, 9]);
cmd.add123.with([1], [2], [3]) ).to.deep.equal([7, 8, 9]);
});

@@ -160,3 +160,3 @@

expect(
cmd.add123.map([100], [200], [300])
cmd.add123.map.with([100], [200], [300])
).to.deep.equal([[106], [206], [306]]);

@@ -190,5 +190,5 @@ });

it('works when no values are given', function () {
expect(cmd.addnum._1()).to.deep.equal([]);
expect(cmd.addnum._2()).to.deep.equal([]);
expect(cmd.addnum._3()).to.deep.equal([]);
expect(cmd.addnum._1.with()).to.deep.equal([]);
expect(cmd.addnum._2.with()).to.deep.equal([]);
expect(cmd.addnum._3.with()).to.deep.equal([]);
});

@@ -198,11 +198,11 @@

expect(
cmd.addnum._3(1) ).to.deep.equal([4]);
cmd.addnum._3.with(1) ).to.deep.equal([4]);
expect(
cmd.addnum._3(1, 2, 3) ).to.deep.equal([4, 5, 6]);
cmd.addnum._3.with(1, 2, 3) ).to.deep.equal([4, 5, 6]);
expect(
cmd.addnum._3(1, [2, 3]) ).to.deep.equal([4, 5, 6]);
cmd.addnum._3.with(1, [2, 3]) ).to.deep.equal([4, 5, 6]);
expect(
cmd.addnum._3([1, 2, 3]) ).to.deep.equal([4, 5, 6]);
cmd.addnum._3.with([1, 2, 3]) ).to.deep.equal([4, 5, 6]);
expect(
cmd.addnum._3([1], [2], [3]) ).to.deep.equal([4, 5, 6]);
cmd.addnum._3.with([1], [2], [3]) ).to.deep.equal([4, 5, 6]);
});

@@ -227,3 +227,3 @@

expect(
cmd.addnum._3.map([100], [200], [300])
cmd.addnum._3.map.with([100], [200], [300])
).to.deep.equal([[103], [203], [303]]);

@@ -251,3 +251,3 @@ });

it('works when no arguments are given', function () {
expect(cmd.interlace()()).to.deep.equal('');
expect(cmd.interlace().with()).to.deep.equal('');
});

@@ -257,11 +257,11 @@

expect(
cmd.interlace('a')() ).to.deep.equal('');
cmd.interlace('a').with() ).to.deep.equal('');
expect(
cmd.interlace('a', 'b', 'c')() ).to.deep.equal('');
cmd.interlace('a', 'b', 'c').with() ).to.deep.equal('');
expect(
cmd.interlace('a', ['b', 'c'])() ).to.deep.equal('');
cmd.interlace('a', ['b', 'c']).with() ).to.deep.equal('');
expect(
cmd.interlace(['a', 'b', 'c'])() ).to.deep.equal('');
cmd.interlace(['a', 'b', 'c']).with() ).to.deep.equal('');
expect(
cmd.interlace(['a'], ['b'], ['c'])() ).to.deep.equal('');
cmd.interlace(['a'], ['b'], ['c']).with() ).to.deep.equal('');
});

@@ -271,11 +271,11 @@

expect(
cmd.interlace()('a') ).to.deep.equal('a');
cmd.interlace().with('a') ).to.deep.equal('a');
expect(
cmd.interlace()('a', 'b', 'c') ).to.deep.equal('abc');
cmd.interlace().with('a', 'b', 'c') ).to.deep.equal('abc');
expect(
cmd.interlace()('a', ['b', 'c']) ).to.deep.equal('abc');
cmd.interlace().with('a', ['b', 'c']) ).to.deep.equal('abc');
expect(
cmd.interlace()(['a', 'b', 'c']) ).to.deep.equal('abc');
cmd.interlace().with(['a', 'b', 'c']) ).to.deep.equal('abc');
expect(
cmd.interlace()(['a'], ['b'], ['c']) ).to.deep.equal('abc');
cmd.interlace().with(['a'], ['b'], ['c']) ).to.deep.equal('abc');
});

@@ -285,11 +285,11 @@

expect(
cmd.interlace('a')('A') ).to.deep.equal('A');
cmd.interlace('a').with('A') ).to.deep.equal('A');
expect(
cmd.interlace('a', 'b', 'c')('A', 'B', 'C') ).to.deep.equal('AabcBabcC');
cmd.interlace('a', 'b', 'c').with('A', 'B', 'C') ).to.deep.equal('AabcBabcC');
expect(
cmd.interlace('a', ['b', 'c'])('A', ['B', 'C']) ).to.deep.equal('AabcBabcC');
cmd.interlace('a', ['b', 'c']).with('A', ['B', 'C']) ).to.deep.equal('AabcBabcC');
expect(
cmd.interlace(['a', 'b', 'c'])(['A', 'B', 'C']) ).to.deep.equal('AabcBabcC');
cmd.interlace(['a', 'b', 'c']).with(['A', 'B', 'C']) ).to.deep.equal('AabcBabcC');
expect(
cmd.interlace(['a'], ['b'], ['c'])(['A'], ['B'], ['C']) ).to.deep.equal('AabcBabcC');
cmd.interlace(['a'], ['b'], ['c']).with(['A'], ['B'], ['C']) ).to.deep.equal('AabcBabcC');
});

@@ -299,3 +299,3 @@

expect(
cmd.interlace.to(['a'], ['b'], ['c'])(['A'], ['B'], ['C'])
cmd.interlace.to(['a'], ['b'], ['c']).with(['A'], ['B'], ['C'])
).to.deep.equal('AabcBabcC');

@@ -314,3 +314,3 @@ });

expect(
cmd.interlace('.').map(['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'])
cmd.interlace('.').map.with(['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'])
).to.deep.equal(['a.b.c', 'd.e.f', 'g.h.i']);

@@ -335,7 +335,7 @@ });

it('called "interlaceUnderscore"', function () {
expect(cmd.interlaceUnderscore).to.be.a('function');
expect(cmd.interlaceUnderscore).to.be.an('object');
});
it('works when no values are given', function () {
expect(cmd.interlaceUnderscore()).to.deep.equal('');
expect(cmd.interlaceUnderscore.with()).to.deep.equal('');
});

@@ -345,11 +345,11 @@

expect(
cmd.interlaceUnderscore('a') ).to.deep.equal('a');
cmd.interlaceUnderscore.with('a') ).to.deep.equal('a');
expect(
cmd.interlaceUnderscore('a', 'b', 'c') ).to.deep.equal('a_b_c');
cmd.interlaceUnderscore.with('a', 'b', 'c') ).to.deep.equal('a_b_c');
expect(
cmd.interlaceUnderscore('a', ['b', 'c']) ).to.deep.equal('a_b_c');
cmd.interlaceUnderscore.with('a', ['b', 'c']) ).to.deep.equal('a_b_c');
expect(
cmd.interlaceUnderscore(['a', 'b', 'c']) ).to.deep.equal('a_b_c');
cmd.interlaceUnderscore.with(['a', 'b', 'c']) ).to.deep.equal('a_b_c');
expect(
cmd.interlaceUnderscore(['a'], ['b'], ['c']) ).to.deep.equal('a_b_c');
cmd.interlaceUnderscore.with(['a'], ['b'], ['c']) ).to.deep.equal('a_b_c');
});

@@ -369,3 +369,3 @@

expect(
cmd.interlaceUnderscore.map(['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'])
cmd.interlaceUnderscore.map.with(['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'])
).to.deep.equal(['a_b_c', 'd_e_f', 'g_h_i']);

@@ -397,4 +397,4 @@ });

it('works when no values are given', function () {
expect(cmd.interlaceWith.space()).to.deep.equal('');
expect(cmd.interlaceWith.dash()).to.deep.equal('');
expect(cmd.interlaceWith.space.with()).to.deep.equal('');
expect(cmd.interlaceWith.dash.with()).to.deep.equal('');
});

@@ -404,11 +404,11 @@

expect(
cmd.interlaceWith.dash('a') ).to.deep.equal('a');
cmd.interlaceWith.dash.with('a') ).to.deep.equal('a');
expect(
cmd.interlaceWith.dash('a', 'b', 'c') ).to.deep.equal('a-b-c');
cmd.interlaceWith.dash.with('a', 'b', 'c') ).to.deep.equal('a-b-c');
expect(
cmd.interlaceWith.dash('a', ['b', 'c']) ).to.deep.equal('a-b-c');
cmd.interlaceWith.dash.with('a', ['b', 'c']) ).to.deep.equal('a-b-c');
expect(
cmd.interlaceWith.dash(['a', 'b', 'c']) ).to.deep.equal('a-b-c');
cmd.interlaceWith.dash.with(['a', 'b', 'c']) ).to.deep.equal('a-b-c');
expect(
cmd.interlaceWith.dash(['a'], ['b'], ['c']) ).to.deep.equal('a-b-c');
cmd.interlaceWith.dash.with(['a'], ['b'], ['c']) ).to.deep.equal('a-b-c');
});

@@ -428,3 +428,3 @@

expect(
cmd.interlaceWith.space.map(['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'])
cmd.interlaceWith.space.map.with(['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'])
).to.deep.equal(['a b c', 'd e f', 'g h i']);

@@ -431,0 +431,0 @@ });

@@ -19,5 +19,5 @@ var cmd = require('../src/cmd');

it('returns the sum of arguments plus each value', function () {
expect(cmd.multiply(1, 2, 3)(4, 40, 400)).to.deep.equal([24, 240, 2400]);
expect(cmd.multiply(1, 2, 3).with(4, 40, 400)).to.deep.equal([24, 240, 2400]);
});
});

@@ -15,3 +15,3 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.not).to.be.a('function');
expect(cmd.not).to.be.an('object');
});

@@ -22,11 +22,11 @@

it('false', function () {
expect(cmd.not(false)).to.deep.equal([true]);
expect(cmd.not.with(false)).to.deep.equal([true]);
});
it('null', function () {
expect(cmd.not(null)).to.deep.equal([true]);
expect(cmd.not.with(null)).to.deep.equal([true]);
});
it('undefined', function () {
expect(cmd.not(undefined)).to.deep.equal([true]);
expect(cmd.not.with(undefined)).to.deep.equal([true]);
});

@@ -39,19 +39,19 @@

it('0', function () {
expect(cmd.not(0)).to.deep.equal([false]);
expect(cmd.not.with(0)).to.deep.equal([false]);
});
it('1', function () {
expect(cmd.not(1)).to.deep.equal([false]);
expect(cmd.not.with(1)).to.deep.equal([false]);
});
it('true', function () {
expect(cmd.not(true)).to.deep.equal([false]);
expect(cmd.not.with(true)).to.deep.equal([false]);
});
it('""', function () {
expect(cmd.not("")).to.deep.equal([false]);
expect(cmd.not.with("")).to.deep.equal([false]);
});
it('{}', function () {
expect(cmd.not({})).to.deep.equal([false]);
expect(cmd.not.with({})).to.deep.equal([false]);
});

@@ -58,0 +58,0 @@

@@ -19,3 +19,3 @@ var cmd = require('../src/cmd');

it('creates an object with keys and values', function () {
expect(cmd.obj('a', 'b', 'c')(1, 2, 3)).to.deep.equal([
expect(cmd.obj('a', 'b', 'c').with(1, 2, 3)).to.deep.equal([
{a: 1, b: 2, c: 3}

@@ -22,0 +22,0 @@ ]);

@@ -15,9 +15,9 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.product).to.be.a('function');
expect(cmd.product).to.be.an('object');
});
it('returns the product of values', function () {
expect(cmd.product(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(3628800);
expect(cmd.product.with(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(3628800);
});
});

@@ -20,3 +20,3 @@ var cmd = require('../src/cmd');

var test = [1, 2, 3];
cmd.push.to(test)(4, 5, 6);
cmd.push.to(test).with(4, 5, 6);
expect(test).to.deep.equal([

@@ -30,3 +30,3 @@ 1, 2, 3, 4, 5, 6

var test2 = [9, 8, 7];
cmd.push.to(test1, test2)(4, 5, 6);
cmd.push.to(test1, test2).with(4, 5, 6);
expect(test1).to.deep.equal([

@@ -42,3 +42,3 @@ 1, 2, 3, 4, 5, 6

var test = [1, 2, 3];
cmd.push([test])(4, 5, 6);
cmd.push([test]).with(4, 5, 6);
expect(test).to.deep.equal([

@@ -52,3 +52,3 @@ 1, 2, 3, 4, 5, 6

var test2 = [9, 8, 7];
cmd.push([test1, test2])(4, 5, 6);
cmd.push([test1, test2]).with(4, 5, 6);
expect(test1).to.deep.equal([

@@ -65,3 +65,3 @@ 1, 2, 3, 4, 5, 6

var test2 = [9, 8, 7];
cmd.push([test1], [test2])(4, 5, 6);
cmd.push([test1], [test2]).with(4, 5, 6);
expect(test1).to.deep.equal([

@@ -68,0 +68,0 @@ 1, 2, 3, 4, 5, 6

@@ -21,3 +21,3 @@ var cmd = require('../src/cmd');

return x % 2 == 0;
})(0, 1, 2, 3, 4)).to.deep.equal([1, 3]);
}).with(0, 1, 2, 3, 4)).to.deep.equal([1, 3]);
});

@@ -30,5 +30,5 @@

return x === 3;
})(0, 1, 2, 3, 4)).to.deep.equal([1]);
}).with(0, 1, 2, 3, 4)).to.deep.equal([1]);
});
});

@@ -15,9 +15,9 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.reverse).to.be.a('function');
expect(cmd.reverse).to.be.an('object');
});
it('returns the reverse of values', function () {
expect(cmd.reverse(6, [5, 4, 3], 2, [1])).to.deep.equal([1, 2, 3, 4, 5, 6]);
expect(cmd.reverse.with(6, [5, 4, 3], 2, [1])).to.deep.equal([1, 2, 3, 4, 5, 6]);
});
});

@@ -19,11 +19,11 @@ var cmd = require('../src/cmd');

it('asc is a function', function () {
expect(cmd.sort.asc).to.be.a('function');
expect(cmd.sort.asc).to.be.an('object');
});
it('desc is a function', function () {
expect(cmd.sort.desc).to.be.a('function');
expect(cmd.sort.desc).to.be.an('object');
});
it('returns numeric array unsorted with 0', function () {
expect(cmd.sort(0)(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(
expect(cmd.sort(0).with(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(
[2, 4, 6, 8, 10, 9, 7, 5, 3, 1]

@@ -34,3 +34,3 @@ );

it('returns numeric array sorted in ascending order with 1', function () {
expect(cmd.sort(1)(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(
expect(cmd.sort(1).with(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

@@ -41,3 +41,3 @@ );

it('returns numeric array sorted in descending order with -1', function () {
expect(cmd.sort(-1)(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(
expect(cmd.sort(-1).with(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

@@ -48,3 +48,3 @@ );

it('returns numeric array sorted in ascending order', function () {
expect(cmd.sort.asc(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(
expect(cmd.sort.asc.with(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

@@ -55,3 +55,3 @@ );

it('returns numeric array sorted in descending order', function () {
expect(cmd.sort.desc(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(
expect(cmd.sort.desc.with(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

@@ -62,3 +62,3 @@ );

it('returns alpha array sorted in ascending order', function () {
expect(cmd.sort.asc('b', 'd', 'f', 'h', 'j', 'i', 'g', 'e', 'c', 'a')).to.deep.equal(
expect(cmd.sort.asc.with('b', 'd', 'f', 'h', 'j', 'i', 'g', 'e', 'c', 'a')).to.deep.equal(
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

@@ -69,3 +69,3 @@ );

it('returns alpha array sorted in descending order', function () {
expect(cmd.sort.desc('b', 'd', 'f', 'h', 'j', 'i', 'g', 'e', 'c', 'a')).to.deep.equal(
expect(cmd.sort.desc.with('b', 'd', 'f', 'h', 'j', 'i', 'g', 'e', 'c', 'a')).to.deep.equal(
['j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a']

@@ -72,0 +72,0 @@ );

@@ -19,5 +19,5 @@ var cmd = require('../src/cmd');

it('returns the sum of arguments plus each value', function () {
expect(cmd.subtract(1, 2, 3)(4, 40, 400)).to.deep.equal([-2, 34, 394]);
expect(cmd.subtract(1, 2, 3).with(4, 40, 400)).to.deep.equal([-2, 34, 394]);
});
});

@@ -15,9 +15,9 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.sum).to.be.a('function');
expect(cmd.sum).to.be.an('object');
});
it('returns the sum of values', function () {
expect(cmd.sum(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(55);
expect(cmd.sum.with(2, 4, 6, 8, 10, 9, 7, 5, 3, 1)).to.deep.equal(55);
});
});

@@ -19,5 +19,5 @@ var cmd = require('../src/cmd');

it('alters a value in the stream', function () {
expect(cmd.tap(function (x) { return 2 * x + 1; })(1, 2, 3, 4, 5)).to.deep.equal([3, 5, 7, 9, 11]);
expect(cmd.tap(function (x) { return 2 * x + 1; }).with(1, 2, 3, 4, 5)).to.deep.equal([3, 5, 7, 9, 11]);
});
});

@@ -10,3 +10,3 @@ var cmd = require('../src/cmd');

it('is a function', function () {
expect(cmd.alert).to.be.a('function');
expect(cmd.use).to.be.a('function');
});

@@ -13,0 +13,0 @@

Sorry, the diff of this file is not supported yet

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