{"id":50334512,"url":"https://github.com/komed3/deepmerge","last_synced_at":"2026-05-29T12:31:00.997Z","repository":{"id":346666719,"uuid":"1190913838","full_name":"komed3/deepmerge","owner":"komed3","description":"Fast and efficient object merging and manipulation library","archived":false,"fork":false,"pushed_at":"2026-03-25T19:10:39.000Z","size":86,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-26T03:35:59.139Z","etag":null,"topics":["deep-merge","merge","merge-objects","npm-package","object-manipulation","objects"],"latest_commit_sha":null,"homepage":"https://npmjs.com/@komed3/deepmerge","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/komed3.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-24T18:35:24.000Z","updated_at":"2026-03-25T19:14:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/komed3/deepmerge","commit_stats":null,"previous_names":["komed3/quickmerge"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/komed3/deepmerge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fdeepmerge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fdeepmerge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fdeepmerge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fdeepmerge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/komed3","download_url":"https://codeload.github.com/komed3/deepmerge/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fdeepmerge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33652977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"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":["deep-merge","merge","merge-objects","npm-package","object-manipulation","objects"],"created_at":"2026-05-29T12:31:00.719Z","updated_at":"2026-05-29T12:31:00.991Z","avatar_url":"https://github.com/komed3.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @komed3/deepmerge\n\nA fast and efficient deep object merging and manipulation library for Node.js and the browser, optimized for performance and flexibility.\n\n`deepmerge` provides a high-performance `Merger` with a non-recursive stack-based implementation and a versatile `Accessor` for safe, deep object manipulation using dot and bracket notation. It includes a built-in path compiler with caching to ensure maximum efficiency during repeated operations.\n\n## Installation\n\nInstall via npm:\n\n```bash\nnpm install @komed3/deepmerge\n```\n\n## Import Methods\n\n`deepmerge` supports multiple module formats for seamless integration across different environments.\n\n### ESM (ECMAScript Modules)\nFor modern projects using `import`:\n\n```ts\nimport { factory, Merger, Accessor } from '@komed3/deepmerge';\n```\n\n### CommonJS\nFor Node.js projects using `require`:\n\n```js\nconst { factory, Merger, Accessor } = require( '@komed3/deepmerge' );\n```\n\n### UMD (Browser)\nInclude the script in your HTML:\n\n```html\n\u003cscript src=\"node_modules/@komed3/deepmerge/dist/index.umd.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    const { factory } = deepmerge;\n\u003c/script\u003e\n```\n\n## Quick Usage\n\nThe easiest way to get started is using the `factory()` function to create a new instance with a shared configuration.\n\n```ts\nimport { factory } from '@komed3/deepmerge';\n\n// initialize with default options\nconst qm = factory();\n\nconst target = { user: { name: 'Max' } };\nconst source = { user: { role: 'admin' }, tags: [ 'lead' ] };\n\n// deep merge objects\nqm.merger.merge( target, source );\nconsole.log( target ); // { user: { name: 'Max', role: 'admin' }, tags: [ 'lead' ] }\n\n// safe property access using dot/bracket notation\nconst name = qm.accessor.get( target, 'user.name' ); // 'Max'\nqm.accessor.set( target, 'user.id', 123 );\nqm.accessor.update( target, 'tags[0]', v =\u003e v.toUpperCase() );\n\nconsole.log( target.user.id ); // 123\nconsole.log( target.tags ); // [ 'LEAD' ]\n```\n\nInstead of using the factory function, you can also create instances of `Merger`, `Accessor`, and `Path` directly:\n\n```ts\nimport { Merger, Accessor, Path } from '@komed3/deepmerge';\n\nconst merger = new Merger( { ... } );\nconst accessor = new Accessor( { ... } );\nconst path = new Path( { ... } );\n```\n\n## API Reference\n\n### factory( options? )\nCreates an object containing pre-configured instances of `Merger`, `Accessor`, and `Path`.\n\n```ts\nconst { merger, accessor, path } = factory( { deep: true, protect: false } );\n```\n\n### Merger\n\n- `merge\u003c T \u003e( target: T, ...sources: any[] ) : T`  \n  Performs a deep merge of all source objects into the target.\n- `mergeAt\u003c T \u003e( target: T, path: PathLike, ...sources: any[] ) : T`  \n  Merges sources into the target at a specific nested path.\n\n### Accessor\n\n- `get\u003c O, V \u003e( obj: O, path: PathLike ) : V | undefined`  \n  Retrieves a value at the given path.\n- `set\u003c O, V \u003e( obj: O, path: PathLike, value: V ) : void`  \n  Sets a value at the path, creating missing structures if needed.\n- `has\u003c O \u003e( obj: O, path: PathLike ) : boolean`  \n  Checks if a nested property exists.\n- `delete\u003c O \u003e( obj: O, path: PathLike ) : void`  \n  Removes a property or array index at the path.\n- `update\u003c O \u003e( obj: O, path: PathLike, fn: ( v: any ) =\u003e any ) : void`  \n  Transforms a value at the path using a function.\n\n### Path\n\n- `compile( path: string ) : CompiledPath`  \n  Parses a path string into tokens and caches the result.\n- `normalize( path: PathLike ) : CompiledPath`  \n  Ensures a path is in its compiled format.\n\n## Options\n\n### MergeOptions\n- `deep` (boolean, default: `true`)  \n  Whether to perform deep merging of nested objects.\n- `protect` (boolean, default: `false`)  \n  If true, existing properties in the target are not overwritten.\n- `mergeUndefined` (boolean, default: `false`)  \n  Whether to allow `undefined` values from sources to overwrite target values.\n- `strict` (boolean, default: `false`)  \n  If true, new objects/arrays will not be created when paths are missing.\n- `createObject` (function, default: `() =\u003e Object.create( null )`)  \n  A factory function for creating new objects when missing structures are encountered during a deep merge.\n- `arrayMode` (`'replace' | 'keep' | 'concat' | 'unique'` | function, default: `'replace'`)  \n  Strategy for merging arrays or a custom merge function `( target: any[], source: any[] ) =\u003e any[]`.\n- `valueFn` (function)  \n  A custom function to handle specific value merging logic: `( key, targetVal, sourceVal ) =\u003e any`.\n- `pathOptions` (`PathOptions`)  \n  Configuration for the internal path compiler.\n\n### PathOptions\n- `cache` (boolean, default: `true`)  \n  Enable or disable caching of compiled path strings.\n- `maxCacheSize` (number, default: `1000`)  \n  The maximum number of paths to keep in the cache.\n\n## Customization\n\n### Custom Object Creation\nUse `createObject` to control how new objects are instantiated, for example to use plain objects instead of null-prototype objects:\n\n```ts\nconst qm = factory( {\n  createObject: () =\u003e ( {} )\n} );\n```\n\n### Custom Array Merging\nPass a function to `arrayMode` to implement your own logic, such as merging by a specific property:\n\n```ts\nconst qm = factory( {\n  arrayMode: ( target, source ) =\u003e {\n    // custom merge logic\n    return [ ...target, ...source ].filter( v =\u003e v.active );\n  }\n} );\n```\n\n### Custom Value Merging\nUse `valueFn` to define custom logic for merging individual values:\n\n```ts\nconst qm = factory( {\n  valueFn: ( key, targetVal, sourceVal ) =\u003e {\n    if ( key === 'count' ) {\n      return targetVal + sourceVal;\n    }\n    return sourceVal;\n  }\n} );\n```\n\n## Array Modes\n\nControl how arrays are handled during a merge using the built-in `ArrayMode` enums:\n\n- `Replace`: Overwrites the target array with the source array (default).\n- `Keep`: Retains the target array and ignores the source.\n- `Concat`: Appends source elements to the target array.\n- `Unique`: Combines both arrays and removes duplicates.\n\n```ts\nimport { factory, ArrayMode } from '@komed3/deepmerge';\n\nconst qm = factory( { arrayMode: ArrayMode.Unique } );\nconst target = { ids: [ 1, 2 ] };\nqm.merger.merge( target, { ids: [ 2, 3 ] } );\n\nconsole.log( target.ids ); // [ 1, 2, 3 ]\n```\n\n----\n\nCopyright (c) 2026 Paul Köhler (komed3). All rights reserved.  \nReleased under the MIT license. See LICENSE file in the project root for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkomed3%2Fdeepmerge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkomed3%2Fdeepmerge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkomed3%2Fdeepmerge/lists"}