@nsnanocat/util 2.5.1 → 2.5.3

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/package.json CHANGED
@@ -15,7 +15,6 @@
15
15
  "bugs": "https://github.com/NSNanoCat/util/issues",
16
16
  "main": "index.js",
17
17
  "types": "types/nsnanocat-util.d.ts",
18
- "type": "module",
19
18
  "scripts": {
20
19
  "tsc:build": "npx tsc",
21
20
  "test": "node --test test/*.test.js",
@@ -42,5 +41,5 @@
42
41
  "registry": "https://registry.npmjs.org/",
43
42
  "access": "public"
44
43
  },
45
- "version": "2.5.1"
44
+ "version": "2.5.3"
46
45
  }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * 跨平台控制台输出适配器。
3
+ * Cross-platform console output adapter.
4
+ */
5
+ export class Console {
6
+ /**
7
+ * 清空控制台输出。
8
+ * Clear the console output.
9
+ */
10
+ static clear(): void;
11
+
12
+ /**
13
+ * 增加指定标签的计数。
14
+ * Increment the counter for the given label.
15
+ *
16
+ * @param label 计数标签 / Counter label.
17
+ */
18
+ static count(label?: string): void;
19
+
20
+ /**
21
+ * 重置指定标签的计数。
22
+ * Reset the counter for the given label.
23
+ *
24
+ * @param label 计数标签 / Counter label.
25
+ */
26
+ static countReset(label?: string): void;
27
+
28
+ /**
29
+ * 输出调试级别日志。
30
+ * Print debug-level log messages.
31
+ *
32
+ * @param msg 日志内容 / Log payloads.
33
+ */
34
+ static debug(...msg: unknown[]): void;
35
+
36
+ /**
37
+ * 输出错误级别日志。
38
+ * Print error-level log messages.
39
+ *
40
+ * @param msg 日志内容 / Log payloads.
41
+ */
42
+ static error(...msg: unknown[]): void;
43
+
44
+ /**
45
+ * 输出异常级别日志。
46
+ * Print exception-level log messages.
47
+ *
48
+ * @param msg 日志内容 / Log payloads.
49
+ */
50
+ static exception(...msg: unknown[]): void;
51
+
52
+ /**
53
+ * 开始一个日志分组。
54
+ * Start a log group.
55
+ *
56
+ * @param label 分组标签 / Group label.
57
+ * @returns 当前分组深度 / Current group depth.
58
+ */
59
+ static group(label: string): number;
60
+
61
+ /**
62
+ * 结束当前日志分组。
63
+ * End the current log group.
64
+ *
65
+ * @returns 已结束的分组标签 / Closed group label.
66
+ */
67
+ static groupEnd(): string | undefined;
68
+
69
+ /**
70
+ * 输出信息级别日志。
71
+ * Print info-level log messages.
72
+ *
73
+ * @param msg 日志内容 / Log payloads.
74
+ */
75
+ static info(...msg: unknown[]): void;
76
+
77
+ /**
78
+ * 获取当前日志级别。
79
+ * Get the current log level.
80
+ */
81
+ static get logLevel(): "OFF" | "ERROR" | "WARN" | "INFO" | "DEBUG" | "ALL";
82
+
83
+ /**
84
+ * 设置日志级别。
85
+ * Set the current log level.
86
+ *
87
+ * @param level 日志级别 / Log level.
88
+ */
89
+ static set logLevel(level: number | string);
90
+
91
+ /**
92
+ * 输出普通日志。
93
+ * Print standard log messages.
94
+ *
95
+ * @param msg 日志内容 / Log payloads.
96
+ */
97
+ static log(...msg: unknown[]): void;
98
+
99
+ /**
100
+ * 启动计时器。
101
+ * Start a timer.
102
+ *
103
+ * @param label 计时器标签 / Timer label.
104
+ * @returns 计时器映射表 / Timer map.
105
+ */
106
+ static time(label?: string): Map<string, number>;
107
+
108
+ /**
109
+ * 结束计时器并返回是否成功结束。
110
+ * End a timer and return whether it was closed.
111
+ *
112
+ * @param label 计时器标签 / Timer label.
113
+ * @returns 是否成功结束 / Whether the timer was closed.
114
+ */
115
+ static timeEnd(label?: string): boolean;
116
+
117
+ /**
118
+ * 输出计时器当前耗时。
119
+ * Print current elapsed time for a timer.
120
+ *
121
+ * @param label 计时器标签 / Timer label.
122
+ */
123
+ static timeLog(label?: string): void;
124
+
125
+ /**
126
+ * 输出警告级别日志。
127
+ * Print warn-level log messages.
128
+ *
129
+ * @param msg 日志内容 / Log payloads.
130
+ */
131
+ static warn(...msg: unknown[]): void;
132
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * 轻量 Lodash 风格工具集。
3
+ * Lightweight Lodash-style utility helpers.
4
+ */
5
+ export class Lodash {
6
+ /**
7
+ * 对 HTML 字符进行转义。
8
+ * Escape HTML characters.
9
+ *
10
+ * @param string 输入字符串 / Input string.
11
+ * @returns 转义后的字符串 / Escaped string.
12
+ */
13
+ static escape(string: string): string;
14
+
15
+ /**
16
+ * 读取对象中的嵌套路径值。
17
+ * Read a nested value from an object path.
18
+ *
19
+ * @param object 目标对象 / Target object.
20
+ * @param path 路径表达式 / Path expression.
21
+ * @param defaultValue 默认值 / Default value.
22
+ * @returns 路径值或默认值 / Path value or default.
23
+ */
24
+ static get<T = unknown, D = undefined>(object?: Record<string, unknown>, path?: string | string[], defaultValue?: D): T | D;
25
+
26
+ /**
27
+ * 深度合并对象。
28
+ * Deep-merge objects.
29
+ *
30
+ * @param object 目标对象 / Target object.
31
+ * @param sources 源对象列表 / Source objects.
32
+ * @returns 合并后的目标对象 / Merged target object.
33
+ */
34
+ static merge<T extends Record<string, unknown>>(object: T, ...sources: Array<Record<string, unknown> | null | undefined>): T;
35
+
36
+ /**
37
+ * 返回排除指定路径后的对象副本。
38
+ * Return a copy without specific paths.
39
+ *
40
+ * @param object 目标对象 / Target object.
41
+ * @param paths 排除路径 / Paths to omit.
42
+ * @returns 排除后的对象 / Object without omitted paths.
43
+ */
44
+ static omit<T extends Record<string, unknown>>(object?: T, paths?: string | string[]): T;
45
+
46
+ /**
47
+ * 返回仅包含指定路径的对象副本。
48
+ * Return a copy with only selected paths.
49
+ *
50
+ * @param object 目标对象 / Target object.
51
+ * @param paths 选择路径 / Paths to pick.
52
+ * @returns 仅保留指定路径的对象 / Object containing picked paths.
53
+ */
54
+ static pick<T extends Record<string, unknown>, K extends keyof T>(object?: T, paths?: K | K[]): Pick<T, K>;
55
+
56
+ /**
57
+ * 写入对象中的嵌套路径值。
58
+ * Set a nested value by path.
59
+ *
60
+ * @param object 目标对象 / Target object.
61
+ * @param path 路径表达式 / Path expression.
62
+ * @param value 写入值 / Value to set.
63
+ * @returns 修改后的目标对象 / Mutated target object.
64
+ */
65
+ static set<T extends Record<string, unknown>>(object: T, path: string | string[], value: unknown): T;
66
+
67
+ /**
68
+ * 将路径字符串转换为路径数组。
69
+ * Convert a path string to path segments.
70
+ *
71
+ * @param value 路径字符串 / Path string.
72
+ * @returns 路径数组 / Path segments.
73
+ */
74
+ static toPath(value: string): string[];
75
+
76
+ /**
77
+ * 还原 HTML 转义字符。
78
+ * Unescape HTML entities.
79
+ *
80
+ * @param string 输入字符串 / Input string.
81
+ * @returns 还原后的字符串 / Unescaped string.
82
+ */
83
+ static unescape(string: string): string;
84
+
85
+ /**
86
+ * 删除对象中的嵌套路径值。
87
+ * Delete a nested value by path.
88
+ *
89
+ * @param object 目标对象 / Target object.
90
+ * @param path 路径表达式 / Path expression.
91
+ * @returns 是否删除成功 / Whether deletion succeeded.
92
+ */
93
+ static unset(object?: Record<string, unknown>, path?: string | string[]): boolean;
94
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * HTTP 状态码文案映射表。
3
+ * HTTP status code text map.
4
+ */
5
+ export const StatusTexts: Record<number, string>;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * 跨平台持久化存储适配器。
3
+ * Cross-platform persistent storage adapter.
4
+ */
5
+ export class Storage {
6
+ /**
7
+ * 运行时缓存的数据对象。
8
+ * Runtime cached data object.
9
+ */
10
+ static data: Record<string, unknown> | null;
11
+
12
+ /**
13
+ * Node.js 分支持久化文件名。
14
+ * Persistent filename for Node.js branch.
15
+ */
16
+ static dataFile: string;
17
+
18
+ /**
19
+ * 读取指定键值。
20
+ * Read a value by key.
21
+ *
22
+ * @param keyName 键名 / Key name.
23
+ * @param defaultValue 默认值 / Default value.
24
+ * @returns 读取结果 / Read value.
25
+ */
26
+ static getItem<T = unknown>(keyName: string, defaultValue?: T): T;
27
+
28
+ /**
29
+ * 写入指定键值。
30
+ * Write a value by key.
31
+ *
32
+ * @param keyName 键名 / Key name.
33
+ * @param keyValue 写入值 / Value to write.
34
+ * @returns 是否写入成功 / Whether write succeeded.
35
+ */
36
+ static setItem(keyName: string, keyValue: unknown): boolean;
37
+
38
+ /**
39
+ * 删除指定键。
40
+ * Remove a value by key.
41
+ *
42
+ * @param keyName 键名 / Key name.
43
+ * @returns 是否删除成功 / Whether removal succeeded.
44
+ */
45
+ static removeItem(keyName: string): boolean;
46
+
47
+ /**
48
+ * 清空存储。
49
+ * Clear the storage.
50
+ *
51
+ * @returns 是否清空成功 / Whether clear succeeded.
52
+ */
53
+ static clear(): boolean;
54
+ }
@@ -33,11 +33,13 @@ export interface FetchResponse {
33
33
  }
34
34
 
35
35
  /**
36
- * 跨平台 `fetch` 适配层。
37
- * Cross-platform `fetch` adapter.
36
+ * 跨平台 `fetch` 函数签名。
37
+ * Cross-platform `fetch` function signature.
38
38
  *
39
39
  * @param resource 请求对象或 URL / Request object or URL string.
40
40
  * @param options 追加参数 / Extra options.
41
41
  * @returns 统一响应结构 / Normalized response payload.
42
42
  */
43
- export function fetch(resource: FetchRequest | string, options?: Partial<FetchRequest>): Promise<FetchResponse>;
43
+ export type Fetch = (resource: FetchRequest | string, options?: Partial<FetchRequest>) => Promise<FetchResponse>;
44
+
45
+ export const fetch: Fetch;
@@ -1,48 +1,6 @@
1
1
  import { fetch as fetchRuntime } from "./fetch.mjs";
2
+ import type { Fetch } from "./fetch.d.ts";
2
3
 
3
- /**
4
- * 统一请求参数。
5
- * Unified request payload.
6
- */
7
- export interface FetchRequest {
8
- url: string;
9
- method?: string;
10
- headers?: Record<string, unknown>;
11
- body?: string | ArrayBuffer | ArrayBufferView | object;
12
- bodyBytes?: ArrayBuffer;
13
- timeout?: number | string;
14
- policy?: string;
15
- redirection?: boolean;
16
- "auto-redirect"?: boolean;
17
- "auto-cookie"?: boolean | number | string;
18
- opts?: Record<string, unknown>;
19
- [key: string]: unknown;
20
- }
4
+ export type { Fetch, FetchRequest, FetchResponse } from "./fetch.d.ts";
21
5
 
22
- /**
23
- * 统一响应结构。
24
- * Unified response payload.
25
- */
26
- export interface FetchResponse {
27
- ok: boolean;
28
- status: number;
29
- statusCode?: number;
30
- statusText?: string;
31
- headers?: Record<string, unknown>;
32
- body?: string | ArrayBuffer;
33
- bodyBytes?: ArrayBuffer;
34
- [key: string]: unknown;
35
- }
36
-
37
- /**
38
- * 跨平台 `fetch` 适配层。
39
- * Cross-platform `fetch` adapter.
40
- *
41
- * @param resource 请求对象或 URL / Request object or URL string.
42
- * @param options 追加参数 / Extra options.
43
- * @returns 统一响应结构 / Normalized response payload.
44
- */
45
- export const fetch: (resource: FetchRequest | string, options?: Partial<FetchRequest>) => Promise<FetchResponse> = fetchRuntime as (
46
- resource: FetchRequest | string,
47
- options?: Partial<FetchRequest>,
48
- ) => Promise<FetchResponse>;
6
+ export const fetch: Fetch = fetchRuntime as Fetch;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Polyfill 模块聚合导出。
3
+ * Aggregated exports for polyfill modules.
4
+ */
5
+ export { Console } from "./Console.mjs";
6
+ export { fetch } from "./fetch.mjs";
7
+ export type { Fetch, FetchRequest, FetchResponse } from "./fetch.mjs";
8
+ export { Lodash } from "./Lodash.mjs";
9
+ export { qs } from "./qs.mjs";
10
+ export { StatusTexts } from "./StatusTexts.mjs";
11
+ export { Storage } from "./Storage.mjs";
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 查询字符串解析与序列化工具。
3
+ * Query string parser and serializer.
4
+ */
5
+ export class qs {
6
+ /**
7
+ * 将查询字符串或对象解析为规范对象。
8
+ * Parse a query string or object into a normalized object.
9
+ *
10
+ * @param query 查询输入 / Query input.
11
+ * @returns 解析结果对象 / Parsed object.
12
+ */
13
+ static parse(query?: string | Record<string, unknown> | null): Record<string, unknown>;
14
+
15
+ /**
16
+ * 将对象序列化为查询字符串。
17
+ * Serialize an object into a query string.
18
+ *
19
+ * @param object 输入对象 / Input object.
20
+ * @returns 序列化后的查询字符串 / Serialized query string.
21
+ */
22
+ static stringify(object?: Record<string, unknown>): string;
23
+ }
@@ -0,0 +1,7 @@
1
+ import type { Lodash as SharedLodash } from "../../polyfill/Lodash.d.ts";
2
+
3
+ declare module "@nsnanocat/util" {
4
+ export interface Lodash extends SharedLodash {}
5
+
6
+ export const Lodash: typeof import("../../polyfill/Lodash.d.ts").Lodash;
7
+ }
@@ -1,29 +1,9 @@
1
+ import type { Fetch as SharedFetch, FetchRequest as SharedFetchRequest, FetchResponse as SharedFetchResponse } from "../../polyfill/fetch.d.ts";
2
+
1
3
  declare module "@nsnanocat/util" {
2
- export interface FetchRequest {
3
- url: string;
4
- method?: string;
5
- headers?: Record<string, unknown>;
6
- body?: string | ArrayBuffer | ArrayBufferView | object;
7
- bodyBytes?: ArrayBuffer;
8
- timeout?: number | string;
9
- policy?: string;
10
- redirection?: boolean;
11
- "auto-redirect"?: boolean;
12
- "auto-cookie"?: boolean | number | string;
13
- opts?: Record<string, unknown>;
14
- [key: string]: unknown;
15
- }
4
+ export interface FetchRequest extends SharedFetchRequest {}
16
5
 
17
- export interface FetchResponse {
18
- ok: boolean;
19
- status: number;
20
- statusCode?: number;
21
- statusText?: string;
22
- headers?: Record<string, unknown>;
23
- body?: string | ArrayBuffer;
24
- bodyBytes?: ArrayBuffer;
25
- [key: string]: unknown;
26
- }
6
+ export interface FetchResponse extends SharedFetchResponse {}
27
7
 
28
- export function fetch(resource: FetchRequest | string, options?: Partial<FetchRequest>): Promise<FetchResponse>;
8
+ export const fetch: SharedFetch;
29
9
  }
@@ -1,40 +1,11 @@
1
- declare module "@nsnanocat/util" {
2
- export class Console {
3
- static clear(): void;
4
- static count(label?: string): void;
5
- static countReset(label?: string): void;
6
- static debug(...msg: unknown[]): void;
7
- static error(...msg: unknown[]): void;
8
- static exception(...msg: unknown[]): void;
9
- static group(label: string): number;
10
- static groupEnd(): string | undefined;
11
- static info(...msg: unknown[]): void;
12
- static get logLevel(): "OFF" | "ERROR" | "WARN" | "INFO" | "DEBUG" | "ALL";
13
- static set logLevel(level: number | string);
14
- static log(...msg: unknown[]): void;
15
- static time(label?: string): Map<string, number>;
16
- static timeEnd(label?: string): boolean;
17
- static timeLog(label?: string): void;
18
- static warn(...msg: unknown[]): void;
19
- }
1
+ import type { Console as SharedConsole } from "../../polyfill/Console.d.ts";
20
2
 
21
- export class Lodash {
22
- static escape(string: string): string;
23
- static get<T = unknown, D = undefined>(object?: Record<string, unknown>, path?: string | string[], defaultValue?: D): T | D;
24
- static merge<T extends Record<string, unknown>>(object: T, ...sources: Array<Record<string, unknown> | null | undefined>): T;
25
- static omit<T extends Record<string, unknown>>(object?: T, paths?: string | string[]): T;
26
- static pick<T extends Record<string, unknown>, K extends keyof T>(object?: T, paths?: K | K[]): Pick<T, K>;
27
- static set<T extends Record<string, unknown>>(object: T, path: string | string[], value: unknown): T;
28
- static toPath(value: string): string[];
29
- static unescape(string: string): string;
30
- static unset(object?: Record<string, unknown>, path?: string | string[]): boolean;
31
- }
3
+ type SharedStatusTexts = typeof import("../../polyfill/StatusTexts.d.ts").StatusTexts;
32
4
 
33
- export class qs {
34
- static parse(query?: string | Record<string, unknown> | null): Record<string, unknown>;
5
+ declare module "@nsnanocat/util" {
6
+ export interface Console extends SharedConsole {}
35
7
 
36
- static stringify(object?: Record<string, unknown>): string;
37
- }
8
+ export const Console: typeof import("../../polyfill/Console.d.ts").Console;
38
9
 
39
- export const StatusTexts: Record<number, string>;
10
+ export const StatusTexts: SharedStatusTexts;
40
11
  }
@@ -0,0 +1,7 @@
1
+ import type { qs as SharedQs } from "../../polyfill/qs.d.ts";
2
+
3
+ declare module "@nsnanocat/util" {
4
+ export interface qs extends SharedQs {}
5
+
6
+ export const qs: typeof import("../../polyfill/qs.d.ts").qs;
7
+ }
@@ -1,10 +1,7 @@
1
+ import type { Storage as SharedStorage } from "../../polyfill/Storage.d.ts";
2
+
1
3
  declare module "@nsnanocat/util" {
2
- export class Storage {
3
- static data: Record<string, unknown> | null;
4
- static dataFile: string;
5
- static getItem<T = unknown>(keyName: string, defaultValue?: T): T;
6
- static setItem(keyName: string, keyValue: unknown): boolean;
7
- static removeItem(keyName: string): boolean;
8
- static clear(): boolean;
9
- }
4
+ export interface Storage extends SharedStorage {}
5
+
6
+ export const Storage: typeof import("../../polyfill/Storage.d.ts").Storage;
10
7
  }
@@ -1,6 +1,8 @@
1
1
  /// <reference path="./modules/core.d.ts" />
2
2
  /// <reference path="./modules/fetch.d.ts" />
3
+ /// <reference path="./modules/Lodash.d.ts" />
3
4
  /// <reference path="./modules/polyfills.d.ts" />
5
+ /// <reference path="./modules/qs.d.ts" />
4
6
  /// <reference path="./modules/storage.d.ts" />
5
7
  /// <reference path="./modules/getStorage.d.ts" />
6
8
  /// <reference path="./modules/environment.d.ts" />