{"name":"defu","version":"6.1.5","license":"MIT","_id":"defu@6.1.5","maintainers":[{"name":"pi0","email":"pyapar@gmail.com"}],"homepage":"https://github.com/unjs/defu#readme","bugs":{"url":"https://github.com/unjs/defu/issues"},"dist":{"shasum":"6dc1b8419ce7c39e709a3fa6dde860bd3de69831","tarball":"http://registry-npm.ywwl.com/defu/download/defu-6.1.5.tgz","fileCount":9,"integrity":"sha512-pwdBJxJuJXmqrLO6s0VBmfbRz+G7FUzkjldAsdi9Yrv86mPyzq0ll1o8+8gB4Gsr6GJHbK1Lh3ngllgTInDCjA==","signatures":[{"sig":"MEQCICJA4Ltct766UK8lTjpfKG3S3CGmiJXOSZL8qDr5fxlfAiAcQs6iJv343rW+tQl0aCBUhHsIKI0VIRyCH+KsAHlR3A==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19683,"size":4674,"noattachment":false,"key":"/defu/-/defu-6.1.5.tgz"},"main":"./lib/defu.cjs","_from":"file:defu-6.1.5.tgz","types":"./dist/defu.d.ts","module":"./dist/defu.mjs","exports":{".":{"types":"./dist/defu.d.ts","import":"./dist/defu.mjs","require":"./lib/defu.cjs"}},"scripts":{"dev":"vitest","lint":"oxlint src && oxfmt --check src test","test":"pnpm lint && pnpm test:types && pnpm vitest run","build":"unbuild","release":"pnpm test && pnpm build && changelogen --release && git push --follow-tags && pnpm publish","lint:fix":"oxlint src --fix && oxfmt src test","test:types":"tsgo --noEmit"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"_resolved":"/tmp/e1bb12d0d1c76b696ff805b04e4d0b1d/defu-6.1.5.tgz","_integrity":"sha512-pwdBJxJuJXmqrLO6s0VBmfbRz+G7FUzkjldAsdi9Yrv86mPyzq0ll1o8+8gB4Gsr6GJHbK1Lh3ngllgTInDCjA==","repository":{"url":"git+https://github.com/unjs/defu.git","type":"git"},"_npmVersion":"11.6.2","description":"Recursively assign default properties. Lightweight and Fast!","directories":{},"_nodeVersion":"24.13.0","_hasShrinkwrap":false,"devDependencies":{"oxfmt":"^0.43.0","oxlint":"^1.58.0","vitest":"^4.1.2","unbuild":"^3.6.1","typescript":"^6.0.2","@types/node":"^25.5.0","changelogen":"^0.6.2","expect-type":"^1.3.0","eslint-config-unjs":"^0.6.2","@vitest/coverage-v8":"^4.1.2","@typescript/native-preview":"7.0.0-dev.20260401.1"},"_npmOperationalInternal":{"tmp":"tmp/defu_6.1.5_1775060766153_0.840459833014755","host":"s3://npm-registry-packages-npm-production"},"readme":"# 🌊 defu\n\nAssign default properties, recursively. Lightweight and Fast.\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![Codecov][codecov-src]][codecov-href]\n[![License][license-src]][license-href]\n\n## Install\n\nInstall package:\n\n```bash\n# yarn\nyarn add defu\n# npm\nnpm install defu\n# pnpm\npnpm install defu\n```\n\n## Usage\n\n```js\nimport { defu } from \"defu\";\n\nconst options = defu(object, ...defaults);\n```\n\nLeftmost arguments have more priority when assigning defaults.\n\n### Arguments\n\n- **object (Object):** The destination object.\n- **source (Object):** The source object.\n\n```js\nimport { defu } from \"defu\";\n\nconsole.log(defu({ a: { b: 2 } }, { a: { b: 1, c: 3 } }));\n// => { a: { b: 2, c: 3 } }\n```\n\n### Using with CommonJS\n\n```js\nconst { defu } = require(\"defu\");\n```\n\n## Custom Merger\n\nSometimes default merging strategy is not desirable. Using `createDefu` we can create a custom instance with different merging strategy.\n\nThis function accepts `obj` (source object), `key` and `value` (current value) and should return `true` if applied custom merging.\n\n**Example:** Sum numbers instead of overriding\n\n```js\nimport { createDefu } from \"defu\";\n\nconst ext = createDefu((obj, key, value) => {\n  if (typeof obj[key] === \"number\" && typeof value === \"number\") {\n    obj[key] += value;\n    return true;\n  }\n});\n\next({ cost: 15 }, { cost: 10 }); // { cost: 25 }\n```\n\n## Function Merger\n\nUsing `defuFn`, if user provided a function, it will be called with default value instead of merging.\n\nIt can be useful for default values manipulation.\n\n**Example:** Filter some items from defaults (array) and add 20 to the count default value.\n\n```js\nimport { defuFn } from \"defu\";\n\ndefuFn(\n  {\n    ignore: (val) => val.filter((item) => item !== \"dist\"),\n    count: (count) => count + 20,\n  },\n  {\n    ignore: [\"node_modules\", \"dist\"],\n    count: 10,\n  },\n);\n/*\n {\n    ignore: ['node_modules'],\n    count: 30\n  }\n  */\n```\n\n**Note:** if the default value is not defined, the function defined won't be called and kept as value.\n\n## Array Function Merger\n\n`defuArrayFn` is similar to `defuFn` but **only applies to array values defined in defaults**.\n\n**Example:** Filter some items from defaults (array) and add 20 to the count default value.\n\n```js\nimport { defuArrayFn } from \"defu\";\n\ndefuArrayFn(\n  {\n    ignore: (val) => val.filter((i) => i !== \"dist\"),\n    count: () => 20,\n  },\n  {\n    ignore: [\"node_modules\", \"dist\"],\n    count: 10,\n  },\n);\n/*\n  {\n    ignore: ['node_modules'],\n    count: () => 20\n  }\n  */\n```\n\n**Note:** the function is called only if the value defined in defaults is an aray.\n\n### Remarks\n\n- `object` and `defaults` are not modified\n- Nullish values ([`null`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null) and [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)) are skipped. Please use [defaults-deep](https://www.npmjs.com/package/defaults-deep) or [omit-deep](http://npmjs.com/package/omit-deep) or [lodash.defaultsdeep](https://www.npmjs.com/package/lodash.defaultsdeep) if you need to preserve or different behavior.\n- Assignment of `__proto__` and `constructor` keys will be skipped to prevent security issues with object pollution.\n- Will concat `array` values (if default property is defined)\n\n```js\nconsole.log(defu({ array: [\"b\", \"c\"] }, { array: [\"a\"] }));\n// => { array: ['b', 'c', 'a'] }\n```\n\n## Type\n\nWe expose `Defu` as a type utility to return a merged type that follows the rules that defu follows.\n\n```js\nimport type { Defu } from 'defu'\n\ntype Options = Defu<{ foo: 'bar' }, [{}, { bar: 'baz' }, { something: 42 }]>\n// returns { foo: 'bar', bar: 'baz', 'something': 42 }\n```\n\n## License\n\nMIT. Made with 💖\n\n<!-- Refs -->\n\n[npm-version-src]: https://img.shields.io/npm/v/defu?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-version-href]: https://npmjs.com/package/defu\n[npm-downloads-src]: https://img.shields.io/npm/dm/defu?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-downloads-href]: https://npmjs.com/package/defu\n[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/defu/main?style=flat&colorA=18181B&colorB=F0DB4F\n[codecov-href]: https://codecov.io/gh/unjs/defu\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/defu?style=flat&colorA=18181B&colorB=F0DB4F\n[bundle-href]: https://bundlephobia.com/result?p=defu\n[license-src]: https://img.shields.io/github/license/unjs/defu.svg?style=flat&colorA=18181B&colorB=F0DB4F\n[license-href]: https://github.com/unjs/defu/blob/main/LICENSE\n","publish_time":1775060766285,"_cnpm_publish_time":1775060766285,"dist-tags":{"alpha":"5.0.2-alpha","latest":"6.1.7"}}