{"name":"defu","version":"5.0.2-alpha","description":"Recursively assign default properties. Lightweight and Fast!","repository":{"type":"git","url":"git+https://github.com/unjs/defu.git"},"license":"MIT","exports":{".":{"require":"./dist/defu.cjs","import":"./lib/defu.mjs"}},"main":"./dist/defu.cjs","module":"./lib/defu.mjs","types":"./lib/defu.d.ts","scripts":{"build":"unbuild","lint":"eslint --ext .ts src","prepack":"yarn build","release":"yarn test && standard-version && git push --follow-tags && npm publish","test":"yarn lint && yarn jest"},"devDependencies":{"@nuxtjs/eslint-config-typescript":"latest","@types/jest":"latest","@types/node":"latest","eslint":"latest","expect-type":"latest","jest":"latest","standard-version":"latest","ts-jest":"latest","typescript":"latest","unbuild":"latest"},"readme":"![defu](.github/banner.svg)\n\n# 🌊 defu\n\n> Assign default properties, recursively. Lightweight and Fast!\n\n[![Standard JS][standard-src]][standard-href]\n[![david dm][david-src]][david-href]\n[![codecov][codecov-src]][codecov-href]\n\n[![npm version][npm-v-src]][npm-v-href]\n[![npm downloads][npm-dm-src]][npm-dm-href]\n[![package phobia][packagephobia-src]][packagephobia-href]\n[![bundle phobia][bundlephobia-src]][bundlephobia-href]\n\n## Install\n\nInstall package:\n\n```bash\nyarn add defu\n# or\nnpm install defu\n```\n\n## Usage\n\n```js\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\nconst defu = require('defu')\n\nconsole.log(defu({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }))\n// => { a: { b: 2, c: 3 } }\n```\n\n## Custom Merger\n\nSometimes default merging strategy is not desirable. Using `defu.extend` 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\nconst ext = defu.extend((obj, key, value) => {\n  if (typeof obj[key] === 'number' && typeof value === 'number') {\n    obj[key] += val\n    return true\n  }\n})\n\next({ cost: 15 }, { cost: 10 }) // { cost: 25 }\n```\n\n## Function Merger\n\nUsing `defu.fn`, if user provided a function, it will be called with default value instead of merging.\n\nI 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\n\ndefu.fn({\n  ignore: (val) => val.filter(item => item !== 'dist'),\n  count: (count) => count + 20\n }, {\n   ignore: ['node_modules','dist'],\n   count: 10\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`defu.arrayFn` is similar to `defu.fn` 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\n\ndefu.arrayFn({\n  ignore(val) => val.filter(i => i !== 'dist'),\n  count: () => 20\n }, {\n   ignore: [\n     'node_modules',\n     'dist'\n   ],\n   count: 10\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```js\nconsole.log(defu({ array: ['b', 'c'] }, { array: ['a'] }))\n// => { array: ['a', 'b', 'c']}\n```\n\n## License\n\nMIT. Made with 💖\n\n<!-- Refs -->\n[standard-src]: https://flat.badgen.net/badge/code%20style/standard/green\n[standard-href]: https://standardjs.com\n\n[npm-v-src]: https://flat.badgen.net/npm/v/defu/latest\n[npm-v-href]: https://npmjs.com/package/defu\n\n[npm-dm-src]: https://flat.badgen.net/npm/dm/defu\n[npm-dm-href]: https://npmjs.com/package/defu\n\n[packagephobia-src]: https://flat.badgen.net/packagephobia/install/defu\n[packagephobia-href]: https://packagephobia.now.sh/result?p=defu\n\n[bundlephobia-src]: https://flat.badgen.net/bundlephobia/min/defu\n[bundlephobia-href]: https://bundlephobia.com/result?p=defu\n\n[david-src]: https://flat.badgen.net/david/dep/unjs/defu\n[david-href]: https://david-dm.org/unjs/defu\n\n[codecov-src]: https://flat.badgen.net/codecov/c/github/unjs/defu/master\n[codecov-href]: https://codecov.io/gh/unjs/defu\n","readmeFilename":"README.md","gitHead":"7b1f284b76d2a4706b37adbdb99c49ec9d2d35aa","bugs":{"url":"https://github.com/unjs/defu/issues"},"homepage":"https://github.com/unjs/defu#readme","_id":"defu@5.0.2-alpha","_nodeVersion":"14.18.2","_npmVersion":"8.3.0","dist":{"integrity":"sha512-8HsAIW6FadNMOknNX/Vw7+YS+Kh7hS97yNhiqZZOR2b8OuuzGY8kjK4gCT21NnZLTJS8uhtNCFfVNzdf27HEdQ==","shasum":"a42ec712b9d1c59ad3434c389245a15121a81e7a","tarball":"http://registry-npm.ywwl.com/defu/download/defu-5.0.2-alpha.tgz","fileCount":8,"unpackedSize":11541,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh89iWCRA9TVsSAnZWagAAZfAQAJbIDDsoxkOemCcWjYkj\n4lfsfAhemgbGeCn3ExsQSL4Ck0f2EVChthY5dJmC3fSCXtpdPb2Cbu1YJUz2\nxvbwLhHhuImLfaX5PBAovrE2i81i8eVWjQaIQwXCWTJheXvLMbhDHrk76ye6\nyKt+XO2m/JDYjQu708dl7Ku5lT4MrPAsgA75ETXMDRJu3XfkII577Zm+uCG5\npJJB68vLvdhoyufayAQG+Yfebt+3zSYnO7uUVAmkr+tsVgyRYWuK5KhQxiSk\nKiPQhqaQZTga/ghXa5L02SDWsxEceLQDYJhMfFMNjjDrozB621ln0tu3H0fH\nOXWdxmCQRJlpfvGwwHx32MORN4h2t8MBlc8AieSEY2EzEe59+8NsSeJ0M0TK\nFxli5fdcidlem5X/1U76qkV5+64FAyXuy68jVl5FIZXFJxcL4fGelNco0I3/\ngZTmNQjCTtA6TFhUicnKZGiXrMJDbOk+r8Z2ZAnScVDw+OvotqlUIg3CUBAj\nsCdtueAV4w15Df8qu0ycHe3AZq7Vtj033k/rHeFcQwfeYw0FYV2gSSqtnSqZ\nfb/rEZAJWIRgJESMBusyRi2SoP325z2KsNd24ZeSxYWLl+rAxvaxTLQxEIL6\nq66juKBCJbK6bAdtRBXKjU8OnfTZ4uOABuM9mglwIRAMGUI3kiXRmwe6f52H\nGAr0\r\n=p1Jl\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF+K1x+JIcefn9xR81f7JJK0pSoyjBoYHaZ6Sv9DcOU3AiEA+kqXZq2TQyu+nSVF0KCt8XOqFSgpTCPO2AEXMyEIb7c="}],"size":3913,"noattachment":false,"key":"/defu/-/defu-5.0.2-alpha.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pyapar@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/defu_5.0.2-alpha_1643370646011_0.42277163407878593"},"_hasShrinkwrap":false,"publish_time":1643370646154,"_cnpm_publish_time":1643370646154,"dist-tags":{"alpha":"5.0.2-alpha","latest":"6.1.7"}}