-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (26 loc) · 799 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class FeatureFlagManager {
constructor(storagePath) {
const fs = require('fs');
if (!fs.existsSync(storagePath)) {
fs.writeFileSync(storagePath, JSON.stringify({}));
}
this.storagePath = storagePath;
this.flags = JSON.parse(fs.readFileSync(storagePath, 'utf8'));
}
isEnabled(flagName) {
return !!this.flags[flagName];
}
enableFlag(flagName) {
this.flags[flagName] = true;
this._persist();
}
disableFlag(flagName) {
this.flags[flagName] = false;
this._persist();
}
_persist() {
const fs = require('fs');
fs.writeFileSync(this.storagePath, JSON.stringify(this.flags, null, 2));
}
}
module.exports = FeatureFlagManager;