From 391328f12883a5e4ef8f35aad4b6f6fd45dfb223 Mon Sep 17 00:00:00 2001 From: naskya Date: Fri, 1 Mar 2024 07:56:05 +0900 Subject: [PATCH] chore: remove nyaification of 'nA' --- packages/backend/src/misc/{nyaize.ts => nyaify.ts} | 6 ++++-- packages/backend/src/models/repositories/note.ts | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) rename packages/backend/src/misc/{nyaize.ts => nyaify.ts} (85%) diff --git a/packages/backend/src/misc/nyaize.ts b/packages/backend/src/misc/nyaify.ts similarity index 85% rename from packages/backend/src/misc/nyaize.ts rename to packages/backend/src/misc/nyaify.ts index 32c54fbd7b..5829461779 100644 --- a/packages/backend/src/misc/nyaize.ts +++ b/packages/backend/src/misc/nyaify.ts @@ -1,11 +1,13 @@ -export function nyaize(text: string, lang?: string): string { +export function nyaify(text: string, lang?: string): string { text = text // ja-JP .replaceAll("な", "にゃ") .replaceAll("ナ", "ニャ") .replaceAll("ナ", "ニャ") // en-US - .replace(/(?<=n)a/gi, (x) => (x === "A" ? "YA" : "ya")) + .replaceAll("na", "nya") + .replaceAll("Na", "Nya") + .replaceAll("NA", "NYA") .replace(/(?<=morn)ing/gi, (x) => (x === "ING" ? "YAN" : "yan")) .replace(/(?<=every)one/gi, (x) => (x === "ONE" ? "NYAN" : "nyan")) .replace(/non(?=[bcdfghjklmnpqrstvwxyz])/gi, (x) => diff --git a/packages/backend/src/models/repositories/note.ts b/packages/backend/src/models/repositories/note.ts index 60e5a8d5ca..a140dd9543 100644 --- a/packages/backend/src/models/repositories/note.ts +++ b/packages/backend/src/models/repositories/note.ts @@ -12,7 +12,7 @@ import { Channels, } from "../index.js"; import type { Packed } from "@/misc/schema.js"; -import { nyaize } from "@/misc/nyaize.js"; +import { nyaify } from "@/misc/nyaify.js"; import { awaitAll } from "@/prelude/await-all.js"; import { convertReactions, decodeReaction } from "@/misc/reaction-lib.js"; import type { NoteReaction } from "@/models/entities/note-reaction.js"; @@ -262,19 +262,19 @@ export const NoteRepository = db.getRepository(Note).extend({ if (packed.user.isCat && packed.user.speakAsCat && packed.text) { const tokens = packed.text ? mfm.parse(packed.text) : []; - function nyaizeNode(node: mfm.MfmNode) { + function nyaifyNode(node: mfm.MfmNode) { if (node.type === "quote") return; if (node.type === "text") - node.props.text = nyaize(node.props.text, packed.lang); + node.props.text = nyaify(node.props.text, packed.lang); if (node.children) { for (const child of node.children) { - nyaizeNode(child); + nyaifyNode(child); } } } - for (const node of tokens) nyaizeNode(node); + for (const node of tokens) nyaifyNode(node); packed.text = mfm.toString(tokens); }