{"name":"smob","version":"0.0.2","description":"Safe merge objects.","main":"./dist/index.js","typings":"dist/index.d.ts","scripts":{"build":"rm -rf ./dist && tsc","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","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":{"@tada5hi/eslint-config-typescript":"^1.0.7","@types/jest":"^27.5.0","@types/node":"^18.7.17","cross-env":"^7.0.3","eslint":"^8.23.1","jest":"^27.5.1","np":"^7.6.2","ts-jest":"^27.1.4","typescript":"^4.8.3"},"gitHead":"22069b4a6da3d8f999fd93a98c13b42ba3040d49","_id":"smob@0.0.2","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-N0u3GH8THbvPCR8ha9pvjSa1hD76xJjAjfLvRNcrTubGF23k7NPxnFpKc95880fo4/vsODLp+STFS8aTwXng7w==","shasum":"6cb458f5c5e818cba54d9a762e35a875f43d4bba","tarball":"http://registry-npm.ywwl.com/smob/download/smob-0.0.2.tgz","fileCount":21,"unpackedSize":20181,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDdY/QmxYKvAo2jZfWq/Dkwyr52CHNUR5aKWTfIWjph1wIgGAIuUji0PkRlGPm9PZPvo8BAsYpMAVnYReRym8aZXHQ="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjJFVNACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpZGw/+PGzE5B2y6+MweYxqfRfTp+bGCKfxGYxBOg2PXiXNcjQWj51s\r\nMJE1UZwSM+t02UEAZhzOitUQsTcuuZftFCrkrj1ifm/QGMSG35c2jOslOLnI\r\n4M8AcJmiFLCUrmUzike1+Ux6xxIyb4+cMd6SJMMXmOUq3vdWuYNESrzb0+CV\r\nd/XENegtzD3IaFBPbkIr+0bMASZhshv9ff9ahJ0pStcrJI5n61X/pPlKaDGU\r\nkfCJxG++2Ado2b3EDIZWb+LG3sVHgXc2yEJrSeVDYqkpcBB2VblWVflfz04Y\r\nE/WPcvbLUAoTiEJHFIzQJec6cSpo0uLrsREQyVs7RN/dOdnGAgHqOCaxZEEN\r\nrQBOWihIOc0EaHK4OsbxjP5S5/6SGVzgTfP5GuruiKX9bZV5ciNZbqDYxHCv\r\n9bOxpSMQymkdehG0uuZWJnkFWuRSNLeVBfgvOjQ6PWlXJrrDXGHZtngvv0bw\r\nvsrolygQZ7RBO0SPZ9PH16AWgMgwAdDO1ZWQkRhEhC37le7/rUIgxG3tLMEP\r\nHnUsb5arfkuIILq4w+0Yp5Mc9OI/NjayweUC3ufMstAK8VhHFKvRyUboIoHf\r\n4BQ/UzkQC2YRIMYLhJ7Hu+96MdIIzps/iSJ/nnnnt2vhwdAV7V//Q9OS3eb2\r\npEEt6GCf6hDX1OAC+hvcUiLR+85xb7sbzL8=\r\n=uwvz\r\n-----END PGP SIGNATURE-----\r\n","size":5785,"noattachment":false,"key":"/smob/-/smob-0.0.2.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.2_1663325517491_0.9466173886639762"},"_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":1663325517643,"_cnpm_publish_time":1663325517643,"dist-tags":{"alpha":"1.3.0-alpha.2","latest":"1.6.2"}}