{"name":"smob","version":"1.3.0","description":"Zero dependency library to safe merge objects.","main":"dist/index.cjs","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{"./package.json":"./package.json",".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"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","object-merge","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":{"@rollup/plugin-node-resolve":"^15.0.2","@swc/core":"^1.3.60","@swc/jest":"^0.2.26","@tada5hi/commitlint-config":"^1.0.2","@tada5hi/eslint-config-typescript":"^1.1.9","@tada5hi/semantic-release":"^0.1.0","@tada5hi/tsconfig":"^0.4.0","@types/jest":"^29.5.1","@types/node":"^20.2.4","cross-env":"^7.0.3","eslint":"^8.41.0","husky":"^8.0.3","jest":"^29.5.0","rollup":"^3.23.0","semantic-release":"^19.0.5","typescript":"^5.0.4"},"gitHead":"f32116345cd945b9bd325955d9a9cbab20e90ffb","_id":"smob@1.3.0","_nodeVersion":"18.16.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-/fIjILUZrqpd2v9GWqaULJ1Gjw4BnWmPnQcqx8aFrSt97C2/ALamtVl9q1XRkuUg9TDkrXzfTsppQnm9DCJH8w==","shasum":"ffc8ed08846a1ad18e8fd9ee58e3f27772329bfe","tarball":"http://registry-npm.ywwl.com/smob/download/smob-1.3.0.tgz","fileCount":19,"unpackedSize":75294,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCsFG4BK/e+pcEBs5ZOhsUXell58Rv4s+o/u0MFMhsoIwIgXu1glK6RfyMrJjcSgJ2kxBP4IFzsu73+BPzwKkz1Cgo="}],"size":12269,"noattachment":false,"key":"/smob/-/smob-1.3.0.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_1.3.0_1685290966302_0.4170337498132657"},"_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":1685290966460,"_cnpm_publish_time":1685290966460,"dist-tags":{"alpha":"1.3.0-alpha.2","latest":"1.6.2"}}