{"_id":"replace-string","_rev":"17-64e2b02deee5fb6e7cb92a18133a9041","name":"replace-string","time":{"modified":"2023-06-17T00:12:17.754Z","created":"2015-08-28T15:38:35.184Z","0.1.0":"2015-08-28T15:38:35.184Z","1.1.1":"2015-12-09T05:21:03.492Z","1.0.0":"2017-01-05T13:02:19.594Z","1.1.0":"2017-01-11T07:24:20.342Z","2.0.0":"2018-10-16T09:07:34.897Z","3.0.0":"2019-04-26T06:45:03.292Z","3.1.0":"2020-05-10T07:11:52.491Z","4.0.0":"2021-08-09T20:24:04.023Z"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"dist-tags":{"latest":"4.0.0"},"description":"Replace all substring matches in a string","readme":"# replace-string\n\n> Replace all substring matches in a string\n\nSimilar to `String#replace()`, but supports replacing multiple matches. You could achieve something similar by putting the string in a `RegExp` constructor with the global flag and passing it to `String#replace()`, but you would then have to first escape the string anyways.\n\n*With [Node.js 16](https://medium.com/@nodejs/node-js-v15-0-0-is-here-deb00750f278), this package is partly moot as there is now a [`String#replaceAll`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll) method. However, it does not have a `caseInsensitive` option.*\n\n## Install\n\n```\n$ npm install replace-string\n```\n\n## Usage\n\n```js\nimport replaceString from 'replace-string';\n\nconst string = 'My friend has a 🐑. I want a 🐑 too!';\n\nreplaceString(string, '🐑', '🦄');\n//=> 'My friend has a 🦄. I want a 🦄 too!'\n```\n\n## API\n\n### replaceString(string, needle, replacement, options?)\n\nReturns a new string with all `needle` matches replaced with `replacement`.\n\n#### string\n\nType: `string`\n\nThe string to work on.\n\n#### needle\n\nType: `string`\n\nThe string to match in `input`.\n\n#### replacement\n\nType: `string | Function`\n\nThe replacement for `needle` matches.\n\nIf a function, it receives the matched substring, the match count, the original input, and the index in which the match happened (as measured from the original input):\n\n```js\nimport replaceString from 'replace-string';\n\nreplaceString('Foo 🐑 Bar', '🐑', (matchedSubstring, matchCount, input, matchIndex) => `${matchedSubstring}❤️`);\n//=> 'Foo 🐑❤️ Bar'\n```\n\n#### options\n\nType: `object`\n\n##### fromIndex\n\nType: `number`\\\nDefault: `0`\n\nIndex at which to start replacing.\n\n##### caseInsensitive\n\nType: `boolean`\\\nDefault: `false`\n\nWhether or not substring matching should be case-insensitive.\n\n## Related\n\n- [execall](https://github.com/sindresorhus/execall) - Find multiple `RegExp` matches in a string\n","versions":{"1.0.0":{"name":"replace-string","version":"1.0.0","description":"Replace all substring matches in a string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/replace-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["replace","string","str","text","all","many","multiple","global","match","matches","replacement","replacer","modify","substring","sub-string","needle","search"],"devDependencies":{"ava":"*","xo":"*"},"xo":{"esnext":true},"gitHead":"bc14d457a3cffb3a34f0a2e65544132eaf99ab77","bugs":{"url":"https://github.com/sindresorhus/replace-string/issues"},"homepage":"https://github.com/sindresorhus/replace-string#readme","_id":"replace-string@1.0.0","_shasum":"5704a780ee07efed4c0eb8168a7fb0551e2efdbf","_from":".","_npmVersion":"2.15.11","_nodeVersion":"4.6.2","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"5704a780ee07efed4c0eb8168a7fb0551e2efdbf","tarball":"https://registry.npmjs.org/replace-string/-/replace-string-1.0.0.tgz","integrity":"sha512-KuXnoXuUnNHyVEeZS0WdpwP9AOVDunf4zvXKD19iHo796KMjzODTFqL96TSjsEMNrBJulgbw8vE591L0T7BRhA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC2X2egE9WcTeNo23VBXWWBhCc0y//M6MjIwPluHtrlbQIhAKRNnxdrMYye+VeqDflW4Gu007/vi9b0hXs3mCfZfn9K"}]},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/replace-string-1.0.0.tgz_1483621337474_0.27186012733727694"},"directories":{}},"1.1.0":{"name":"replace-string","version":"1.1.0","description":"Replace all substring matches in a string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/replace-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["replace","string","str","text","all","many","multiple","global","match","matches","replacement","replacer","modify","substring","sub-string","needle","search"],"devDependencies":{"ava":"*","xo":"*"},"xo":{"esnext":true},"gitHead":"236a8774847d66418531a5d9c0d3940ccffb7219","bugs":{"url":"https://github.com/sindresorhus/replace-string/issues"},"homepage":"https://github.com/sindresorhus/replace-string#readme","_id":"replace-string@1.1.0","_shasum":"87062117f823fe5800c306bacb2cfa359b935fea","_from":".","_npmVersion":"2.15.11","_nodeVersion":"4.6.2","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"87062117f823fe5800c306bacb2cfa359b935fea","tarball":"https://registry.npmjs.org/replace-string/-/replace-string-1.1.0.tgz","integrity":"sha512-/pWUYHKTWjFSn33KGpK88kNnv7pVgH3mzOasxjUcM0vAO9JpKi3QL+sZiNAXuiYQrDRLEO9B9XUB4DEIksmB0A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCmQQfwf74n3nvTS5jh3SoidAYwRJHd2SBHxIh2uCyBQgIhAOk21/c/Dk3Da6szBwIhwT0bOb6xKUBgvD6CNBmEqSVv"}]},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/replace-string-1.1.0.tgz_1484119460096_0.7858717523049563"},"directories":{}},"2.0.0":{"name":"replace-string","version":"2.0.0","description":"Replace all substring matches in a string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/replace-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"keywords":["replace","string","text","all","many","multiple","global","match","matches","replacement","replacer","modify","substring","sub-string","needle","search"],"devDependencies":{"ava":"^0.25.0","xo":"^0.23.0"},"gitHead":"4b67554beff2fde0938028cf20ead68dce87205f","bugs":{"url":"https://github.com/sindresorhus/replace-string/issues"},"homepage":"https://github.com/sindresorhus/replace-string#readme","_id":"replace-string@2.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.12.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-e6cHLIPJeIReWRcKFXdGC2bVR9dC4Bdwf2LIhzefHNPNR5ob90LtopHVGisQmaYEVfEtB945lmTA8B+e2lMJvQ==","shasum":"2ba068708a4a88672e93b83acdb9f865f9e323ef","tarball":"https://registry.npmjs.org/replace-string/-/replace-string-2.0.0.tgz","fileCount":4,"unpackedSize":4475,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbxapXCRA9TVsSAnZWagAAIikP/0Rqh8HF2A3q1oGAre4g\nfC1Q7pSFS8AK2Y7aD9PpIpOTcilVWC5Tg2HpzwxVVzKZlDIs+BKJ8NvwXdqj\n7Cp4OrMXfIwD8JfMSMsneziR/9Wv4ACH+kaOa8221qenJHbTGRrbdvsPBX0J\ncguCuynWtDvEbVCZfWE+D6ij0hSDwIzqtI9pGRmTIv6B4qiZlz7iYXcwtfzh\n+gVRzCAGVSYQrwWQcBR/b9xrP1IkyY0u6ZMpepurccpQGOZdYmCgYDSvdR3c\nwD3zU8tKJtaUBWBUzenCSpis1i+1Jq9Wr/9dLbe5bO/XV4geGacORNDuvEB9\nLY/m7xo6hliC16rfajBNdL3JK7QXA25dz0gPcVKni6zJmXJ/7skvFMm9t5/0\nat+3AUpMGq0IXhiL0mNSZeMrn2TJxOGBIwGoXZZSjzyqe6r7czv6FPaVP/kc\niENVWd1gBmGIHDrh1OCzXUnFsIflyy5pwwUqcH0BbrjwwteeUPIGdQCU5Nxi\ncdS4DFHJ8fX271fvpeE15EkOYSYOSIMoQzQhNLIEmo/acFYJzd800tVSzvqN\nKLX/gwtfCVl9venug3hOBB7CIL3KbM1CG6s3NqlDC7lwQX3Z1P8yvwAQLs66\nBjZVbtrCUF3FZgE2HwMIE/5XNs72ZLtYjxFPv794dhwcPOpkHWvkDudg2E1H\nHez2\r\n=wUlx\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCCIdOiFu+CDta++/O1DgxodDoniRZ7tE/hhWY9wQps9gIhAJMmz3Qj/jRys+kuoA73Msn3UhLp12ymQkqCaPVNq0Zj"}]},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/replace-string_2.0.0_1539680854758_0.9229143704817409"},"_hasShrinkwrap":false},"3.0.0":{"name":"replace-string","version":"3.0.0","description":"Replace all substring matches in a string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/replace-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["replace","string","text","all","many","multiple","global","match","matches","replacement","replacer","modify","substring","sub-string","needle","search"],"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"b873ad85607c736834e728bf5e452f1c926432f3","bugs":{"url":"https://github.com/sindresorhus/replace-string/issues"},"homepage":"https://github.com/sindresorhus/replace-string#readme","_id":"replace-string@3.0.0","_nodeVersion":"10.15.3","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-jE5X/k3p2v8p6+wxhM1Ti0Oj9lYtwPbMj0ty8iSFpAFIihkiNpl6uHgYW1De/r9DG3vA7HGIgIBMjlwJZXL02w==","shasum":"49deafb57839fa3bab9c11ad449b006e0d436e69","tarball":"https://registry.npmjs.org/replace-string/-/replace-string-3.0.0.tgz","fileCount":5,"unpackedSize":5614,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcwqjvCRA9TVsSAnZWagAAMtMP/AmahjVJ/OsIYobdAO4O\npkEP/+vn/WMzIQ0w2SZvGBE2YJMMUjeVDP3W+NqCGMiOwxCb4/yfkFhk6Eza\nQoMkJqJI69JDMxlzCFYt/+07pTYPhlXMQALnhVQia6TzBvFXfjfhnds7sSU7\nAzDZrMp4hHent1Pjdyzl6yJk4yLmJkCVnpPD2yuUTPEjQtrin6/I8zlSFHMc\nFgzOLSAvxt6G7e9/tKzSKqBRDTNOwQXGOv1TNWuQAEq21QieyRs6ffl9iWaz\nOr6Bu6GOHkyQ6mmkSkCRw4dt7aM+5lkFqceLWSadjroWZ54k7/kI8u7gk0Fv\nlWeH9GBvnM2lBiD68j8q9KGhaQYiM22jglP1PG53zft7ayInXX15UXkJ/20d\n+74m+G5jS5jol5oItjt9Se+yLV7qFJglTSLr98/IarAOoRIAICnrrJtPb8xw\nW6OVmsWk+cXz8ZgeYvGkfTMzVXOKrPzjoKmqNC78KfcQMQ+9XTRv0zjXdwYf\nglIKN1XaELwGA+9bTjRFePXJhdR9JfmxJeOFF0CepMVXJWHJ8HXJ6viVus11\niKY8XMFBlQpxG1M+FZk16qlc+VtFs2uxMwpm6rle5972QDR828aLcsM6iE/m\nn2HtO0Jw63MhE26KSrulydFO2z8BX9BC77mx1LXcCq518pANjeXkWT96QMvc\n/CBT\r\n=tFfn\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDZaf9QPM+2o5LHdbYJzQfi3t+ok/YEOtdJW/dJHwWbbAIgNzSa4RK8j2yaT8dicawKAjU0ztwNFVpsrz1Qbu7iPto="}]},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/replace-string_3.0.0_1556261103138_0.06110468490332632"},"_hasShrinkwrap":false},"3.1.0":{"name":"replace-string","version":"3.1.0","description":"Replace all substring matches in a string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/replace-string.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["replace","string","text","all","many","multiple","global","match","matches","replacement","replacer","modify","substring","sub-string","needle","search"],"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"9b0208efd71d8a43988db164914e0b759666ebb6","bugs":{"url":"https://github.com/sindresorhus/replace-string/issues"},"homepage":"https://github.com/sindresorhus/replace-string#readme","_id":"replace-string@3.1.0","_nodeVersion":"10.20.1","_npmVersion":"6.14.5","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-yPpxc4ZR2makceA9hy/jHNqc7QVkd4Je/N0WRHm6bs3PtivPuPynxE5ejU/mp5EhnCv8+uZL7vhz8rkluSlx+Q==","shasum":"77a087d88580fbac59851237891aa4b0e283db72","tarball":"https://registry.npmjs.org/replace-string/-/replace-string-3.1.0.tgz","fileCount":5,"unpackedSize":6231,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJet6k4CRA9TVsSAnZWagAAdVEQAIQdx6KAFeyzKXWjsFxa\n5k/tbO+9oVbGVMDkKJnZopGnvG8661u3GmOlBJn7IKvpQuYJpb1AtWsVp2bz\nbQCy59w5RF3Sw1pgHW6zvPPy/ElMRDQTAd12qIYGynKt0qmWeGjXo5JPB5lP\nCaIvMvYUOJhegBrB/lwshTJ1JLy5OuznlvwrxNmgjW7BK+s18H2yy3vyeb2f\n6mJlobWkC2FuivloPv4EQHQo4haiAyary1cL6l/D950Mzl6Y3yObauXAFiB0\nOx2E2A6UH12C2ARKC78oanOppoHSB9bhOBl8XvQCQYw1gZVtKSPTdYILv9Xi\nH37bhbbjUy8ri/lOObR8Hcz87UkycwWi4KogKJ4JqwZdDrKW5+yvqJPdv0M5\noq3nWFW8X9tcmbpso+pHOt8xkRJGFbG/dxY6fDywjSc8DMACnZ/O5QPnvmvV\nY0Hzj7AwahTwLd7hto9BBl/HbZnn3chlXSmfxrx2GtXgQR0qN1DwXcFokrRT\nYS/zOVhAqdRHd7FaObxU2sIp4ZjNVeHf1Wb6LSbYELhTfvldZxL07JdQkIqB\ncqZ/KX4ruAWEvls2XAkYA1p9GFPTfBhBOj6K0gvHKuzfaBftUR40TgGpl8F3\nCj9uDUDUccMDoQpY0mpM+/TDoBQtrzPsbHQ8VhA+VrMg88/T0CajweHdDZ4H\nGclp\r\n=k7Y4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBoJFXyEmY7ryDQM36AVimJE0HQwqRu387P2eBsoS8IiAiEA+D/jl8b9YhaGtaNh7xB+HL+qECYsKXP4AgGDh2IRCkg="}]},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/replace-string_3.1.0_1589094712382_0.6159361584627039"},"_hasShrinkwrap":false},"4.0.0":{"name":"replace-string","version":"4.0.0","description":"Replace all substring matches in a string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/replace-string.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"test":"xo && ava && tsd"},"keywords":["replace","string","text","all","many","multiple","global","match","matches","replacement","replacer","modify","substring","sub-string","needle","search","replaceall"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"gitHead":"b9fb6b1f143121ba93ffbcc24ee2a17f62fa7bda","bugs":{"url":"https://github.com/sindresorhus/replace-string/issues"},"homepage":"https://github.com/sindresorhus/replace-string#readme","_id":"replace-string@4.0.0","_nodeVersion":"12.22.1","_npmVersion":"7.10.0","dist":{"integrity":"sha512-fcgyZ62o26oBaihEC302pZQ2WectvmZ4sGOq4Lwa8ad12lPbhIlZCvLpgpI1sOAsbN83kpXiH5KCcr3pcZa8bA==","shasum":"2f7270b3e38d118a00ff328481305561c7fe74cf","tarball":"https://registry.npmjs.org/replace-string/-/replace-string-4.0.0.tgz","fileCount":5,"unpackedSize":6518,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhEY7kCRA9TVsSAnZWagAAxAQP/3yeQY8hWPi4HB0PXWP8\nqF56VJlOTbWfSoIFrgSLUEdFBSVPNcoEBKM+q6mg4C1iDwSjcVcea1XwIrt3\n9w/+llW7tS0eMPyCidWefTGbl1g+YjNigQ9YclIuRA8zXAvg+h6MVxoNomYL\n3MhbgWaHlFB9ZuoNAY61LZaoyIHL724it2sRXz0cN2xk/bj6WTZbODAGievg\n0z2oze3wmNG8fLr3juMXVCpH9RM9QGzoBFa/44qd8dRuU3MTXO4WRP6d9fHh\nQcyWsqsasRNMR6qpVo3eHwKo4jPm9qhwNtE+DNUwzU3/OmD1DAjxXjFxVUrk\nLapV3rofcWBK6dQu8ch4ksfTJdMZ50tOlKvsOclPKhMJqPm8tlbmJByXtSgE\nVCVReERsBoNJys1VKQKbycUb2R6XJ0+Xc1zIFd73fuPkammzE98V/uRE8sab\npxLwXNhvGm3R77XHQOixjBiwbwA/h6euQ8SlH6l7Mfrdl1X9cM7U0A2F8Xik\nGpOrqR2V/lsOgZco0YDXkNOj8Kiym+CbmcqQXpprC2am/LqE0xU5W1ELFQhB\n5Jx200WYkOs8IllUZVlRmon+RVXfCKbMSqp6js9r+GUKOWIg4E/tdwmWXVSL\nIf97cd7AQDBq3+voaofGdG976NSVJQZWsEiyVye1S0XXRbkzlhDnUgi4CTeJ\n2WKD\r\n=dc7C\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBrHhgAOi/lMIGo7zstcDUSJokEANf2nlQOlhj1BEDulAiEAi6gof+XGjK3i8dvCCaIPoE5O8gtV389B9x+ODuX3XPY="}]},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/replace-string_4.0.0_1628540643889_0.42599064551134824"},"_hasShrinkwrap":false}},"homepage":"https://github.com/sindresorhus/replace-string#readme","keywords":["replace","string","text","all","many","multiple","global","match","matches","replacement","replacer","modify","substring","sub-string","needle","search","replaceall"],"repository":{"type":"git","url":"git+https://github.com/sindresorhus/replace-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"bugs":{"url":"https://github.com/sindresorhus/replace-string/issues"},"license":"MIT","readmeFilename":"readme.md","users":{"rocket0191":true,"felegz":true,"codeinpixel":true,"flumpus-dev":true}}