UNPKG

docutils-ts

Version:

Port of the Python Docutils library to TypeScript

19 lines (18 loc) 556 B
export function xmlescape(string, ignore) { var pattern; const map = { '>': '&gt;', '<': '&lt;', "'": '&apos;', '"': '&quot;', '&': '&amp;' }; if (string === null || string === undefined) throw new Error('xmlescape: string is null or undefined'); ignore = (ignore || '').replace(/[^&"<>\']/g, ''); pattern = '([&"<>\'])'.replace(new RegExp('[' + ignore + ']', 'g'), ''); return string.replace(new RegExp(pattern, 'g'), function (str, item) { return map[item]; }); } ;