{"id":23593945,"url":"https://github.com/hutsoninc/object-auger","last_synced_at":"2025-06-16T14:08:28.104Z","repository":{"id":93009134,"uuid":"191416102","full_name":"hutsoninc/object-auger","owner":"hutsoninc","description":"Safely get or set values in nested objects and arrays.","archived":false,"fork":false,"pushed_at":"2019-07-11T21:17:28.000Z","size":54,"stargazers_count":0,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-17T13:52:47.107Z","etag":null,"topics":["array","fetch","get","key","nested","object","prop","properties","property","props","set","value","values"],"latest_commit_sha":null,"homepage":null,"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/hutsoninc.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-11T17:09:41.000Z","updated_at":"2019-07-11T21:17:29.000Z","dependencies_parsed_at":"2023-03-23T08:03:53.678Z","dependency_job_id":null,"html_url":"https://github.com/hutsoninc/object-auger","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"d6fc41421466988d9dd463385e50f8a33eb6516e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hutsoninc/object-auger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hutsoninc%2Fobject-auger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hutsoninc%2Fobject-auger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hutsoninc%2Fobject-auger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hutsoninc%2Fobject-auger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hutsoninc","download_url":"https://codeload.github.com/hutsoninc/object-auger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hutsoninc%2Fobject-auger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260173901,"owners_count":22969870,"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":["array","fetch","get","key","nested","object","prop","properties","property","props","set","value","values"],"created_at":"2024-12-27T09:14:23.313Z","updated_at":"2025-06-16T14:08:28.075Z","avatar_url":"https://github.com/hutsoninc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Object Auger\n\n[![Build Status](https://travis-ci.com/hutsoninc/object-auger.svg?branch=master)](https://travis-ci.com/hutsoninc/object-auger) [![Current npm package version](https://img.shields.io/npm/v/object-auger.svg)](https://www.npmjs.com/package/object-auger)\n\nSafely get or set values in nested objects and arrays.\n\n## Installation\n\n`npm install --save object-auger`\n\n## Usage\n\nSee the [tests](test/test.js) for more examples. Passing\n\n```js\nconst auger = require('object-auger');\n\nlet haystack = {};\n\nhaystack = auger.set(haystack, ['a', 'b', 'c', 0], 'needle');\n// =\u003e { a: { b: { c: ['needle'] } } }\n\nauger.has(haystack, ['a', 'b', 'c']);\n// =\u003e true\n\nauger.get(haystack, ['a', 'b', 'c', 0]);\n// =\u003e 'needle'\n\nauger.get(haystack, ['a', 'b', 'c', 1], 'no needle here');\n// =\u003e 'no needle here'\n```\n\n### auger.has(object, path)\n\nSafely check if a value exists in an object. Returns a boolean.\n\n#### object\n\nType: `object` or `array`\n\nObject to look for a value in.\n\n#### path\n\nType: `array`\n\nPath to the value.\n\n### auger.get(object, path, defaultValue)\n\nSafely retrieve a value from an object. Returns the retrieved value or the defaultValue if the it cannot be found.\n\n#### object\n\nType: `object` or `array`\n\nObject to retrieve a value from.\n\n#### path\n\nType: `array`\n\nPath to the value.\n\n#### default\n\nType: `any`\u003cbr /\u003e\nDefault: `undefined`\n\nDefault value. (Optional)\n\n### auger.set(object, path, value)\n\nSafely set a value in an object. Returns the new object.\n\n#### object\n\nType: `object` or `array`\n\nObject to set a value in.\n\n#### path\n\nType: `array`\n\nPath to where the value will be set.\n\n#### value\n\nType: `any`\n\nValue to set at the path.\n\n## Why?\n\nThere are tons of other libraries that have similar functionality (notably [dot-prop](https://www.npmjs.com/package/dot-prop) and [lodash](https://www.npmjs.com/package/lodash)). While these packages are great, they can cause confusion when working with arrays in a nested object.\n\nTrying to set an object with a number as the key in `lodash` will result in an array:\n\n```js\nconst _ = require('lodash');\n\n_.set({}, ['a', '0'], 'b');\n// =\u003e { a: [ 'b' ] }\n// Expected =\u003e { a: { '0': 'b' } }\n\n_.set({}, ['a', 0], 'b');\n// =\u003e { a: [ 'b' ] }\n// Expected =\u003e { a: [ 'b' ] }\n```\n\nUsing the same dot path syntax with `lodash` and `dot-prop` will result in different outcomes:\n\n```js\nconst _ = require('lodash');\nconst dotProp = require('dot-prop');\n\n_.set({}, 'a.0', 'b');\n// =\u003e { a: [ 'b' ] }\n\ndotProp.set({}, 'a.0', 'b');\n// =\u003e { a: { '0': 'b' } }\n```\n\nWith the dot path syntax, it's hard to tell if you're working with an array index number or an object property key. Dot path also makes it difficult to dynamically build up the path.\n\nWith `object-auger`, you can set the value and know exactly what the outcome will be:\n\n```js\nconst auger = require('object-auger');\n\nauger.set({}, ['a', '0'], 'b');\n// =\u003e { a: { '0': 'b' } }\n\nauger.set({}, ['a', 0], 'b');\n// =\u003e { a: [ 'b' ] }\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhutsoninc%2Fobject-auger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhutsoninc%2Fobject-auger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhutsoninc%2Fobject-auger/lists"}