{"name":"smob","version":"1.6.0","keywords":["object","object-merge","merge","safe","deep-merge","merge-deep"],"author":{"url":"https://github.com/tada5hi","name":"Peter Placzek","email":"contact@tada5hi.net"},"license":"MIT","_id":"smob@1.6.0","maintainers":[{"name":"tada5hi","email":"peter.placzek1996@gmail.com"}],"homepage":"https://github.com/Tada5hi/smob#readme","bugs":{"url":"https://github.com/Tada5hi/smob/issues"},"dist":{"shasum":"065bd757b978b0cc690a65e1cf83f247ef74adde","tarball":"http://registry-npm.ywwl.com/smob/download/smob-1.6.0.tgz","fileCount":18,"integrity":"sha512-m/Bpm2tsx68FEr4zgGaMdcjHSkq7x7uOPJIQudT/gS7slXH5y2VatJru4POV0dKbmk7ZYntX29fKgwWCXJKwvQ==","signatures":[{"sig":"MEUCIDJZ4e+IxDK+oDmWaB68f+ikVYHTp77WsISe30WuIQaVAiEAr0nh8GwrAp1p62BZK8K0NFN+Dhg7RJETcqvq7Ncqd6M=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":75023,"size":12520,"noattachment":false,"key":"/smob/-/smob-1.6.0.tgz"},"main":"dist/index.cjs","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=22.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"},"./package.json":"./package.json"},"scripts":{"lint":"eslint --ext .js,.ts ./src","test":"cross-env NODE_ENV=test vitest run --config test/vitest.config.ts","build":"rimraf dist && npm run build:types && npm run build:js","commit":"npx git-cz","prepare":"npx husky install","build:js":"rollup -c","lint:fix":"npm run lint -- --fix","build:types":"tsc --emitDeclarationOnly","test:coverage":"cross-env NODE_ENV=test vitest run --config test/vitest.config.ts --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"tada5hi","email":"peter.placzek1996@gmail.com"},"repository":{"url":"git+https://github.com/Tada5hi/smob.git","type":"git"},"description":"Zero dependency library to safe merge objects.","directories":{},"_nodeVersion":"22.21.1","_hasShrinkwrap":false,"devDependencies":{"husky":"^9.1.7","eslint":"^8.57.1","rollup":"^4.57.1","vitest":"^4.0.18","@swc/core":"^1.15.11","cross-env":"^10.1.0","typescript":"^5.9.3","@types/node":"^25.2.3","@tada5hi/tsconfig":"^0.7.0","workspaces-publish":"^1.6.0","@vitest/coverage-v8":"^4.0.18","@tada5hi/commitlint-config":"^1.2.7","@rollup/plugin-node-resolve":"^16.0.3","@tada5hi/eslint-config-typescript":"^1.2.18"},"_npmOperationalInternal":{"tmp":"tmp/smob_1.6.0_1770815409507_0.36270412552033227","host":"s3://npm-registry-packages-npm-production"},"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":1770815409650,"_cnpm_publish_time":1770815409650,"dist-tags":{"alpha":"1.3.0-alpha.2","latest":"1.6.2"}}