Comparing version
{ | ||
"name": "cmd.js", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A chainable utility toolkit for JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -34,3 +34,3 @@ # cmd.js | ||
// Test | ||
cmd.log('Hello World'); | ||
cmd.log.with('Hello World'); | ||
``` | ||
@@ -48,3 +48,3 @@ | ||
// Test | ||
cmd.log('Hello World'); | ||
cmd.log.with('Hello World'); | ||
</script> | ||
@@ -179,5 +179,5 @@ ``` | ||
var sortAndPrint = cmd.sort(cmd.get('age')). | ||
and.logger(cmd.get('name'), cmd.get('id')); | ||
logger(cmd.get('name'), cmd.get('id')); | ||
sortAndPrint(users); | ||
sortAndPrint.with(users); | ||
@@ -198,5 +198,5 @@ // The output: | ||
```js | ||
cmd.add(...arguments)(...values); | ||
cmd.add(...arguments).with(...values); | ||
cmd.add(100, 200)(7, 8, 9); // [307, 308, 309] | ||
cmd.add(100, 200).with(7, 8, 9); // [307, 308, 309] | ||
``` | ||
@@ -217,3 +217,3 @@ | ||
```js | ||
cmd.filter(cmd.exists)(1, 2, null, 3); // [1, 2, 3] | ||
cmd.filter(cmd.exists).with(1, 2, null, 3); // [1, 2, 3] | ||
@@ -220,0 +220,0 @@ cmd.filter(function (x) { |
@@ -10,4 +10,4 @@ ### cmd.add | ||
```js | ||
cmd.add(10)(1, 2, 3, 4, 5); | ||
cmd.add(10).with(1, 2, 3, 4, 5); | ||
// [11, 12, 13, 14, 15] | ||
``` |
@@ -10,3 +10,3 @@ ### cmd.call | ||
```js | ||
cmd.call('toPrecision', 3)(1, 10, 100); | ||
cmd.call('toPrecision', 3).with(1, 10, 100); | ||
// [1.00, 10.0, 100] | ||
@@ -18,7 +18,7 @@ ``` | ||
```js | ||
cmd.call(Math.pow, 2, cmd.it)(1, 2, 3); | ||
cmd.call(Math.pow, 2, cmd.it).with(1, 2, 3); | ||
// [2, 4, 8] | ||
cmd.call(Math.pow, cmd.it, 2)(1, 2, 3); | ||
cmd.call(Math.pow, cmd.it, 2).with(1, 2, 3); | ||
// [1, 4, 9] | ||
``` |
@@ -10,4 +10,4 @@ ### cmd.default | ||
```js | ||
cmd.default(9)(1, null, 3) | ||
cmd.default(9).with(1, null, 3) | ||
// [1, 9, 3] | ||
``` |
@@ -10,4 +10,4 @@ ### cmd.divide | ||
```js | ||
cmd.divide(10)(1, 2, 3, 4, 5); | ||
cmd.divide(10).with(1, 2, 3, 4, 5); | ||
// [0.1, 0.2, 0.3, 0.4, 0.5] | ||
``` |
@@ -10,4 +10,4 @@ ### cmd.equals | ||
```js | ||
cmd.equals(30, 50)(100, 20, 50, 30); | ||
cmd.equals(30, 50).with(100, 20, 50, 30); | ||
// [false, false, true, true] | ||
``` |
@@ -10,4 +10,4 @@ ### cmd.extend | ||
```js | ||
cmd.extend({color: 'red'})({item: 'wrench'}, {item: 'apple'}); | ||
cmd.extend({color: 'red'}).with({item: 'wrench'}, {item: 'apple'}); | ||
// [{item: 'wrench', color: 'red'}, {item: 'apple', color: 'red'}] | ||
``` |
@@ -14,4 +14,4 @@ ### cmd.filter | ||
return x > 5; | ||
})(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | ||
}).with(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | ||
// [6, 8, 10] | ||
``` |
@@ -10,4 +10,4 @@ ### cmd.format | ||
```js | ||
cmd.format('I love {}pples, {}lueberries, and {}ake', '{} + {} = {}')('a', 'b', 'c'); | ||
cmd.format('I love {}pples, {}lueberries, and {}ake', '{} + {} = {}').with('a', 'b', 'c'); | ||
// ["I love apples, blueberries, and cake", "a + b = c"] | ||
``` |
@@ -29,4 +29,4 @@ ### cmd.get | ||
}]; | ||
cmd.get('pet', 'name')(people); | ||
cmd.get('pet', 'name').with(people); | ||
// ["Sherlock", "Rosa", "Maxximus"] | ||
``` |
@@ -10,3 +10,3 @@ ### cmd.group | ||
```js | ||
cmd.group(2)(1, 2, 3, 4); | ||
cmd.group(2).with(1, 2, 3, 4); | ||
// [[1, 2], [3, 4]] | ||
@@ -16,4 +16,4 @@ | ||
return x > 2; | ||
})(1, 2, 3, 4)); | ||
}).with(1, 2, 3, 4); | ||
// [[1, 2], [3, 4]] | ||
``` |
@@ -10,4 +10,4 @@ ### cmd.has | ||
```js | ||
cmd.has('a', 'length')({a: 'something'}, {b: 'something'}); | ||
cmd.has('a', 'length').with({a: 'something'}, {b: 'something'}); | ||
// [true, false] | ||
``` |
@@ -10,4 +10,4 @@ ### cmd.join | ||
```js | ||
cmd.join('-', '+')('a', 'b', 'c'); | ||
cmd.join('-', '+').with('a', 'b', 'c'); | ||
// ["a-b-c", "a+b+c"] | ||
``` |
@@ -13,3 +13,3 @@ ### cmd.logger | ||
}; | ||
cmd.logger(withDate, 'and the number is: {}')(1, 2, 3); | ||
cmd.logger(withDate, 'and the number is: {}').with(1, 2, 3); | ||
// Log at Sat Jan 31 2015 23:05:59 GMT-0800 (PST): 1 and the number is: 1 | ||
@@ -16,0 +16,0 @@ // Log at Sat Jan 31 2015 23:05:59 GMT-0800 (PST): 2 and the number is: 2 |
@@ -10,4 +10,4 @@ ### cmd.multiply | ||
```js | ||
cmd.multiply(10)(1, 2, 3, 4, 5); | ||
cmd.multiply(10).with(1, 2, 3, 4, 5); | ||
// [10, 20, 30, 40, 50] | ||
``` |
@@ -5,3 +5,3 @@ ### cmd.obj | ||
|----------|------------------|---------------| | ||
| `obj` | `[{ ... }, ...]` | Zips up an object using arguments as keys and values as values. | | ||
| `obj` | `[{ ... }, ...]` | Zips up an object using arguments as keys and values as values. | | ||
@@ -11,3 +11,3 @@ The following example builds an object with keys and repeated values. Note the `[[wrapped array]]` syntax to avoid spreading the array as arguments: | ||
```js | ||
cmd.obj('name', 'age', 'city', 'interests')( | ||
cmd.obj('name', 'age', 'city', 'interests').with( | ||
'Nate', 25, 'Los Angeles, CA', [['tech', 'javascript', 'node.js', 'space']] | ||
@@ -14,0 +14,0 @@ ); |
@@ -14,4 +14,4 @@ ### cmd.reject | ||
return x > 5; | ||
})(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | ||
}).with(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | ||
// [1, 2, 3, 4, 5, 7, 9] | ||
``` |
@@ -21,3 +21,3 @@ ### cmd.sort | ||
return typeof x; | ||
})('c', 'a', 'b', 3, 1, 2); | ||
}).with('c', 'a', 'b', 3, 1, 2); | ||
// [3, 1, 2, "c", "a", "b"] | ||
@@ -28,3 +28,3 @@ | ||
return x.price; | ||
})( | ||
}).with( | ||
{name: 'TV', price: 899.00}, | ||
@@ -31,0 +31,0 @@ {name: 'Car', price: 16999.00}, |
@@ -10,4 +10,4 @@ ### cmd.subtract | ||
```js | ||
cmd.subtract(10)(1, 2, 3, 4, 5); | ||
cmd.subtract(10).with(1, 2, 3, 4, 5); | ||
// [-9, -8, -7, -6, -5] | ||
``` |
(function () { | ||
'use strict'; | ||
/** | ||
* From: http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object/728694#728694 | ||
*/ | ||
function clone(obj) { | ||
var copy; | ||
this.export = function (cmd) { | ||
// Handle the 3 simple types, and null or undefined | ||
if (obj === null || typeof obj !== 'object') { | ||
return obj; | ||
} | ||
/** | ||
* Command: clone(null) === [false] | ||
* clone.raw(null) === false | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return clone(val, cmd); | ||
}; | ||
// Handle Date | ||
if (obj instanceof Date) { | ||
copy = new Date(); | ||
copy.setTime(obj.getTime()); | ||
return copy; | ||
} | ||
/** | ||
* From: http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object/728694#728694 | ||
*/ | ||
function clone(obj) { | ||
var copy; | ||
// Handle Array | ||
if (obj instanceof Array) { | ||
copy = []; | ||
for (var i = 0, len = obj.length; i < len; i++) { | ||
copy[i] = clone(obj[i]); | ||
// Handle the 3 simple types, and null or undefined | ||
if (obj === null || typeof obj !== 'object') { | ||
return obj; | ||
} | ||
return copy; | ||
// Handle Date | ||
if (obj instanceof Date) { | ||
copy = new Date(); | ||
copy.setTime(obj.getTime()); | ||
return copy; | ||
} | ||
// Handle Array | ||
if (obj instanceof Array) { | ||
copy = []; | ||
for (var i = 0, len = obj.length; i < len; i++) { | ||
copy[i] = clone(obj[i]); | ||
} | ||
return copy; | ||
} | ||
// Never clone commands | ||
if (obj.constructor === cmd.constructor) { | ||
return obj; | ||
} | ||
// Handle Object | ||
if (obj instanceof Object) { | ||
return cloneObject(obj); | ||
} | ||
throw new Error('Unable to copy obj! Its type (' + typeof obj + ')is not supported.'); | ||
} | ||
// Handle Object | ||
if (obj instanceof Object) { | ||
copy = {}; | ||
function cloneObject(obj) { | ||
var copy = {}; | ||
for (var attr in obj) { | ||
@@ -41,18 +65,3 @@ if (obj.hasOwnProperty(attr)) { | ||
} | ||
throw new Error('Unable to copy obj! Its type (' + typeof obj + ')is not supported.'); | ||
} | ||
this.export = function () { | ||
/** | ||
* Command: clone(null) === [false] | ||
* clone.raw(null) === false | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return clone(val); | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].clone = {} : this); |
(function () { | ||
'use strict'; | ||
this.export = function () { | ||
this.export = function (cmd) { | ||
@@ -28,2 +28,5 @@ var arraysEqual = function (a, b) { | ||
var by = args.map(function (arg) { | ||
if (arg && arg.constructor === cmd.constructor) { | ||
return arg.raw(val); | ||
} | ||
switch (typeof arg) { | ||
@@ -30,0 +33,0 @@ case 'number': |
@@ -22,2 +22,5 @@ (function () { | ||
args.forEach(function (arg) { | ||
if (arg && arg.constructor === cmd.constructor) { | ||
arg = arg.raw(val); | ||
} | ||
var log = typeof arg === 'function' ? arg(val) : ( | ||
@@ -24,0 +27,0 @@ typeof arg === 'string' ? cmd.format(arg).raw(val) : arg |
@@ -34,6 +34,12 @@ (function () { | ||
local.map(function (arg) { | ||
return arg(a); | ||
if (arg && arg.constructor === cmd.constructor) { | ||
return arg.raw(a); | ||
} | ||
return (arg.raw || arg)(a); | ||
}), | ||
local.map(function (arg) { | ||
return arg(b); | ||
if (arg && arg.constructor === cmd.constructor) { | ||
return arg.raw(b); | ||
} | ||
return (arg.raw || arg)(b); | ||
}) | ||
@@ -40,0 +46,0 @@ ); |
110213
0.98%2437
0.79%