ly-utils-lib 1.0.12 → 2.4.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.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +889 -686
  3. package/dist/array.cjs +237 -0
  4. package/dist/array.cjs.map +1 -0
  5. package/dist/array.d.cts +2 -0
  6. package/dist/array.d.ts +2 -0
  7. package/dist/array.js +150 -0
  8. package/dist/array.js.map +1 -0
  9. package/dist/crypto.cjs +193 -0
  10. package/dist/crypto.cjs.map +1 -0
  11. package/dist/crypto.d.cts +3 -0
  12. package/dist/crypto.d.ts +3 -0
  13. package/dist/crypto.js +144 -0
  14. package/dist/crypto.js.map +1 -0
  15. package/dist/date.cjs +563 -0
  16. package/dist/date.cjs.map +1 -0
  17. package/dist/date.d.cts +2 -0
  18. package/dist/date.d.ts +2 -0
  19. package/dist/date.js +451 -0
  20. package/dist/date.js.map +1 -0
  21. package/dist/excel.cjs +227 -0
  22. package/dist/excel.cjs.map +1 -0
  23. package/dist/excel.d.cts +2 -0
  24. package/dist/excel.d.ts +2 -0
  25. package/dist/excel.js +196 -0
  26. package/dist/excel.js.map +1 -0
  27. package/dist/index-B80SEVzM.d.cts +382 -0
  28. package/dist/index-B80SEVzM.d.ts +382 -0
  29. package/dist/index-Ba1rjTzj.d.cts +299 -0
  30. package/dist/index-Ba1rjTzj.d.ts +299 -0
  31. package/dist/index-Bg1ise7y.d.cts +253 -0
  32. package/dist/index-Bg1ise7y.d.ts +253 -0
  33. package/dist/index-BoqNpwNa.d.cts +203 -0
  34. package/dist/index-BoqNpwNa.d.ts +203 -0
  35. package/dist/index-C0qUnb9Y.d.cts +533 -0
  36. package/dist/index-C0qUnb9Y.d.ts +533 -0
  37. package/dist/index-Cy-mb5v_.d.cts +262 -0
  38. package/dist/index-Cy-mb5v_.d.ts +262 -0
  39. package/dist/index-D1f9Sym2.d.cts +148 -0
  40. package/dist/index-D1f9Sym2.d.ts +148 -0
  41. package/dist/index-Dan5oF-5.d.cts +213 -0
  42. package/dist/index-Dan5oF-5.d.ts +213 -0
  43. package/dist/index-XABfrs7z.d.cts +596 -0
  44. package/dist/index-XABfrs7z.d.ts +596 -0
  45. package/dist/index-YXWfKCK7.d.cts +109 -0
  46. package/dist/index-YXWfKCK7.d.ts +109 -0
  47. package/dist/index.cjs +3355 -0
  48. package/dist/index.cjs.map +1 -0
  49. package/dist/index.d.cts +21 -0
  50. package/dist/index.d.ts +21 -0
  51. package/dist/index.js +3294 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/map.cjs +839 -0
  54. package/dist/map.cjs.map +1 -0
  55. package/dist/map.d.cts +6 -0
  56. package/dist/map.d.ts +6 -0
  57. package/dist/map.js +811 -0
  58. package/dist/map.js.map +1 -0
  59. package/dist/object.cjs +316 -0
  60. package/dist/object.cjs.map +1 -0
  61. package/dist/object.d.cts +2 -0
  62. package/dist/object.d.ts +2 -0
  63. package/dist/object.js +247 -0
  64. package/dist/object.js.map +1 -0
  65. package/dist/pdf.cjs +197 -0
  66. package/dist/pdf.cjs.map +1 -0
  67. package/dist/pdf.d.cts +3 -0
  68. package/dist/pdf.d.ts +3 -0
  69. package/dist/pdf.js +173 -0
  70. package/dist/pdf.js.map +1 -0
  71. package/dist/storage.cjs +255 -0
  72. package/dist/storage.cjs.map +1 -0
  73. package/dist/storage.d.cts +1 -0
  74. package/dist/storage.d.ts +1 -0
  75. package/dist/storage.js +226 -0
  76. package/dist/storage.js.map +1 -0
  77. package/dist/string.cjs +232 -0
  78. package/dist/string.cjs.map +1 -0
  79. package/dist/string.d.cts +2 -0
  80. package/dist/string.d.ts +2 -0
  81. package/dist/string.js +170 -0
  82. package/dist/string.js.map +1 -0
  83. package/dist/utils.cjs +429 -0
  84. package/dist/utils.cjs.map +1 -0
  85. package/dist/utils.d.cts +2 -0
  86. package/dist/utils.d.ts +2 -0
  87. package/dist/utils.js +371 -0
  88. package/dist/utils.js.map +1 -0
  89. package/package.json +159 -33
  90. package/dist/ly-utils-lib.cjs.js +0 -115
  91. package/dist/ly-utils-lib.cjs.js.map +0 -1
  92. package/dist/ly-utils-lib.es.js +0 -58589
  93. package/dist/ly-utils-lib.es.js.map +0 -1
  94. package/dist/ly-utils-lib.umd.js +0 -115
  95. package/dist/ly-utils-lib.umd.js.map +0 -1
  96. package/dist/types/index.d.ts +0 -15
  97. package/dist/types/utils/esToolkit.d.ts +0 -2
  98. package/dist/types/utils/ol.d.ts +0 -175
  99. package/dist/types/utils/router.d.ts +0 -10
  100. package/dist/types/utils/storage.d.ts +0 -42
  101. package/dist/types/utils/time.d.ts +0 -66
  102. package/dist/types/utils/tool.d.ts +0 -80
  103. package/dist/vite.svg +0 -1
