{"id":16347630,"url":"https://github.com/privatenumber/chainset","last_synced_at":"2025-07-26T12:37:22.948Z","repository":{"id":48130296,"uuid":"516488262","full_name":"privatenumber/chainset","owner":"privatenumber","description":"Set object values using property chaining syntax","archived":false,"fork":false,"pushed_at":"2022-07-21T21:21:44.000Z","size":47,"stargazers_count":21,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-03-18T16:04:05.795Z","etag":null,"topics":["chain","deep","object","property","set"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/privatenumber.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":"2022-07-21T18:52:11.000Z","updated_at":"2022-08-10T06:29:24.000Z","dependencies_parsed_at":"2022-08-19T13:40:50.960Z","dependency_job_id":null,"html_url":"https://github.com/privatenumber/chainset","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fchainset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fchainset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fchainset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fchainset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/privatenumber","download_url":"https://codeload.github.com/privatenumber/chainset/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245040235,"owners_count":20551297,"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":["chain","deep","object","property","set"],"created_at":"2024-10-11T00:44:17.951Z","updated_at":"2025-03-23T00:32:54.325Z","avatar_url":"https://github.com/privatenumber.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chainset\n\nSet object values using property chaining syntax.\n\n\u003csub\u003eSupport this project by ⭐️ starring and sharing it. [Follow me](https://github.com/privatenumber) to see what other cool projects I'm working on! ❤️\u003c/sub\u003e\n\n## Why?\n\nSetting a value on an arbitrary nested path can be cumbersome to do correctly.\n\nFor example, `someObject.propA.propB.propC = 'value'` on a potentially empty `someObject` requires a guard for each nested property.\n\n\n#### Without `chainset`\n```ts\nconst someObject = {}\n\nif (!Object.hasOwn(someObject, 'propA')) {\n    someObject.propA = {}\n}\n\nif (!Object.hasOwn(someObject.propA, 'propB')) {\n    someObject.propA.propB = {}\n}\n\nsomeObject.propA.propB.propC = 'value'\n```\n\n#### With `chainset`\n\n```ts\nconst someObject = chainset()\n\nsomeObject.propA.propB.propC = 'value'\n```\n\n## Usage\n\n### Create a new object\n```ts\nimport chainset from 'chainset'\n\nconst object = chainset() // =\u003e {}\n\n// Automatically initializes 'propB' \u0026 'propC' to objects\nobject.propA.propB.propC = 'value'\n\nconsole.log(object)\n/*\n{\n    propA: {\n        propB: {\n            propC: 'value'\n        }\n    }\n}\n*/\n```\n\n### Use an existing object\n```ts\nconst object = chainset({\n    foo: {\n        bar: {}\n    }\n})\n\n// Automatically initializes 'propA' \u0026 'propB' to objects\nobject.foo.bar.propA.propB = 'value'\n\nconsole.log(object)\n/*\n{\n    foo: {\n        bar: {\n            propA: {\n                propB: 'value'\n            }\n        }\n    }\n}\n*/\n```\n\n## API\n\n### chainset(object, options)\n\n#### object\nType: `object`\n\nDefault: `Object.create(null)` (a pure, prototype-less object)\n\nThe object to ehance with \"chain-setting\" support.\n\n#### options\n\n##### deep\n\nType: `boolean | number`\n\nDefault: `true`\n\nHow deep to add automatic object initialization support on access. Set to `true` to add support infinitely. Set a number to limit the depth of objects to add support to. Set to `false` to only add support to the immediate object.\n\n##### allowedKeys\n\nType: `RegExp | (string|RegExp)[] | (path, object) =\u003e boolean`\n\nA regular expression pattern, array of strings/patterns, or function that restrict what property names will be initialized on access.\n\n\n##### defaultObject\n\nType: `(key?: string) =\u003e object`\n\nDefault: `() =\u003e Object.create(null)`\n\nA function that creates a new object to use when a property is accessed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprivatenumber%2Fchainset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprivatenumber%2Fchainset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprivatenumber%2Fchainset/lists"}