081f4327a7c25e70b2a400811bdbdc3273cc3a25
[yaffs-website] / node_modules / uncss / node_modules / lodash / internal / assignValue.js
1 var eq = require('../eq');
2
3 /** Used for built-in method references. */
4 var objectProto = global.Object.prototype;
5
6 /** Used to check objects for own properties. */
7 var hasOwnProperty = objectProto.hasOwnProperty;
8
9 /**
10  * Assigns `value` to `key` of `object` if the existing value is not equivalent
11  * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
12  * for equality comparisons.
13  *
14  * @private
15  * @param {Object} object The object to modify.
16  * @param {string} key The key of the property to assign.
17  * @param {*} value The value to assign.
18  */
19 function assignValue(object, key, value) {
20   var objValue = object[key];
21   if ((!eq(objValue, value) ||
22         (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) ||
23       (value === undefined && !(key in object))) {
24     object[key] = value;
25   }
26 }
27
28 module.exports = assignValue;