code: function replace(string, pattern, replacement) {
      var isReplaced = false;
  
      var result = string.replace(pattern, function () {
        isReplaced = true;
  
        // arguments are $0, $1, ..., offset, string
        return Array.prototype.slice.call(arguments, 1, -2)
          .reduce(function (pattern, match, index) {
            // '$1' from strings like '$11 $12' shouldn't be replaced.
            return pattern.replace(
              new RegExp('\\$' + (index + 1) + '(?=[^\\d]|$)', 'g'),
              match
            );
          }, replacement);
      });
  
      if (!isReplaced) {
        throw new Error(
          format(
            'we couldn\'t replace pattern: \'%s\' with value: \'%s\' ' +
            'in file: \'%s\'',
            pattern, replacement, path
          )
        );
      }
      return result;
    }
docs: String.prototype.replace in javascript is defected by design. https://stackoverflow.com/questions/5257000/how-to-know-if-javascript-string-replace-did-anything