Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/lib/lowdb/adapters/JSONFile.js
1126 views
1
const { TextFile } = require('./TextFile.js');
2
class JSONFile {
3
constructor(filename) {
4
this.adapter = new TextFile(filename);
5
}
6
async read() {
7
const data = await this.adapter.read();
8
if (data === null) {
9
return null;
10
}
11
else {
12
return JSON.parse(data);
13
}
14
}
15
write(obj) {
16
return this.adapter.write(JSON.stringify(obj, null, 2));
17
}
18
}
19
module.exports = { JSONFile };
20
21