@stream-io/escape-string-regexp
Version:
Escape RegExp special characters
1 lines • 724 B
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["../index.js"],"sourcesContent":["export default function escapeStringRegexp(string) {\n\tif (typeof string !== 'string') {\n\t\tthrow new TypeError('Expected a string');\n\t}\n\n\t// Escape characters with special meaning either inside or outside character sets.\n\t// Use a simple backslash escape when it’s always valid, and a `\\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.\n\treturn string\n\t\t.replace(/[|\\\\{}()[\\]^$+*?.]/g, '\\\\$&')\n\t\t.replace(/-/g, '\\\\x2d');\n}\n"],"names":["string","TypeError","replace"],"mappings":"wBAA2CA,GAC1C,GAAsB,iBAAXA,EACV,UAAUC,UAAU,qBAKrB,OAAOD,EACLE,QAAQ,sBAAuB,QAC/BA,QAAQ,KAAM"}