{"id":17651342,"url":"https://github.com/nash403/set-safe","last_synced_at":"2025-09-22T22:58:06.224Z","repository":{"id":57356952,"uuid":"71243382","full_name":"nash403/set-safe","owner":"nash403","description":"safe access to deeply nested properties and functions in JS objects without getting a TypeError","archived":false,"fork":false,"pushed_at":"2016-10-18T19:26:37.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-08T08:48:10.476Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nash403.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-18T11:57:45.000Z","updated_at":"2016-10-18T17:12:07.000Z","dependencies_parsed_at":"2022-09-06T06:52:38.964Z","dependency_job_id":null,"html_url":"https://github.com/nash403/set-safe","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/nash403%2Fset-safe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nash403%2Fset-safe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nash403%2Fset-safe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nash403%2Fset-safe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nash403","download_url":"https://codeload.github.com/nash403/set-safe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246296615,"owners_count":20754635,"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-10-23T11:41:55.876Z","updated_at":"2025-09-22T22:58:01.180Z","avatar_url":"https://github.com/nash403.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# set-safe\r\n#### Safely set value at property, create intermediate properties if necessary, without getting an Error if a parent is undefined.\r\n***\r\nYou can even whether alter the original object or create an altered copy of it.\r\n***\r\n#### Install:\r\n`npm install set-safe --save`\r\n\r\n#### How to use\r\n ```JavaScript\r\n\r\n const set = require ('set-safe');\r\n const toto = {\r\n   foo: {\r\n     bar: {\r\n       baz: ['winter','is','coming'],\r\n       fifo (arg1, arg2) {\r\n         return 42;\r\n       }\r\n     },\r\n     astring: \"John Doe\"\r\n   }\r\n };\r\n\r\n // Tests\r\n let i = 1;\r\n console.log('The tested object is:', JSON.stringify(toto));\r\n\r\n console.log(`\\nExample ${i}:\\n`,\r\n   JSON.stringify(set('foo.bar.baz.2','there', toto))); // sets \"coming\" to \"there\"\r\n\r\n console.log(`\\nExample ${++i}:\\n`,\r\n   JSON.stringify(set('foo.astring','Leonardo Di Caprio', toto))); // sets \"astring\" property\r\n\r\n console.log(`\\nExample ${++i}:\\n`,\r\n     JSON.stringify(set(['opt1','sub1','subsub1','subsubsub1'].join('.'),'a value'))); // creates a new object with nested props\r\n\r\n console.log(`\\nExample ${++i}:\\n`,\r\n     JSON.stringify(set('foo.inexistant.property',42,toto))); // adds a new property\r\n\r\n console.log(`\\nExample ${++i}:\\n`,\r\n     JSON.stringify(set('foo.bar.baz.fifo',42,toto, true)), ' - ',JSON.stringify(toto)); // creates an altered copy of toto object\r\n```\r\nThe browser version adds `setSafe` to the *window* object.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnash403%2Fset-safe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnash403%2Fset-safe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnash403%2Fset-safe/lists"}