You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * lodash 3.2.0 (Custom Build) <https://lodash.com/>
  3. * Build: `lodash modern modularize exports="npm" -o ./`
  4. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  5. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  6. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  7. * Available under MIT license <https://lodash.com/license>
  8. */
  9. var baseAssign = require('lodash._baseassign'),
  10. createAssigner = require('lodash._createassigner'),
  11. keys = require('lodash.keys');
  12. /**
  13. * A specialized version of `_.assign` for customizing assigned values without
  14. * support for argument juggling, multiple sources, and `this` binding `customizer`
  15. * functions.
  16. *
  17. * @private
  18. * @param {Object} object The destination object.
  19. * @param {Object} source The source object.
  20. * @param {Function} customizer The function to customize assigned values.
  21. * @returns {Object} Returns `object`.
  22. */
  23. function assignWith(object, source, customizer) {
  24. var index = -1,
  25. props = keys(source),
  26. length = props.length;
  27. while (++index < length) {
  28. var key = props[index],
  29. value = object[key],
  30. result = customizer(value, source[key], key, object, source);
  31. if ((result === result ? (result !== value) : (value === value)) ||
  32. (value === undefined && !(key in object))) {
  33. object[key] = result;
  34. }
  35. }
  36. return object;
  37. }
  38. /**
  39. * Assigns own enumerable properties of source object(s) to the destination
  40. * object. Subsequent sources overwrite property assignments of previous sources.
  41. * If `customizer` is provided it is invoked to produce the assigned values.
  42. * The `customizer` is bound to `thisArg` and invoked with five arguments:
  43. * (objectValue, sourceValue, key, object, source).
  44. *
  45. * **Note:** This method mutates `object` and is based on
  46. * [`Object.assign`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign).
  47. *
  48. * @static
  49. * @memberOf _
  50. * @alias extend
  51. * @category Object
  52. * @param {Object} object The destination object.
  53. * @param {...Object} [sources] The source objects.
  54. * @param {Function} [customizer] The function to customize assigned values.
  55. * @param {*} [thisArg] The `this` binding of `customizer`.
  56. * @returns {Object} Returns `object`.
  57. * @example
  58. *
  59. * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
  60. * // => { 'user': 'fred', 'age': 40 }
  61. *
  62. * // using a customizer callback
  63. * var defaults = _.partialRight(_.assign, function(value, other) {
  64. * return _.isUndefined(value) ? other : value;
  65. * });
  66. *
  67. * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  68. * // => { 'user': 'barney', 'age': 36 }
  69. */
  70. var assign = createAssigner(function(object, source, customizer) {
  71. return customizer
  72. ? assignWith(object, source, customizer)
  73. : baseAssign(object, source);
  74. });
  75. module.exports = assign;