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.

setWith.js 1.0KB

1234567891011121314151617181920212223242526272829303132
  1. var baseSet = require('./_baseSet');
  2. /**
  3. * This method is like `_.set` except that it accepts `customizer` which is
  4. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  5. * path creation is handled by the method instead. The `customizer` is invoked
  6. * with three arguments: (nsValue, key, nsObject).
  7. *
  8. * **Note:** This method mutates `object`.
  9. *
  10. * @static
  11. * @memberOf _
  12. * @since 4.0.0
  13. * @category Object
  14. * @param {Object} object The object to modify.
  15. * @param {Array|string} path The path of the property to set.
  16. * @param {*} value The value to set.
  17. * @param {Function} [customizer] The function to customize assigned values.
  18. * @returns {Object} Returns `object`.
  19. * @example
  20. *
  21. * var object = {};
  22. *
  23. * _.setWith(object, '[0][1]', 'a', Object);
  24. * // => { '0': { '1': 'a' } }
  25. */
  26. function setWith(object, path, value, customizer) {
  27. customizer = typeof customizer == 'function' ? customizer : undefined;
  28. return object == null ? object : baseSet(object, path, value, customizer);
  29. }
  30. module.exports = setWith;