mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-19 02:08:37 +08:00
28 lines
512 B
JavaScript
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
|
|
}
|