stringExtras
April 30, 2018 ยท View on GitHub
escapeRegExp
Escapes a string to safely be included in regular expressions.
import { escapeRegExp } from '@dojo/core/string';
const str = 'cat file.js | grep -c';
const result = escapeRegExp(str);
result === 'cat file\\.js \\| grep -c'; // true
escapeXml
Escapes XML (or HTML) content in a string.
import { escapeXml } from '@dojo/core/string';
const badCode = "<script>alert('hi')</script>";
const sanitized = escapeXml(badCode);
sanitized === '<script>alert('hi')</script>'; // true