rubick/static/utils.js
2021-07-12 12:54:08 +08:00

28 lines
512 B
JavaScript

const fs = require("fs");
const getlocalDataFile = () => {
let localDataFile = process.env.HOME;
if (!localDataFile) {
localDataFile = process.env.LOCALAPPDATA;
}
return localDataFile;
};
function saveData(path, value) {
fs.writeFileSync(path, JSON.stringify(value));
}
function getData(path, defaultValue) {
try {
return JSON.parse(fs.readFileSync(path, 'utf8'));
} catch (e) {
return defaultValue || undefined;
}
}
module.exports = {
getlocalDataFile,
saveData,
getData
}