|
@@ -40,14 +40,14 @@ exports.stringHasIntersect = (string, arr) => {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Load JSON file in async style
|
|
* Load JSON file in async style
|
|
|
-* @param {string} path path to file
|
|
|
|
|
|
|
+* @param {string} filepath path to file
|
|
|
* @param {string} encoding file encoding
|
|
* @param {string} encoding file encoding
|
|
|
* @returns {Object|false} return false if failed or Object if successful
|
|
* @returns {Object|false} return false if failed or Object if successful
|
|
|
*/
|
|
*/
|
|
|
-exports.loadJsonAsync = async (path, encoding = "utf8") => {
|
|
|
|
|
|
|
+exports.loadJsonAsync = async (filepath, encoding = "utf8") => {
|
|
|
let result = false;
|
|
let result = false;
|
|
|
try {
|
|
try {
|
|
|
- result = await fsAsync.readFile(path, encoding);
|
|
|
|
|
|
|
+ result = await fsAsync.readFile(filepath, encoding);
|
|
|
}
|
|
}
|
|
|
// eslint-disable-next-line no-empty
|
|
// eslint-disable-next-line no-empty
|
|
|
catch (ex) { }
|
|
catch (ex) { }
|
|
@@ -66,13 +66,13 @@ exports.getFullPath = (str1, str2) => path.resolve(str1, str2);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Load JSON file iin sync way
|
|
* Load JSON file iin sync way
|
|
|
-* @param {string} path path to file
|
|
|
|
|
|
|
+* @param {string} filepath path to file
|
|
|
* @param {string} encoding file encoding
|
|
* @param {string} encoding file encoding
|
|
|
* @returns {Object|false} return false if failed or Object if successful
|
|
* @returns {Object|false} return false if failed or Object if successful
|
|
|
*/
|
|
*/
|
|
|
-exports.loadJson = (path, encoding = "utf8") => {
|
|
|
|
|
|
|
+exports.loadJson = (filepath, encoding = "utf8") => {
|
|
|
try {
|
|
try {
|
|
|
- return JSON.parse(fs.readFileSync(path, encoding));
|
|
|
|
|
|
|
+ return JSON.parse(fs.readFileSync(filepath, encoding));
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -81,12 +81,12 @@ exports.loadJson = (path, encoding = "utf8") => {
|
|
|
/**
|
|
/**
|
|
|
* Save JSON file synchronously with format
|
|
* Save JSON file synchronously with format
|
|
|
* @param {string} obj object to save
|
|
* @param {string} obj object to save
|
|
|
-* @param {string} path path
|
|
|
|
|
|
|
+* @param {string} filepath path
|
|
|
* @returns {undefined|false} returns false if error happened
|
|
* @returns {undefined|false} returns false if error happened
|
|
|
*/
|
|
*/
|
|
|
-exports.saveJson = (obj, path) => {
|
|
|
|
|
|
|
+exports.saveJson = (obj, filepath) => {
|
|
|
try {
|
|
try {
|
|
|
- fs.writeFileSync(path, JSON.stringify(obj, null, "\t"));
|
|
|
|
|
|
|
+ fs.writeFileSync(filepath, JSON.stringify(obj, null, "\t"));
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|