set.cjs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. // @ts-nocheck
  3. var __importDefault = (this && this.__importDefault) || function (mod) {
  4. return (mod && mod.__esModule) ? mod : { "default": mod };
  5. };
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. const baseSet_js_1 = __importDefault(require("./baseSet.cjs"));
  8. /**
  9. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  10. * it's created. Arrays are created for missing index properties while objects
  11. * are created for all other missing properties. Use `setWith` to customize
  12. * `path` creation.
  13. *
  14. * **Note:** This method mutates `object`.
  15. *
  16. * Inlined to just use set functionality and patch vulnerabilities
  17. * on existing isolated "lodash.set" package.
  18. *
  19. * @since 3.7.0
  20. * @category Object
  21. * @param {Object} object The object to modify.
  22. * @param {Array|string} path The path of the property to set.
  23. * @param {*} value The value to set.
  24. * @returns {Object} Returns `object`.
  25. * @see has, hasIn, get, unset
  26. * @example
  27. *
  28. * const object = { 'a': [{ 'b': { 'c': 3 } }] }
  29. *
  30. * set(object, 'a[0].b.c', 4)
  31. * console.log(object.a[0].b.c)
  32. * // => 4
  33. *
  34. * set(object, ['x', '0', 'y', 'z'], 5)
  35. * console.log(object.x[0].y.z)
  36. * // => 5
  37. */
  38. function set(object, path, value) {
  39. return object == null ? object : (0, baseSet_js_1.default)(object, path, value);
  40. }
  41. exports.default = set;