Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Latest commit

 

History

History
30 lines (17 loc) · 563 Bytes

stringExtras.md

File metadata and controls

30 lines (17 loc) · 563 Bytes

stringExtras

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 === '&lt;script&gt;alert(&#39;hi&#39;)&lt;/script&gt;'; // true