my-uniapp-tools 1.0.8 → 1.0.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.
@@ -2,8 +2,37 @@
2
2
  * 剪贴板相关工具函数
3
3
  */
4
4
  /**
5
- * 跨平台文本复制功能
5
+ * 剪贴板操作配置
6
+ */
7
+ interface ClipboardConfig {
8
+ showToast?: boolean;
9
+ successMessage?: string;
10
+ failMessage?: string;
11
+ timeout?: number;
12
+ }
13
+ /**
14
+ * 跨平台文本复制功能(优化版本)
6
15
  * @param text 要复制的文本内容
16
+ * @param config 配置选项
7
17
  * @description 支持 H5、App、小程序。H5 平台优先使用现代的 Clipboard API,失败时回退到传统方法
18
+ * @returns Promise<boolean> 复制是否成功
19
+ */
20
+ export declare function copyText(text: string, config?: ClipboardConfig): Promise<boolean>;
21
+ /**
22
+ * 读取剪贴板内容(仅H5平台支持)
23
+ * @param config 配置选项
24
+ * @returns Promise<string | null> 剪贴板内容,失败时返回null
25
+ */
26
+ export declare function readClipboard(config?: ClipboardConfig): Promise<string | null>;
27
+ /**
28
+ * 检查剪贴板API是否可用
29
+ * @returns boolean 是否支持剪贴板操作
30
+ */
31
+ export declare function isClipboardSupported(): boolean;
32
+ /**
33
+ * 清空剪贴板(仅H5平台支持)
34
+ * @param config 配置选项
35
+ * @returns Promise<boolean> 是否成功
8
36
  */
9
- export declare function copyText(text: string): void;
37
+ export declare function clearClipboard(config?: ClipboardConfig): Promise<boolean>;
38
+ export {};
@@ -0,0 +1,44 @@
1
+ /**
2
+ * 统一错误处理机制
3
+ */
4
+ export interface ErrorInfo {
5
+ code: string;
6
+ message: string;
7
+ module: string;
8
+ timestamp: number;
9
+ stack?: string;
10
+ }
11
+ export declare class UniAppToolsError extends Error {
12
+ code: string;
13
+ module: string;
14
+ timestamp: number;
15
+ constructor(code: string, message: string, module: string);
16
+ }
17
+ /**
18
+ * 全局错误处理器
19
+ */
20
+ export declare class ErrorHandler {
21
+ private static instance;
22
+ private errorCallbacks;
23
+ static getInstance(): ErrorHandler;
24
+ /**
25
+ * 注册错误回调
26
+ */
27
+ onError(callback: (error: ErrorInfo) => void): void;
28
+ /**
29
+ * 处理错误
30
+ */
31
+ handleError(error: Error | UniAppToolsError, module: string): void;
32
+ /**
33
+ * 创建模块专用的错误处理函数
34
+ */
35
+ createModuleErrorHandler(moduleName: string): (code: string, message: string, originalError?: Error) => UniAppToolsError;
36
+ }
37
+ /**
38
+ * 异步操作包装器,统一错误处理
39
+ */
40
+ export declare function safeAsync<T>(operation: () => Promise<T>, moduleName: string, errorCode?: string): Promise<T | null>;
41
+ /**
42
+ * 同步操作包装器,统一错误处理
43
+ */
44
+ export declare function safeSync<T>(operation: () => T, moduleName: string, errorCode?: string, defaultValue?: T | null): T | null;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * 性能监控工具
3
+ */
4
+ export interface PerformanceMetric {
5
+ name: string;
6
+ startTime: number;
7
+ endTime?: number;
8
+ duration?: number;
9
+ module: string;
10
+ metadata?: Record<string, any>;
11
+ }
12
+ export declare class PerformanceMonitor {
13
+ private static instance;
14
+ private metrics;
15
+ private completedMetrics;
16
+ private maxStoredMetrics;
17
+ static getInstance(): PerformanceMonitor;
18
+ /**
19
+ * 开始性能测量
20
+ */
21
+ start(name: string, module: string, metadata?: Record<string, any>): void;
22
+ /**
23
+ * 结束性能测量
24
+ */
25
+ end(name: string): PerformanceMetric | null;
26
+ /**
27
+ * 获取性能报告
28
+ */
29
+ getReport(): {
30
+ byModule: Record<string, PerformanceMetric[]>;
31
+ slowest: PerformanceMetric[];
32
+ average: Record<string, number>;
33
+ };
34
+ /**
35
+ * 清除性能记录
36
+ */
37
+ clear(): void;
38
+ }
39
+ /**
40
+ * 性能装饰器
41
+ */
42
+ export declare function measurePerformance(moduleName: string): (target: any, propertyName: string, descriptor: PropertyDescriptor) => void;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
+ export function initUniAppTools(config?: {}): void;
2
+ export * from "./core/errorHandler";
3
+ export * from "./core/performance";
1
4
  export * from "./ui";
