/** * Escapes a string to AO1 escape codes. * @param {string} estring the string to be escaped */ export function escapeChat(estring: string): string { return estring .replace(/#/g, '') .replace(/&/g, '') .replace(/%/g, '') .replace(/\$/g, ''); } /** * Unescapes a string to AO1 escape codes. * @param {string} estring the string to be unescaped */ export function unescapeChat(estring: string): string { return estring .replace(//g, '#') .replace(//g, '&') .replace(//g, '%') .replace(//g, '$'); } /** * Escapes a string to be HTML-safe. * * XXX: This is unnecessary if we use `createTextNode` instead! * @param {string} unsafe an unsanitized string */ export function safeTags(unsafe: string): string { if (unsafe) { return unsafe .replace(/>/g, '>') .replace(/ String.fromCharCode(parseInt(group, 16))); } /** * XXX: a nasty hack made by gameboyprinter. * @param {string} msg chat message to prepare for display */ export function prepChat(msg: string): string { // TODO: make this less awful return unescapeChat(decodeChat(msg)); }