/
vinderman
/
presentation
Обзор
Документация
Войти
/
vinderman
/
presentation
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
node/backend-app/mock-db.ts
1 строка
577 B
kalev
initial commit
06 май 2024, 12:05
06 май 2024, 12:05
4258fa9
Код
Авторство
О чём код?
import fs from 'fs' import path from 'path' import db from './db.json' import { format } from 'prettier' const dbPath = path.resolve('./db.json') export type DBType = typeof db class Database { read(): DBType { return JSON.parse(fs.readFileSync(dbPath) as unknown as string) } write(data: DBType): void { const writeData = JSON.stringify(data) void format(writeData, { filepath: '../.prettierrc.json' }) .then((result) => { fs.writeFileSync(dbPath, result, 'utf-8') }) .catch() } } const DB = new Database() export default DB