This commit is contained in:
jpmvaz
2026-09-13 20:23:05 +01:00
commit 34900bf069
45 changed files with 4879 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
import fs from 'node:fs/promises';
import path from 'node:path';
export async function readJson(file, fallback = null) {
try {
return JSON.parse(await fs.readFile(file, 'utf8'));
} catch {
return fallback;
}
}
export async function writeJson(file, data) {
await fs.mkdir(path.dirname(file), { recursive: true });
const tmp = `${file}.tmp`;
await fs.writeFile(tmp, JSON.stringify(data, null, 2));
await fs.rename(tmp, file); // atomic replace
}