Make multiple replacements in a string without replacing ones that have already been replaced.
npm install --save replace-onceconst replaceOnce = require('replace-once')
var str = 'abc abcd a ab'
var find = ['abcd', 'abc', 'ab', 'a']
var replace = ['a', 'ab', 'abc', 'abcd']
replaceOnce(str, find, replace, 'gi')
//=> 'ab a abcd abc'The string to do replacements on.
An array of strings to search for when doing replacements. Must be in the same order as their replacement specified inside of the replace parameter. Strings may contain Regular Expressions (regexp).
An array of strings to replace the strings specified inside of the find parameter with. Must be in the same order as their counterpart specified inside of the find parameter.
Optional
RegExp flags to use when doing replacements. (e.g g for global, i for case-insensitive)
MIT. See the license.md file for more info.