From ee22820da253a77a86bcc2561e8c705fa0de0061 Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Sat, 31 Aug 2024 09:55:03 +0900 Subject: [PATCH] refactor --- .../frontend-embed/src/components/EmMfm.ts | 7 +++-- .../global/MkMisskeyFlavoredMarkdown.ts | 7 +++-- packages/frontend/src/scripts/aiscript/api.ts | 4 +-- packages/frontend/src/scripts/nyaize.ts | 27 ------------------- packages/misskey-js/src/index.ts | 3 ++- .../to-be-shared => misskey-js/src}/nyaize.ts | 0 6 files changed, 10 insertions(+), 38 deletions(-) delete mode 100644 packages/frontend/src/scripts/nyaize.ts rename packages/{frontend-embed/src/to-be-shared => misskey-js/src}/nyaize.ts (100%) diff --git a/packages/frontend-embed/src/components/EmMfm.ts b/packages/frontend-embed/src/components/EmMfm.ts index bd68d94c8f..20c5716436 100644 --- a/packages/frontend-embed/src/components/EmMfm.ts +++ b/packages/frontend-embed/src/components/EmMfm.ts @@ -14,7 +14,6 @@ import EmEmoji from '@/components/EmEmoji.vue'; import EmCustomEmoji from '@/components/EmCustomEmoji.vue'; import EmA from '@/components/EmA.vue'; import { host } from '@/config.js'; -import { nyaize as doNyaize } from '@/to-be-shared/nyaize.js'; import { safeParseFloat } from '@/to-be-shared/safe-parse.js'; const QUOTE_STYLE = ` @@ -81,7 +80,7 @@ export default function (props: MfmProps, { emit }: { emit: SetupContext { return new Promise(ok => { @@ -87,7 +87,7 @@ export function createAiScriptEnv(opts) { }), 'Mk:nyaize': values.FN_NATIVE(([text]) => { utils.assertString(text); - return values.STR(nyaize(text.value)); + return values.STR(Misskey.nyaize(text.value)); }), }; } diff --git a/packages/frontend/src/scripts/nyaize.ts b/packages/frontend/src/scripts/nyaize.ts deleted file mode 100644 index abc8ada461..0000000000 --- a/packages/frontend/src/scripts/nyaize.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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; - -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') - // ko-KR - .replace(koRegex1, match => String.fromCharCode( - match.charCodeAt(0)! + '냐'.charCodeAt(0) - '나'.charCodeAt(0), - )) - .replace(koRegex2, '다냥') - .replace(koRegex3, '냥'); -} diff --git a/packages/misskey-js/src/index.ts b/packages/misskey-js/src/index.ts index cf267f3281..e4c9364aa1 100644 --- a/packages/misskey-js/src/index.ts +++ b/packages/misskey-js/src/index.ts @@ -22,7 +22,8 @@ import * as api from './api.js'; import * as entities from './entities.js'; import * as acct from './acct.js'; import * as note from './note.js'; -export { api, entities, acct, note }; +import { nyaize } from './nyaize.js'; +export { api, entities, acct, note, nyaize }; //#region standalone types import type { Endpoints } from './api.types.js'; diff --git a/packages/frontend-embed/src/to-be-shared/nyaize.ts b/packages/misskey-js/src/nyaize.ts similarity index 100% rename from packages/frontend-embed/src/to-be-shared/nyaize.ts rename to packages/misskey-js/src/nyaize.ts