{"name":"smob","version":"0.0.7","description":"Zero dependency library to safe merge objects.","main":"dist/index.cjs.js","module":"dist/index.esm.js","browser":"dist/index.browser.js","unpkg":"dist/index.iife.js","types":"dist/types/index.d.ts","scripts":{"build:types":"tsc --emitDeclarationOnly","build:js":"rollup -c","build":"rimraf dist && npm run build:types && npm run build:js","commit":"npx git-cz","lint":"eslint --ext .js,.ts ./src","lint:fix":"npm run lint -- --fix","test":"cross-env NODE_ENV=test jest --config ./test/jest.config.js","test:coverage":"npm run test -- --coverage","prepare":"npx husky install","prepublishOnly":"npm run build"},"author":{"name":"Peter Placzek","email":"contact@tada5hi.net","url":"https://github.com/tada5hi"},"license":"MIT","keywords":["object","merge","safe","deep-merge","merge-deep"],"repository":{"type":"git","url":"git+https://github.com/Tada5hi/smob.git"},"bugs":{"url":"https://github.com/Tada5hi/smob/issues"},"homepage":"https://github.com/Tada5hi/smob#readme","devDependencies":{"@babel/core":"^7.20.12","@babel/plugin-proposal-class-properties":"7.18.6","@babel/plugin-proposal-object-rest-spread":"7.20.7","@babel/preset-env":"^7.20.2","@babel/preset-typescript":"^7.18.6","@commitlint/cli":"^17.4.1","@commitlint/config-angular":"^17.4.0","@commitlint/config-conventional":"^17.4.0","@commitlint/cz-commitlint":"^17.4.1","@semantic-release/changelog":"^6.0.2","@semantic-release/commit-analyzer":"^9.0.2","@semantic-release/git":"^10.0.1","@semantic-release/github":"^8.0.7","@semantic-release/npm":"^9.0.1","@semantic-release/release-notes-generator":"^10.0.3","@rollup/plugin-babel":"^6.0.3","@rollup/plugin-commonjs":"^24.0.0","@rollup/plugin-node-resolve":"^15.0.1","@rollup/plugin-terser":"^0.3.0","@tada5hi/eslint-config-typescript":"^1.1.0","@types/jest":"^27.5.0","@types/node":"^18.11.18","cross-env":"^7.0.3","eslint":"^8.31.0","husky":"^8.0.3","jest":"^27.5.1","rollup":"^3.9.1","semantic-release":"^19.0.5","ts-jest":"^27.1.4","typescript":"^4.9.4"},"config":{"commitizen":{"path":"@commitlint/cz-commitlint"}},"gitHead":"d924cf897d486523436eaf669c1eb183f140b3c1","_id":"smob@0.0.7","_nodeVersion":"18.13.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-281Gl0ANIQcGGEZTQf5K3GETIE82JnhaZhY+sGJzQT5268qZR1zoXVVr60CEkdRRZS6PPo0h0Ilp0qJNYvpiow==","shasum":"99166e107b516c06fec0d6005a3e8a5bd2c6e18b","tarball":"http://registry-npm.ywwl.com/smob/download/smob-0.0.7.tgz","fileCount":16,"unpackedSize":24175,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBL826dDA6DkGiovU9DUEe9+Gpm7ASqCmqitWiwF7oCkAiBb49KwhY4HfibvK5y0q5FsJVGg/jQPS/2Qy3aHlD58Wg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvpxQACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr5txAAn7a5xcCjhOEnQtnjpVE06SOSB5DzJeddg6pQuDZYyKpJplas\r\nifq1Vkw4jRLxvQv5BljKedBasxmh5LDqGgN4lLQH/rqq+HayY0io+fNBISub\r\nl+6CtYrHPzFB+TjqO4Tcm2Vd1z4Dv1uBwAtpUbiGMsj54jyXwnISn9PpEoOS\r\nMcPMBr2kATQfyz+GOOWpvdSua7LLV7Qml/6GdjbqP26RYt3h8Wxi8LuX5+8r\r\naCDJhwWF03a5gz1n/VBoeZTzoxZSU+AJPC4BVOnmt3FYftU4dofNVI6NwNUP\r\nvlqNuqt/W6+uQ3V1TKsGKv4bgWboZlq3z2ED4T4yeJ0rMddcdAQ90FvcQZFi\r\nhrdE+R+AY3XUfzmv6TwPRWlGvDSwZwGvLeyxwPAgoSJIHst0J6HKCUfDMN9J\r\nSll0XZLVdBhlt3lElqtWTX5KTKuVBxke9mZW3rt1Ii/OHL1rYMHYr8WVxCMJ\r\nMZ/u1fVmUY1IZMgGWuKCsUNf3SmGn7V/4QVdTli5VJUA+k3qgnY/gcKLNuFR\r\nLI6XVl0JD/n4i2l8CgrERk2XOf4QxbALso6veanL4xKH16H/q6Ev2fZVOwQh\r\n/fUTP6CYuY4IuzU3oIkj+ey3WUPh25EPCVMvCKwtXkFIan/HkhUb0fRzI+TI\r\ncpFQhSc8VubQPvCXr+MiZ45QuW853D+qya4=\r\n=zy6/\r\n-----END PGP SIGNATURE-----\r\n","size":5976,"noattachment":false,"key":"/smob/-/smob-0.0.7.tgz"},"_npmUser":{"name":"tada5hi","email":"peter.placzek1996@gmail.com"},"directories":{},"maintainers":[{"name":"tada5hi","email":"peter.placzek1996@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/smob_0.0.7_1673436240658_0.6530380037381209"},"_hasShrinkwrap":false,"readme":"# SMOB 🧪\n\n[![npm version](https://badge.fury.io/js/smob.svg)](https://badge.fury.io/js/smob)\n[![main](https://github.com/tada5hi/smob/actions/workflows/main.yml/badge.svg)](https://github.com/tada5hi/smob/actions/workflows/main.yml)\n[![codecov](https://codecov.io/gh/tada5hi/smob/branch/master/graph/badge.svg?token=0VL41WO0CG)](https://codecov.io/gh/tada5hi/smob)\n[![Known Vulnerabilities](https://snyk.io/test/github/Tada5hi/smob/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Tada5hi/smob?targetFile=package.json)\n[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)\n\nA zero dependency library to **s**afe **m**erge **ob**jects and arrays with customizable behavior.\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Merger](#merger)\n  - [Utils](#utils)\n- [License](#license)\n\n## Installation\n\n```bash\nnpm install smob --save\n```\n\n## Usage\n\n```typescript\nimport { merge } from \"smob\";\n\nconst output = merge(...sources);\n```\n\nThe following merge options are set by default:\n- **array**: `true` Merge object array properties.\n- **arrayDistinct**: `false` Remove duplicates, when merging array elements.\n- **arrayPriority**: `left` (options.priority) The source aka leftmost array has by **default** the highest priority.\n- **clone**: `false` Deep clone input sources.\n- **inPlace**: `false` Merge sources in place.\n- **priority**: `left` The source aka leftmost object has by **default** the highest priority.\n\nThe merge behaviour can be changed by creating a custom [merger](#merger).\n\n**Arguments**\n- sources `(any[] | Record<string, any>)[]`: The source arrays/objects.\n\n```typescript\nimport { merge } from 'smob';\n\nmerge({ a: 1 }, { b: 2 }, { c: 3 });\n// { a: 1, b: 2, c: 3 }\n\nmerge(['foo'], ['bar']);\n// ['foo', 'bar']\n\n```\n\n### Merger\n\nA custom merger can simply be created by using the `createMerger` method.\n\n**Array**\n```typescript\nimport { createMerger } from 'smob';\n\nconst merge = createMerger({ array: false });\n\nmerge({ a: [1,2,3] }, { a: [4,5,6] });\n// { a: [1,2,3] }\n```\n\n**ArrayDistinct**\n```typescript\nimport { createMerger } from 'smob';\n\nconst merge = createMerger({ arrayDistinct: true });\n\nmerge({ a: [1,2,3] }, { a: [3,4,5] });\n// { a: [1,2,3,4,5] }\n```\n\n**Priority**\n```typescript\nimport { createMerger } from 'smob';\n\nconst merge = createMerger({ priority: 'right' });\n\nmerge({ a: 1 }, { a: 2 }, { a: 3 })\n// { a: 3 }\n```\n\n**Strategy**\n```typescript\nimport { createMerger } from 'smob';\n\nconst merge = createMerger({\n    strategy: (target, key, value) => {\n        if (\n            typeof target[key] === 'number' &&\n            typeof value === 'number'\n        ) {\n            target[key] += value;\n            return target;\n        }\n    }\n});\n\nmerge({ a: 1 }, { a: 2 }, { a: 3 });\n// { a: 6 }\n```\n\nA returned value indicates that the strategy has been applied.\n\n## Utils\n\n### distinctArray\n\n```typescript\nimport { distinctArray } from 'smob';\n\ndistnctArray(['foo', 'bar', 'foo']);\n// ['foo', 'bar']\n```\n\nThe function also removes non-primitive\nelements that are identical by value or reference.\n\n**Objects**\n```typescript\nimport { distinctArray } from 'smob';\n\ndistinctArray([{ foo: 'bar' }, { foo: 'bar' }]);\n// [{ foo: 'bar' }]\n```\n\n**Arrays**\n```typescript\nimport { distinctArray } from 'smob';\n\ndistinctArray([['foo', 'bar'], ['foo', 'bar']]);\n// [['foo', 'bar']]\n```\n\n### isEqual\n\nChecks if two (non-primitive) elements\nare identical by value or reference.\n\n````typescript\nimport { isEqual } from 'smob';\n\nisEqual({foo: 'bar'}, {foo: 'bar'});\n// true\n\nisEqual(['foo', 'bar'], ['foo', 'bar']);\n// true\n````\n\n## License\n\nMade with 💚\n\nPublished under [MIT License](./LICENSE).\n","publish_time":1673436240845,"_cnpm_publish_time":1673436240845,"dist-tags":{"alpha":"1.3.0-alpha.2","latest":"1.6.2"}}