summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2020-02-05 20:56:28 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2020-02-05 20:56:28 +0900
commit3c4bae763fba61b05e1410aad61be120b19807cf (patch)
tree24d6a577340cb831b346b83521e443e777f9fc99 /src/misc
parent12.0.0-beta.1 (diff)
downloadmisskey-3c4bae763fba61b05e1410aad61be120b19807cf.tar.gz
misskey-3c4bae763fba61b05e1410aad61be120b19807cf.tar.bz2
misskey-3c4bae763fba61b05e1410aad61be120b19807cf.zip
Revert "Korean, English Nyaziation and special case exclusion (#5813)"
This reverts commit c110f0860e2ae7bc378c36f8eb6048956ebc3a28.
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/nyaize.ts50
1 files changed, 2 insertions, 48 deletions
diff --git a/src/misc/nyaize.ts b/src/misc/nyaize.ts
index 0b9b83d9af..38c7101766 100644
--- a/src/misc/nyaize.ts
+++ b/src/misc/nyaize.ts
@@ -1,57 +1,11 @@
-import rndstr from 'rndstr';
-
export function nyaize(text: string): string {
- const [toNyaize, exclusionMap] = exclude(text);
- const nyaized = toNyaize
+ return text
// ja-JP
.replace(/な/g, 'にゃ').replace(/ナ/g, 'ニャ').replace(/ナ/g, 'ニャ')
// en-US
.replace(/morning/gi, 'mornyan').replace(/everyone/gi, 'everynyan')
- .replace(/o/g, 'owo').replace(/u/g, 'uwu')
// ko-KR
.replace(/[나-낳]/g, match => String.fromCharCode(
- match.charCodeAt(0)! + '냐'.charCodeAt(0) - '나'.charCodeAt(0)
- )).replace(/(다$)|(다(?=\.))|(다(?= ))|(다(?=!))|(다(?=\?))/gm, '다냥')
- .replace(/(야(?=\?))|(야$)|(야(?= ))/gm, '냥');
- return replaceExceptions(nyaized, exclusionMap);
-}
-
-export function denyaize(text: string): string {
- return text
- .replace(/にゃ/g, 'な').replace(/ニャ/g, 'ナ').replace(/ニャ/g, 'ナ')
- .replace(/owo/g, 'o').replace(/uwu/g, 'u')
- .replace(/mornyan/gi, 'morning').replace(/everynyan/gi, 'everyone') // this will result in case related bug
- .replace(/(다냥$)|(다냥(?=\.))|(다냥(?= ))|(다냥(?=!))|(다냥(?=\?))/gm, '다')
- .replace(/(냥(?=\?))|(냥$)|(냥(?= ))/gm, '야')
- .replace(/[냐-냫]/g, match => String.fromCharCode(
- match.charCodeAt(0)! + '나'.charCodeAt(0) - '냐'.charCodeAt(0)
+ match.codePointAt(0)! + '냐'.charCodeAt(0) - '나'.charCodeAt(0)
));
}
-
-function exclude(text: string): [string, Record<string, string>] {
- const map: Record<string, string> = {};
- function substitute(match: string): string {
- let randomstr: string;
- do {
- randomstr = rndstr({ length: 16, chars: '🀀-🀫' });
- } while(Object.prototype.hasOwnProperty.call(map, randomstr));
- map[randomstr] = match;
- return randomstr;
- }
- const replaced = text
- .replace(/(https?:\/\/.*?)(?= |$)/gm, match => substitute(match)) // URL
- .replace(/:([a-z0-9_+-]+):/gim, match => substitute(match)) // emoji
- .replace(/#([^\s.,!?'"#:\/\[\]【】]+)/gm, match => substitute(match)) // hashtag
- .replace(/@\w([\w-]*\w)?(?:@[\w.\-]+\w)?/gm, match => substitute(match)) // mention
- .replace(/<\/?[a-zA-Z]*?>/g, match => substitute(match)) // <jump>, <motion>, etc.
- .replace(/`([^`\n]+?)`/g, match => substitute(match)) // inline code
- .replace(/```(.+?)?\n([\s\S]+?)```(\n|$)/gm, match => substitute(match)); // code block
- return [replaced, map];
-}
-
-function replaceExceptions(text: string, map: Record<string, string>): string {
- for(const rule in map)
- if(Object.prototype.hasOwnProperty.call(map, rule))
- text = text.replace(rule, map[rule]);
- return text;
-} \ No newline at end of file