blob: fd6fb14601f40d3a78779e5011c9af2c18da8da2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import fs from "fs";
export default (path, initial = {}) => {
if (!initial || !Object.keys(initial).length) {
try {
initial = JSON.parse(fs.readFileSync("/app/" + path));
} catch (e) {
console.log(e);
}
}
return new Proxy(initial, {
set(obj, prop, value) {
fs.writeFileSync(
path,
JSON.stringify({ ...obj, [prop]: value }, null, 2),
"utf-8"
);
return Reflect.set(...arguments);
}
});
};
|