18 lines
479 B
JavaScript
18 lines
479 B
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const DATA_DIR = path.join(__dirname, '../data');
|
|
|
|
function readTable(name) {
|
|
const file = path.join(DATA_DIR, `${name}.json`);
|
|
if (!fs.existsSync(file)) return [];
|
|
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
}
|
|
|
|
function writeTable(name, data) {
|
|
const file = path.join(DATA_DIR, `${name}.json`);
|
|
fs.writeFileSync(file, JSON.stringify(data, null, 2), 'utf8');
|
|
}
|
|
|
|
module.exports = { readTable, writeTable };
|