/
mustreets
/
CreateTransactions
Обзор
Документация
Войти
/
mustreets
/
CreateTransactions
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
libJS/services/Reporting.ts
47 строк
1 KB
Slava
Initialize project with essential configurations and structures
14 май 2026, 22:23
14 май 2026, 22:23
a89cd26
Код
Авторство
О чём код?
enum AppMode { DEV = "dev", PROD = "prod", } interface IReporterConfig { mode: AppMode; onLog?: (msg: string, data?: unknown) => void; onTrack?: (event: string, params?: Record<string, unknown>) => void; } class Reporter { private readonly mode: AppMode; private readonly config: IReporterConfig; public constructor(config: IReporterConfig) { this.mode = config.mode; this.config = config; } public log(message: string, data?: unknown): void { if (this.mode === AppMode.DEV) { // eslint-disable-next-line no-console -- dev-only sink console.log(`[LOG] ${message}`, data ?? ""); } else if (this.config.onLog) { this.config.onLog(message, data); } } public track(event: string, params?: Record<string, unknown>): void { if (this.mode === AppMode.DEV) { // eslint-disable-next-line no-console -- dev-only sink console.info(`[TRACK] ${event}`, params ?? ""); } else if (this.config.onTrack) { this.config.onTrack(event, params); } } } const defaultMode = process.env.NODE_ENV === "production" ? AppMode.PROD : AppMode.DEV; const reporter = new Reporter({ mode: defaultMode, }); export type { IReporterConfig }; export { AppMode, Reporter, reporter };