`String.prototype.replaceAll` ponyfill.
npm install string-replace-all-ponyfill[![Build Status][ci-img]][ci]
[![BrowserStack Status][browserstack-img]][browserstack]
String.prototype.replaceAll
ponyfill.
> The replaceAll() method returns a new string with all matches of a pattern
> replaced by a replacement. The pattern can be a string or a RegExp, and the
> replacement can be a string or a function to be called for each match.
``sh`
npm install string-replace-all-ponyfill --save
`js
import replaceAll from 'string-replace-all-ponyfill';
replaceAll('abba', 'b', 'c'); // acca
`
You can **use named export preferNative if you wish to use native
implementation if it’s available**. In all other cases, ponyfill will be used.
Beware of
caveats!
Returns: string
#### stringToReplace
Type: string
String to replace.
#### searchValue
Type: string|RegExp
If string, stringToReplace will be searched for this value.
If RegExp, the matches are replaced with replaceValue or the value returnedRegExp
by the specified function. A without the global flag will throw aTypeError.
##### replaceValue
Type: string|Function
If string, searchValue will be replaced with this value. A number of
special replacement patterns
are supported.
If Function, it’s invoked to create the new substring which is used to replacesearchValue
the matches of parameter. See
arguments for the function).
Tested in IE11+ and all modern browsers.
- StackOverflow discussion for legacy browser support
Test suite is taken and modified from following packages:
- polyfill-library
- es-shims
- core-js
For automated tests, run npm run test:automated (append :watch` for watcher
support).
MIT © Ivan Nikolić
[ci]: https://travis-ci.com/niksy/string-replace-all-ponyfill
[ci-img]: https://travis-ci.com/niksy/string-replace-all-ponyfill.svg?branch=master
[browserstack]: https://www.browserstack.com/
[browserstack-img]: https://www.browserstack.com/automate/badge.svg?badge_key=YWxRMDN6MGFhYWdJMzlRSTBOVXMxSFllQytwWGcyb3ROM3YrSFh2cUNpOD0tLTM0c2RvVEZvSjJ0THhTcjRYSFBqZ1E9PQ==--90d6150a6b3215895fe99e8441c93a87da12a8b5