Skip to content
Snippets Groups Projects
Commit fc0ea0dd authored by syuilo's avatar syuilo
Browse files

perf(frontend): improve nyaize performance

parent 3733cbf8
No related branches found
No related tags found
No related merge requests found
......@@ -3,18 +3,25 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
const enRegex1 = /(?<=n)a/gi;
const enRegex2 = /(?<=morn)ing/gi;
const enRegex3 = /(?<=every)one/gi;
const koRegex1 = /[나-낳]/g;
const koRegex2 = /(다$)|((?=\.))|((?= ))|((?=!))|((?=\?))/gm;
const koRegex3 = /((?=\?))|(야$)|((?= ))/gm;
export function nyaize(text: string): string {
return text
// ja-JP
.replaceAll('', 'にゃ').replaceAll('', 'ニャ').replaceAll('', 'ニャ')
// en-US
.replace(/(?<=n)a/gi, x => x === 'A' ? 'YA' : 'ya')
.replace(/(?<=morn)ing/gi, x => x === 'ING' ? 'YAN' : 'yan')
.replace(/(?<=every)one/gi, x => x === 'ONE' ? 'NYAN' : 'nyan')
.replace(enRegex1, x => x === 'A' ? 'YA' : 'ya')
.replace(enRegex2, x => x === 'ING' ? 'YAN' : 'yan')
.replace(enRegex3, x => x === 'ONE' ? 'NYAN' : 'nyan')
// ko-KR
.replace(/[나-낳]/g, match => String.fromCharCode(
.replace(koRegex1, match => String.fromCharCode(
match.charCodeAt(0)! + ''.charCodeAt(0) - ''.charCodeAt(0),
))
.replace(/(다$)|((?=\.))|((?= ))|((?=!))|((?=\?))/gm, '다냥')
.replace(/((?=\?))|(야$)|((?= ))/gm, '');
.replace(koRegex2, '다냥')
.replace(koRegex3, '');
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment