areplace

Replace a set of strings contained in an array with a corresponding string in the 'replacement' array, or use a single string used as 'replacement'. If arrays are used they MUST be the same length. Using the 'g' flag replaces all occurences of search, 'i'

Usage no npm install needed!

<script type="module">
  import areplace from 'https://cdn.skypack.dev/areplace';
</script>

README

Similar to string.replace, except "search" is an array, and "replace" can be an array or a string.

Example:

var str = 'This fuzzy chipmunk can fly'; str = str.areplace(['fuzzy', 'fly'], ['happy', 'run'], 'gi');

The new string would read 'This happy chipmunk can run'.

The 'gi' is for global replacement, and case insensitive.