{"name":"find-replace","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"4.0.1","description":"Replace or remove multiple items in an array.","repository":{"type":"git","url":"git+https://github.com/75lb/find-replace.git"},"license":"MIT","main":"dist/index.js","module":"index.mjs","keywords":["find","replace","array","remove","splice"],"engines":{"node":">=10"},"scripts":{"test":"npm run dist && esm-runner test.mjs && web-runner test.mjs","docs":"jsdoc2md -c jsdoc.conf -t README.hbs index.mjs > README.md","dist":"rollup -c"},"devDependencies":{"@test-runner/web":"^0.3.4","esm-runner":"^0.3.4","isomorphic-assert":"^0.1.1","jsdoc-to-markdown":"^5.0.3","rollup":"^2.7.2","rollup-plugin-node-resolve":"^5.2.0"},"dependencies":{"array-back":"^4.0.1"},"standard":{"ignore":["dist"]},"gitHead":"dde0c6df1c6cb545d298ae1506c0588bd9ef5670","bugs":{"url":"https://github.com/75lb/find-replace/issues"},"homepage":"https://github.com/75lb/find-replace#readme","_id":"find-replace@4.0.1","_nodeVersion":"13.13.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-JpqnNRzJk9TAF7Xun1f7uv5nyywi/efdD9kd5m/nhJFEEHK7OA/IAY3HWOTAP8xu4SIw/Py7emv+3XxTD26e7Q==","shasum":"075833459d3e7d32badcada355db19b6d9216c6a","tarball":"http://registry-npm.ywwl.com/find-replace/download/find-replace-4.0.1.tgz","fileCount":7,"unpackedSize":14953,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeoaTWCRA9TVsSAnZWagAAalMP/j//7D5fl3nqtp/FpYvx\nAfVDoFMWjaz3SSELM3KNReR1xko6flpeAbttaEuyAt5GLL+yBSuoae+j5IbF\nqLLOpX7hWkLJnKApi6E73/5ccZSZi9Y5w6O6a2bRYUFQSQC7ZfKgbO2I12k3\ndESLJpD4tlH6x7tT8iYwb9sk4cNwv5h6UfEv6kQwzQH4slHtuJbrkssjQqYS\n+P2AqIqaFzRdw/6YtiiBK0IwdWXwgdzbAJfbpGTVsETzgdYi35/vPESBe6A4\nnxlcViQk8RbrW0iMH0X8JKV1szvie63cmmld0wySPWcs+8UiLOTrv7rdXwQw\nPrDxX96Kem3Dz6qMyKTu9LnOrCqR2DZBGhGxtWQawaoP90IrqOBew3ZWeD67\n0zpiM43pN/owT68NThqBAN28yYqcu0H9CmVB4SuOQm0v/q44ycFt8aUISKS1\nkGQpz/4pdllhWl50T9lta+cg3TVyQcEfRT1Ru5jKmSo9PItAScBxaSU450VC\nBBnrcKU7slygDWYUywFG/OelY09snGkbDZdvmPWy/cWWrZLA0R7UsQa6km9M\nmmA4689pX0g+yJIUfsTB/553k9434D5xhZceGQiOU5GJXuMrdO7lz5mayxf7\n5gt8OGGqpv8NLr8dmmBNUPJTAETlrksIsm2sUK4QVbm1zDsuIcTC+pdFXyH4\n4yW9\r\n=szqM\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCcjtJ7Ey6UDhH6DmvHfwqKFlTYoL4Ze2+0M8JIjHCMSQIhAPTieWWmBxp9t+klHXvzKnqut0mrR3ZJZt6jBMF3yZ9l"}],"size":3727,"noattachment":false,"key":"/find-replace/-/find-replace-4.0.1.tgz"},"maintainers":[{"name":"75lb","email":"75pound@gmail.com"}],"_npmUser":{"name":"75lb","email":"75pound@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/find-replace_4.0.1_1587651797603_0.34861782971170574"},"_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":1587651797814,"_cnpm_publish_time":1587651797814,"dist-tags":{"latest":"5.0.2"}}