@nsnanocat/util 2.5.16 → 2.5.17
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.
- package/getStorage.mjs +1 -1
- package/{index.mjs → index.js} +2 -2
- package/package.json +4 -3
- package/polyfill/{Storage.js → Storage.mjs} +36 -27
- package/polyfill/fetch.mts +6 -0
- package/polyfill/index.d.ts +3 -3
- package/polyfill/index.js +2 -2
- /package/lib/{index.mjs → index.js} +0 -0
- /package/polyfill/{fetch.js → fetch.mjs} +0 -0
package/getStorage.mjs
CHANGED
package/{index.mjs → index.js}
RENAMED
|
@@ -5,11 +5,11 @@ export * from "./lib/notification.mjs";
|
|
|
5
5
|
export * from "./lib/time.mjs";
|
|
6
6
|
export * from "./lib/wait.mjs";
|
|
7
7
|
export * from "./polyfill/Console.mjs";
|
|
8
|
-
export * from "./polyfill/fetch.
|
|
8
|
+
export * from "./polyfill/fetch.mjs";
|
|
9
9
|
export * from "./polyfill/Lodash.mjs";
|
|
10
10
|
export * from "./polyfill/qs.mjs";
|
|
11
11
|
export * from "./polyfill/StatusTexts.mjs";
|
|
12
|
-
export * from "./polyfill/Storage.
|
|
12
|
+
export * from "./polyfill/Storage.mjs";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* 已标准化的 `$argument` 快照。
|
package/package.json
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
],
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"bugs": "https://github.com/NSNanoCat/util/issues",
|
|
16
|
-
"main": "index.
|
|
16
|
+
"main": "index.js",
|
|
17
17
|
"types": "types/nsnanocat-util.d.ts",
|
|
18
|
+
"type": "module",
|
|
18
19
|
"scripts": {
|
|
19
20
|
"tsc:build": "npx tsc",
|
|
20
21
|
"test": "node --test test/*.test.js",
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
"url": "git+https://github.com/NSNanoCat/util.git"
|
|
28
29
|
},
|
|
29
30
|
"files": [
|
|
30
|
-
"index.
|
|
31
|
+
"index.js",
|
|
31
32
|
"lib",
|
|
32
33
|
"polyfill",
|
|
33
34
|
"getStorage.mjs",
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
"registry": "https://registry.npmjs.org/",
|
|
42
43
|
"access": "public"
|
|
43
44
|
},
|
|
44
|
-
"version": "2.5.
|
|
45
|
+
"version": "2.5.17"
|
|
45
46
|
}
|
|
@@ -284,22 +284,24 @@ export class Storage {
|
|
|
284
284
|
* @param {string} dataFile 数据文件名 / Data file name.
|
|
285
285
|
* @returns {Record<string, any>}
|
|
286
286
|
*/
|
|
287
|
-
static #loaddata
|
|
288
|
-
if ($app
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
287
|
+
static #loaddata = dataFile => {
|
|
288
|
+
if ($app === "Node.js") {
|
|
289
|
+
this.fs = this.fs ? this.fs : require("node:fs");
|
|
290
|
+
this.path = this.path ? this.path : require("node:path");
|
|
291
|
+
const curDirDataFilePath = this.path.resolve(dataFile);
|
|
292
|
+
const rootDirDataFilePath = this.path.resolve(process.cwd(), dataFile);
|
|
293
|
+
const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath);
|
|
294
|
+
const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath);
|
|
295
|
+
if (isCurDirDataFile || isRootDirDataFile) {
|
|
296
|
+
const datPath = isCurDirDataFile ? curDirDataFilePath : rootDirDataFilePath;
|
|
297
|
+
try {
|
|
298
|
+
return JSON.parse(this.fs.readFileSync(datPath));
|
|
299
|
+
} catch (e) {
|
|
300
|
+
return {};
|
|
301
|
+
}
|
|
302
|
+
} else return {};
|
|
303
|
+
} else return {};
|
|
304
|
+
};
|
|
303
305
|
|
|
304
306
|
/**
|
|
305
307
|
* 将内存数据写入 Node.js 数据文件。
|
|
@@ -309,15 +311,22 @@ export class Storage {
|
|
|
309
311
|
* @param {string} [dataFile=this.dataFile] 数据文件名 / Data file name.
|
|
310
312
|
* @returns {void}
|
|
311
313
|
*/
|
|
312
|
-
static #writedata(dataFile = this.dataFile) {
|
|
313
|
-
if ($app
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
314
|
+
static #writedata = (dataFile = this.dataFile) => {
|
|
315
|
+
if ($app === "Node.js") {
|
|
316
|
+
this.fs = this.fs ? this.fs : require("node:fs");
|
|
317
|
+
this.path = this.path ? this.path : require("node:path");
|
|
318
|
+
const curDirDataFilePath = this.path.resolve(dataFile);
|
|
319
|
+
const rootDirDataFilePath = this.path.resolve(process.cwd(), dataFile);
|
|
320
|
+
const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath);
|
|
321
|
+
const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath);
|
|
322
|
+
const jsondata = JSON.stringify(this.data);
|
|
323
|
+
if (isCurDirDataFile) {
|
|
324
|
+
this.fs.writeFileSync(curDirDataFilePath, jsondata);
|
|
325
|
+
} else if (isRootDirDataFile) {
|
|
326
|
+
this.fs.writeFileSync(rootDirDataFilePath, jsondata);
|
|
327
|
+
} else {
|
|
328
|
+
this.fs.writeFileSync(curDirDataFilePath, jsondata);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
323
332
|
}
|
package/polyfill/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Aggregated exports for polyfill modules.
|
|
4
4
|
*/
|
|
5
5
|
export { Console } from "./Console.mjs";
|
|
6
|
-
export { fetch } from "./fetch.
|
|
7
|
-
export type { Fetch, FetchRequest, FetchResponse } from "./fetch.
|
|
6
|
+
export { fetch } from "./fetch.mjs";
|
|
7
|
+
export type { Fetch, FetchRequest, FetchResponse } from "./fetch.mjs";
|
|
8
8
|
export { Lodash } from "./Lodash.mjs";
|
|
9
9
|
export { qs } from "./qs.mjs";
|
|
10
10
|
export { StatusTexts } from "./StatusTexts.mjs";
|
|
11
|
-
export { Storage } from "./Storage.
|
|
11
|
+
export { Storage } from "./Storage.mjs";
|
package/polyfill/index.js
CHANGED
|
File without changes
|
|
File without changes
|