{"name":"smob","version":"0.0.6","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.19.3","@babel/plugin-proposal-class-properties":"7.18.6","@babel/plugin-proposal-object-rest-spread":"7.19.4","@babel/preset-env":"^7.19.4","@babel/preset-typescript":"^7.18.6","@commitlint/cli":"^17.1.2","@commitlint/config-angular":"^17.1.0","@commitlint/config-conventional":"^17.1.0","@commitlint/cz-commitlint":"^17.1.2","@semantic-release/changelog":"^6.0.1","@semantic-release/commit-analyzer":"^9.0.2","@semantic-release/git":"^10.0.1","@semantic-release/github":"^8.0.6","@semantic-release/npm":"^9.0.1","@semantic-release/release-notes-generator":"^10.0.3","@rollup/plugin-babel":"^6.0.0","@rollup/plugin-commonjs":"^23.0.0","@rollup/plugin-node-resolve":"^15.0.0","@tada5hi/eslint-config-typescript":"^1.0.8","@types/jest":"^27.5.0","@types/node":"^18.11.0","cross-env":"^7.0.3","eslint":"^8.25.0","husky":"^8.0.1","jest":"^27.5.1","rollup":"^2.79.1","rollup-plugin-terser":"^7.0.2","ts-jest":"^27.1.4","typescript":"^4.8.4"},"config":{"commitizen":{"path":"@commitlint/cz-commitlint"}},"gitHead":"c26e01f880004e87cc0a6504571b38a5f33d9348","_id":"smob@0.0.6","_nodeVersion":"18.10.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-V21+XeNni+tTyiST1MHsa84AQhT1aFZipzPpOFAVB8DkHzwJyjjAmt9bgwnuZiZWnIbMo2duE29wybxv/7HWUw==","shasum":"09b268fea916158a2781c152044c6155adbb8aa1","tarball":"http://registry-npm.ywwl.com/smob/download/smob-0.0.6.tgz","fileCount":16,"unpackedSize":22918,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFcvOV09DQcUEd1mznd0YL0jyspW1UaxhcqvK5leN2mKAiEAiPlH8zGvwl4+imNMUAAAbXbQgr3LdgpOmlhspt9cl2c="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjUACcACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmroBQ/+KnbBQ8Hlfz/nKu51dq3SjBGQ4NegVFNXnelVLxMyk1M1wRRK\r\n0iTCRGBillyJbHMBSCcckchCGpBLF0C4Hb5YoqhzS76AbmMEhxXJuQL1AiuJ\r\nMW1tWT2PkXFOuGemEcZub9Y0qKcJVARnaIft28sLY2mF8ftMyGCgEI+60MIC\r\nIDCWdBMSylu6XqCZufg4OO0yIU2MddlMkIOJE1MhMzCYLsimAgmhKb0na/8B\r\nuIABmzjoBLD/VDGWlIYclCTyb66YrlwT1bpYsrRGdDWpT2ao6TPTeBDOkMbt\r\nvBkchQxSvL3titkKmoFVoflFTPpuc2mzQhkYMnPuJAPs9s1ePmGskgv5JwCR\r\nWemOciwTsl5v1k9rL8hb9rRCsKHaIrU0/Ewg2GemiN5bdkLR5q8muaAc1tU0\r\nlD12g/XYRIAl/T3hz1DeiNLTBJ4LB4pqf/+5USYR1X/exfR/6BcW+4Kur4BV\r\nZHImWwJVB5vhwZMmMWKzpmYfzlZMyG35dSbm+a3pc56MFNfylYMJzOcXpErd\r\nCUYOhbMOp1/kEpFwmURfEPVi4nowJzVGq77hUb9nE6TXMXKru5yM0rdGbs/k\r\nnz4GfKnsUKnH0u/3Jz6S9HzKlrJ9lglCbGtWgsvoLtwE/A1IYWfZtAS/PPqF\r\n2BNptvuL3JS0DGh+aBqJRWJZrtc26kgXyoU=\r\n=OZs3\r\n-----END PGP SIGNATURE-----\r\n","size":5935,"noattachment":false,"key":"/smob/-/smob-0.0.6.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.6_1666187420257_0.9309702959659145"},"_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":1666187420453,"_cnpm_publish_time":1666187420453,"dist-tags":{"alpha":"1.3.0-alpha.2","latest":"1.6.2"}}