@@ -0,0 +1,382 @@
1
+ import { DebouncedFunction, ThrottledFunction, debounce, throttle } from 'es-toolkit';
2
+
3
+ /**
4
+ * 通用工具模块
5
+ * 提供颜色转换、图片处理、文件下载、类型判断、数组/对象操作等通用功能
6
+ */
7
+
8
+ /**
9
+ * 深度克隆对象
10
+ * @param obj 要克隆的对象
11
+ * @returns 克隆后的对象
12
+ */
13
+ declare const clone: <T>(obj: T) => T;
14
+ /**
15
+ * 深度比较两个对象是否相等
16
+ * @param a 对象 a
17
+ * @param b 对象 b
18
+ * @returns 是否相等
19
+ */
20
+ declare const isEqual: (a: any, b: any) => boolean;
21
+ /**
22
+ * 深度合并对象
23
+ * @param objects 要合并的对象
24
+ * @returns 合并后的对象
25
+ */
26
+ declare const deepMerge: <T extends Record<string, any>>(...objects: Partial<T>[]) => T;
27
+ /**
28
+ * 获取对象的路径值
29
+ * @param obj 对象
30
+ * @param path 路径(例如:'user.name')
31
+ * @returns 路径对应的值
32
+ */
33
+ declare const get: (obj: any, path: string) => any;
34
+ /**
35
+ * 设置对象的路径值
36
+ * @param obj 对象
37
+ * @param path 路径(例如:'user.name')
38
+ * @param value 要设置的值
39
+ */
40
+ declare const set: (obj: any, path: string, value: any) => void;
41
+ /**
42
+ * 省略对象中的某些属性
43
+ * @param obj 对象
44
+ * @param keys 要省略的键
45
+ * @returns 省略后的对象
46
+ */
47
+ declare const omit: <T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
48
+ /**
49
+ * 选择对象中的某些属性
50
+ * @param obj 对象
51
+ * @param keys 要选择的键
52
+ * @returns 选择后的对象
53
+ */
54
+ declare const pick: <T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
55
+ /**
56
+ * 判断是否为对象
57
+ * @param value 要判断的值
58
+ * @returns 是否为对象
59
+ */
60
+ declare const isObject: (value: any) => value is Record<string, any>;
61
+ /**
62
+ * 判断是否为数组
63
+ * @param value 要判断的值
64
+ * @returns 是否为数组
65
+ */
66
+ declare const isArray: (value: any) => value is any[];
67
+ /**
68
+ * 判断是否为字符串
69
+ * @param value 要判断的值
70
+ * @returns 是否为字符串
71
+ */
72
+ declare const isString: (value: any) => value is string;
73
+ /**
74
+ * 判断是否为数字
75
+ * @param value 要判断的值
76
+ * @returns 是否为数字
77
+ */
78
+ declare const isNumber: (value: any) => value is number;
79
+ /**
80
+ * 判断是否为布尔值
81
+ * @param value 要判断的值
82
+ * @returns 是否为布尔值
83
+ */
84
+ declare const isBoolean: (value: any) => value is boolean;
85
+ /**
86
+ * 判断是否为函数
87
+ * @param value 要判断的值
88
+ * @returns 是否为函数
89
+ */
90
+ declare const isFunction: (value: any) => value is Function;
91
+ /**
92
+ * 判断是否为空值
93
+ * @param value 要判断的值
94
+ * @returns 是否为空
95
+ */
96
+ declare const isEmpty: (value: any) => boolean;
97
+ /**
98
+ * 数组去重
99
+ * @param array 数组
100
+ * @returns 去重后的数组
101
+ */
102
+ declare const uniq: <T>(array: T[]) => T[];
103
+ /**
104
+ * 数组排序
105
+ * @param array 数组
106
+ * @param key 排序键
107
+ * @returns 排序后的数组
108
+ */
109
+ declare const sortBy: <T>(array: T[], key: keyof T | ((item: T) => any)) => T[];
110
+ /**
111
+ * 数组分块
112
+ * @param array 数组
113
+ * @param size 分块大小
114
+ * @returns 分块后的二维数组
115
+ */
116
+ declare const chunk: <T>(array: T[], size: number) => T[][];
117
+ /**
118
+ * 数组分组
119
+ * @param array 数组
120
+ * @param key 分组键
121
+ * @returns 分组后的对象
122
+ */
123
+ declare const groupBy: <T>(array: T[], key: keyof T | ((item: T) => string)) => Record<string, T[]>;
124
+ /**
125
+ * 数组求和
126
+ * @param array 数组
127
+ * @returns 总和
128
+ */
129
+ declare const sum: (array: number[]) => number;
130
+ /**
131
+ * 数组平均值
132
+ * @param array 数组
133
+ * @returns 平均值
134
+ */
135
+ declare const avg: (array: number[]) => number;
136
+ /**
137
+ * 数组最大值
138
+ * @param array 数组
139
+ * @returns 最大值
140
+ */
141
+ declare const max: (array: number[]) => number;
142
+ /**
143
+ * 数组最小值
144
+ * @param array 数组
145
+ * @returns 最小值
146
+ */
147
+ declare const min: (array: number[]) => number;
148
+ /**
149
+ * 驼峰转下划线
150
+ * @param str 字符串
151
+ * @returns 转换后的字符串
152
+ */
153
+ declare const camelToSnake: (str: string) => string;
154
+ /**
155
+ * 下划线转驼峰
156
+ * @param str 字符串
157
+ * @returns 转换后的字符串
158
+ */
159
+ declare const snakeToCamel: (str: string) => string;
160
+ /**
161
+ * 首字母大写
162
+ * @param str 字符串
163
+ * @returns 转换后的字符串
164
+ */
165
+ declare const capitalize: (str: string) => string;
166
+ /**
167
+ * 截断字符串
168
+ * @param str 字符串
169
+ * @param length 最大长度
170
+ * @param suffix 后缀
171
+ * @returns 截断后的字符串
172
+ */
173
+ declare const truncate: (str: string, length?: number, suffix?: string) => string;
174
+ /**
175
+ * 格式化文件大小
176
+ * @param bytes 字节数
177
+ * @returns 格式化后的字符串
178
+ */
179
+ declare const formatFileSize: (bytes: number) => string;
180
+ /**
181
+ * 格式化数字(千分位)
182
+ * @param num 数字
183
+ * @returns 格式化后的字符串
184
+ */
185
+ declare const formatNumber: (num: number) => string;
186
+ /**
187
+ * 检查是否为有效的 URL
188
+ * @param str 字符串
189
+ * @returns 是否为有效 URL
190
+ */
191
+ declare const isValidUrl: (str: string) => boolean;
192
+ /**
193
+ * 检查是否为有效的邮箱
194
+ * @param email 邮箱地址
195
+ * @returns 是否为有效邮箱
196
+ */
197
+ declare const isValidEmail: (email: string) => boolean;
198
+ /**
199
+ * 检查是否为有效的手机号(中国)
200
+ * @param phone 手机号
201
+ * @returns 是否为有效手机号
202
+ */
203
+ declare const isValidPhone: (phone: string) => boolean;
204
+ /**
205
+ * 生成范围内的随机整数
206
+ * @param min 最小值
207
+ * @param max 最大值
208
+ * @returns 随机整数
209
+ */
210
+ declare const randomInt: (min: number, max: number) => number;
211
+ /**
212
+ * 生成唯一 ID
213
+ * @param prefix 前缀
214
+ * @returns 唯一 ID
215
+ */
216
+ declare const uniqueId: (prefix?: string) => string;
217
+ /**
218
+ * 延迟执行
219
+ * @param ms 延迟时间(毫秒)
220
+ * @returns Promise
221
+ */
222
+ declare const delay: (ms: number) => Promise<void>;
223
+ /**
224
+ * 重试函数
225
+ * @param fn 要执行的函数
226
+ * @param retries 重试次数
227
+ * @param delayMs 重试延迟
228
+ * @returns Promise
229
+ */
230
+ declare const retry: <T>(fn: () => Promise<T>, retries?: number, delayMs?: number) => Promise<T>;
231
+ /**
232
+ * Hex 颜色转 RGB 颜色
233
+ * @param str Hex 颜色(如 #FFFFFF 或 FFFFFF)
234
+ * @returns RGB 颜色数组 [r, g, b]
235
+ */
236
+ declare const hexToRgb: (str: string) => number[] | null;
237
+ /**
238
+ * Hex 颜色转 RGB 字符串
239
+ * @param str Hex 颜色(如 #FFFFFF 或 FFFFFF)
240
+ * @returns RGB 字符串(如 rgb(255, 255, 255))
241
+ */
242
+ declare const hexToRgbString: (str: string) => string | null;
243
+ /**
244
+ * RGB 颜色转 Hex 颜色
245
+ * @param r 红色值 (0-255)
246
+ * @param g 绿色值 (0-255)
247
+ * @param b 蓝色值 (0-255)
248
+ * @returns Hex 颜色字符串(如 #FFFFFF)
249
+ */
250
+ declare const rgbToHex: (r: number, g: number, b: number) => string | null;
251
+ /**
252
+ * RGB 颜色转 Hex 颜色(数组版本)
253
+ * @param rgb RGB 数组 [r, g, b]
254
+ * @returns Hex 颜色字符串(如 #FFFFFF)
255
+ */
256
+ declare const rgbArrayToHex: (rgb: number[]) => string | null;
257
+ /**
258
+ * 变浅颜色值
259
+ * @param color Hex 颜色(如 #FFFFFF 或 FFFFFF)
260
+ * @param alpha 透明度因子 (0-1),值越大颜色越浅
261
+ * @returns 变浅后的 Hex 颜色
262
+ */
263
+ declare const getLightColor: (color: string, alpha: number) => string | null;
264
+ /**
265
+ * 变深颜色值
266
+ * @param color Hex 颜色(如 #FFFFFF 或 FFFFFF)
267
+ * @param alpha 暗化因子 (0-1),值越大颜色越深
268
+ * @returns 变深后的 Hex 颜色
269
+ */
270
+ declare const getDarkColor: (color: string, alpha: number) => string | null;
271
+ /**
272
+ * 图片转 Base64
273
+ * @param url 图片 URL
274
+ * @param type 图片类型(默认 image/png)
275
+ * @returns Base64 字符串
276
+ */
277
+ declare const imgToBase64: (url: string, type?: "image/jpeg" | "image/png") => Promise<string>;
278
+ /**
279
+ * Base64 转 File 对象
280
+ * @param base64 Base64 字符串
281
+ * @param fileName 文件名
282
+ * @param mimeType MIME 类型(默认 image/jpeg)
283
+ * @returns File 对象
284
+ */
285
+ declare const base64toFile: (base64: string, fileName: string, mimeType?: string) => File;
286
+ /**
287
+ * Base64 转 Blob 对象
288
+ * @param base64 Base64 字符串
289
+ * @param mimeType MIME 类型
290
+ * @returns Blob 对象
291
+ */
292
+ declare const base64toBlob: (base64: string, mimeType?: string) => Blob;
293
+ /**
294
+ * 下载文件
295
+ * @param url 文件 URL 或 Data URL
296
+ * @param fileName 文件名
297
+ * @param target 是否在新标签页打开(默认 false)
298
+ */
299
+ declare const downloadFile: (url: string, fileName?: string, target?: boolean) => void;
300
+ /**
301
+ * 下载 Blob 文件
302
+ * @param blob Blob 对象
303
+ * @param fileName 文件名
304
+ */
305
+ declare const downloadBlob: (blob: Blob, fileName: string) => void;
306
+ /**
307
+ * 下载 Base64 文件
308
+ * @param base64 Base64 字符串
309
+ * @param fileName 文件名
310
+ * @param mimeType MIME 类型
311
+ */
312
+ declare const downloadBase64: (base64: string, fileName: string, mimeType?: string) => void;
313
+ /**
314
+ * 复制文本到剪贴板
315
+ * @param text 要复制的文本
316
+ * @returns 是否成功
317
+ */
318
+ declare const copyToClipboard: (text: string) => Promise<boolean>;
319
+ /**
320
+ * 从剪贴板读取文本
321
+ * @returns 剪贴板文本
322
+ */
323
+ declare const readFromClipboard: () => Promise<string>;
324
+
325
+ declare const index_DebouncedFunction: typeof DebouncedFunction;
326
+ declare const index_ThrottledFunction: typeof ThrottledFunction;
327
+ declare const index_avg: typeof avg;
328
+ declare const index_base64toBlob: typeof base64toBlob;
329
+ declare const index_base64toFile: typeof base64toFile;
330
+ declare const index_camelToSnake: typeof camelToSnake;
331
+ declare const index_capitalize: typeof capitalize;
332
+ declare const index_chunk: typeof chunk;
333
+ declare const index_clone: typeof clone;
334
+ declare const index_copyToClipboard: typeof copyToClipboard;
335
+ declare const index_debounce: typeof debounce;
336
+ declare const index_deepMerge: typeof deepMerge;
337
+ declare const index_delay: typeof delay;
338
+ declare const index_downloadBase64: typeof downloadBase64;
339
+ declare const index_downloadBlob: typeof downloadBlob;
340
+ declare const index_downloadFile: typeof downloadFile;
341
+ declare const index_formatFileSize: typeof formatFileSize;
342
+ declare const index_formatNumber: typeof formatNumber;
343
+ declare const index_get: typeof get;
344
+ declare const index_getDarkColor: typeof getDarkColor;
345
+ declare const index_getLightColor: typeof getLightColor;
346
+ declare const index_groupBy: typeof groupBy;
347
+ declare const index_hexToRgb: typeof hexToRgb;
348
+ declare const index_hexToRgbString: typeof hexToRgbString;
349
+ declare const index_imgToBase64: typeof imgToBase64;
350
+ declare const index_isArray: typeof isArray;
351
+ declare const index_isBoolean: typeof isBoolean;
352
+ declare const index_isEmpty: typeof isEmpty;
353
+ declare const index_isEqual: typeof isEqual;
354
+ declare const index_isFunction: typeof isFunction;
355
+ declare const index_isNumber: typeof isNumber;
356
+ declare const index_isObject: typeof isObject;
357
+ declare const index_isString: typeof isString;
358
+ declare const index_isValidEmail: typeof isValidEmail;
359
+ declare const index_isValidPhone: typeof isValidPhone;
360
+ declare const index_isValidUrl: typeof isValidUrl;
361
+ declare const index_max: typeof max;
362
+ declare const index_min: typeof min;
363
+ declare const index_omit: typeof omit;
364
+ declare const index_pick: typeof pick;
365
+ declare const index_randomInt: typeof randomInt;
366
+ declare const index_readFromClipboard: typeof readFromClipboard;
367
+ declare const index_retry: typeof retry;
368
+ declare const index_rgbArrayToHex: typeof rgbArrayToHex;
369
+ declare const index_rgbToHex: typeof rgbToHex;
370
+ declare const index_set: typeof set;
371
+ declare const index_snakeToCamel: typeof snakeToCamel;
372
+ declare const index_sortBy: typeof sortBy;
373
+ declare const index_sum: typeof sum;
374
+ declare const index_throttle: typeof throttle;
375
+ declare const index_truncate: typeof truncate;
376
+ declare const index_uniq: typeof uniq;
377
+ declare const index_uniqueId: typeof uniqueId;
378
+ declare namespace index {
379
+ export { index_DebouncedFunction as DebouncedFunction, index_ThrottledFunction as ThrottledFunction, index_avg as avg, index_base64toBlob as base64toBlob, index_base64toFile as base64toFile, index_camelToSnake as camelToSnake, index_capitalize as capitalize, index_chunk as chunk, index_clone as clone, index_copyToClipboard as copyToClipboard, index_debounce as debounce, index_deepMerge as deepMerge, index_delay as delay, index_downloadBase64 as downloadBase64, index_downloadBlob as downloadBlob, index_downloadFile as downloadFile, index_formatFileSize as formatFileSize, index_formatNumber as formatNumber, index_get as get, index_getDarkColor as getDarkColor, index_getLightColor as getLightColor, index_groupBy as groupBy, index_hexToRgb as hexToRgb, index_hexToRgbString as hexToRgbString, index_imgToBase64 as imgToBase64, index_isArray as isArray, index_isBoolean as isBoolean, index_isEmpty as isEmpty, index_isEqual as isEqual, index_isFunction as isFunction, index_isNumber as isNumber, index_isObject as isObject, index_isString as isString, index_isValidEmail as isValidEmail, index_isValidPhone as isValidPhone, index_isValidUrl as isValidUrl, index_max as max, index_min as min, index_omit as omit, index_pick as pick, index_randomInt as randomInt, index_readFromClipboard as readFromClipboard, index_retry as retry, index_rgbArrayToHex as rgbArrayToHex, index_rgbToHex as rgbToHex, index_set as set, index_snakeToCamel as snakeToCamel, index_sortBy as sortBy, index_sum as sum, index_throttle as throttle, index_truncate as truncate, index_uniq as uniq, index_uniqueId as uniqueId };
380
+ }
381
+
382
+ export { isEqual as A, isFunction as B, isNumber as C, isObject as D, isString as E, isValidEmail as F, isValidPhone as G, isValidUrl as H, max as I, min as J, omit as K, pick as L, randomInt as M, readFromClipboard as N, retry as O, rgbArrayToHex as P, rgbToHex as Q, set as R, snakeToCamel as S, sortBy as T, sum as U, truncate as V, uniq as W, uniqueId as X, avg as a, base64toBlob as b, base64toFile as c, camelToSnake as d, capitalize as e, chunk as f, clone as g, copyToClipboard as h, index as i, deepMerge as j, delay as k, downloadBase64 as l, downloadBlob as m, downloadFile as n, formatFileSize as o, formatNumber as p, get as q, getDarkColor as r, getLightColor as s, groupBy as t, hexToRgb as u, hexToRgbString as v, imgToBase64 as w, isArray as x, isBoolean as y, isEmpty as z };
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Storage Module - 浏览器存储工具
3
+ *
4
+ * 提供统一的浏览器存储操作 API
5
+ */
6
+ /**
7
+ * 存储数据类型
8
+ */
9
+ type StorageValue = string | number | boolean | null | undefined | object | unknown[];
10
+ /**
11
+ * 存储选项
12
+ */
13
+ interface StorageOptions {
14
+ /** 过期时间(毫秒),0 表示永不过期 */
15
+ ttl?: number;
16
+ }
17
+ /**
18
+ * Cookie 选项
19
+ */
20
+ interface CookieOptions extends Cookies.CookieAttributes {
21
+ /** 过期天数 */
22
+ days?: number;
23
+ }
24
+ /**
25
+ * 设置永久缓存
26
+ * @param key - 缓存名称
27
+ * @param value - 缓存内容
28
+ * @param options - 存储选项
29
+ * @example
30
+ * ```ts
31
+ * setLocal('user', { name: 'Alice', age: 25 })
32
+ * setLocal('token', 'abc123', { ttl: 3600000 }) // 1小时后过期
33
+ * ```
34
+ */
35
+ declare function setLocal<T = StorageValue>(key: string, value: T, options?: StorageOptions): void;
36
+ /**
37
+ * 获取永久缓存
38
+ * @param key - 缓存名称
39
+ * @returns 缓存内容,不存在或已过期返回 undefined
40
+ * @example
41
+ * ```ts
42
+ * const user = getLocal<{ name: string; age: number }>('user')
43
+ * console.log(user?.name) // 'Alice'
44
+ * ```
45
+ */
46
+ declare function getLocal<T = StorageValue>(key: string): T | undefined;
47
+ /**
48
+ * 移除永久缓存
49
+ * @param key - 缓存名称
50
+ * @example
51
+ * ```ts
52
+ * removeLocal('user')
53
+ * ```
54
+ */
55
+ declare function removeLocal(key: string): void;
56
+ /**
57
+ * 移除全部永久缓存
58
+ * @example
59
+ * ```ts
60
+ * clearLocal()
61
+ * ```
62
+ */
63
+ declare function clearLocal(): void;
64
+ /**
65
+ * 获取所有 localStorage 的键
66
+ * @returns 键数组
67
+ */
68
+ declare function getLocalKeys(): string[];
69
+ /**
70
+ * 获取 localStorage 中键的数量
71
+ * @returns 键的数量
72
+ */
73
+ declare function getLocalSize(): number;
74
+ /**
75
+ * 设置临时缓存
76
+ * @param key - 缓存名称
77
+ * @param value - 缓存内容
78
+ * @param options - 存储选项
79
+ * @example
80
+ * ```ts
81
+ * setSession('temp', { data: [1, 2, 3] })
82
+ * setSession('session', 'abc123', { ttl: 60000 }) // 1分钟后过期
83
+ * ```
84
+ */
85
+ declare function setSession<T = StorageValue>(key: string, value: T, options?: StorageOptions): void;
86
+ /**
87
+ * 获取临时缓存
88
+ * @param key - 缓存名称
89
+ * @returns 缓存内容,不存在或已过期返回 undefined
90
+ * @example
91
+ * ```ts
92
+ * const temp = getSession<{ data: number[] }>('temp')
93
+ * console.log(temp?.data) // [1, 2, 3]
94
+ * ```
95
+ */
96
+ declare function getSession<T = StorageValue>(key: string): T | undefined;
97
+ /**
98
+ * 移除临时缓存
99
+ * @param key - 缓存名称
100
+ * @example
101
+ * ```ts
102
+ * removeSession('temp')
103
+ * ```
104
+ */
105
+ declare function removeSession(key: string): void;
106
+ /**
107
+ * 移除全部临时缓存
108
+ * @example
109
+ * ```ts
110
+ * clearSession()
111
+ * ```
112
+ */
113
+ declare function clearSession(): void;
114
+ /**
115
+ * 获取所有 sessionStorage 的键
116
+ * @returns 键数组
117
+ */
118
+ declare function getSessionKeys(): string[];
119
+ /**
120
+ * 获取 sessionStorage 中键的数量
121
+ * @returns 键的数量
122
+ */
123
+ declare function getSessionSize(): number;
124
+ /**
125
+ * 设置 Cookie
126
+ * @param key - Cookie 名称
127
+ * @param value - Cookie 值
128
+ * @param options - Cookie 选项
129
+ * @example
130
+ * ```ts
131
+ * setCookie('token', 'abc123', { days: 7 })
132
+ * setCookie('user', { name: 'Alice' }, { secure: true }) // 自动序列化对象
133
+ * ```
134
+ */
135
+ declare function setCookie(key: string, value: string | object, options?: CookieOptions): void;
136
+ /**
137
+ * 获取 Cookie
138
+ * @param key - Cookie 名称
139
+ * @returns Cookie 值,不存在返回 undefined
140
+ * @example
141
+ * ```ts
142
+ * const token = getCookie('token')
143
+ * console.log(token) // 'abc123'
144
+ * ```
145
+ */
146
+ declare function getCookie(key: string): string | undefined;
147
+ /**
148
+ * 移除 Cookie
149
+ * @param key - Cookie 名称
150
+ * @param options - Cookie 选项(需要匹配设置时的 path 和 domain)
151
+ * @example
152
+ * ```ts
153
+ * removeCookie('token')
154
+ * removeCookie('user', { path: '/', domain: '.example.com' })
155
+ * ```
156
+ */
157
+ declare function removeCookie(key: string, options?: CookieOptions): void;
158
+ /**
159
+ * 获取所有 Cookie
160
+ * @returns Cookie 对象
161
+ * @example
162
+ * ```ts
163
+ * const cookies = getAllCookies()
164
+ * console.log(cookies) // { token: 'abc123', user: '{"name":"Alice"}' }
165
+ * ```
166
+ */
167
+ declare function getAllCookies(): Record<string, string>;
168
+ /**
169
+ * 检查 Cookie 是否存在
170
+ * @param key - Cookie 名称
171
+ * @returns 是否存在
172
+ * @example
173
+ * ```ts
174
+ * if (hasCookie('token')) {
175
+ * console.log('Token exists')
176
+ * }
177
+ * ```
178
+ */
179
+ declare function hasCookie(key: string): boolean;
180
+ /**
181
+ * 获取 JSON 格式的 Cookie
182
+ * @param key - Cookie 名称
183
+ * @returns 解析后的对象,不存在或解析失败返回 undefined
184
+ * @example
185
+ * ```ts
186
+ * const user = getCookieJSON<{ name: string; age: number }>('user')
187
+ * console.log(user?.name) // 'Alice'
188
+ * ```
189
+ */
190
+ declare function getCookieJSON<T = object>(key: string): T | undefined;
191
+ /**
192
+ * 设置 JSON 格式的 Cookie(自动序列化)
193
+ * @param key - Cookie 名称
194
+ * @param value - 对象值
195
+ * @param options - Cookie 选项
196
+ * @example
197
+ * ```ts
198
+ * setCookieJSON('user', { name: 'Alice', age: 25 }, { days: 7 })
199
+ * ```
200
+ */
201
+ declare function setCookieJSON<T = object>(key: string, value: T, options?: CookieOptions): void;
202
+ /**
203
+ * 获取所有 Cookie 的数量
204
+ * @returns Cookie 数量
205
+ * @example
206
+ * ```ts
207
+ * console.log(getCookieSize()) // 3
208
+ * ```
209
+ */
210
+ declare function getCookieSize(): number;
211
+ /**
212
+ * 存储类型
213
+ */
214
+ type StorageType = 'local' | 'session' | 'cookie';
215
+ /**
216
+ * 统一设置存储
217
+ * @param type - 存储类型
218
+ * @param key - 键
219
+ * @param value - 值
220
+ * @param options - 选项
221
+ * @example
222
+ * ```ts
223
+ * setStorage('local', 'user', { name: 'Alice' })
224
+ * setStorage('cookie', 'token', 'abc123', { days: 7 })
225
+ * ```
226
+ */
227
+ declare function setStorage<T extends string | object>(type: 'local', key: string, value: T, options?: StorageOptions): void;
228
+ declare function setStorage<T extends string | object>(type: 'session', key: string, value: T, options?: StorageOptions): void;
229
+ declare function setStorage<T extends string | object>(type: 'cookie', key: string, value: T, options?: CookieOptions): void;
230
+ /**
231
+ * 统一获取存储
232
+ * @param type - 存储类型
233
+ * @param key - 键
234
+ * @returns 值
235
+ * @example
236
+ * ```ts
237
+ * const user = getStorage<{ name: string }>('local', 'user')
238
+ * const token = getStorage('cookie', 'token')
239
+ * ```
240
+ */
241
+ declare function getStorage<T = StorageValue>(type: 'local', key: string): T | undefined;
242
+ declare function getStorage<T = StorageValue>(type: 'session', key: string): T | undefined;
243
+ declare function getStorage(type: 'cookie', key: string): string | undefined;
244
+ /**
245
+ * 统一移除存储
246
+ * @param type - 存储类型
247
+ * @param key - 键
248
+ * @example
249
+ * ```ts
250
+ * removeStorage('local', 'user')
251
+ * removeStorage('cookie', 'token')
252
+ * ```
253
+ */
254
+ declare function removeStorage(type: StorageType, key: string): void;
255
+ /**
256
+ * 统一清除存储
257
+ * @param type - 存储类型
258
+ * @example
259
+ * ```ts
260
+ * clearStorage('local')
261
+ * clearStorage('session')
262
+ * clearStorage('cookie') // 注意:cookie 只能逐个删除
263
+ * ```
264
+ */
265
+ declare function clearStorage(type: StorageType): void;
266
+
267
+ type index_CookieOptions = CookieOptions;
268
+ type index_StorageOptions = StorageOptions;
269
+ type index_StorageType = StorageType;
270
+ type index_StorageValue = StorageValue;
271
+ declare const index_clearLocal: typeof clearLocal;
272
+ declare const index_clearSession: typeof clearSession;
273
+ declare const index_clearStorage: typeof clearStorage;
274
+ declare const index_getAllCookies: typeof getAllCookies;
275
+ declare const index_getCookie: typeof getCookie;
276
+ declare const index_getCookieJSON: typeof getCookieJSON;
277
+ declare const index_getCookieSize: typeof getCookieSize;
278
+ declare const index_getLocal: typeof getLocal;
279
+ declare const index_getLocalKeys: typeof getLocalKeys;
280
+ declare const index_getLocalSize: typeof getLocalSize;
281
+ declare const index_getSession: typeof getSession;
282
+ declare const index_getSessionKeys: typeof getSessionKeys;
283
+ declare const index_getSessionSize: typeof getSessionSize;
284
+ declare const index_getStorage: typeof getStorage;
285
+ declare const index_hasCookie: typeof hasCookie;
286
+ declare const index_removeCookie: typeof removeCookie;
287
+ declare const index_removeLocal: typeof removeLocal;
288
+ declare const index_removeSession: typeof removeSession;
289
+ declare const index_removeStorage: typeof removeStorage;
290
+ declare const index_setCookie: typeof setCookie;
291
+ declare const index_setCookieJSON: typeof setCookieJSON;
292
+ declare const index_setLocal: typeof setLocal;
293
+ declare const index_setSession: typeof setSession;
294
+ declare const index_setStorage: typeof setStorage;
295
+ declare namespace index {
296
+ export { type index_CookieOptions as CookieOptions, type index_StorageOptions as StorageOptions, type index_StorageType as StorageType, type index_StorageValue as StorageValue, index_clearLocal as clearLocal, index_clearSession as clearSession, index_clearStorage as clearStorage, index_getAllCookies as getAllCookies, index_getCookie as getCookie, index_getCookieJSON as getCookieJSON, index_getCookieSize as getCookieSize, index_getLocal as getLocal, index_getLocalKeys as getLocalKeys, index_getLocalSize as getLocalSize, index_getSession as getSession, index_getSessionKeys as getSessionKeys, index_getSessionSize as getSessionSize, index_getStorage as getStorage, index_hasCookie as hasCookie, index_removeCookie as removeCookie, index_removeLocal as removeLocal, index_removeSession as removeSession, index_removeStorage as removeStorage, index_setCookie as setCookie, index_setCookieJSON as setCookieJSON, index_setLocal as setLocal, index_setSession as setSession, index_setStorage as setStorage };
297
+ }
298
+
299
+ export { setStorage as A, type CookieOptions as C, type StorageOptions as S, type StorageType as a, type StorageValue as b, clearLocal as c, clearSession as d, clearStorage as e, getCookie as f, getAllCookies as g, getCookieJSON as h, index as i, getCookieSize as j, getLocal as k, getLocalKeys as l, getLocalSize as m, getSession as n, getSessionKeys as o, getSessionSize as p, getStorage as q, hasCookie as r, removeCookie as s, removeLocal as t, removeSession as u, removeStorage as v, setCookie as w, setCookieJSON as x, setLocal as y, setSession as z };