{"name":"find-replace","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"4.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","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.3","esm-runner":"^0.3.4","isomorphic-assert":"^0.1.1","jsdoc-to-markdown":"^5.0.3","rollup":"^1.27.12","rollup-plugin-node-resolve":"^5.2.0"},"dependencies":{"array-back":"^4.0.1"},"standard":{"ignore":["dist"]},"gitHead":"868fa5c7e19699ef608707f9a885af6b49193305","bugs":{"url":"https://github.com/75lb/find-replace/issues"},"homepage":"https://github.com/75lb/find-replace#readme","_id":"find-replace@4.0.0","_nodeVersion":"13.3.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-oTXVqeAJ7cuaqmkeNKekO0iUD3CUjGP1x+RYl6/QWspaz2Dd3Ro/1JZG6C4EUiH8ypWMufHSCb5fOEwdWIk0mQ==","shasum":"31364804813c454aa1b1cd9282c964de0291b077","tarball":"http://registry-npm.ywwl.com/find-replace/download/find-replace-4.0.0.tgz","fileCount":7,"unpackedSize":12131,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd83NACRA9TVsSAnZWagAAh0gP/AhKZEmtIV4htmgxPOY+\n1udCo5UqEl/Txbfa7uEbDFq1GAqLiuO0lfXk3SGkVFgiBkATG+qPOk3/WnpR\nRYqqwl6kaawp6qhlitl6WB+7YpRJZ5LS9rppVcBrE0iiKn6p/qsNdaLHUxnh\nlsqAf14joY2912hHXLJmW7BiklD2dDay05xNU3LYXhUwyvTac0NGkD/39kIM\nOBboBnPytVUICbChZaKmD8lGKI2zwvCOv1ISpPJt/El6uBYpw+OQPL4yC4Ln\nRztknGXF2t5oKkjB9YYAL4aTmoTaStaVuGfoi+ZZTHc1fZi+mNKlmeirPxiC\nJjftliYTKKqAjbuVR0Iqz671HMGw6r4jn39QHGnrNjl2o7MIMEguWK4Z5eZ7\nbmUjL7bZxizK/Iii+518QmMnTNF/T/pHU3+Kp0/2/lkVgdc2qLU0HMrtDzGD\nr2ejNJhrgVhSida9r4kp7w15wXmRMkWhM+a/sENWzz7Z7S5cltzPthMZLd46\nJbkuKNd8usWQs+54t10qUbjGzIS1ktPLMs1jJ6bGdpjslKbtCPv/5vGri4A+\ndYSKPd/nFzPziSTsszc/5GgtXhLii51mqxE588opGKabFCDgiPhmslumNdb0\naDgbCem9oMFxhgEl6wH/JI0VFBX4LdLuOM7b7g7og8KKzli8Ifdzvf1f9DmA\nnmuU\r\n=h1N/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAKa0c/6jl57RnSnOSSK8vTy+zTwoRlhyvkTvt01Y51yAiEAzcCkZ3MWF8SqUtwR8bxBmHkcJlD018afZJ0JCCJuaCM="}],"size":3318,"noattachment":false,"key":"/find-replace/-/find-replace-4.0.0.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.0_1576235840146_0.4145213451293033"},"_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":1576235840258,"_cnpm_publish_time":1576235840258,"dist-tags":{"latest":"5.0.2"}}