{"name":"find-replace","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"1.0.2","description":"Find and either replace or remove items from an array","repository":{"type":"git","url":"git+https://github.com/75lb/find-replace.git"},"license":"MIT","main":"./lib/find-replace.js","keywords":["find","replace","array","remove","splice"],"engines":{"node":">=0.10.0"},"scripts":{"test":"tape test/*.js","docs":"jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo"},"devDependencies":{"jsdoc-to-markdown":"^1.3.3","tape":"^4.5.1"},"dependencies":{"array-back":"^1.0.2","test-value":"^2.0.0"},"gitHead":"39236e40b8d1e710d5ea7c7692f8884ce81dc3ac","bugs":{"url":"https://github.com/75lb/find-replace/issues"},"homepage":"https://github.com/75lb/find-replace#readme","_id":"find-replace@1.0.2","_shasum":"a2d6ce740d15f0d92b1b26763e2ce9c0e361fd98","_from":".","_npmVersion":"3.8.2","_nodeVersion":"5.8.0","_npmUser":{"name":"75lb","email":"75pound@gmail.com"},"dist":{"shasum":"a2d6ce740d15f0d92b1b26763e2ce9c0e361fd98","tarball":"http://registry-npm.ywwl.com/find-replace/download/find-replace-1.0.2.tgz","integrity":"sha512-kbvD+pEjqZZ6VTUT3U5QicrA3zqtCoyEinhaNm+ag4fpCb/NfVNnL7L5vI9fCmuhwReoUF+EP6MBDJsMo41SpQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBCA66QzXIR+O1tBnHRYxIY7wJggCmTC5YDHB3A82wyHAiABqPQahURWhrp2/6QJ6w+oFclExh90pqK1m9k5DDlX4A=="}],"size":2742,"noattachment":false,"key":"/find-replace/-/find-replace-1.0.2.tgz"},"maintainers":[{"name":"75lb","email":"75pound@gmail.com"}],"_npmOperationalInternal":{"host":"packages-13-west.internal.npmjs.com","tmp":"tmp/find-replace-1.0.2.tgz_1458408771428_0.38012153864838183"},"directories":{},"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":1458408773942,"_cnpm_publish_time":1458408773942,"dist-tags":{"latest":"5.0.2"}}