Files
vimx/06-integration/project/index.ts
T
fukunee e8dfa0e2f1 Add Vim exercises, cheatsheet, and project polish
Add code golf challenges for Vim practice, a weekly review template, and
extend the cheatsheet with high-frequency commands. Fix the calculator
`multiply` implementation and correct a logger import path.
2026-05-31 23:01:37 +08:00

58 lines
1.6 KiB
TypeScript

// ============================================================
// 模拟项目 — src/index.ts
// 练习项目导航和重构的入口文件
// ============================================================
import { Calculator } from "./calculator";
import { Formatter, type FormatOptions } from "./formatter";
import { DataStore } from "./store";
import { logger, LogLevel } from "./logger";
// TODO: Add more test cases
// FIXME: Handle edge cases for negative numbers
async function main(): Promise<void> {
logger.log(LogLevel.INFO, "Starting application...");
try {
const calc = new Calculator();
const store = new DataStore();
const formatter = new Formatter();
const a = 42;
const b = 8;
const sumResult = calc.add(a, b);
const productResult = calc.multiply(a, b);
const quotientResult = calc.divide(a, b);
const differenceResult = calc.subtract(a, b);
const options: FormatOptions = {
decimals: 2,
prefix: "$",
suffix: "",
locale: "en-US",
};
logger.log(LogLevel.INFO, `Sum: ${sumResult}`);
logger.log(LogLevel.INFO, `Product: ${productResult}`);
logger.log(LogLevel.INFO, `Quotient: ${formatter.format(quotientResult, options)}`);
logger.log(LogLevel.INFO, `Difference: ${differenceResult}`);
await store.save("last_calculation", {
sum: sumResult,
product: productResult,
quotient: quotientResult,
difference: differenceResult,
timestamp: Date.now(),
});
logger.log(LogLevel.INFO, "Application finished successfully.");
} catch (error) {
logger.log(LogLevel.ERROR, `Application error: ${error}`);
process.exit(1);
}
}
main();