项目文件夹

文件
wehub-resource-sync 2114b14ee0
Sync main into demo / sync (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:26 +08:00

36 行
884 B
TypeScript

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
/**
* 表达式符号转换器 — 翻译自 CalculatorExpressionTokenizer.java
*
* ASCII (内部) ↔ 显示 (本地化) 符号映射
*/
const TOKEN_MAP: [string, string][] = [
['/', '÷'],
['*', '×'],
['-', '\u2212'], // U+2212 MINUS SIGN
['Infinity', '∞'],
];
/** 将显示字符串转换为 ASCII 内部表示 */
export function normalize(expr: string): string {
let result = expr;
for (const [ascii, display] of TOKEN_MAP) {
result = result.replaceAll(display, ascii);
}
return result;
}
/** 将 ASCII 内部表示转换为显示字符串 */
export function localize(expr: string): string {
let result = expr;
for (const [ascii, display] of TOKEN_MAP) {
result = result.replaceAll(ascii, display);
}
return result;
}
/** 判断字符是否为数字 */
export function isDigit(ch: string): boolean {
return ch >= '0' && ch <= '9';
}