变更项目结构

This commit is contained in:
2026-09-08 20:04:50 +08:00
parent 9a69ca4ef3
commit b109e49fcf
29 changed files with 463 additions and 974 deletions
+40
View File
@@ -0,0 +1,40 @@
// ============================================================
// 模拟项目 — src/formatter.ts
// ============================================================
export interface FormatOptions {
decimals: number;
prefix: string;
suffix: string;
locale: string;
}
export class Formatter {
format(value: number, options: FormatOptions): string {
const { decimals, prefix, suffix, locale } = options;
const formatted = value.toLocaleString(locale, {
minimumFractionDigits: decimals,
maximumFractionDigits: decimals,
});
return `${prefix}${formatted}${suffix}`;
}
formatPercent(value: number, decimals: number = 1): string {
return `${(value * 100).toFixed(decimals)}%`;
}
formatCurrency(value: number, currency: string = "USD"): string {
return value.toLocaleString("en-US", {
style: "currency",
currency,
});
}
truncate(value: number, maxLength: number): string {
const str = value.toString();
if (str.length <= maxLength) {
return str;
}
return str.slice(0, maxLength) + "...";
}
}