{"name":"find-replace","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"5.0.2","description":"Replace or remove multiple items in an array.","repository":{"type":"git","url":"git+https://github.com/75lb/find-replace.git"},"license":"MIT","type":"module","exports":{"import":"./index.js","require":"./dist/index.cjs"},"keywords":["find","replace","array","remove","splice"],"engines":{"node":">=14"},"scripts":{"test":"npm run dist && npm run test:ci","test:ci":"75lb-nature test-runner test.js","docs":"75lb-nature jsdoc2md -t README.hbs index.js > README.md","dist":"75lb-nature cjs-build index.js && 75lb-nature simple-rollup index.js"},"peerDependencies":{"@75lb/nature":"latest"},"peerDependenciesMeta":{"@75lb/nature":{"optional":true}},"standard":{"ignore":["dist"]},"_id":"find-replace@5.0.2","gitHead":"49a7b2a585532a4af897ab3cb421a3b70765d4f6","bugs":{"url":"https://github.com/75lb/find-replace/issues"},"homepage":"https://github.com/75lb/find-replace#readme","_nodeVersion":"22.8.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-Y45BAiE3mz2QsrN2fb5QEtO4qb44NcS7en/0y9PEVsg351HsLeVclP8QPMH79Le9sH3rs5RSwJu99W0WPZO43Q==","shasum":"fe27ff0be05975aef6fc679c1139bbabea564e26","tarball":"http://registry-npm.ywwl.com/find-replace/download/find-replace-5.0.2.tgz","fileCount":8,"unpackedSize":16717,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCQ2Qz9fWcQEnFj2mwfuUkUQCNxs9ndUHn78EUOJDRyjwIhAJkfD8m2IiBHg5T4FolsHZzdi+48Oi8uhKZkQLNx5WaU"}],"size":3762,"noattachment":false,"key":"/find-replace/-/find-replace-5.0.2.tgz"},"_npmUser":{"name":"75lb","email":"75pound@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/find-replace_5.0.2_1726532081744_0.7752432708430572"},"_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-25 Lloyd Brookes \\<75pound@gmail.com\\>.\n\nTest suite by [test-runner](https://github.com/test-runner-js/test-runner). Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).\n","publish_time":1726532081916,"maintainers":[{"name":"75lb","email":"75pound@gmail.com"}],"_cnpm_publish_time":1726532081916,"dist-tags":{"latest":"5.0.2"}}