{"id":18091253,"url":"https://github.com/dfsp-spirit/js-object-util","last_synced_at":"2025-04-06T02:42:51.980Z","repository":{"id":57283400,"uuid":"82586722","full_name":"dfsp-spirit/js-object-util","owner":"dfsp-spirit","description":"A simple static utility class to access nested object properties. Inspired by Immutable API methods like hasIn and getIn.","archived":false,"fork":false,"pushed_at":"2017-03-07T00:27:44.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-13T01:36:15.268Z","etag":null,"topics":["ignore","javascript","test","useless"],"latest_commit_sha":null,"homepage":"","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/dfsp-spirit.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":"2017-02-20T17:58:46.000Z","updated_at":"2022-02-15T22:02:41.000Z","dependencies_parsed_at":"2022-09-19T23:23:09.233Z","dependency_job_id":null,"html_url":"https://github.com/dfsp-spirit/js-object-util","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfsp-spirit%2Fjs-object-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfsp-spirit%2Fjs-object-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfsp-spirit%2Fjs-object-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfsp-spirit%2Fjs-object-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dfsp-spirit","download_url":"https://codeload.github.com/dfsp-spirit/js-object-util/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247426985,"owners_count":20937197,"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":["ignore","javascript","test","useless"],"created_at":"2024-10-31T18:11:09.342Z","updated_at":"2025-04-06T02:42:51.957Z","avatar_url":"https://github.com/dfsp-spirit.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"js-object-util\n===============\n\nA simple static utility class to access nested JSON object properties. Inspired by Immutable API methods like hasIn, getIn and setIn.\n\n## Installation\n\n  The package is available at npmjs, so all you need to do to install it is to tell npm that you want it:\n\n  `npm install js-object-util`\n  \n  You can find linkes to try it online etc at https://www.npmjs.com/package/js-object-util\n\n## Usage\n\n    var objectUtil = require('js-object-util');\n\t\n\t// Some deeply nested JSON example input:\n\tvar book = {\n\t\tpublisher: {\n\t\t\tname: \"dpunkt\",\n\t\t\taddress: {\n\t\t\t\tcity: \"Heidelberg\",\n\t\t\t\tplz: 69123\n\t\t\t}\n\t\t},\n\t\ttitle : \"React\",\n\t\tyear: 2015,\n\t\tproperties: {\n\t\t\tincludes_ebook: false,\n\t\t\twhatever: null,\n\t\t\tdunno: undefined\n\t\t},\n\t\treaders: [\n\t\t\t{\n\t\t\t\ttype: \"user\",\n\t\t\t\tname: \"Johnny\",\n\t\t\t\tage: 32,\n\t\t\t\tnickname: null\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: \"user\",\n\t\t\t\tname: \"Brad\",\n\t\t\t\tage: 13,\n\t\t\t\tnickname: \"Bratze\"\n\t\t\t}\n\t\t]\n\t};\n\t\n\t// Let's go. Checking for properties:\n\tvar keyExists;\n\tkeyExists = objectUtil.hasIn(book, ['publisher', 'address', 'city']);\t\t// true\n\tkeyExists = objectUtil.hasIn(book, ['publisher', 'address', 'notthere']);\t// false\n\t// Retrieving properties:\n\tvar value;\n\tvalue = ObjectUtil.getIn(book, ['year']);\t\t\t\t\t\t\t// 2015\n\tvalue = objectUtil.getIn(book, ['readers', 1, 'name']);\t\t\t// Brad\n\tvalue = objectUtil.getIn(book, ['readers', 5, 'notthere'], null);\t\t\t// null\n\t// Setting properties:\n\tvar new_book;\n\tnew_book = ObjectUtil.setIn(book, ['readers', 2, 'name'], 'Dan');\n\tnew_book = ObjectUtil.setIn(new_book, ['readers', 2, 'age'], 14);\n      \n  \n    See the tests for more examples.  \n\n\n## Tests\n\n   Unit tests using jest are included. They also show code coverage. Tun run them:\n\n  `npm test`\n  \n## Project status badges\n\n[![Build Status](https://travis-ci.org/dfsp-spirit/js-object-util.svg?branch=master)](https://travis-ci.org/dfsp-spirit/js-object-util)\n\n[![Coverage Status](https://coveralls.io/repos/github/dfsp-spirit/js-object-util/badge.svg?branch=master)](https://coveralls.io/github/dfsp-spirit/js-object-util?branch=master)\n\n## Contributing\n\nThe repo is at: https://github.com/dfsp-spirit/js-object-util\n\nTake care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code, also make sure you agree with the license. Then send pull request.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfsp-spirit%2Fjs-object-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdfsp-spirit%2Fjs-object-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfsp-spirit%2Fjs-object-util/lists"}