{"id":14384682,"url":"https://github.com/jonschlinkert/set-value","last_synced_at":"2025-05-15T07:06:45.260Z","repository":{"id":29302729,"uuid":"32835871","full_name":"jonschlinkert/set-value","owner":"jonschlinkert","description":"Set nested properties on an object using dot-notation.","archived":false,"fork":false,"pushed_at":"2023-02-08T02:11:26.000Z","size":164,"stargazers_count":277,"open_issues_count":12,"forks_count":40,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-01T04:03:37.828Z","etag":null,"topics":["deep-property","dot","dot-notation","dot-prop","get","getobject","javascript","lodash","nested","node","object","object-path","path","properties","property","set","set-deep","val","value"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["jonschlinkert","doowb"]}},"created_at":"2015-03-25T01:40:43.000Z","updated_at":"2025-04-03T20:31:52.000Z","dependencies_parsed_at":"2024-06-18T12:17:16.732Z","dependency_job_id":"c334cb99-d618-4ce3-83ad-01f8860d29ba","html_url":"https://github.com/jonschlinkert/set-value","commit_stats":{"total_commits":92,"total_committers":14,"mean_commits":6.571428571428571,"dds":"0.28260869565217395","last_synced_commit":"c574eb8d94ba21d22b6fe5a5741fd4dbfc9dc47a"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fset-value","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fset-value/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fset-value/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fset-value/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/set-value/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253096373,"owners_count":21853591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-property","dot","dot-notation","dot-prop","get","getobject","javascript","lodash","nested","node","object","object-path","path","properties","property","set","set-deep","val","value"],"created_at":"2024-08-28T18:01:34.660Z","updated_at":"2025-05-15T07:06:40.250Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","readme":"# set-value [![NPM version](https://img.shields.io/npm/v/set-value.svg?style=flat)](https://www.npmjs.com/package/set-value) [![NPM monthly downloads](https://img.shields.io/npm/dm/set-value.svg?style=flat)](https://npmjs.org/package/set-value) [![NPM total downloads](https://img.shields.io/npm/dt/set-value.svg?style=flat)](https://npmjs.org/package/set-value)  [![Tests](https://github.com/jonschlinkert/set-value/actions/workflows/main.yml/badge.svg)](https://github.com/jonschlinkert/set-value/actions/workflows/main.yml)\n\n\u003e Set nested properties on an object using dot notation.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) \u003e=11.0):\n\n```sh\n$ npm install --save set-value\n```\n\n## Heads up!\n\n[Please update](https://github.com/update/update) to version 3.0.1 or later, a critical bug was fixed in that version.\n\n## Usage\n\n```js\nconst set = require('set-value');\n\nconst obj = {};\nset(obj, 'a.b.c', 'd');\n\nconsole.log(obj);\n//=\u003e { a: { b: { c: 'd' } } }\n```\n\n### Params\n\nSignature:\n\n```js\nset(object, property_path, value[, options]);\n```\n\n* `object` **{Object}**: The object to set `value` on\n* `path` **{String|Symbol|Array}**: The [path](#object-paths) of the property to set.\n* `value` **{any}**: The value to set on `obj[prop]`\n* `options` **{Object}**: See all [available options](#options)\n\n### Object paths\n\nYou may pass a string, symbol, or array of strings or symbols. By default, when a string is passed this library will split the string on `.` or a [custom separator](#options-separator) It's useful to pass an array\n\n### Escaping\n\n**Escaping with backslashes**\n\nPrevent set-value from splitting on a dot by prefixing it with backslashes:\n\n```js\nconsole.log(set({}, 'a\\\\.b.c', 'd'));\n//=\u003e { 'a.b': { c: 'd' } }\n\nconsole.log(set({}, 'a\\\\.b\\\\.c', 'd'));\n//=\u003e { 'a.b.c': 'd' }\n```\n\n## Options\n\n### options.preservePaths\n\nDo not split properties that include a `/`. By default, set-value assumes that properties with a `/` are not intended to be split. This option allows you to disable default behavior.\n\nNote that this option cannot be used if `options.separator` is set to `/`.\n\n**Type**: `boolean`\n\n**Default**: `true`\n\n**Example**\n\n```js\nconsole.log(set({}, 'https://github.com', true));\n//=\u003e { 'https://github.com': true }\n\nconsole.log(set({}, 'https://github.com', true, { preservePaths: false }));\n//=\u003e { 'https://github': { com: true } }\n```\n\n### options.separator\n\nCustom separator to use for splitting object paths.\n\n**Type**: `string`\n\n**Default**: `.`\n\n**Example**\n\n```js\nconsole.log(set(obj, 'auth/userpass/users/bob', '*****', { separator: '/' }));\n//=\u003e { auth: { userpass: { users: { bob: '*****' } } } }\n```\n\n### options.split\n\nCustom `.split()` function to use.\n\n### options.merge\n\nAllows you to update plain object values, instead of overwriting them.\n\n**Type**: `boolean|function` - A custom `merge` function may be defined if you need to deep merge. Otherwise, when `merge` is `true`, a shallow merge will be performed by `Object.assign()`.\n\n**Default**: `undefined`\n\n**Example**\n\n```js\nconst obj = { foo: { bar: { baz: 'qux' } } };\nset(obj, 'foo.bar.fez', 'zzz', { merge: true });\n//=\u003e { foo: { bar: { baz: 'qux', fez: 'zzz' } } }\n```\n\n## Benchmarks\n\nBenchmarks were run on a MacBook Pro 2.5 GHz Intel Core i7, 16 GB 1600 MHz DDR3.\n\n```\n# deep (194 bytes)\n  deep-object x 823,287 ops/sec ±1.00% (90 runs sampled)\n  deep-property x 1,787,990 ops/sec ±0.82% (92 runs sampled)\n  deephas x 840,700 ops/sec ±0.95% (93 runs sampled)\n  dot-prop x 1,249,663 ops/sec ±0.89% (90 runs sampled)\n  dot2val x 2,067,212 ops/sec ±1.08% (91 runs sampled)\n  es5-dot-prop x 1,668,806 ops/sec ±0.92% (92 runs sampled)\n  lodash-set x 1,286,725 ops/sec ±0.82% (90 runs sampled)\n  object-path-set x 1,261,242 ops/sec ±1.63% (90 runs sampled)\n  object-set x 285,369 ops/sec ±0.91% (90 runs sampled)\n  set-value x 2,076,931 ops/sec ±0.86% (93 runs sampled)\n\n  fastest is set-value, dot2val (by 203% avg)\n\n# medium (98 bytes)\n  deep-object x 5,811,161 ops/sec ±1.12% (90 runs sampled)\n  deep-property x 4,075,885 ops/sec ±0.91% (90 runs sampled)\n  deephas x 1,508,136 ops/sec ±0.82% (92 runs sampled)\n  dot-prop x 2,809,838 ops/sec ±1.16% (87 runs sampled)\n  dot2val x 4,600,890 ops/sec ±0.76% (91 runs sampled)\n  es5-dot-prop x 3,263,790 ops/sec ±0.97% (91 runs sampled)\n  lodash-set x 3,486,628 ops/sec ±1.20% (90 runs sampled)\n  object-path-set x 3,729,018 ops/sec ±0.90% (92 runs sampled)\n  object-set x 973,961 ops/sec ±0.80% (92 runs sampled)\n  set-value x 6,941,474 ops/sec ±1.24% (90 runs sampled)\n\n  fastest is set-value (by 206% avg)\n\n# shallow (101 bytes)\n  deep-object x 9,416,410 ops/sec ±1.19% (89 runs sampled)\n  deep-property x 5,108,536 ops/sec ±0.98% (93 runs sampled)\n  deephas x 1,706,979 ops/sec ±0.98% (86 runs sampled)\n  dot-prop x 4,045,902 ops/sec ±1.10% (92 runs sampled)\n  dot2val x 5,862,418 ops/sec ±0.88% (91 runs sampled)\n  es5-dot-prop x 4,439,646 ops/sec ±1.18% (90 runs sampled)\n  lodash-set x 9,303,292 ops/sec ±1.19% (89 runs sampled)\n  object-path-set x 5,657,479 ops/sec ±0.95% (93 runs sampled)\n  object-set x 2,020,041 ops/sec ±0.92% (91 runs sampled)\n  set-value x 11,272,227 ops/sec ±1.36% (88 runs sampled)\n\n  fastest is set-value (by 213% avg)\n\n```\n\n### Running the benchmarks\n\nClone this library into a local directory:\n\n```sh\n$ git clone https://github.com/jonschlinkert/set-value.git\n```\n\nThen install devDependencies and run benchmarks:\n\n```sh\n$ npm install \u0026\u0026 node benchmark\n```\n\n## Comparisons to other libs, or _\"the list of shame\"_\n\nThese are just a few of the duplicate libraries on NPM.\n\n* [bury](https://github.com/kalmbach/bury) fails all of the tests. I even wrapped it to have it return the object instead of the value, but with all of that work it still fails the vast majority of tests.\n* [deep-get-set](https://github.com/acstll/deep-get-set) fails 22 of 26 unit tests.\n* [deep-object](https://github.com/ayushgp/deep-object) fails 25 of 26 unit tests, completely butchered given objects.\n* [deep-property](https://github.com/mikattack/node-deep-property) fails 17 of 26 unit tests.\n* [deep-set](https://github.com/klaemo/deep-set) fails 13 of 26 unit tests.\n* [deephas](https://github.com/sharpred/deepHas) fails 17 of 26 unit tests.\n* [dot-prop](https://github.com/sindresorhus/dot-prop) fails 9 of 26 unit tests.\n* [dot2val](https://github.com/yangg/dot2val) fails 17 of 26 unit tests.\n* [es5-dot-prop](https://github.com/sindresorhus/dot-prop) fails 15 of 26 unit tests.\n* [getsetdeep](https://github.com/bevry/getsetdeep) fails all unit tests due to `this` being used improperly in the methods. I was able to patch it by binding the (plain) object to the methods, but it still fails 17 of 26 unit tests.\n* [lodash.set](https://lodash.com/) fails 11 of 26 unit tests.\n* [object-path-set](https://github.com/skratchdot/object-path-set) fails 12 of 26 unit tests.\n* [object-path](https://github.com/mariocasciaro/object-path) fails 16 of 26 unit tests.\n* [object-set](https://github.com/gearcase/object-set) fails 13 of 26 unit tests.\n* [set-nested-prop](https://github.com/tiaanduplessis/set-nested-prop) fails 24 of 26 unit tests.\n* [setvalue](https://github.com/blakeembrey/setvalue) (this library is almost identical to a previous version of this library)\n* Many dozens of others\n\n**Others that do the same thing, but use a completely different API**\n\n* [deep-set-in](https://github.com/KulikovskyIgor/deep-set-in)\n* [set-deep](https://github.com/radubrehar/set-deep)\n* [set-deep-prop](https://github.com/mmckelvy/set-deep-prop)\n* [bury](https://github.com/kalmbach/bury)\n* Many dozens of others\n\n## History\n\n### v3.0.0\n\n* Added support for a custom `split` function to be passed on the options.\n* Removed support for splitting on brackets, since a [custom function](https://github.com/jonschlinkert/split-string) can be passed to do this now.\n\n### v2.0.0\n\n* Adds support for escaping with double or single quotes. See [escaping](#escaping) for examples.\n* Will no longer split inside brackets or braces. See [bracket support](#bracket-support) for examples.\n\nIf there are any regressions please create a [bug report](../../issues/new). Thanks!\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [assign-value](https://www.npmjs.com/package/assign-value): Assign a value or extend a deeply nested property of an object using object path… [more](https://github.com/jonschlinkert/assign-value) | [homepage](https://github.com/jonschlinkert/assign-value \"Assign a value or extend a deeply nested property of an object using object path notation.\")\n* [get-value](https://www.npmjs.com/package/get-value): Use property paths like 'a.b.c' to get a nested value from an object. Even works… [more](https://github.com/jonschlinkert/get-value) | [homepage](https://github.com/jonschlinkert/get-value \"Use property paths like 'a.b.c' to get a nested value from an object. Even works when keys have dots in them (no other dot-prop library can do this!).\")\n* [has-value](https://www.npmjs.com/package/has-value): Returns true if a value exists, false if empty. Works with deeply nested values using… [more](https://github.com/jonschlinkert/has-value) | [homepage](https://github.com/jonschlinkert/has-value \"Returns true if a value exists, false if empty. Works with deeply nested values using object paths.\")\n* [merge-value](https://www.npmjs.com/package/merge-value): Similar to assign-value but deeply merges object values or nested values using object path/dot notation. | [homepage](https://github.com/jonschlinkert/merge-value \"Similar to assign-value but deeply merges object values or nested values using object path/dot notation.\")\n* [omit-value](https://www.npmjs.com/package/omit-value): Omit properties from an object or deeply nested property of an object using object path… [more](https://github.com/jonschlinkert/omit-value) | [homepage](https://github.com/jonschlinkert/omit-value \"Omit properties from an object or deeply nested property of an object using object path notation.\")\n* [set-value](https://www.npmjs.com/package/set-value): Set nested properties on an object using dot notation. | [homepage](https://github.com/jonschlinkert/set-value \"Set nested properties on an object using dot notation.\")\n* [union-value](https://www.npmjs.com/package/union-value): Set an array of unique values as the property of an object. Supports setting deeply… [more](https://github.com/jonschlinkert/union-value) | [homepage](https://github.com/jonschlinkert/union-value \"Set an array of unique values as the property of an object. Supports setting deeply nested properties using using object-paths/dot notation.\")\n* [unset-value](https://www.npmjs.com/package/unset-value): Delete nested properties from an object using dot notation. | [homepage](https://github.com/jonschlinkert/unset-value \"Delete nested properties from an object using dot notation.\")\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 87 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 4  | [doowb](https://github.com/doowb) |  \n| 2  | [mbelsky](https://github.com/mbelsky) |  \n| 1  | [dkebler](https://github.com/dkebler) |  \n| 1  | [GlennKintscher](https://github.com/GlennKintscher) |  \n| 1  | [petermorlion](https://github.com/petermorlion) |  \n| 1  | [abetomo](https://github.com/abetomo) |  \n| 1  | [zeidoo](https://github.com/zeidoo) |  \n| 1  | [ready-research](https://github.com/ready-research) |  \n| 1  | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |  \n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2021, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on September 12, 2021._","funding_links":["https://github.com/sponsors/jonschlinkert","https://github.com/sponsors/doowb"],"categories":["Modules","模块","JavaScript"],"sub_categories":["Object","对象"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fset-value","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fset-value","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fset-value/lists"}