X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=node_modules%2Fgrunt-legacy-log%2Fnode_modules%2Flodash%2Fobject%2Fset.js;fp=node_modules%2Fgrunt-legacy-log%2Fnode_modules%2Flodash%2Fobject%2Fset.js;h=7a1e4e9ba92e864b2ea1b1874e64983826a2a2e0;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/node_modules/grunt-legacy-log/node_modules/lodash/object/set.js b/node_modules/grunt-legacy-log/node_modules/lodash/object/set.js new file mode 100644 index 000000000..7a1e4e9ba --- /dev/null +++ b/node_modules/grunt-legacy-log/node_modules/lodash/object/set.js @@ -0,0 +1,55 @@ +var isIndex = require('../internal/isIndex'), + isKey = require('../internal/isKey'), + isObject = require('../lang/isObject'), + toPath = require('../internal/toPath'); + +/** + * Sets the property value of `path` on `object`. If a portion of `path` + * does not exist it's created. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to augment. + * @param {Array|string} path The path of the property to set. + * @param {*} value The value to set. + * @returns {Object} Returns `object`. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }] }; + * + * _.set(object, 'a[0].b.c', 4); + * console.log(object.a[0].b.c); + * // => 4 + * + * _.set(object, 'x[0].y.z', 5); + * console.log(object.x[0].y.z); + * // => 5 + */ +function set(object, path, value) { + if (object == null) { + return object; + } + var pathKey = (path + ''); + path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path); + + var index = -1, + length = path.length, + lastIndex = length - 1, + nested = object; + + while (nested != null && ++index < length) { + var key = path[index]; + if (isObject(nested)) { + if (index == lastIndex) { + nested[key] = value; + } else if (nested[key] == null) { + nested[key] = isIndex(path[index + 1]) ? [] : {}; + } + } + nested = nested[key]; + } + return object; +} + +module.exports = set;