@fast-china/utils 1.0.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.
@@ -0,0 +1,380 @@
1
+ import * as vue from 'vue';
2
+ import { Plugin, Directive, PropType, ComputedRef, SlotsType, VNode } from 'vue';
3
+
4
+ declare const base64Util: {
5
+ bota(string: string): string;
6
+ atob(string: string): string;
7
+ /**
8
+ * 字符串ToBase64
9
+ */
10
+ toBase64(str: string, prefixStrLength?: number): string;
11
+ /**
12
+ * Base64转字符串
13
+ */
14
+ base64ToStr(str: string, prefixStrLength?: number): string;
15
+ };
16
+
17
+ declare const clickUtil: {
18
+ /**
19
+ * 防抖
20
+ * @param fn - 执行函数
21
+ * @param delay - 延时毫秒
22
+ * @returns 返回一个新的防抖函数
23
+ */
24
+ debounce(fn: () => void, delay?: number): void;
25
+ /**
26
+ * 异步防抖
27
+ * @param fn - 执行函数
28
+ * @param delay - 延时毫秒
29
+ * @returns 返回一个新的防抖函数
30
+ */
31
+ debounceAsync(fn: () => Promise<void>, delay?: number): Promise<void>;
32
+ /**
33
+ * 节流
34
+ * @param fn - 执行函数
35
+ * @param delay - 延时毫秒
36
+ * @returns 返回一个新的节流函数
37
+ */
38
+ throttle(fn: () => void, delay?: number): void;
39
+ /**
40
+ * 异步节流
41
+ * @param fn - 执行函数
42
+ * @param delay - 延时毫秒
43
+ * @returns 返回一个新的节流函数
44
+ */
45
+ throttleAsync(fn: () => Promise<void>, delay?: number): Promise<void>;
46
+ };
47
+
48
+ declare const colorUtil: {
49
+ /**
50
+ * hex颜色转rgb颜色
51
+ * @param str 颜色值字符串
52
+ * @returns 返回处理后的颜色值
53
+ */
54
+ hexToRgb(str: any): any;
55
+ /**
56
+ * rgb颜色转Hex颜色
57
+ * @param r 代表红色
58
+ * @param g 代表绿色
59
+ * @param b 代表蓝色
60
+ * @returns 返回处理后的颜色值
61
+ */
62
+ rgbToHex(r: any, g: any, b: any): string;
63
+ /**
64
+ * 加深颜色值
65
+ * @param color 颜色值字符串
66
+ * @param level 加深的程度,限0-1之间
67
+ * @returns 返回处理后的颜色值
68
+ */
69
+ getDarkColor(color: string, level: number): string;
70
+ /**
71
+ * 变浅颜色值
72
+ * @param color 颜色值字符串
73
+ * @param level 加深的程度,限0-1之间
74
+ * @returns 返回处理后的颜色值
75
+ */
76
+ getLightColor(color: string, level: number): string;
77
+ };
78
+
79
+ /**
80
+ * 打印 Log 日志
81
+ * @param name 来源名称
82
+ */
83
+ declare const consoleLog: (name: string, message?: string | false, error?: any) => void;
84
+ /**
85
+ * 打印 Warn 日志
86
+ * @param name 来源名称
87
+ */
88
+ declare const consoleWarn: (name: string, message?: string | false, error?: any) => void;
89
+ /**
90
+ * 打印 Debug 日志
91
+ * @param name 来源名称
92
+ */
93
+ declare const consoleDebug: (name: string, message?: string | false, error?: any) => void;
94
+ /**
95
+ * 打印 Error 日志
96
+ * @param name 来源名称
97
+ */
98
+ declare const consoleError: (name: string, message?: any) => void;
99
+ /**
100
+ * 抛出错误
101
+ * @param name 来源名称
102
+ */
103
+ declare const throwError: (name: string, message?: any) => never;
104
+
105
+ /**
106
+ * 加密解密
107
+ */
108
+ declare const cryptoUtil: {
109
+ /**
110
+ * AES
111
+ */
112
+ aes: {
113
+ /**
114
+ * AES加密
115
+ * @param dataStr 要加密的字符串
116
+ * @param key 用于加密的密钥
117
+ * @param vector 用于加密的向量(IV)
118
+ * @param cipherMode 加密模式,默认为CBC模式
119
+ */
120
+ encrypt(dataStr: string, key: string, vector: string, cipherMode?: any): string;
121
+ /**
122
+ * AES解密
123
+ * @param dataStr 要解密的Base64编码字符串
124
+ * @param key 用于解密的密钥
125
+ * @param vector 用于解密的向量(IV)
126
+ * @param cipherMode 解密模式,默认为CBC模式
127
+ */
128
+ decrypt<T = string>(dataStr: string, key: string, vector: string, cipherMode?: any): T | null;
129
+ };
130
+ /**
131
+ * SHA1
132
+ */
133
+ sha1: {
134
+ /**
135
+ * SHA1加密
136
+ * @param dataStr 要加密的字符串
137
+ */
138
+ encrypt(dataStr: string): string;
139
+ };
140
+ /**
141
+ * MD5
142
+ */
143
+ MD5: {
144
+ /**
145
+ * MD5加密
146
+ * @param dataStr 要加密的字符串
147
+ */
148
+ encrypt(dataStr: string): string;
149
+ };
150
+ };
151
+
152
+ /**
153
+ * Date工具类
154
+ */
155
+ declare const dateUtil: {
156
+ /**
157
+ * 根据当前时间生成问候语
158
+ */
159
+ getGreet(): string;
160
+ /**
161
+ * 时间处理翻译
162
+ */
163
+ dateTimeFix(date: string | Date | null | undefined): string;
164
+ getDefaultTime(): Date[];
165
+ getSimpleTime(): Date;
166
+ getSimpleShortcuts(): {
167
+ text: string;
168
+ value: () => Date;
169
+ }[];
170
+ getShortcuts(): {
171
+ text: string;
172
+ value: () => Date[];
173
+ }[];
174
+ getDisabledDate(time: Date): boolean;
175
+ };
176
+
177
+ /**
178
+ * 添加单位
179
+ * @param value 字符串或数字类型
180
+ * @param defaultUnit 单位
181
+ */
182
+ declare const addUnit: (value?: string | number, defaultUnit?: string) => string;
183
+
184
+ declare class FastError extends Error {
185
+ constructor(m: string);
186
+ }
187
+
188
+ /**
189
+ * 对象工具类
190
+ */
191
+ declare const objectUtil: {
192
+ /**
193
+ * 对象URL参数化
194
+ */
195
+ objectToQueryString(obj: any): string;
196
+ /**
197
+ * 是否存在重复值
198
+ */
199
+ hasDuplicateProperty<T>(arr: T[], prop: keyof T): boolean;
200
+ /**
201
+ * 是否存在非重复值
202
+ */
203
+ hasDifferentProperty<T>(arr: T[], prop: keyof T): boolean;
204
+ /**
205
+ * 时间处理翻译
206
+ */
207
+ dateTimeFix(date: string | Date | null | undefined): string;
208
+ };
209
+
210
+ /**
211
+ * 本地缓存前缀 Key
212
+ */
213
+ declare const CACHE_PREFIX: vue.ComputedRef<string>;
214
+ /**
215
+ * 本地缓存过期值后缀 Key
216
+ */
217
+ declare const CACHE_EXPIRE_SUFFIX: vue.ComputedRef<string>;
218
+ declare const useStorage: () => {
219
+ /**
220
+ * 设置缓存前缀 Key
221
+ * @param key
222
+ */
223
+ prefix(key: string): void;
224
+ /**
225
+ * 缓存过期值后缀 Key
226
+ * @param key
227
+ */
228
+ expireSuffix(key: string): void;
229
+ /**
230
+ * 设置缓存是否加密
231
+ * @param crypto
232
+ */
233
+ crypto(crypto: boolean): void;
234
+ };
235
+ /**
236
+ * window.localStorage
237
+ * - 如果是 UniApp 环境则使用的是 uni.xxxStorage
238
+ */
239
+ declare const Local: {
240
+ /**
241
+ * 设置
242
+ * @param key 缓存的Key
243
+ * @param val 缓存值
244
+ * @param expire 过期时间,单位分钟
245
+ * @param encrypt 是否对缓存的数据加密
246
+ */
247
+ set(key: string, val: any, expire?: number, encrypt?: boolean): void;
248
+ /**
249
+ * 获取
250
+ * @param key 缓存的Key
251
+ * @param decrypt 是否对缓存的数据解密
252
+ * @returns {T} 传入的对象类型,默认为 string
253
+ */
254
+ get<T = string>(key: string, decrypt?: boolean): T;
255
+ /**
256
+ * 移除
257
+ * @param key 缓存的Key
258
+ */
259
+ remove(key: string): void;
260
+ /**
261
+ * 根据前缀移除
262
+ * @param key 缓存的Key
263
+ */
264
+ removeByPrefix(key: string): void;
265
+ /**
266
+ * 移除全部
267
+ */
268
+ clear(): void;
269
+ };
270
+ /**
271
+ * window.sessionStorage
272
+ * - UniApp 环境下不可用
273
+ */
274
+ declare const Session: {
275
+ /**
276
+ * 设置会话缓存
277
+ * @param key 缓存的Key
278
+ * @param val 缓存值
279
+ * @param expire 过期时间,单位分钟
280
+ * @param encrypt 是否对缓存的数据加密
281
+ */
282
+ set(key: string, val: any, expire?: number, encrypt?: boolean): void;
283
+ /**
284
+ * 获取会话缓存
285
+ * @param key 缓存的Key
286
+ * @param decrypt 是否对缓存的数据解密
287
+ * @returns {T} 传入的对象类型,默认为 string
288
+ */
289
+ get<T = string>(key: string, decrypt?: boolean): T;
290
+ /**
291
+ * 移除会话缓存
292
+ * @param key 缓存的Key
293
+ */
294
+ remove(key: string): void;
295
+ /**
296
+ * 根据前缀移除会话缓存
297
+ * @param key 缓存的Key
298
+ */
299
+ removeByPrefix(key: string): void;
300
+ /**
301
+ * 移除全部会话缓存
302
+ */
303
+ clear(): void;
304
+ };
305
+
306
+ /**
307
+ * 字符串工具类
308
+ */
309
+ declare const stringUtil: {
310
+ /**
311
+ * 获取Url参数
312
+ */
313
+ getUrlParams(url: string): Record<string, any>;
314
+ /**
315
+ * 是否为JSON字符串
316
+ */
317
+ isJson(value: string): boolean;
318
+ /**
319
+ * 生成随机字符串
320
+ */
321
+ generateRandomString(length: number): string;
322
+ /**
323
+ * @description 生成唯一 uuid
324
+ */
325
+ generateUUID(): string;
326
+ /**
327
+ * 复制
328
+ */
329
+ copy(value: string): Promise<void>;
330
+ };
331
+
332
+ /**
333
+ * 构建 expose 和 vue.js devtools 状态查看
334
+ */
335
+ declare const useExpose: <Exposed extends Record<string, any> = Record<string, any>>(expose: (exposed?: Exposed) => void, exposed?: Exposed) => Exposed;
336
+
337
+ /**
338
+ * 执行方法
339
+ * @param fn 要执行的方法
340
+ * @param args 参数
341
+ */
342
+ declare const execFunction: <T = void>(fn: Function, ...args: any[]) => Promise<T>;
343
+
344
+ type TSXWithInstall<T> = T & Plugin;
345
+ declare const withInstall: <T, E extends Record<string, any>>(main: T, extra?: E) => TSXWithInstall<T> & E;
346
+ declare const withNoopInstall: <T>(component: T) => TSXWithInstall<T>;
347
+ declare const withInstallDirective: <T extends Directive>(directive: T, name: string) => TSXWithInstall<T>;
348
+
349
+ declare const definePropType: <T>(val: any) => PropType<T>;
350
+ /**
351
+ * 构建 props
352
+ * @param props props
353
+ * @param rawProps 原生 props
354
+ * @param ignoreRawProps 忽略 原生 props 的 key
355
+ */
356
+ declare const useProps: <T extends Record<string, unknown>, RT extends Record<string, unknown>>(props: T, rawProps?: RT, ignoreRawProps?: (keyof RT)[]) => ComputedRef<Record<string, unknown>>;
357
+
358
+ type RawSlots = Record<string, unknown>;
359
+ type VueSlots<T> = [T] extends [never] ? () => VNode[] : (arg: T) => VNode[];
360
+ type MakeSlots<T extends RawSlots> = {
361
+ [K in keyof T]: VueSlots<T[K]>;
362
+ };
363
+ /**
364
+ * 构建 slots
365
+ */
366
+ declare const makeSlots: <Slots extends RawSlots>() => SlotsType<Partial<MakeSlots<Slots>>>;
367
+
368
+ /**
369
+ * 使用渲染
370
+ * @description 为了解决使用 TSX 语法返回渲染函数,状态不会出现在 vue.js devtools 中
371
+ */
372
+ declare const useRender: (render: () => VNode) => void;
373
+
374
+ /**
375
+ * 定义类型数据
376
+ * @description 传入什么就返回什么,用来定义reactive或其他对象的响应式数据
377
+ */
378
+ declare const withDefineType: <T>(data?: T) => T;
379
+
380
+ export { CACHE_EXPIRE_SUFFIX, CACHE_PREFIX, FastError, Local, Session, type TSXWithInstall, addUnit, base64Util, clickUtil, colorUtil, consoleDebug, consoleError, consoleLog, consoleWarn, cryptoUtil, dateUtil, definePropType, execFunction, makeSlots, objectUtil, stringUtil, throwError, useExpose, useProps, useRender, useStorage, withDefineType, withInstall, withInstallDirective, withNoopInstall };