index.js 236 B

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