ly-utils-lib 1.0.2 → 1.0.4

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 ADDED
@@ -0,0 +1,386 @@
1
+ # 自定义函数库,集成 day.js 和 es-toolkit
2
+
3
+ 安装:npm install dayjs jspdf es-toolkit ly-utils-lib
4
+
5
+ # 时间函数
6
+
7
+ ## 日期格式化函数 formatDate
8
+
9
+ /\*\*
10
+
11
+ - 日期格式化函数
12
+ - @param {Date | string} date - 日期
13
+ - @param {string} format - 格式模板
14
+ - @returns {string} 格式化后的日期字符串
15
+ \*/
16
+
17
+ formatDate(date: Date | string = new Date(), format: string = 'YYYY-MM-DD HH:mm:ss')
18
+
19
+ 例:formatDate()
20
+
21
+ ## 日期计算函数 computeDate
22
+
23
+ /\*\*
24
+
25
+ - 日期计算函数
26
+ - @param {string} compute - 计算方式 'after' | 'before'
27
+ - @param {Date | string} date - 日期
28
+ - @param {string} type - 计算类型 'day' | 'week' | 'month' | 'quarter' | 'year' | 'hour' | 'minute' | 'second' | 'millisecond'
29
+ - @param {number} num - 计算数量
30
+ - @param {string} format - 格式模板
31
+ - @returns {string} 格式化后的日期字符串
32
+ \*/
33
+
34
+ computeDate(compute: string = 'after', date: Date | string = new Date(), type: ManipulateType | undefined = 'day', num: number = 1, format: string = 'YYYY-MM-DD')
35
+
36
+ 例:computeDate('after', Date.now(), 'day')
37
+
38
+ ## 开始时间函数 startDate
39
+
40
+ /\*\*
41
+
42
+ - 开始时间函数
43
+ - @param {string} type - 类型 'date' | 'day' | 'month' | 'quarter' | 'year' | 'week' | 'isoWeek' | 'hour' | 'minute' | 'second' | 'millisecond'
44
+ - @param {string} format - 格式模板
45
+ - @returns {string} 格式化后的日期字符串
46
+ \*/
47
+
48
+ startDate(type: ManipulateType | undefined = 'month', format: string = 'YYYY-MM-DD')
49
+
50
+ 例:startDate('day', 'HH:mm')
51
+
52
+ ## 结束时间函数 endDate
53
+
54
+ /\*\*
55
+
56
+ - 结束时间函数
57
+ - @param {string} type - 类型 'date' | 'day' | 'month' | 'quarter' | 'year' | 'week' | 'isoWeek' | 'hour' | 'minute' | 'second' | 'millisecond'
58
+ - @param {string} format - 格式模板
59
+ - @returns {string} 格式化后的日期字符串
60
+ \*/
61
+
62
+ endDate(type: ManipulateType | undefined = 'month', format: string = 'YYYY-MM-DD')
63
+
64
+ 例:endDate('day', 'HH:mm')
65
+
66
+ ## 获取时间戳函数 getTimeStamp
67
+
68
+ /\*\*
69
+
70
+ - 获取时间戳函数
71
+ - @param {Date | string} date - 日期
72
+ - @returns {number} 时间戳
73
+ \*/
74
+
75
+ getTimeStamp(date: Date | string = new Date())
76
+
77
+ 例:getTimeStamp('2025-12-31')
78
+
79
+ ## 时间戳格式化函数 formatTimeStamp
80
+
81
+ /\*\*
82
+
83
+ - 时间戳格式化函数
84
+ - @param {number} timeStamp - 时间戳
85
+ - @param {string} format - 格式模板
86
+ - @returns {string} 格式化后的日期字符串
87
+ \*\*/
88
+
89
+ formatTimeStamp(timeStamp: number = 0, format: string = 'YYYY-MM-DD HH:mm:ss')
90
+
91
+ 例:formatTimeStamp(1767110400, 'YYYY-MM-DD')
92
+
93
+ ## 获取两个日期时间之间的差异函数 getDateDiff
94
+
95
+ /\*\*
96
+
97
+ - 获取两个日期时间之间的差异函数
98
+ - @param {string} type - 类型 'week' | 'day' | 'month' | 'quarter' | 'year' | 'hour' | 'minute' | 'second' | 'millisecond'
99
+ - @param {Date | string} startDate - 起始时间
100
+ - @param {Date | string} endDate - 结束时间
101
+ - @returns {number} 差异值
102
+ \*/
103
+
104
+ getDateDiff(type: OpUnitType = 'day', startDate: Date | string, endDate: Date | string = new Date())
105
+
106
+ 例: getDateDiff('day', '2025-12-01', '2025-12-10')
107
+
108
+ ## 获取一段范围内日期函数 getRangeDate
109
+
110
+ /\*\*
111
+
112
+ - 获取一段范围内日期函数
113
+ - @param {Date | string} startDate - 起始时间
114
+ - @param {Date | string} endDate - 结束时间
115
+ - @returns {array} 日期集合
116
+ \*/
117
+
118
+ getRangeDate(startDate: Date | string, endDate: Date | string): Array<any>
119
+
120
+ 例: getRangeDate('2025-12-01', '2025-12-10')
121
+
122
+ ## 获取相对时间函数 getRelativeTime
123
+
124
+ /\*\*
125
+
126
+ - 获取相对时间函数
127
+ - @param {Date | string} date - 日期
128
+ - @returns {string} 相对时间描述
129
+ \*/
130
+
131
+ getRelativeTime(date: Date | string)
132
+
133
+ 例: getRelativeTime('2025-12-10')
134
+
135
+ # 缓存函数
136
+
137
+ ## 设置永久缓存 setLocal
138
+
139
+ /\*\*
140
+
141
+ - 设置永久缓存
142
+ - @param {string} key - 缓存名称
143
+ - @param {string | number | object | Array<any>} value - 缓存内容
144
+ \*/
145
+
146
+ setLocal(key: string, value: string | number | object | Array<any>)
147
+
148
+ 例: setLocal('key', '1234')
149
+
150
+ ## 获取永久缓存 getLocal
151
+
152
+ /\*\*
153
+
154
+ - 获取永久缓存
155
+ - @param {string} key - 缓存名称
156
+ - @returns {string} 格式化后的value
157
+ \*/
158
+
159
+ getLocal(key: string)
160
+
161
+ 例: getLocal('key')
162
+
163
+ ## 移除永久缓存 removeLocal
164
+
165
+ /\*\*
166
+
167
+ - 移除永久缓存
168
+ - @param {string} key - 缓存名称
169
+ \*/
170
+
171
+ removeLocal(key: string)
172
+
173
+ 例: removeLocal('key')
174
+
175
+ ## 移除全部永久缓存 clearLocal
176
+
177
+ clearLocal()
178
+
179
+ 例: clearLocal()
180
+
181
+ ## 设置临时缓存 setSession
182
+
183
+ /\*\*
184
+
185
+ - 设置永久缓存
186
+ - @param {string} key - 缓存名称
187
+ - @param {string | number | object | Array<any>} value - 缓存内容
188
+ \*/
189
+
190
+ setSession(key: string, value: string | number | object | Array<any>)
191
+
192
+ 例: setSession('key', '1234')
193
+
194
+ ## 获取永久缓存 getSession
195
+
196
+ /\*\*
197
+
198
+ - 获取临时缓存
199
+ - @param {string} key - 缓存名称
200
+ - @returns {string} 格式化后的value
201
+ \*/
202
+
203
+ getSession(key: string)
204
+
205
+ 例: getSession('key')
206
+
207
+ ## 移除永久缓存 removeSession
208
+
209
+ /\*\*
210
+
211
+ - 移除临时缓存
212
+ - @param {string} key - 缓存名称
213
+ \*/
214
+
215
+ removeSession(key: string)
216
+
217
+ 例: removeSession('key')
218
+
219
+ ## 移除全部临时缓存 clearSession
220
+
221
+ clearSession()
222
+
223
+ 例: clearSession()
224
+
225
+ # 工具函数
226
+
227
+ ## 生成UUID createUUID
228
+
229
+ createUUID()
230
+
231
+ 例: createUUID()
232
+
233
+ ## 导出xlsx文件 exportExcel
234
+
235
+ /\*\*
236
+
237
+ - 导出xlsx文件
238
+ - @param {string} name - 文件名称
239
+ - @param {any} title - xlsx表头
240
+ - @param {any} data - xlsx数据
241
+ - @param {any} cols - xlsx宽度
242
+ - @param {any} sheetName - xlsx页签名称
243
+ - @returns {Promise<unknown>} 导出是否成功
244
+ \*/
245
+
246
+ exportExcel(name: string, title: any, data: any, cols: any, sheetName: any = {})
247
+
248
+ 例: exportExcel('1111', { id: 'ID' }, [[{ id: 10 }, { id: 11 }]], [{ width: 20 }], ['111'])
249
+
250
+ ## 导入xlsx文件 importExcel
251
+
252
+ /\*\*
253
+
254
+ - 导入xlsx文件
255
+ - @param {string} file - xlsx文件
256
+ - @returns {Promise<any>} xlsx表格数据
257
+ \*/
258
+
259
+ importExcel(file: any)
260
+
261
+ 例: importExcel(xlsx文件)
262
+
263
+ ## 导出xlsx文件 exportPdf
264
+
265
+ /\*\*
266
+
267
+ - 导出pdf文件
268
+ - @param {string} name - 文件名称
269
+ - @param {any} dom - 页面dom
270
+ - @param {any} type - 是否直接导出
271
+ - @returns {Promise<unknown>} 不直接导出返回base64文件
272
+ \*/
273
+
274
+ exportPdf(name: string, dom: any, type: boolean = true)
275
+
276
+ 例: exportPdf('aa.pdf', document.getElementById('aaa'))
277
+
278
+ ## 生成图片文件 importImage
279
+
280
+ /\*\*
281
+
282
+ - 生成图片文件
283
+ - @param {any} dom - 页面dom
284
+ - @param {string} type - 图片格式
285
+ - @returns {Promise<unknown>} base64文件
286
+ \*/
287
+
288
+ importImage(dom: any, type: string = 'image/jpeg')
289
+
290
+ 例: await importImage(document.getElementById('aaa'))
291
+
292
+ ## hex 颜色转 rgb 颜色 hexToRgb
293
+
294
+ /\*\*
295
+
296
+ - hex 颜色转 rgb 颜色
297
+ - @param {string} str - hex 颜色
298
+ - @returns {string} rgb 颜色
299
+ \*/
300
+
301
+ hexToRgb(str: string)
302
+
303
+ 例: hexToRgb('#ff0000')
304
+
305
+ ## rgb 颜色转 Hex 颜色 rgbToHex
306
+
307
+ /\*\*
308
+
309
+ - rgb 颜色转 Hex 颜色
310
+ - @param {number} r - r 颜色
311
+ - @param {number} g - g 颜色
312
+ - @param {number} b - b 颜色
313
+ - @returns {string} hex 颜色
314
+ \*/
315
+
316
+ rgbToHex(r: number, g: number, b: number)
317
+
318
+ 例: rgbToHex(255, 0, 0)
319
+
320
+ ## hex 颜色变浅颜色值 getLightColor
321
+
322
+ /\*\*
323
+
324
+ - hex 颜色变浅颜色值
325
+ - @param {string} color - hex 颜色
326
+ - @param {number} alpha - 透明度
327
+ - @returns {string} hex 颜色
328
+ \*/
329
+
330
+ getLightColor(color: string, alpha: number)
331
+
332
+ 例: getLightColor('#ff0000', 0.1)
333
+
334
+ ## hex 颜色变深颜色值 getDarkColor
335
+
336
+ /\*\*
337
+
338
+ - hex 颜色变深颜色值
339
+ - @param {string} color - hex 颜色
340
+ - @param {number} alpha - 透明度
341
+ - @returns {string} hex 颜色
342
+ \*/
343
+
344
+ getDarkColor(color: string, alpha: number)
345
+
346
+ 例: getDarkColor('#ff0000', 0.1)
347
+
348
+ ## 图片转base64 imgToBase64
349
+
350
+ /\*\*
351
+
352
+ - 图片转base64
353
+ - @param {string} url - 图片路径
354
+ - @returns {Promise<string>} base64图片内容
355
+ \*/
356
+
357
+ imgToBase64(url: string)
358
+
359
+ 例: await imgToBase64(new URL(`./file1.png`, import.meta.url).href)
360
+
361
+ ## base64转文件 base64toFile
362
+
363
+ /\*\*
364
+
365
+ - base64转文件
366
+ - @param {string} url - base64文件
367
+ - @param {string} fileName - 文件名称
368
+ - @returns {File} 文件
369
+ \*/
370
+
371
+ base64toFile(url: string, fileName: string)
372
+
373
+ 例: base64toFile('base64', 'aa.jpg')
374
+
375
+ ## base64转文件 downloadFile
376
+
377
+ /\*\*
378
+
379
+ - 下载文件
380
+ - @param {string} url - 文件路径
381
+ - @param {string} fileName - 文件名称
382
+ \*/
383
+
384
+ downloadFile(url: string, fileName: string)
385
+
386
+ 例: downloadFile('url', 'aa.jpg')
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ export * as esToolkit from 'es-toolkit';
1
2
  export { default as dayjs } from 'dayjs';
2
- export * from 'es-toolkit';
3
+ export { default as jsPDF } from 'jspdf';
3
4
  export * from './utils/time';
5
+ export * from './utils/tool';
6
+ export * from './utils/storage';