{"name":"smob","version":"1.6.2","description":"Zero dependency library to safe merge objects.","type":"module","main":"dist/index.cjs","module":"dist/index.mjs","types":"dist/index.d.mts","exports":{"./package.json":"./package.json",".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"engines":{"node":">=20.0.0"},"scripts":{"build:types":"tsc","build:js":"tsdown","build":"npm run build:types && npm run build:js","lint":"eslint","lint:fix":"npm run lint -- --fix","test":"vitest --config test/vitest.config.ts --run","test:coverage":"vitest --config test/vitest.config.ts --run --coverage","prepare":"husky"},"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","publishConfig":{"access":"public"},"devDependencies":{"@tada5hi/commitlint-config":"^1.3.1","@tada5hi/eslint-config":"^2.3.0","@tada5hi/tsconfig":"^0.7.2","@vitest/coverage-v8":"^4.1.5","eslint":"^10.3.0","husky":"^9.1.7","tsdown":"^0.22.0","typescript":"^5.9.3","typescript-eslint":"^8.59.2","vitest":"^4.1.5"},"_id":"smob@1.6.2","gitHead":"a3fac78f200ec7f8d5b20eaf09add25f1c2c4208","_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-RQsvleCbF8cVHEv+xuDGaA4pOizFqJ0GgjtMSRo6oP8pnN7WsigHgVGey6aILRBKv4W2YOMHLqbKdnB6hpB9fw==","shasum":"190b94c25530c631a7ccc63de0d4c0087222d21d","tarball":"http://registry-npm.ywwl.com/smob/download/smob-1.6.2.tgz","fileCount":9,"unpackedSize":61738,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBZ91g5uD90CJlOPb+PwCKZlY9wTSTVV7Xz7Cl4GdZfrAiEAqr9JIZ51/Mbh8BRMenfdCO4j38VAhWynU6hkBAzcmtM="}],"size":11090,"noattachment":false,"key":"/smob/-/smob-1.6.2.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:0dc82ac9-f5d2-42ac-b58d-b295055b0ba2"}},"directories":{},"maintainers":[{"name":"tada5hi","email":"peter.placzek1996@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/smob_1.6.2_1778762822484_0.6809830792945253"},"_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":1778762822649,"_cnpm_publish_time":1778762822649,"dist-tags":{"alpha":"1.3.0-alpha.2","latest":"1.6.2"}}