@zwa73/utils 1.0.214 → 1.0.215

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -142,37 +142,49 @@ var UtilFT;
142
142
  }
143
143
  UtilFT.ensurePathExistsSync = ensurePathExistsSync;
144
144
  function loadJSONFileSync(filePath, opt) {
145
- if (opt?.forceExt !== true && pathe_1.default.extname(filePath) !== '.json')
146
- filePath += '.json';
147
- const str = pathExistsSync(filePath)
148
- ? fs.readFileSync(filePath, "utf-8")
149
- : "";
150
- // 如果不存在则返回默认值
151
- if (str == "" || str == null) {
152
- if (opt?.default !== undefined)
153
- return opt.default;
154
- return {};
145
+ try {
146
+ if (opt?.forceExt !== true && pathe_1.default.extname(filePath) !== '.json')
147
+ filePath += '.json';
148
+ const str = pathExistsSync(filePath)
149
+ ? fs.readFileSync(filePath, "utf-8")
150
+ : "";
151
+ // 如果不存在则返回默认值
152
+ if (str == "" || str == null) {
153
+ if (opt?.default !== undefined)
154
+ return opt.default;
155
+ return {};
156
+ }
157
+ if (opt?.json5)
158
+ return JSON5.parse(str);
159
+ return JSON.parse(str);
160
+ }
161
+ catch (e) {
162
+ UtilLogger_1.SLogger.error(`loadJSONFileSync 错误 filePath:${filePath}`);
163
+ throw e;
155
164
  }
156
- if (opt?.json5)
157
- return JSON5.parse(str);
158
- return JSON.parse(str);
159
165
  }
160
166
  UtilFT.loadJSONFileSync = loadJSONFileSync;
161
167
  async function loadJSONFile(filePath, opt) {
162
- if (opt?.forceExt !== true && pathe_1.default.extname(filePath) !== '.json')
163
- filePath += '.json';
164
- const str = (await pathExists(filePath))
165
- ? await fs.promises.readFile(filePath, "utf-8")
166
- : "";
167
- // 如果不存在则返回默认值
168
- if (str == "" || str == null) {
169
- if (opt?.default !== undefined)
170
- return opt.default;
171
- return {};
168
+ try {
169
+ if (opt?.forceExt !== true && pathe_1.default.extname(filePath) !== '.json')
170
+ filePath += '.json';
171
+ const str = (await pathExists(filePath))
172
+ ? await fs.promises.readFile(filePath, "utf-8")
173
+ : "";
174
+ // 如果不存在则返回默认值
175
+ if (str == "" || str == null) {
176
+ if (opt?.default !== undefined)
177
+ return opt.default;
178
+ return {};
179
+ }
180
+ if (opt?.json5)
181
+ return JSON5.parse(str);
182
+ return JSON.parse(str);
183
+ }
184
+ catch (e) {
185
+ UtilLogger_1.SLogger.error(`loadJSONFile 错误 filePath:${filePath}`);
186
+ throw e;
172
187
  }
173
- if (opt?.json5)
174
- return JSON5.parse(str);
175
- return JSON.parse(str);
176
188
  }
177
189
  UtilFT.loadJSONFile = loadJSONFile;
178
190
  /**写入JSON文件
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.214",
3
+ "version": "1.0.215",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {