index.js 226 B

123456789101112
  1. 'use strict';
  2. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  3. module.exports = function (str) {
  4. if (typeof str !== 'string') {
  5. throw new TypeError('Expected a string');
  6. }
  7. return str.replace(matchOperatorsRe, '\\$&');
  8. };