{"id":18256153,"url":"https://github.com/serapath/setval","last_synced_at":"2025-06-11T03:03:44.347Z","repository":{"id":57357110,"uuid":"45144298","full_name":"serapath/setval","owner":"serapath","description":"write values to a nested object like to a flat key value store","archived":false,"fork":false,"pushed_at":"2016-09-06T23:03:33.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-27T05:14:23.385Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/setval","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/serapath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-28T21:57:27.000Z","updated_at":"2016-09-04T00:12:30.000Z","dependencies_parsed_at":"2022-09-26T16:32:58.803Z","dependency_job_id":null,"html_url":"https://github.com/serapath/setval","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serapath%2Fsetval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serapath%2Fsetval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serapath%2Fsetval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serapath%2Fsetval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serapath","download_url":"https://codeload.github.com/serapath/setval/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serapath%2Fsetval/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259189613,"owners_count":22819076,"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":[],"created_at":"2024-11-05T10:20:11.387Z","updated_at":"2025-06-11T03:03:44.263Z","avatar_url":"https://github.com/serapath.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# setval\nwrite values to a nested object like to a flat key value store\n\n# usage\n`npm install setval`\n\n```js\nvar setval = require('setval')\n// setval(state, path, value, [delimiter])\n// return `path` or `undefined` if set was not successful\nvar state = { a: { b: [5,6,7] }, '': 3 }\nsetval(state, undefined, { x: 5}) // =\u003e { a: { b: [5,6,7] }, '': 3 }\nsetval(state) // =\u003e { a: { b: [5,6,7] }, '': 3 }\nsetval(state, '') // =\u003e { a: { b: [5,6,7] } }\nsetval(state, '', 6) // =\u003e { a: { b: [5,6,7] }, '': 6 }\nsetval(state, '/') // =\u003e { '': 6, a: { b: [5,6,7] } }\nsetval(state, '/', 'yay') // =\u003e { a: { b: [5,6,7] }, '': { '': 'yay' } }\n\nvar state = { a: { b: [5,6,7] }, '': 3 }\nsetval(state, 'a', 'm3h') // =\u003e { '': 3, a: 'm3h' }\nsetval(state, 'a') // =\u003e { '': 3 }\nsetval(state, '/a', { b: 5 }) // =\u003e { '': { a: { b: 5 } } }\nsetval(state, '/a/', 123 ) // =\u003e { '': { a: { b: 5, '': 123 } } }\nsetval(state, '//', 'yay' ) // =\u003e { '':{ a: { b:5,'':123 }, '':{'':'yay'}}}\nsetval(state, 'a/', { x: 5} )\n// =\u003e { '': { a: { b: 5,'': 123 }, '': { '': 'yay' } }, a: { '': { x: 5 } } }\n\nvar state = { }\nsetval(state, ['a','b'], 'hello world') // =\u003e { a: { b: 'hello world' } }\nsetval(state, ['a','b']) // =\u003e { a: {} }\n\nsetval(state, 'a/b', 'hello world') // =\u003e { a: { b: 'hello world' } }\nsetval(state, 'a/c', 'foobar') // =\u003e { a: { b: 'hello world', c: 'foobar' } }\nsetval(state, 'a/c', null) // =\u003e { a: { b: 'hello world', c: null } }\nsetval(state, 'a/c') // =\u003e  { a: { b: 'hello world' } }\nsetval(state, 'a/b/c', true) // =\u003e { a: { b: { c: true } } }\n\nvar state = { }\nsetval(state, 'a/b', 'hello world') // =\u003e { a: { b: 'hello world' } }\nsetval(state, 'a', [5,6,7]) // =\u003e { a: [5,6,7] }\nsetval(state, 'b', { y: 2 }) // =\u003e { a: [5,6,7], b: { y: 2} }\nsetval(state, 'b/0', { x: 2 }) // =\u003e { a: [5,6,7], b: { y: 2, 0: { x: 2 } } }\nsetval(state, 'b/y') // =\u003e { a: [5,6,7], b: { 0: { x: 2 } } }\nsetval(state, 'a/1', { x: 1 }) // =\u003e { a: [5,{ x: 1 },7], b: { 0: { x: 2 } } }\n\nvar x = { a: [5,{ x: 1 },7], b: { 0: { x: 2 } } }\nx.a.y = { foo: 'bar' }\n// works, but state is not JSON.stringifiable\nsetval(state, 'a/y', { foo: 'bar' }) // =\u003e x\n\nvar state = { }\nsetval(state, 'a.b', 'hello world', '.') // =\u003e { a: { b: 'hello world' } }\n```\n\n# Related\n* see [getval](https://www.npmjs.com/package/getval)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserapath%2Fsetval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserapath%2Fsetval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserapath%2Fsetval/lists"}