summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts/nyaize.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/frontend/src/scripts/nyaize.ts')
-rw-r--r--packages/frontend/src/scripts/nyaize.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/packages/frontend/src/scripts/nyaize.ts b/packages/frontend/src/scripts/nyaize.ts
new file mode 100644
index 0000000000..0ac77e1006
--- /dev/null
+++ b/packages/frontend/src/scripts/nyaize.ts
@@ -0,0 +1,20 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+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')
+ // ko-KR
+ .replace(/[나-낳]/g, match => String.fromCharCode(
+ match.charCodeAt(0)! + '냐'.charCodeAt(0) - '나'.charCodeAt(0),
+ ))
+ .replace(/(다$)|(다(?=\.))|(다(?= ))|(다(?=!))|(다(?=\?))/gm, '다냥')
+ .replace(/(야(?=\?))|(야$)|(야(?= ))/gm, '냥');
+}