mol-proto
Advanced tools
Comparing version 0.1.10 to 0.1.11
{ | ||
"name": "proto", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"homepage": "https://github.com/MailOnline/proto", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -24,2 +24,3 @@ 'use strict'; | ||
* - [waitFor](#waitFor) | ||
* - [not](#not) | ||
* | ||
@@ -43,3 +44,4 @@ * These methods can be [chained](proto.js.html#Proto) | ||
once: once, | ||
waitFor: waitFor | ||
waitFor: waitFor, | ||
not: not | ||
}; | ||
@@ -182,3 +184,3 @@ | ||
args = args.concat(this, slice.call(arguments, 1)); | ||
deferFunc.apply(null, args); | ||
return deferFunc.apply(null, args); | ||
} | ||
@@ -197,3 +199,3 @@ | ||
var args = slice.call(arguments, 2); | ||
_delayMethod(this, funcOrMethodName, wait, args); | ||
return _delayMethod(this, funcOrMethodName, wait, args); | ||
} | ||
@@ -211,3 +213,3 @@ | ||
var args = slice.call(arguments, 1); | ||
_delayMethod(this, funcOrMethodName, 1, args); | ||
return _delayMethod(this, funcOrMethodName, 1, args); | ||
} | ||
@@ -228,2 +230,3 @@ | ||
* The context in function when it is executed is set to `null`. | ||
* Arguments passed to the function are appended to the arguments passed to delayed. | ||
* | ||
@@ -238,4 +241,5 @@ * @param {Function} self function which execution has to be deferred | ||
, args = slice.call(arguments, 1); | ||
return function() { | ||
return _delay(func, wait, args, this); | ||
return function() { // ... arguments | ||
var passArgs = args.concat(slice.call(arguments)); | ||
return _delay(func, wait, passArgs, this); | ||
}; | ||
@@ -248,2 +252,3 @@ } | ||
* The context in function when it is executed is set to `null`. | ||
* Arguments passed to the function are appended to the arguments passed to deferred. | ||
* | ||
@@ -256,5 +261,6 @@ * @param {Function} self function which execution has to be deferred | ||
var func = this | ||
, args = arguments; | ||
return function() { | ||
return _delay(func, 1, args, this); | ||
, args = slice.call(arguments); | ||
return function() { // ... arguments | ||
var passArgs = args.concat(slice.call(arguments)); | ||
return _delay(func, 1, passArgs, this); | ||
}; | ||
@@ -382,1 +388,14 @@ } | ||
} | ||
/** | ||
* returns the function that negates (! operator) the result of the original function | ||
* @param {Function} self function to negate | ||
* @return {Function} | ||
*/ | ||
function not() { | ||
var func = this; | ||
return function() { | ||
return !func.apply(this, arguments); | ||
}; | ||
} |
@@ -614,6 +614,8 @@ 'use strict'; | ||
}); | ||
else | ||
return everyKey.call(this, function(value, key) { | ||
return isEqual.call(value, obj[key]); | ||
}); | ||
else { | ||
return allKeys.call(this).length == allKeys.call(obj).length | ||
&& everyKey.call(this, function(value, key) { | ||
return isEqual.call(value, obj[key]); | ||
}); | ||
} | ||
} |
@@ -91,3 +91,3 @@ 'use strict'; | ||
// and use "this" instead | ||
__.extend.call(subclass, thisClass, true); | ||
__.deepExtend.call(subclass, thisClass, true); | ||
@@ -94,0 +94,0 @@ return subclass; |
@@ -39,3 +39,3 @@ 'use strict'; | ||
function firstUpperCase() { | ||
return this[0].toUpperCase() + this.slice(1); | ||
return this ? this[0].toUpperCase() + this.slice(1) : this; | ||
} | ||
@@ -50,3 +50,3 @@ | ||
function firstLowerCase() { | ||
return this[0].toLowerCase() + this.slice(1); | ||
return this ? this[0].toLowerCase() + this.slice(1) : this; | ||
} | ||
@@ -53,0 +53,0 @@ |
@@ -10,2 +10,4 @@ 'use strict'; | ||
* - [property](#property) | ||
* - [compareProperty](#compareProperty) | ||
* - [noop](#noop) | ||
*/ | ||
@@ -18,3 +20,5 @@ var utilMethods = module.exports = { | ||
identity: identity, | ||
property: property | ||
property: property, | ||
compareProperty: compareProperty, | ||
noop: noop | ||
}; | ||
@@ -105,1 +109,25 @@ | ||
} | ||
/** | ||
* Returns function that can be used in array sort to sort by a given property | ||
* | ||
* @param {String} self | ||
* @return {Function} | ||
*/ | ||
function compareProperty() { | ||
var key = this; | ||
return function(a, b) { | ||
return a[key] < b[key] | ||
? -1 | ||
: a[key] > b[key] | ||
? 1 | ||
: 0; | ||
}; | ||
} | ||
/** | ||
* Function that does nothing | ||
*/ | ||
function noop() {} |
@@ -121,2 +121,4 @@ 'use strict'; | ||
* - [property](proto_util.js.html#property) | ||
* - [compareProperty](proto_util.js.html#compareProperty) | ||
* - [noop](proto_util.js.html#noop) | ||
*/ | ||
@@ -123,0 +125,0 @@ var utilMethods = require('./proto_util'); |
{ | ||
"name": "mol-proto", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"description": "ES5 object manipulation library for node and modern browsers", | ||
@@ -5,0 +5,0 @@ "main": "lib/proto.js", |
@@ -6,3 +6,3 @@ proto | ||
[![Build Status](https://travis-ci.org/MailOnline/proto.png?branch=master)](https://travis-ci.org/MailOnline/proto) | ||
[![Build Status](https://travis-ci.org/MailOnline/proto.png?branch=master)](https://travis-ci.org/MailOnline/proto) [![Code Climate](https://codeclimate.com/github/MailOnline/proto/badges/gpa.svg)](https://codeclimate.com/github/MailOnline/proto) | ||
@@ -139,1 +139,3 @@ Documentation: http://mailonline.github.io/proto/ | ||
* [property](http://mailonline.github.io/proto/proto_util.js.html#property) | ||
* [compareProperty](http://mailonline.github.io/proto/proto_util.js.html#compareProperty) | ||
* [noop](http://mailonline.github.io/proto_util.js.html#noop) |
@@ -188,3 +188,3 @@ 'use strict'; | ||
delayedFunc.call(context); | ||
delayedFunc.call(context, 4, 5); | ||
@@ -196,3 +196,3 @@ assert.equal(called, undefined); | ||
assert.equal(called, true); | ||
assert.deepEqual(args, [1, 2, 3]); | ||
assert.deepEqual(args, [1, 2, 3, 4, 5]); | ||
done(); | ||
@@ -214,3 +214,3 @@ }, 20); | ||
deferredFunc.call(context); | ||
deferredFunc.call(context, 4, 5); | ||
@@ -222,3 +222,3 @@ assert.equal(called, undefined); | ||
assert.equal(called, true); | ||
assert.deepEqual(args, [1, 2, 3]); | ||
assert.deepEqual(args, [1, 2, 3, 4, 5]); | ||
done(); | ||
@@ -455,2 +455,20 @@ }, 5); | ||
it('should define not function', function() { | ||
function odd(number) { | ||
return !!(number % 2); | ||
} | ||
var even = _.not(odd); | ||
assert.equal(odd(3), true); | ||
assert.equal(odd(5), true); | ||
assert.equal(odd(2), false); | ||
assert.equal(odd(4), false); | ||
assert.equal(even(3), false); | ||
assert.equal(even(5), false); | ||
assert.equal(even(2), true); | ||
assert.equal(even(4), true); | ||
}); | ||
}); |
@@ -697,2 +697,3 @@ 'use strict'; | ||
, obj3 = { name: 'milo', info: { test: 2 } } | ||
, obj4 = { name: 'milo' } | ||
, arr1 = [ 1, 2, [ 3, 4, { test: 5 } ] ] | ||
@@ -712,3 +713,6 @@ , arr2 = [ 1, 2, [ 3, 4, { test: 5 } ] ] | ||
assert(! _.isEqual(/[a-c]/, /[a-c]/i)); | ||
assert(! _.isEqual(obj3, obj4)); | ||
assert(! _.isEqual(obj4, obj3)); | ||
}) | ||
}); |
@@ -73,2 +73,28 @@ 'use strict'; | ||
}); | ||
it('should define compareProperty function', function() { | ||
var arr = [ | ||
{ value: 1, label: 'a'}, | ||
{ value: 4, label: 'c'}, | ||
{ value: 3, label: 'd'}, | ||
{ value: 2, label: 'b'} | ||
]; | ||
arr.sort(_.compareProperty('value')); | ||
assert.deepEqual(arr, [ | ||
{ value: 1, label: 'a'}, | ||
{ value: 2, label: 'b'}, | ||
{ value: 3, label: 'd'}, | ||
{ value: 4, label: 'c'} | ||
]); | ||
arr.sort(_.compareProperty('label')); | ||
assert.deepEqual(arr, [ | ||
{ value: 1, label: 'a'}, | ||
{ value: 2, label: 'b'}, | ||
{ value: 4, label: 'c'}, | ||
{ value: 3, label: 'd'} | ||
]); | ||
}); | ||
}); |
193851
4795
140