@nsnanocat/util 1.7.6 → 1.8.0
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/lib/notification.mjs +6 -3
- package/package.json +1 -1
- package/polyfill/Lodash.mjs +35 -23
package/lib/notification.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import { Console } from "../polyfill/Console.mjs";
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
export function notification(title = `ℹ️ ${$app} 通知`, subtitle = "", body = "", content = {}) {
|
|
21
|
+
const mutableContent = MutableContent(content);
|
|
21
22
|
switch ($app) {
|
|
22
23
|
case "Surge":
|
|
23
24
|
case "Loon":
|
|
@@ -25,15 +26,17 @@ export function notification(title = `ℹ️ ${$app} 通知`, subtitle = "", bod
|
|
|
25
26
|
case "Egern":
|
|
26
27
|
case "Shadowrocket":
|
|
27
28
|
default:
|
|
28
|
-
$notification.post(title, subtitle, body,
|
|
29
|
+
$notification.post(title, subtitle, body, mutableContent);
|
|
29
30
|
break;
|
|
30
31
|
case "Quantumult X":
|
|
31
|
-
$notify(title, subtitle, body,
|
|
32
|
+
$notify(title, subtitle, body, mutableContent);
|
|
32
33
|
break;
|
|
33
34
|
case "Node.js":
|
|
34
35
|
break;
|
|
35
36
|
}
|
|
36
|
-
Console.
|
|
37
|
+
Console.group("📣 系统通知");
|
|
38
|
+
Console.log(title, subtitle, body, JSON.stringify(mutableContent, null, 2));
|
|
39
|
+
Console.groupEnd();
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
const MutableContent = content => {
|
package/package.json
CHANGED
package/polyfill/Lodash.mjs
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
/* https://www.lodashjs.com */
|
|
2
2
|
export class Lodash {
|
|
3
|
+
static escape(string) {
|
|
4
|
+
const map = {
|
|
5
|
+
"&": "&",
|
|
6
|
+
"<": "<",
|
|
7
|
+
">": ">",
|
|
8
|
+
'"': """,
|
|
9
|
+
"'": "'",
|
|
10
|
+
};
|
|
11
|
+
return string.replace(/[&<>"']/g, m => map[m]);
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
static get(object = {}, path = "", defaultValue = undefined) {
|
|
4
15
|
// translate array case to dot case, then split with .
|
|
5
16
|
// a[0].b -> a.0.b -> ['a', '0', 'b']
|
|
@@ -11,22 +22,22 @@ export class Lodash {
|
|
|
11
22
|
return result === undefined ? defaultValue : result;
|
|
12
23
|
}
|
|
13
24
|
|
|
14
|
-
static
|
|
15
|
-
if (!Array.isArray(
|
|
16
|
-
|
|
25
|
+
static omit(object = {}, paths = []) {
|
|
26
|
+
if (!Array.isArray(paths)) paths = [paths.toString()];
|
|
27
|
+
paths.forEach(path => Lodash.unset(object, path));
|
|
17
28
|
return object;
|
|
18
29
|
}
|
|
19
30
|
|
|
20
|
-
static
|
|
31
|
+
static pick(object = {}, paths = []) {
|
|
32
|
+
if (!Array.isArray(paths)) paths = [paths.toString()];
|
|
33
|
+
const filteredEntries = Object.entries(object).filter(([key, value]) => paths.includes(key));
|
|
34
|
+
return Object.fromEntries(filteredEntries);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static set(object, path, value) {
|
|
21
38
|
if (!Array.isArray(path)) path = Lodash.toPath(path);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
delete previousValue[currentValue];
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
return Object(previousValue)[currentValue];
|
|
28
|
-
}, object);
|
|
29
|
-
return result;
|
|
39
|
+
path.slice(0, -1).reduce((previousValue, currentValue, currentIndex) => (Object(previousValue[currentValue]) === previousValue[currentValue] ? previousValue[currentValue] : (previousValue[currentValue] = /^\d+$/.test(path[currentIndex + 1]) ? [] : {})), object)[path[path.length - 1]] = value;
|
|
40
|
+
return object;
|
|
30
41
|
}
|
|
31
42
|
|
|
32
43
|
static toPath(value) {
|
|
@@ -36,17 +47,6 @@ export class Lodash {
|
|
|
36
47
|
.filter(Boolean);
|
|
37
48
|
}
|
|
38
49
|
|
|
39
|
-
static escape(string) {
|
|
40
|
-
const map = {
|
|
41
|
-
"&": "&",
|
|
42
|
-
"<": "<",
|
|
43
|
-
">": ">",
|
|
44
|
-
'"': """,
|
|
45
|
-
"'": "'",
|
|
46
|
-
};
|
|
47
|
-
return string.replace(/[&<>"']/g, m => map[m]);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
50
|
static unescape(string) {
|
|
51
51
|
const map = {
|
|
52
52
|
"&": "&",
|
|
@@ -57,4 +57,16 @@ export class Lodash {
|
|
|
57
57
|
};
|
|
58
58
|
return string.replace(/&|<|>|"|'/g, m => map[m]);
|
|
59
59
|
}
|
|
60
|
+
|
|
61
|
+
static unset(object = {}, path = "") {
|
|
62
|
+
if (!Array.isArray(path)) path = Lodash.toPath(path);
|
|
63
|
+
const result = path.reduce((previousValue, currentValue, currentIndex) => {
|
|
64
|
+
if (currentIndex === path.length - 1) {
|
|
65
|
+
delete previousValue[currentValue];
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return Object(previousValue)[currentValue];
|
|
69
|
+
}, object);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
60
72
|
}
|