ly-utils-lib 1.0.2 → 1.0.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/README.md ADDED
@@ -0,0 +1,248 @@
1
+ # 自定义函数库,集成 day.js 和 es-toolkit
2
+
3
+ 安装:npm install dayjs 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'])
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export { default as dayjs } from 'dayjs';
2
2
  export * from 'es-toolkit';
3
3
  export * from './utils/time';
4
+ export * from './utils/tool';
5
+ export * from './utils/storage';