@nsnanocat/util 2.6.7 → 2.6.9
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/README.md +6 -1
- package/lib/notification.mjs +3 -2
- package/package.json +1 -1
- package/polyfill/Console.d.ts +5 -0
- package/polyfill/Console.mjs +6 -0
- package/polyfill/qs.mjs +23 -1
package/README.md
CHANGED
|
@@ -655,9 +655,11 @@ console.log(value); // 1
|
|
|
655
655
|
|
|
656
656
|
当前行为:
|
|
657
657
|
- 当 `query` 为 `string` 时:
|
|
658
|
+
- 支持前导 `?`(会先去掉)。
|
|
658
659
|
- 按 `&` / `=` 切分。
|
|
660
|
+
- key 与 value 都会先执行 URL 解码(`decodeURIComponent`,并将 `+` 视为空格)。
|
|
659
661
|
- 去掉值中的双引号。
|
|
660
|
-
-
|
|
662
|
+
- 支持点路径、数组下标路径,以及方括号 key(如 `a[b]`)展开对象。
|
|
661
663
|
- 当 `query` 为 `object` 时:
|
|
662
664
|
- 将 key 当路径写入新对象(`{"a.b":"1"}` -> `{ a: { b: "1" } }`)。
|
|
663
665
|
- 当 `query` 为 `null` 或 `undefined` 时:
|
|
@@ -669,6 +671,9 @@ import { qs } from "@nsnanocat/util";
|
|
|
669
671
|
console.log(qs.parse("mode=on&a.b=1"));
|
|
670
672
|
// { mode: "on", a: { b: "1" } }
|
|
671
673
|
|
|
674
|
+
console.log(qs.parse("a%5Bb%5D=c%20d"));
|
|
675
|
+
// { a: { b: "c d" } }
|
|
676
|
+
|
|
672
677
|
console.log(qs.parse({ "list[0]": "x", "list[1]": "y" }));
|
|
673
678
|
// { list: ["x", "y"] }
|
|
674
679
|
```
|
package/lib/notification.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $app } from "./app.mjs";
|
|
2
1
|
import { Console } from "../polyfill/Console.mjs";
|
|
2
|
+
import { $app } from "./app.mjs";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 通知内容扩展参数。
|
|
@@ -42,6 +42,7 @@ import { Console } from "../polyfill/Console.mjs";
|
|
|
42
42
|
*/
|
|
43
43
|
export function notification(title = `ℹ️ ${$app} 通知`, subtitle = "", body = "", content = {}) {
|
|
44
44
|
const mutableContent = MutableContent(content);
|
|
45
|
+
const bodyLines = body.split(/\r?\n/u);
|
|
45
46
|
switch ($app) {
|
|
46
47
|
case "Surge":
|
|
47
48
|
case "Loon":
|
|
@@ -59,7 +60,7 @@ export function notification(title = `ℹ️ ${$app} 通知`, subtitle = "", bod
|
|
|
59
60
|
break;
|
|
60
61
|
}
|
|
61
62
|
Console.group("📣 系统通知");
|
|
62
|
-
Console.log(title, subtitle,
|
|
63
|
+
Console.log(title, subtitle, bodyLines, JSON.stringify(mutableContent, null, 2));
|
|
63
64
|
Console.groupEnd();
|
|
64
65
|
}
|
|
65
66
|
|
package/package.json
CHANGED
package/polyfill/Console.d.ts
CHANGED
|
@@ -92,6 +92,11 @@ export class Console {
|
|
|
92
92
|
* 输出普通日志。
|
|
93
93
|
* Print standard log messages.
|
|
94
94
|
*
|
|
95
|
+
* 说明:
|
|
96
|
+
* Notes:
|
|
97
|
+
* - 顶层数组参数会按多个独立日志项展开。
|
|
98
|
+
* - Top-level array arguments are expanded into multiple log entries.
|
|
99
|
+
*
|
|
95
100
|
* @param msg 日志内容 / Log payloads.
|
|
96
101
|
*/
|
|
97
102
|
static log(...msg: unknown[]): void;
|
package/polyfill/Console.mjs
CHANGED
|
@@ -224,11 +224,17 @@ export class Console {
|
|
|
224
224
|
* 输出通用日志。
|
|
225
225
|
* Print generic logs.
|
|
226
226
|
*
|
|
227
|
+
* 说明:
|
|
228
|
+
* Notes:
|
|
229
|
+
* - 顶层数组参数会按多个独立日志项展开。
|
|
230
|
+
* - Top-level array arguments are expanded into multiple log entries.
|
|
231
|
+
*
|
|
227
232
|
* @param {...any} msg 日志内容 / Log messages.
|
|
228
233
|
* @returns {void}
|
|
229
234
|
*/
|
|
230
235
|
static log = (...msg) => {
|
|
231
236
|
if (Console.#level === 0) return;
|
|
237
|
+
msg = msg.flatMap(log => (Array.isArray(log) ? log : [log]));
|
|
232
238
|
msg = msg.map(log => {
|
|
233
239
|
switch (typeof log) {
|
|
234
240
|
case "object":
|
package/polyfill/qs.mjs
CHANGED
|
@@ -31,7 +31,18 @@ export class qs {
|
|
|
31
31
|
let result = {};
|
|
32
32
|
switch (typeof query) {
|
|
33
33
|
case "string": {
|
|
34
|
-
const
|
|
34
|
+
const source = query.replace(/^\?/, "");
|
|
35
|
+
if (!source) break;
|
|
36
|
+
const obj = Object.fromEntries(
|
|
37
|
+
source
|
|
38
|
+
.split("&")
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.map(item => {
|
|
41
|
+
const [rawKey = "", rawValue = ""] = item.split("=", 2);
|
|
42
|
+
const key = qs.#decode(rawKey).replace(/\[([^\[\]]+)\]/g, ".$1");
|
|
43
|
+
return [key, qs.#decode(rawValue).replace(/\"/g, "")];
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
35
46
|
Object.keys(obj).forEach(key => _.set(result, key, obj[key]));
|
|
36
47
|
break;
|
|
37
48
|
}
|
|
@@ -139,4 +150,15 @@ export class qs {
|
|
|
139
150
|
static #encode(value) {
|
|
140
151
|
return encodeURIComponent(value);
|
|
141
152
|
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 解码查询字符串片段。
|
|
156
|
+
* Decode a query-string fragment.
|
|
157
|
+
*
|
|
158
|
+
* @param {string} value 编码值 / Encoded value.
|
|
159
|
+
* @returns {string}
|
|
160
|
+
*/
|
|
161
|
+
static #decode(value) {
|
|
162
|
+
return decodeURIComponent(value.replace(/\+/g, " "));
|
|
163
|
+
}
|
|
142
164
|
}
|