You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 461B

12345678910111213
  1. 'use strict';
  2. module.exports = string => {
  3. if (typeof string !== 'string') {
  4. throw new TypeError('Expected a string');
  5. }
  6. // Escape characters with special meaning either inside or outside character sets.
  7. // Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
  8. return string
  9. .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
  10. .replace(/-/g, '\\x2d');
  11. };