{"name":"find-replace","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"5.0.0","description":"Replace or remove multiple items in an array.","repository":{"type":"git","url":"git+https://github.com/75lb/find-replace.git"},"license":"MIT","exports":{"import":"./index.mjs","require":"./dist/index.cjs"},"keywords":["find","replace","array","remove","splice"],"engines":{"node":">=14"},"scripts":{"test":"npm run dist && test-runner test.mjs","docs":"jsdoc2md -c jsdoc.conf -t README.hbs index.mjs > README.md","dist":"rollup -c"},"devDependencies":{"@rollup/plugin-node-resolve":"^13.0.0","@test-runner/web":"^0.3.5","isomorphic-assert":"^0.2.0","jsdoc-to-markdown":"^7.0.1","rollup":"^2.52.3","test-runner":"^0.9.2"},"dependencies":{"array-back":"^6.0.1"},"standard":{"ignore":["dist"]},"gitHead":"765afd8575899ee1c17735048dd7dc0ecea51e6f","bugs":{"url":"https://github.com/75lb/find-replace/issues"},"homepage":"https://github.com/75lb/find-replace#readme","_id":"find-replace@5.0.0","_nodeVersion":"16.4.0","_npmVersion":"7.18.1","dist":{"integrity":"sha512-tCXiqMDFJ4YOchkJ8ObwyG8FNRYKZ4wtNiW0RFWK306qrvo37uQ8Bs96MNimOsK2lH09Y4yPFjql/R8TqW4Udg==","shasum":"fe2ab6c557401004820f7dc0bd00d107574d6341","tarball":"http://registry-npm.ywwl.com/find-replace/download/find-replace-5.0.0.tgz","fileCount":8,"unpackedSize":16854,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg1lPfCRA9TVsSAnZWagAAHwgP/0lNBEL/TdVaf91+Mi5v\nhMJITlkfApAGQYxAveZ16+BYWYpTjGXuE3TQwmvIlubq/hYA2VfpYrFSvluK\nJXoN/Inb3RZH2OnuuMDtyXwfr6ojqUKPKewyNdYuK0i+YUJjOWlqJlpo/iix\nuOAavxm4ab7wK+tePpSrUJaeYU/at5gpImHi+GxCwxXOP/d/szzHyvu7xjw0\nG0NE+HeFgVe/04QhXmxOdsvpJNlwrPX8ki1YcK7r+YPtBPHE0TuuTtKjgFab\nC0QI9gcM0N+BiNp5+BzqgdokYeS/OeIvxX4sMZhpIJQmmT246qXm5sSSpgWT\nivAMBO6y2wYzd+FlynlF1hVhCk1DUOiFj17ltna5MBAukMEuUUEgABURN0Dk\njTxRTS/EaaRA8HuqaTDjStD0fnbHQ+EHe2+HnHRECnEn7lwt0TIzAW3X89EN\nsMATBwRJxdL7j0xDNY2A62UR5L6S1TO7OmhAo9MtJabytk6anq7j5F2ZvhUQ\n+sp4G/nbxzLmc64OoH6jXvawm2NOpO00FpV9qOkoNpW2LurCfTcU7xeePyU5\nrwzudvmd/LTIksD8I2X4sVIPShhs3gEsP/GjVaotfzAoH9aAj+/bnCWfOqcb\nSaeV7skMVnLG+UlCFiJjJPWx/+LmiXDTMrgVuPwGwq45ZAxw1tRaFarixv/g\nvxe2\r\n=jsL/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBGR5ZBBgTH170a4zNTbYGvy6wX4wLTdmlXzSW8I2jFSAiEAnvLKxF2Fmc4CdVeP09MwwICQ0vesjFFFbuvPUS5jRCM="}],"size":3812,"noattachment":false,"key":"/find-replace/-/find-replace-5.0.0.tgz"},"_npmUser":{"name":"75lb","email":"75pound@gmail.com"},"directories":{},"maintainers":[{"name":"75lb","email":"75pound@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/find-replace_5.0.0_1624658910989_0.24127585626133818"},"_hasShrinkwrap":false,"readme":"[![view on npm](https://badgen.net/npm/v/find-replace)](https://www.npmjs.org/package/find-replace)\n[![npm module downloads](https://badgen.net/npm/dt/find-replace)](https://www.npmjs.org/package/find-replace)\n[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/find-replace)](https://github.com/75lb/find-replace/network/dependents?dependent_type=REPOSITORY)\n[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/find-replace)](https://github.com/75lb/find-replace/network/dependents?dependent_type=PACKAGE)\n[![Node.js CI](https://github.com/75lb/find-replace/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/find-replace/actions/workflows/node.js.yml)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)\n\n# find-replace\n\nReplace or remove multiple items in an array.\n\nSimilar to [array.prototype.splice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) with the following differences:\n\n* `splice` only operates on one item at a time requiring you to know its index. `find-replace` will operate on every item satisfying the find function.\n* If a function is passed as a `replaceWith` argument, `find-replace` will invoke it to compute the replacement value.\n\n## Synopsis\n\n```js\nimport findReplace from 'find-replace'\n\nconst colours = ['red', 'white', 'blue', 'white']\n\nconst result = findReplace(\n  colours,\n  colour => colour === 'white',\n  'gold'\n)\n\nconsole.log(result)\n// [ 'red', 'gold', 'blue', 'gold' ]\n```\n\nIf the `replaceWith` value is a function, it will be invoked with the found item and its result used as the replace value. For example:\n\n\n```js\nconst colours = ['red', 'white', 'blue', 'white']\n\nconst result = findReplace(\n  colours,\n  colour => colour === 'red',\n  colour => colour.split('')\n)\n\nconsole.log(result)\n// [ 'r', 'e', 'd', 'white', 'blue', 'white' ]\n```\n\n## Real world examples\n\n### Replace with an array of strings\n\nThis example explodes combined (`-vrf`) into individual flags (`-v -r -f`).\n\n```js\nimport findReplace from 'find-replace'\n\nconst argv = ['-vrf', 'file1.js', 'file2.js']\nconst combinedShortOptionRe = /^-[^\\d-]{2,}$/\n\nconst result = findReplace(\n  argv,\n  arg => combinedShortOptionRe.test(arg),\n  arg => {\n    return arg\n      .slice(1) /* remove initial hypen */\n      .split('')\n      .map(letter => '-' + letter)\n  }\n)\n\nconsole.log(result)\n```\n\nOutput:\n\n```\n$ node example/argv.mjs\n[ '-v', '-r', '-f', 'file1.js', 'file2.js' ]\n```\n\n### Delete found items\n\nIf you omit the third `replaceWith` argument, all found items will be deleted.\n\n```js\nimport findReplace from 'find-replace'\n\nconst fruits = ['apple', 'pear', 'nectarine', 'pineapple', 'peach']\nconst bad = ['pear', 'pineapple']\n\nconst result = findReplace(\n  fruits,\n  fruit => bad.includes(fruit)\n)\n\nconsole.log(result)\n```\n\nOutput:\n\n```\n$ node example/delete.mjs\n[ 'apple', 'nectarine', 'peach' ]\n```\n\n# API Reference\n\n<a name=\"module_find-replace\"></a>\n\n## find-replace\n<a name=\"exp_module_find-replace--findReplace\"></a>\n\n### findReplace(array, findFn, [...replaceWith]) ⇒ <code>array</code> ⏏\n**Kind**: Exported function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| array | <code>array</code> | The input array |\n| findFn | <code>function</code> | A predicate function which, if returns `true` causes the current item to be operated on. |\n| [...replaceWith] | <code>any</code> | If not specified, each found value will be removed. If specified, each found value will be replaced with this value. If the `replaceWith` value is a function, it will be invoked with the found value and its result used as the replace value. If the `replaceWith` function returns an array, the found value will be replaced with each item in the array (not replaced with the array itself). |\n\n\n# Load anywhere\n\nThis library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.\n\nNode.js (CommonJS):\n\n```js\nconst findReplace = require('find-replace')\n```\n\nNode.js (ECMAScript Module):\n\n```js\nimport findReplace from 'find-replace'\n```\n\nModern browser (ECMAScript Module):\n\n```js\nimport findReplace from './node_modules/find-replace/dist/index.mjs'\n```\n\nOld browser (adds `window.findReplace`):\n\n```html\n<script nomodule src=\"./node_modules/find-replace/dist/index.js\"></script>\n```\n\n* * *\n\n&copy; 2015-22 Lloyd Brookes \\<75pound@gmail.com\\>.\n\nIsomorphic test suite by [test-runner](https://github.com/test-runner-js/test-runner) and [web-runner](https://github.com/test-runner-js/web-runner). Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).\n","publish_time":1624658911208,"_cnpm_publish_time":1624658911208,"dist-tags":{"latest":"5.0.2"}}