diff options
| author | stonedDiscord <stonedDiscord@users.noreply.github.com> | 2024-11-20 13:31:50 +0000 |
|---|---|---|
| committer | GitHub Action <actions@github.com> | 2024-11-20 13:31:50 +0000 |
| commit | 6684f3fce6e90fd0574d7bab63b629554ab03ef6 (patch) | |
| tree | b2a62247d17e23a77af57aea355ba621666817c2 /webAO/encoding.ts | |
| parent | 95a2d1361d84c61b454ebe506e6963b93f6d8dee (diff) | |
Prettified Code!
Diffstat (limited to 'webAO/encoding.ts')
| -rw-r--r-- | webAO/encoding.ts | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/webAO/encoding.ts b/webAO/encoding.ts index c878cb5..37f064a 100644 --- a/webAO/encoding.ts +++ b/webAO/encoding.ts @@ -3,11 +3,11 @@ * @param {string} estring the string to be escaped */ export function escapeChat(estring: string): string { - return estring - .replaceAll('#', '<num>') - .replaceAll('&', '<and>') - .replaceAll('%', '<percent>') - .replaceAll('$', '<dollar>'); + return estring + .replaceAll("#", "<num>") + .replaceAll("&", "<and>") + .replaceAll("%", "<percent>") + .replaceAll("$", "<dollar>"); } /** @@ -15,11 +15,11 @@ export function escapeChat(estring: string): string { * @param {string} estring the string to be unescaped */ export function unescapeChat(estring: string): string { - return estring - .replaceAll('<num>', '#') - .replaceAll('<and>', '&') - .replaceAll('<percent>', '%') - .replaceAll('<dollar>', '$'); + return estring + .replaceAll("<num>", "#") + .replaceAll("<and>", "&") + .replaceAll("<percent>", "%") + .replaceAll("<dollar>", "$"); } /** @@ -29,12 +29,10 @@ export function unescapeChat(estring: string): string { * @param {string} unsafe an unsanitized string */ export function safeTags(unsafe: string): string { - if (unsafe) { - return unsafe - .replaceAll('>', '>') - .replaceAll('<', '<'); - } - return ''; + if (unsafe) { + return unsafe.replaceAll(">", ">").replaceAll("<", "<"); + } + return ""; } /** @@ -42,8 +40,10 @@ export function safeTags(unsafe: string): string { * @param {string} estring the string to be decoded */ export function decodeChat(estring: string): string { - // Source: https://stackoverflow.com/questions/7885096/how-do-i-decode-a-string-with-escaped-unicode - return estring.replace(/\\u([\d\w]{1,})/gi, (match, group) => String.fromCharCode(parseInt(group, 16))); + // Source: https://stackoverflow.com/questions/7885096/how-do-i-decode-a-string-with-escaped-unicode + return estring.replace(/\\u([\d\w]{1,})/gi, (match, group) => + String.fromCharCode(parseInt(group, 16)), + ); } /** @@ -51,6 +51,6 @@ export function decodeChat(estring: string): string { * @param {string} msg chat message to prepare for display */ export function prepChat(msg: string): string { - // TODO: make this less awful - return safeTags(unescapeChat(decodeChat(msg))); + // TODO: make this less awful + return safeTags(unescapeChat(decodeChat(msg))); } |