2
5
  export * from "./navigation";
3
6
  export * from "./clipboard";
4
7
  export * from "./system";
5
8
  export * from "./localStorage";
6
9
  export * from "./utils";
10
+ export const VERSION: "1.0.8";
@@ -1,26 +1,75 @@
1
1
  /**
2
- * 本地存储相关工具函数
2
+ * 本地存储相关工具函数(优化版本)
3
3
  */
4
4
  /**
5
- * 同步设置本地缓存
5
+ * 存储配置选项
6
+ */
7
+ interface StorageOptions {
8
+ compress?: boolean;
9
+ encrypt?: boolean;
10
+ ttl?: number;
11
+ }
12
+ /**
13
+ * 同步设置本地缓存(优化版本)
6
14
  * @param key 缓存键
7
15
  * @param obj 要缓存的值,可以是任何类型
8
- * @description 如果值是字符串,直接存储;否则,尝试将其 JSON 序列化后存储。
9
- * 添加了错误处理,以防 JSON 序列化失败。
16
+ * @param options 存储选项
17
+ * @returns 是否设置成功
10
18
  */
11
- export declare function setStorageSync(key: string, obj: unknown): void;
19
+ export declare function setStorageSync<T>(key: string, obj: T, options?: StorageOptions): boolean;
12
20
  /**
13
- * 同步获取本地缓存
21
+ * 同步获取本地缓存(优化版本)
14
22
  * @param key 缓存键
15
- * @returns 缓存的值。如果存储的是 JSON 字符串,则返回解析后的对象;否则返回原始值。
16
- * @description 获取指定键的值。如果值是非空字符串,尝试进行 JSON 解析。
17
- * 如果解析成功,返回解析后的对象;如果解析失败或值不是有效字符串,返回原始值。
23
+ * @param defaultValue 默认值
24
+ * @returns 缓存的值
18
25
  */
19
- export declare function getStorageSync(key: string): any;
26
+ export declare function getStorageSync<T>(key: string, defaultValue?: T): T | undefined;
20
27
  /**
21
- * 同步清理本地缓存
28
+ * 同步清理本地缓存(优化版本)
22
29
  * @param key 可选的缓存键
23
- * @description 如果传入 key,则删除对应的缓存项。
24
- * 如果不传入 key,则清除所有本地缓存。
30
+ * @returns 是否清理成功
31
+ */
32
+ export declare function clearStorageSync(key?: string): boolean;
33
+ /**
34
+ * 异步设置本地缓存
35
+ * @param key 缓存键
36
+ * @param obj 要缓存的值
37
+ * @param options 存储选项
38
+ * @returns Promise<boolean>
39
+ */
40
+ export declare function setStorage<T>(key: string, obj: T, options?: StorageOptions): Promise<boolean>;
41
+ /**
42
+ * 异步获取本地缓存
43
+ * @param key 缓存键
44
+ * @param defaultValue 默认值
45
+ * @returns Promise<T | undefined>
46
+ */
47
+ export declare function getStorage<T>(key: string, defaultValue?: T): Promise<T | undefined>;
48
+ /**
49
+ * 获取存储信息
50
+ * @returns 存储信息
51
+ */
52
+ export declare function getStorageInfo(): {
53
+ keys: string[];
54
+ currentSize: number;
55
+ limitSize: number;
56
+ };
57
+ /**
58
+ * 清理过期数据
59
+ * @returns 清理的数据条数
60
+ */
61
+ export declare function cleanExpiredStorage(): number;
62
+ /**
63
+ * 批量设置存储
64
+ * @param items 要设置的键值对
65
+ * @param options 存储选项
66
+ * @returns 成功设置的数量
67
+ */
68
+ export declare function batchSetStorage(items: Record<string, any>, options?: StorageOptions): number;
69
+ /**
70
+ * 批量获取存储
71
+ * @param keys 要获取的键数组
72
+ * @returns 键值对对象
25
73
  */
26
- export declare function clearStorageSync(key?: string): void;
74
+ export declare function batchGetStorage<T = any>(keys: string[]): Record<string, T | undefined>;
75
+ export {};