@nsnanocat/util 2.1.4 → 2.1.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/README.md +1 -1
- package/getStorage.mjs +4 -1
- package/package.json +4 -2
- package/types/nsnanocat-util.d.ts +134 -0
package/README.md
CHANGED
|
@@ -331,7 +331,7 @@ await runScript("$done({})", { timeout: 20 });
|
|
|
331
331
|
|
|
332
332
|
示例:
|
|
333
333
|
```js
|
|
334
|
-
import
|
|
334
|
+
import getStorage from "@nsnanocat/util/getStorage.mjs";
|
|
335
335
|
|
|
336
336
|
const store = getStorage("@my_box", ["YouTube", "Global"], database);
|
|
337
337
|
```
|
package/getStorage.mjs
CHANGED
|
@@ -36,8 +36,11 @@ import { Storage } from "./polyfill/Storage.mjs";
|
|
|
36
36
|
* @param {string|string[]|Array<string|string[]>} names 目标配置名 / Target profile names.
|
|
37
37
|
* @param {Record<string, any>} database 默认数据库 / Default database object.
|
|
38
38
|
* @returns {StorageProfile}
|
|
39
|
+
*
|
|
40
|
+
* @module getStorage
|
|
41
|
+
* @default
|
|
39
42
|
*/
|
|
40
|
-
export function getStorage(key, names, database) {
|
|
43
|
+
export default function getStorage(key, names, database) {
|
|
41
44
|
if (database?.Default?.Settings?.LogLevel) Console.logLevel = database.Default.Settings.LogLevel;
|
|
42
45
|
Console.debug("☑️ getStorage");
|
|
43
46
|
names = [names].flat(Number.POSITIVE_INFINITY);
|
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"bugs": "https://github.com/NSNanoCat/util/issues",
|
|
16
16
|
"main": "index.js",
|
|
17
|
+
"types": "types/nsnanocat-util.d.ts",
|
|
17
18
|
"type": "module",
|
|
18
19
|
"scripts": {
|
|
19
20
|
"tsc:build": "npx tsc",
|
|
@@ -30,7 +31,8 @@
|
|
|
30
31
|
"index.js",
|
|
31
32
|
"lib",
|
|
32
33
|
"polyfill",
|
|
33
|
-
"getStorage.mjs"
|
|
34
|
+
"getStorage.mjs",
|
|
35
|
+
"types"
|
|
34
36
|
],
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"typescript": "^5.6.3"
|
|
@@ -39,5 +41,5 @@
|
|
|
39
41
|
"registry": "https://registry.npmjs.org/",
|
|
40
42
|
"access": "public"
|
|
41
43
|
},
|
|
42
|
-
"version": "2.1.
|
|
44
|
+
"version": "2.1.5"
|
|
43
45
|
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
declare module "@nsnanocat/util" {
|
|
2
|
+
export type AppName = "Quantumult X" | "Loon" | "Shadowrocket" | "Node.js" | "Egern" | "Surge" | "Stash";
|
|
3
|
+
|
|
4
|
+
export const $app: AppName | undefined;
|
|
5
|
+
export const $argument: Record<string, unknown>;
|
|
6
|
+
export const argument: typeof $argument;
|
|
7
|
+
|
|
8
|
+
export interface DonePayload {
|
|
9
|
+
status?: number | string;
|
|
10
|
+
url?: string;
|
|
11
|
+
headers?: Record<string, unknown>;
|
|
12
|
+
body?: string | ArrayBuffer | ArrayBufferView;
|
|
13
|
+
bodyBytes?: ArrayBuffer;
|
|
14
|
+
policy?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function done(object?: DonePayload): void;
|
|
18
|
+
|
|
19
|
+
export interface NotificationContentObject {
|
|
20
|
+
open?: string;
|
|
21
|
+
"open-url"?: string;
|
|
22
|
+
url?: string;
|
|
23
|
+
openUrl?: string;
|
|
24
|
+
copy?: string;
|
|
25
|
+
"update-pasteboard"?: string;
|
|
26
|
+
updatePasteboard?: string;
|
|
27
|
+
media?: string;
|
|
28
|
+
"media-url"?: string;
|
|
29
|
+
mediaUrl?: string;
|
|
30
|
+
mime?: string;
|
|
31
|
+
"auto-dismiss"?: number;
|
|
32
|
+
sound?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type NotificationContent = NotificationContentObject | string | number | boolean;
|
|
36
|
+
|
|
37
|
+
export function notification(
|
|
38
|
+
title?: string,
|
|
39
|
+
subtitle?: string,
|
|
40
|
+
body?: string,
|
|
41
|
+
content?: NotificationContent,
|
|
42
|
+
): void;
|
|
43
|
+
|
|
44
|
+
export function time(format: string, ts?: number): string;
|
|
45
|
+
export function wait(delay?: number): Promise<void>;
|
|
46
|
+
|
|
47
|
+
export interface FetchRequest {
|
|
48
|
+
url: string;
|
|
49
|
+
method?: string;
|
|
50
|
+
headers?: Record<string, unknown>;
|
|
51
|
+
body?: string | ArrayBuffer | ArrayBufferView | object;
|
|
52
|
+
bodyBytes?: ArrayBuffer;
|
|
53
|
+
timeout?: number | string;
|
|
54
|
+
policy?: string;
|
|
55
|
+
redirection?: boolean;
|
|
56
|
+
"auto-redirect"?: boolean;
|
|
57
|
+
opts?: Record<string, unknown>;
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface FetchResponse {
|
|
62
|
+
ok: boolean;
|
|
63
|
+
status: number;
|
|
64
|
+
statusCode?: number;
|
|
65
|
+
statusText?: string;
|
|
66
|
+
headers?: Record<string, unknown>;
|
|
67
|
+
body?: string | ArrayBuffer;
|
|
68
|
+
bodyBytes?: ArrayBuffer;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function fetch(resource: FetchRequest | string, options?: Partial<FetchRequest>): Promise<FetchResponse>;
|
|
73
|
+
|
|
74
|
+
export class Console {
|
|
75
|
+
static clear(): void;
|
|
76
|
+
static count(label?: string): void;
|
|
77
|
+
static countReset(label?: string): void;
|
|
78
|
+
static debug(...msg: unknown[]): void;
|
|
79
|
+
static error(...msg: unknown[]): void;
|
|
80
|
+
static exception(...msg: unknown[]): void;
|
|
81
|
+
static group(label: string): number;
|
|
82
|
+
static groupEnd(): string | undefined;
|
|
83
|
+
static info(...msg: unknown[]): void;
|
|
84
|
+
static get logLevel(): "OFF" | "ERROR" | "WARN" | "INFO" | "DEBUG" | "ALL";
|
|
85
|
+
static set logLevel(level: number | string);
|
|
86
|
+
static log(...msg: unknown[]): void;
|
|
87
|
+
static time(label?: string): Map<string, number>;
|
|
88
|
+
static timeEnd(label?: string): boolean;
|
|
89
|
+
static timeLog(label?: string): void;
|
|
90
|
+
static warn(...msg: unknown[]): void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class Lodash {
|
|
94
|
+
static escape(string: string): string;
|
|
95
|
+
static get<T = unknown, D = undefined>(object?: Record<string, unknown>, path?: string | string[], defaultValue?: D): T | D;
|
|
96
|
+
static merge<T extends Record<string, unknown>>(object: T, ...sources: Array<Record<string, unknown> | null | undefined>): T;
|
|
97
|
+
static omit<T extends Record<string, unknown>>(object?: T, paths?: string | string[]): T;
|
|
98
|
+
static pick<T extends Record<string, unknown>, K extends keyof T>(object?: T, paths?: K | K[]): Pick<T, K>;
|
|
99
|
+
static set<T extends Record<string, unknown>>(object: T, path: string | string[], value: unknown): T;
|
|
100
|
+
static toPath(value: string): string[];
|
|
101
|
+
static unescape(string: string): string;
|
|
102
|
+
static unset(object?: Record<string, unknown>, path?: string | string[]): boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const StatusTexts: Record<number, string>;
|
|
106
|
+
|
|
107
|
+
export class Storage {
|
|
108
|
+
static data: Record<string, unknown> | null;
|
|
109
|
+
static dataFile: string;
|
|
110
|
+
static getItem<T = unknown>(keyName: string, defaultValue?: T): T;
|
|
111
|
+
static setItem(keyName: string, keyValue: unknown): boolean;
|
|
112
|
+
static removeItem(keyName: string): boolean;
|
|
113
|
+
static clear(): boolean;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
declare module "@nsnanocat/util/getStorage.mjs" {
|
|
118
|
+
export interface StorageProfile {
|
|
119
|
+
Settings: Record<string, unknown>;
|
|
120
|
+
Configs: Record<string, unknown>;
|
|
121
|
+
Caches: Record<string, unknown>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export default function getStorage(
|
|
125
|
+
key: string,
|
|
126
|
+
names: string | string[] | Array<string | string[]>,
|
|
127
|
+
database: Record<string, unknown>,
|
|
128
|
+
): StorageProfile;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
declare module "@nsnanocat/util/lib/environment.mjs" {
|
|
132
|
+
export const $environment: Record<string, unknown>;
|
|
133
|
+
export function environment(): Record<string, unknown>;
|
|
134
|
+
}
|