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.
npm install fast-replaceall --save
const replaceAll = require('fast-replaceall'); const string = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?'; replaceAll(string, 'dog', 'monkey'); //=> 'The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?'
export default function ( str: string, substr: string, replacement: (match: string, offset: number, str: string) => string | any, options?: object ): string
Returns a new string with all
substr matches replaced with
<string>String to work on.
<string>String to match in input.
<string | function>Replacement for substr matches.
0. Index at which to start replacing.
false. Whether or not substring matching should be case-insensitive.