fix to an infinite loop when the same word is in the search and replace
modified that it can be used as a library (separate main.js)
fixed to error when mapping.source is undefined.