diff options
Diffstat (limited to 'node_modules/lodash.defaults/index.js')
-rw-r--r-- | node_modules/lodash.defaults/index.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/node_modules/lodash.defaults/index.js b/node_modules/lodash.defaults/index.js new file mode 100644 index 000000000..52eec906a --- /dev/null +++ b/node_modules/lodash.defaults/index.js @@ -0,0 +1,54 @@ +/** + * Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/> + * Build: `lodash modularize modern exports="npm" -o ./npm/` + * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/> + * Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE> + * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license <http://lodash.com/license> + */ +var keys = require('lodash.keys'), + objectTypes = require('lodash._objecttypes'); + +/** + * Assigns own enumerable properties of source object(s) to the destination + * object for all destination properties that resolve to `undefined`. Once a + * property is set, additional defaults of the same property will be ignored. + * + * @static + * @memberOf _ + * @type Function + * @category Objects + * @param {Object} object The destination object. + * @param {...Object} [source] The source objects. + * @param- {Object} [guard] Allows working with `_.reduce` without using its + * `key` and `object` arguments as sources. + * @returns {Object} Returns the destination object. + * @example + * + * var object = { 'name': 'barney' }; + * _.defaults(object, { 'name': 'fred', 'employer': 'slate' }); + * // => { 'name': 'barney', 'employer': 'slate' } + */ +var defaults = function(object, source, guard) { + var index, iterable = object, result = iterable; + if (!iterable) return result; + var args = arguments, + argsIndex = 0, + argsLength = typeof guard == 'number' ? 2 : args.length; + while (++argsIndex < argsLength) { + iterable = args[argsIndex]; + if (iterable && objectTypes[typeof iterable]) { + var ownIndex = -1, + ownProps = objectTypes[typeof iterable] && keys(iterable), + length = ownProps ? ownProps.length : 0; + + while (++ownIndex < length) { + index = ownProps[ownIndex]; + if (typeof result[index] == 'undefined') result[index] = iterable[index]; + } + } + } + return result +}; + +module.exports = defaults; |