summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts/nyaize.ts
diff options
context:
space:
mode:
authorKaity A <kaity@atikayda.au>2024-02-24 05:05:25 +0000
committerKaity A <kaity@atikayda.au>2024-02-24 05:05:25 +0000
commitdef2e8dff03da399e68045eec02dddc9d1781a0a (patch)
tree6246b4898fb88d045c09accaf51d6a60b554d80e /packages/frontend/src/scripts/nyaize.ts
parentfix: delete old follow request (if exists) before creating new (diff)
parentmerge: Reactions not working on child notes in detailed view (!438) (diff)
downloadsharkey-def2e8dff03da399e68045eec02dddc9d1781a0a.tar.gz
sharkey-def2e8dff03da399e68045eec02dddc9d1781a0a.tar.bz2
sharkey-def2e8dff03da399e68045eec02dddc9d1781a0a.zip
Merge remote-tracking branch 'origin/develop' into fix/failed-follow
Diffstat (limited to 'packages/frontend/src/scripts/nyaize.ts')
-rw-r--r--packages/frontend/src/scripts/nyaize.ts19
1 files changed, 12 insertions, 7 deletions
diff --git a/packages/frontend/src/scripts/nyaize.ts b/packages/frontend/src/scripts/nyaize.ts
index 62833b4de3..58ed88fed1 100644
--- a/packages/frontend/src/scripts/nyaize.ts
+++ b/packages/frontend/src/scripts/nyaize.ts
@@ -1,23 +1,28 @@
/*
- * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-FileCopyrightText: syuilo and misskey-project
* 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;
+function ifAfter(prefix, fn) {
+ const preLen = prefix.length;
+ const regex = new RegExp(prefix,'i');
+ return (x,pos,string) => {
+ return pos > 0 && string.substring(pos-preLen,pos).match(regex) ? fn(x) : x;
+ };
+}
+
export function nyaize(text: string): string {
return text
// ja-JP
.replaceAll('な', 'にゃ').replaceAll('ナ', 'ニャ').replaceAll('ナ', 'ニャ')
// en-US
- .replace(enRegex1, x => x === 'A' ? 'YA' : 'ya')
- .replace(enRegex2, x => x === 'ING' ? 'YAN' : 'yan')
- .replace(enRegex3, x => x === 'ONE' ? 'NYAN' : 'nyan')
+ .replace(/a/gi, ifAfter('n', x => x === 'A' ? 'YA' : 'ya'))
+ .replace(/ing/gi, ifAfter('morn', x => x === 'ING' ? 'YAN' : 'yan'))
+ .replace(/one/gi, ifAfter('every', x => x === 'ONE' ? 'NYAN' : 'nyan'))
// ko-KR
.replace(koRegex1, match => String.fromCharCode(
match.charCodeAt(0)! + '냐'.charCodeAt(0) - '나'.charCodeAt(0),