Comparing version 0.8.2 to 0.9.0
@@ -5,14 +5,20 @@ /** | ||
var isFunction = require('./is-function'); | ||
var exists = require('./exists'); | ||
/** | ||
* Copies enumerable and own properties from a source object(s) to a target object, aka extend. | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign | ||
* I added functionality to support assign as a partial function | ||
* @function module:101/assign | ||
* @param {object} target - object which source objects are extending (being assigned to) | ||
* @param {object} [target] - object which source objects are extending (being assigned to) | ||
* @param {object} sources... - objects whose properties are being assigned to the source object | ||
* @return {object} source with extended properties | ||
*/ | ||
module.exports = function(target, firstSource) { | ||
module.exports = assign; | ||
function assign (target, firstSource) { | ||
if (arguments.length === 1) { | ||
firstSource = arguments[0]; | ||
return function (target) { | ||
return assign(target, firstSource); | ||
}; | ||
} | ||
if (target === undefined || target === null) | ||
@@ -27,3 +33,3 @@ throw new TypeError('Cannot convert first argument to object'); | ||
var nextKey = keysArray[nextIndex]; | ||
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); | ||
Object.getOwnPropertyDescriptor(nextSource, nextKey); | ||
// I changed the following line to get 100% test coverage. | ||
@@ -39,2 +45,2 @@ // if (desc !== undefined && desc.enumerable) to[nextKey] = nextSource[nextKey]; | ||
return to; | ||
}; | ||
} |
17
not.js
@@ -5,6 +5,8 @@ /** | ||
var isFunction = require('./is-function'); | ||
/** | ||
* Functional version of ! | ||
* @function module:101/not | ||
* @param {function} fn - function to inverse | ||
* @param {*} val - value to inverse | ||
* @return {function} - function whose arguments and context are applied to fn and result is inversed | ||
@@ -14,6 +16,11 @@ */ | ||
function not (fn) { | ||
return function (/* args */) { | ||
return !fn.apply(this, arguments); | ||
}; | ||
function not (val) { | ||
if (isFunction(val)) { | ||
return function (/* args */) { | ||
return not(val.apply(this, arguments)); | ||
}; | ||
} | ||
else { | ||
return !val; | ||
} | ||
} |
{ | ||
"name": "101", | ||
"version": "0.8.2", | ||
"version": "0.9.0", | ||
"description": "common javascript utils that can be required selectively that assume es5+", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -208,2 +208,3 @@ ![101](http://i.imgur.com/MFrmMt6.png) | ||
Supports partial functionality (great with array functions, and 101/find). | ||
NOTE: I am considering deprecating this method, bc it is so similar to has-keypaths. | ||
@@ -213,7 +214,5 @@ ```js | ||
var obj = { | ||
foo: { | ||
bar: 1 | ||
}, | ||
qux: 1 | ||
}; | ||
obj['foo.bar'] = 1 | ||
@@ -220,0 +219,0 @@ hasProps(obj, ['foo', 'qux']); // true |
@@ -31,2 +31,22 @@ var Lab = require('lab'); | ||
}); | ||
it('should support partial functionality', function (done) { | ||
var obj = { | ||
foo: 1, | ||
bar: 1, | ||
qux: 1 | ||
}; | ||
var obj2 = { | ||
you: 1 | ||
}; | ||
var assignPartial = assign(obj2); | ||
var assigned = assignPartial(obj); // works great with map | ||
expect(assigned).to.equal(obj); | ||
expect(assigned).to.eql({ | ||
foo: 1, | ||
bar: 1, | ||
qux: 1, | ||
you: 1 | ||
}); | ||
done(); | ||
}); | ||
it('should throw an error if source is undefined', function (done) { | ||
@@ -33,0 +53,0 @@ try { |
@@ -17,2 +17,7 @@ var Lab = require('lab'); | ||
}); | ||
it('should inverse a function (and work with array functions)', function (done) { | ||
expect([true, 1, false].map(not)) | ||
.to.eql([false, false, true]); | ||
done(); | ||
}); | ||
}); |
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
79113
70
2299
470