mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-05-16 04:36:46 +08:00
💄 处理转义
This commit is contained in:
@@ -11,6 +11,8 @@ import type { KEYWORD } from "color-convert/conversions.js";
|
||||
import { v4 } from "uuid";
|
||||
import { score } from "wcag-color";
|
||||
|
||||
import TGConstant from "@/web/constant/TGConstant.js";
|
||||
|
||||
/**
|
||||
* @description 时间戳转换为时间字符串
|
||||
* @returns {string} 时间字符串 d天 hh:mm:ss
|
||||
@@ -250,3 +252,42 @@ export function getVideoDuration(durationMill: number): string {
|
||||
result += `${seconds.toString().padStart(2, "0")}`;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 转义正则表达式
|
||||
* @since Beta v0.3.3
|
||||
* @param {string} data 内容
|
||||
* @returns {string} 转义后的内容
|
||||
*/
|
||||
export function decodeRegExp(data: string): string {
|
||||
let res = data;
|
||||
if (res.length === 0) return res;
|
||||
res = res.replace(/</g, "<");
|
||||
res = res.replace(/>/g, ">");
|
||||
res = res.replace(/ /g, " ");
|
||||
res = res.replace(/'/g, "'");
|
||||
res = res.replace(/"/g, `"`);
|
||||
res = res.replace(/'/g, "'");
|
||||
res = res.replace(/&/g, "&");
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据 gid 获取游戏名称
|
||||
* @param {number} gid
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getGameName(gid: number): string {
|
||||
const game = TGConstant.BBS.CHANNELS.find((item) => item.gid === gid.toString());
|
||||
return game ? game.title : "未知游戏";
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取游戏id
|
||||
* @param {string} mini
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getGameId(mini: string): string {
|
||||
const game = TGConstant.BBS.CHANNELS.find((item) => item.mini === mini);
|
||||
return game ? game.gid : "0";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user