{"id":25306774,"url":"https://github.com/davidcalhoun/deep-object-assign-with-reduce","last_synced_at":"2025-08-01T19:32:00.937Z","repository":{"id":26889761,"uuid":"111750512","full_name":"davidcalhoun/deep-object-assign-with-reduce","owner":"davidcalhoun","description":"Deep merging of objects with the same function signature as Object.assign() (useful for overriding default options objects)","archived":false,"fork":false,"pushed_at":"2023-01-09T14:36:04.000Z","size":570,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T02:51:07.818Z","etag":null,"topics":["assign","deep","defaults","merge","object","options","recursive","reduce"],"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/davidcalhoun.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-23T01:45:46.000Z","updated_at":"2021-12-24T01:37:47.000Z","dependencies_parsed_at":"2023-01-14T05:30:04.556Z","dependency_job_id":null,"html_url":"https://github.com/davidcalhoun/deep-object-assign-with-reduce","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/davidcalhoun/deep-object-assign-with-reduce","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcalhoun%2Fdeep-object-assign-with-reduce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcalhoun%2Fdeep-object-assign-with-reduce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcalhoun%2Fdeep-object-assign-with-reduce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcalhoun%2Fdeep-object-assign-with-reduce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidcalhoun","download_url":"https://codeload.github.com/davidcalhoun/deep-object-assign-with-reduce/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcalhoun%2Fdeep-object-assign-with-reduce/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268285964,"owners_count":24225832,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["assign","deep","defaults","merge","object","options","recursive","reduce"],"created_at":"2025-02-13T10:52:43.942Z","updated_at":"2025-08-01T19:32:00.898Z","avatar_url":"https://github.com/davidcalhoun.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deep-object-assign-with-reduce\n[![Build Status](https://travis-ci.org/davidcalhoun/deep-object-assign-with-reduce.svg?branch=master)](https://travis-ci.org/davidcalhoun/deep-object-assign-with-reduce)\n[![Downloads][downloads-image]][npm-url]\n\n## Introduction\nDeep `Object.assign()` written with modern, functional JavaScript.  Inspired by `deep-assign` and the need for a deeper `Object.assign`.\n\nNo dependencies and very tiny - only ~450 bytes gzipped.\n\n## Installation\nRequires [Node.js](https://nodejs.org) 10+, which comes with `npm`.\n\nIn your project directory, type:\n\n`npm install deep-object-assign-with-reduce`\n\nor\n\n`yarn add deep-object-assign-with-reduce`\n\n## Changelog\n* `3.0.0` - dropped Node 8 and 9 support.  Please use `2.x` if you wish to use an older version of Node.\n* `2.0.0` - dropped IE 11 support in order to dramatically reduce filesize.\n* `1.2.0` - added `deepAssignOptions` to give more control over array and object merging\n* `1.1.0` - fixed RegExp as values, Symbols as keys.  Moved to Rollup, Jest.  Updated Babel.\n\n## Examples\n\n### Merge complex objects\n```js\nimport { deepAssign } from 'deep-object-assign-with-reduce';\n\ndeepAssign({}, { dimensions: { width: 100, height: 100 } }, { dimensions: { width: 200 } });\n// -\u003e { dimensions: { width: 200, height: 100 } }\n```\n\n### Merge arrays\n```js\nimport { deepAssign } from 'deep-object-assign-with-reduce';\n\ndeepAssign({}, { numbers: [1, 2, 3] }, { numbers: [4, 5, 6] });\n// -\u003e { numbers: [1, 2, 3, 4, 5, 6] }\n```\n\n### Custom overwriting behavior\n`deepAssign` merges objects and arrays by default.  If you want to disable this behavior and instead overwrite objects and/or arrays, you can use `deepAssignOptions` instead, which accepts an `options` object as the first parameter:\n\n```js\nimport { deepAssignOptions } from 'deep-object-assign-with-reduce';\n\ndeepAssignOptions({overwriteArrays: true}, {}, { numbers: [1, 2] }, { numbers: [3, 4] });\n// -\u003e { numbers: [3, 4] }\n\ndeepAssignOptions({overwriteObjects: true}, {}, { a: { b: 1 } }, { a: { c: 2 } });\n// -\u003e { a: { c: 2 } }\n```\n\n## Why not just use `Object.assign()` or Object spread?\n\n### Where `Object.assign()` works fine\nHere's the motivation: the native `Object.assign()` works great on its own as long as you use simple objects that are one level deep.\n\nThere's a common use case where we have some \"defaults\" configuration object, in which properties\ncan be selectively overridden while retaining the remaining default properties.\n\nSay we have some component which has default dimensions, which we want to be able to selectively\noverride:\n\n```js\n// Default properties to \"fallback\" to.\nconst componentDefaults = { width: 100, height: 100 };\n\n// Selectively overrides one property.\nconst componentOptions = { width: 200 };\n\n// Constructs the final options object by merging the objects.\nconst options = Object.assign({}, componentDefaults, componentOptions);\n// -\u003e { width: 200, height: 100 }\n```\n\nThis works because `Object.assign` will merge the simple objects together - and if the same property\n(such as `width`) appears in a later object, it will override the previous value.  In this case the\n`width` in `componentOptions` overrides the previously set default in `componentDefaults`.\n\n\n### Where `Object.assign()` DOESN'T work fine\nIf your configuration object is more complicated and contains nested objects, `Object.assign()`\nturns out not to work so well:\n\n```js\nconst componentDefaults = { dimensions: { width: 100, height: 100 } };\nconst componentOptions = { dimensions: { width: 200 } };\n\nconst options = Object.assign({}, componentDefaults, componentOptions);\n// -\u003e { dimensions: { width: 200 } }\n```\n\nWhat happened to the `height` property?!  It turns out that the previously set `dimensions`\nproperty was completely overwritten, not merged with the new `dimensions` object.\n\nMaybe we can use Object spread?  But that turns out to have the same limitation with complex\nobjects:\n\n```js\nconst objSpreadTest = { ...componentDefaults, ...componentOptions };\n// -\u003e { dimensions: { width: 200 } }\n```\n\n\n## Testing\nTo run the test suite, simply type:\n\n`npm test`\n\nNote that I've used some of the same tests as `deep-assign` in addition to my own.  More\ncontributions are welcome!\n\n## License\nMIT\n\n[downloads-image]: https://img.shields.io/npm/dm/deep-object-assign-with-reduce.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/deep-object-assign-with-reduce\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidcalhoun%2Fdeep-object-assign-with-reduce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidcalhoun%2Fdeep-object-assign-with-reduce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidcalhoun%2Fdeep-object-assign-with-reduce/lists"}