{"id":19124430,"url":"https://github.com/panates/putil-merge","last_synced_at":"2025-05-05T19:22:28.472Z","repository":{"id":22840759,"uuid":"97453111","full_name":"panates/putil-merge","owner":"panates","description":"Lightweight solution for merging multiple objects into one. Also it supports deep merge","archived":false,"fork":false,"pushed_at":"2024-08-04T15:21:07.000Z","size":878,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-05T20:33:57.445Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/panates.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":"2017-07-17T08:28:21.000Z","updated_at":"2024-08-04T15:21:11.000Z","dependencies_parsed_at":"2024-06-18T20:07:55.110Z","dependency_job_id":"8ce32a7c-37de-4daf-b2de-ee968c7c62b3","html_url":"https://github.com/panates/putil-merge","commit_stats":{"total_commits":103,"total_committers":3,"mean_commits":"34.333333333333336","dds":0.4563106796116505,"last_synced_commit":"156337b422a1d6019b1211ca25373682daaad693"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fputil-merge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fputil-merge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fputil-merge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fputil-merge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/panates","download_url":"https://codeload.github.com/panates/putil-merge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223262516,"owners_count":17115774,"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-11-09T05:29:05.265Z","updated_at":"2024-11-09T05:29:05.759Z","avatar_url":"https://github.com/panates.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# putil-merge\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n[![DevDependencies][devdependencies-image]][devdependencies-url]\n\nA 'swiss army knife' solution for merging two or more objects. It supports deep merge, cloning properties, copying descriptors and filtering.\n\n## Installation\n\n`$ npm install putil-merge --save`\n\n## Table of contents\n\n- [merge()](#merge)\n- [merge.all()](#mergeall)\n\n\n## Merge\n\n`merge(target, source[, options])`\n\n- `target:object`:\n- `source:object`:\n- `options:object` \n    - `deep:boolean` (optional): If true, it performs deep merge operation. **Default:** `false`\n    - `clone:boolean` (optional): If true, clones object properties rather than assigning references.  **Default:** `false`\n    - `adjunct:boolean`(optional): If true, it copies only non-existing properties. **Default:** `false`\n    - `descriptor:boolean`(optional): If true, copies property descriptors.  **Default:** `false`\n    - `filter:function` (optional): A callback function to test if source property will be merged to target.\n    - `arrayMerge:boolean|function` (optional): If true, it combines array values. It this is a function, result of call will be assigned to target.\n\n**Copying source properties to target object**\n\n```javascript\nconst a = {x: 1, y: 2};\nconst b = {x: {}, z: [1, 2, 3, 4]};\nconst merged = merge(a, b);\nassert(merged.x===b.x); // References copied\nassert(merged.z===b.z); // References copied\n```\n\n**Cloning source properties to target object**\n\n```js\nconst a = {x: 1, y: 2};\nconst b = {x: {}, z: [1, 2, 3, 4]};\nconst merged = merge(a, b, {clone: true});\nassert(merged.x!==b.x); // Object cloned\nassert(merged.z!==b.z); // Array cloned\n```\n\n\n**Applying filter while merge**\n\n```js\nconst a = {x: 1, y: 2};\nconst b = {x: {}, z: [1, 2, 3, 4]};\nconst merged = merge(a, b, {filter: (src, key)=\u003ekey!=='z'});\nassert(!merged.z); // Z will not be merged\n```\n\n\n**Copying descriptors**\n\n```javascript\nconst b = {};\nObject.defineProperty(b, 'foo', {\n  enumerable: false\n});\nconst merged = merge({}, b, {descriptor: true});\nassert.strictEqual(Object.getOwnPropertyDescriptor(merged, 'foo').enumerable, false);\n```\n\n**Copying getters and setters**\n\n```javascript\nconst b = {\n  bar: 1,\n  get foo(){\n    return this.bar; \n  }\n};\nconst merged = merge({}, b, {descriptor: true});\nassert.strictEqual(merged.foo, 1);\n```\n\n\n**Copying function properties**\n\n```javascript\nconst b = {\n  bar: 1,\n  getFoo(){\n    return this.bar; \n  }\n};\nconst merged = merge({}, b, {descriptor: true});\nassert.strictEqual(merged.getFoo(), 1);\n```\n\n\n## Merge.all()\n\nPerforms merge with more than two objects.\n\n`merge.all(arrayOfObjects[, options])`\n\n- `arrayOfObjects:Array\u003cobject\u003e`:\n- `options:object` \n    - `deep:boolean` (optional): If true, it performs deep merge operation. **Default:** `false`\n    - `clone:boolean` (optional): If true, clones object properties rather than assigning references.  **Default:** `false`\n    - `combine:boolean`(optional): If true, it copies only non-existing properties. **Default:** `false`\n    - `descriptor:boolean`(optional): If true, copies property descriptors.  **Default:** `false`\n    - `filter:function` (optional): A callback function to test if source property will be merged to target.\n    - `arrayMerge:boolean|function` (optional): If true, it combines array values. It this is a function, result of call will be assigned to target.\n\n\n## Node Compatibility\n\n  - node `\u003e= 6.0`;\n  \n### License\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/putil-merge.svg\n[npm-url]: https://npmjs.org/package/putil-merge\n[travis-image]: https://img.shields.io/travis/panates/putil-merge/master.svg\n[travis-url]: https://travis-ci.org/panates/putil-merge\n[coveralls-image]: https://img.shields.io/coveralls/panates/putil-merge/master.svg\n[coveralls-url]: https://coveralls.io/r/panates/putil-merge\n[downloads-image]: https://img.shields.io/npm/dm/putil-merge.svg\n[downloads-url]: https://npmjs.org/package/putil-merge\n[devdependencies-image]: https://david-dm.org/panates/putil-merge/dev-status.svg\n[devdependencies-url]:https://david-dm.org/panates/putil-merge?type=dev\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanates%2Fputil-merge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpanates%2Fputil-merge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanates%2Fputil-merge/lists"}