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

perf: use replaceAll instead of regex

parent 5173ed37
No related branches found
No related tags found
No related merge requests found
......@@ -274,7 +274,7 @@ export class ApRendererService {
} as any;
if (reaction.startsWith(':')) {
const name = reaction.replace(/:/g, '');
const name = reaction.replaceAll(':', '');
const emoji = await this.emojisRepository.findOneBy({
name,
host: IsNull(),
......
export function nyaize(text: string): string {
return text
// ja-JP
.replace(/な/g, 'にゃ').replace(/ナ/g, 'ニャ').replace(/ナ/g, 'ニャ')
.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')
// ko-KR
.replace(/[나-낳]/g, match => String.fromCharCode(
match.charCodeAt(0)! + ''.charCodeAt(0) - ''.charCodeAt(0)
match.charCodeAt(0)! + ''.charCodeAt(0) - ''.charCodeAt(0),
))
.replace(/(다$)|((?=\.))|((?= ))|((?=!))|((?=\?))/gm, '다냥')
.replace(/((?=\?))|(야$)|((?= ))/gm, '');
......
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