Files
Firefly_Srtools_Live/src/helper/getName.ts
T
Kain344 73b6fc268f
Gitea Auto Deploy / Deploy-Container (push) Failing after 46s
Refactor TypeScript interfaces and types across multiple files for consistency and clarity
- Updated metadata interfaces in `metaData.ts` for improved readability.
- Refactored `mics.ts` types to enhance structure and maintainability.
- Added `Invasion` type to `mocDetail.ts` and `peakDetail.ts` for new functionality.
- Simplified modal configuration in `modelConfig.ts`.
- Cleaned up monster detail interfaces in `monsterDetail.ts`.
- Enhanced battle configuration types in `pfDetail.ts` to include `Invasion`.
- Updated JSON schemas in `srtools.zod.ts` to use `nullish` for optional fields.
- Introduced new skills-lock.json for skill management.
- Added global type declarations for CSS and SCSS modules in `global.d.ts`.
2026-08-27 00:41:35 +07:00

62 lines
1.6 KiB
TypeScript

import { listCurrentLanguageApi } from "@/constant/constant";
import { AvatarDetail } from "@/types";
import { useTranslations } from "next-intl"
type TFunc = ReturnType<typeof useTranslations>
function cleanText(text: string): string {
if (!text) return ""
return text.replace(/<unbreak>(.*?)<\/unbreak>/g, "$1")
}
export function getNameChar(
locale: string,
t: TFunc,
data: AvatarDetail | undefined
): string {
if (!data) return "";
if (!Object.prototype.hasOwnProperty.call(listCurrentLanguageApi, locale)) {
return "";
}
const langKey = listCurrentLanguageApi[locale as keyof typeof listCurrentLanguageApi].toLowerCase();
let text = data.Name[langKey] ?? "";
if (!text) {
text = data.Name["en"] ?? "";
}
if (data.ID > 8000) {
text = `${t("trailblazer")} • ${t(data?.BaseType?.toLowerCase() ?? "")}`;
}
return cleanText(text)
}
export function getLocaleName(locale: string, data: Record<string, string> | undefined | null): string {
if (!data) {
return ""
}
if (!Object.prototype.hasOwnProperty.call(listCurrentLanguageApi, locale)) {
return ""
}
const langKey = listCurrentLanguageApi[locale as keyof typeof listCurrentLanguageApi].toLowerCase();
let text = data[langKey] ?? "";
if (!text) {
text = data["en"] ?? "";
}
return cleanText(text)
}
export function parseRuby(text: string): string {
const rubyRegex = /\{RUBY_B#(.*?)\}(.*?)\{RUBY_E#\}/gs;
return text.replace(rubyRegex, (_match, furigana, kanji) => {
return `<ruby>${kanji}<rt>${furigana}</rt></ruby>`;
});
}