Files
usa/src/utils/tickerText.ts
2026-03-02 16:41:57 +08:00

22 lines
624 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 滚动情报文本处理:过滤非中文为主的内容
*/
/** 简体中文字符范围 */
const ZH_REGEX = /[\u4e00-\u9fff]/g
/** 文本中中文占比是否达标至少30% */
export function isMostlyChinese(text: string): boolean {
if (!text?.trim()) return false
const zh = text.match(ZH_REGEX)
const zhCount = zh ? zh.length : 0
return zhCount / text.length >= 0.3
}
/** 处理滚动情报项:非中文为主则过滤 */
export function processTickerText(text: string): string | null {
const t = (text || '').trim()
if (!t) return null
if (!isMostlyChinese(t)) return null
return t
}