@nsnanocat/util 1.9.3 → 1.9.5
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 +25 -35
- package/package.json +1 -1
package/getStorage.mjs
CHANGED
|
@@ -12,66 +12,55 @@ import { Storage } from "./polyfill/Storage.mjs";
|
|
|
12
12
|
* @return {object} { Settings, Caches, Configs }
|
|
13
13
|
*/
|
|
14
14
|
export function getStorage(key, names, database) {
|
|
15
|
+
Console.debug("☑️ getStorage");
|
|
15
16
|
names = [names].flat(Number.POSITIVE_INFINITY);
|
|
16
|
-
//Console.log("☑️ getStorage");
|
|
17
17
|
/***************** Default *****************/
|
|
18
18
|
const Store = { Settings: database?.Default?.Settings || {}, Configs: database?.Default?.Configs || {}, Caches: {} };
|
|
19
|
-
|
|
20
|
-
/***************** Database *****************/
|
|
21
|
-
names.forEach(name => {
|
|
22
|
-
_.merge(Store.Settings, database?.[name]?.Settings);
|
|
23
|
-
_.merge(Store.Configs, database?.[name]?.Configs);
|
|
24
|
-
});
|
|
25
|
-
//Console.debug("Database", `Store.Settings类型: ${typeof Store.Settings}`, `Store.Settings: ${JSON.stringify(Store.Settings)}`);
|
|
19
|
+
Console.debug("Default", `Store.Settings类型: ${typeof Store.Settings}`, `Store.Settings: ${JSON.stringify(Store.Settings)}`);
|
|
26
20
|
/***************** Argument *****************/
|
|
21
|
+
Console.debug(`☑️ $argument`);
|
|
22
|
+
const argument = {};
|
|
27
23
|
switch (typeof $argument) {
|
|
28
24
|
// biome-ignore lint/suspicious/noFallthroughSwitchClause: <explanation>
|
|
29
25
|
case "string":
|
|
30
26
|
$argument = Object.fromEntries($argument.split("&").map(item => item.split("=", 2).map(i => i.replace(/\"/g, ""))));
|
|
31
|
-
case "object":
|
|
32
|
-
const argument = {};
|
|
27
|
+
case "object":
|
|
33
28
|
Object.keys($argument).forEach(key => _.set(argument, key, $argument[key]));
|
|
34
|
-
//Console.debug(`✅ $argument`, `argument: ${JSON.stringify(argument)}`);
|
|
35
|
-
_.merge(Store.Settings, argument);
|
|
36
29
|
break;
|
|
37
|
-
}
|
|
38
30
|
case "undefined":
|
|
39
31
|
break;
|
|
40
32
|
}
|
|
41
|
-
|
|
33
|
+
if (argument.LogLevel) Console.logLevel = argument.LogLevel;
|
|
34
|
+
Console.debug(`✅ $argument`, `argument: ${JSON.stringify(argument)}`);
|
|
42
35
|
/***************** BoxJs *****************/
|
|
43
36
|
// 包装为局部变量,用完释放内存
|
|
44
37
|
// BoxJs的清空操作返回假值空字符串, 逻辑或操作符会在左侧操作数为假值时返回右侧操作数。
|
|
45
38
|
const BoxJs = Storage.getItem(key);
|
|
46
39
|
if (BoxJs) {
|
|
47
|
-
Console.debug("BoxJs", `BoxJs类型: ${typeof BoxJs}`, `BoxJs内容: ${JSON.stringify(BoxJs || {})}`);
|
|
40
|
+
Console.debug("☑️ BoxJs", `BoxJs类型: ${typeof BoxJs}`, `BoxJs内容: ${JSON.stringify(BoxJs || {})}`);
|
|
48
41
|
names.forEach(name => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
case "string":
|
|
52
|
-
BoxJs[name].Settings = JSON.parse(BoxJs[name].Settings || "{}");
|
|
53
|
-
case "object":
|
|
54
|
-
_.merge(Store.Settings, BoxJs[name].Settings);
|
|
55
|
-
break;
|
|
56
|
-
case "undefined":
|
|
57
|
-
break;
|
|
42
|
+
if (typeof BoxJs?.[name]?.Settings === "string") {
|
|
43
|
+
BoxJs[name].Settings = JSON.parse(BoxJs[name].Settings || "{}");
|
|
58
44
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
case "string":
|
|
62
|
-
BoxJs[name].Caches = JSON.parse(BoxJs[name].Caches || "{}");
|
|
63
|
-
case "object":
|
|
64
|
-
_.merge(Store.Caches, BoxJs[name].Caches);
|
|
65
|
-
break;
|
|
66
|
-
case "undefined":
|
|
67
|
-
break;
|
|
45
|
+
if (typeof BoxJs?.[name]?.Caches === "string") {
|
|
46
|
+
BoxJs[name].Caches = JSON.parse(BoxJs[name].Caches || "{}");
|
|
68
47
|
}
|
|
69
48
|
});
|
|
70
|
-
|
|
49
|
+
if (BoxJs.LogLevel) Console.logLevel = BoxJs.LogLevel;
|
|
50
|
+
Console.debug("✅ BoxJs", `Store.Settings类型: ${typeof Store.Settings}`, `Store.Settings: ${JSON.stringify(Store.Settings)}`);
|
|
71
51
|
}
|
|
52
|
+
/***************** Merge *****************/
|
|
53
|
+
names.forEach(name => {
|
|
54
|
+
_.merge(Store.Settings, database?.[name]?.Settings, BoxJs?.[name]?.Settings);
|
|
55
|
+
_.merge(Store.Configs, database?.[name]?.Configs);
|
|
56
|
+
_.merge(Store.Caches, BoxJs?.[name]?.Caches);
|
|
57
|
+
});
|
|
58
|
+
_.merge(Store.Settings, argument);
|
|
59
|
+
if (Store.Settings.LogLevel) Console.logLevel = Store.Settings.LogLevel;
|
|
60
|
+
Console.debug("✅ Merge", `Store.Settings类型: ${typeof Store.Settings}`, `Store.Settings: ${JSON.stringify(Store.Settings)}`);
|
|
72
61
|
/***************** traverseObject *****************/
|
|
73
62
|
traverseObject(Store.Settings, (key, value) => {
|
|
74
|
-
|
|
63
|
+
Console.debug("☑️ traverseObject", `${key}: ${typeof value}`, `${key}: ${JSON.stringify(value)}`);
|
|
75
64
|
if (value === "true" || value === "false")
|
|
76
65
|
value = JSON.parse(value); // 字符串转Boolean
|
|
77
66
|
else if (typeof value === "string") {
|
|
@@ -82,6 +71,7 @@ export function getStorage(key, names, database) {
|
|
|
82
71
|
return value;
|
|
83
72
|
});
|
|
84
73
|
Console.debug("✅ traverseObject", `Store.Settings类型: ${typeof Store.Settings}`, `Store.Settings: ${JSON.stringify(Store.Settings)}`);
|
|
74
|
+
Console.debug("✅ getStorage");
|
|
85
75
|
return Store;
|
|
86
76
|
}
|
|
87
77
|
|
package/package.json
CHANGED