pen-it 1.0.9 → 1.0.10
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 +519 -384
- package/dist/copy/index.d.ts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,599 +11,734 @@ pnpm add pen-it
|
|
|
11
11
|
## 使用
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { isArray, formatFull, deepClone, unique } from
|
|
14
|
+
import { isArray, formatFull, deepClone, unique } from "pen-it";
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
### 类型判断
|
|
20
|
+
|
|
17
21
|
---
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
#### isArray(value)
|
|
24
|
+
|
|
25
|
+
> — 判断是否为数组。
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
isArray([1, 2, 3]); // true
|
|
29
|
+
```
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
#### isObject(value)
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
> — 判断是否为对象(不含数组)。
|
|
24
34
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
```ts
|
|
36
|
+
isObject({ a: 1 }); // true
|
|
37
|
+
```
|
|
28
38
|
|
|
29
|
-
|
|
39
|
+
#### is(val, type)
|
|
30
40
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
> — 通用类型判断(内部工具)。
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
is([], "Array"); // true
|
|
45
|
+
```
|
|
34
46
|
|
|
35
|
-
|
|
47
|
+
#### isFunction(val)
|
|
36
48
|
|
|
37
|
-
|
|
38
|
-
is([], 'Array') // true
|
|
39
|
-
```
|
|
49
|
+
> — 判断是否为函数。
|
|
40
50
|
|
|
41
|
-
|
|
51
|
+
```ts
|
|
52
|
+
isFunction(() => {}); // true
|
|
53
|
+
```
|
|
42
54
|
|
|
43
|
-
|
|
44
|
-
isFunction(() => {}) // true
|
|
45
|
-
```
|
|
55
|
+
#### isAsyncFunction(val)
|
|
46
56
|
|
|
47
|
-
|
|
57
|
+
> — 判断是否为异步函数。
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
```ts
|
|
60
|
+
isAsyncFunction(async () => {}); // true
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### isPromise(value)
|
|
64
|
+
|
|
65
|
+
> — 判断是否为 Promise。
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
isPromise(Promise.resolve()); // true
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### isDate(val)
|
|
72
|
+
|
|
73
|
+
> — 判断是否为 Date 对象。
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
isDate(new Date()); // true
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### isNumber(val)
|
|
80
|
+
|
|
81
|
+
> — 判断是否为数字(含 NaN/Infinity)。
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
isNumber(42); // true
|
|
85
|
+
```
|
|
52
86
|
|
|
53
|
-
|
|
87
|
+
#### isInt(val)
|
|
54
88
|
|
|
55
|
-
|
|
56
|
-
isPromise(Promise.resolve()) // true
|
|
57
|
-
```
|
|
89
|
+
> — 判断是否为整数。
|
|
58
90
|
|
|
59
|
-
|
|
91
|
+
```ts
|
|
92
|
+
isInt(42); // true
|
|
93
|
+
```
|
|
60
94
|
|
|
61
|
-
|
|
62
|
-
isDate(new Date()) // true
|
|
63
|
-
```
|
|
95
|
+
#### isFloat(val)
|
|
64
96
|
|
|
65
|
-
|
|
97
|
+
> — 判断是否为浮点数。
|
|
66
98
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
99
|
+
```ts
|
|
100
|
+
isFloat(3.14); // true
|
|
101
|
+
```
|
|
70
102
|
|
|
71
|
-
|
|
103
|
+
#### isString(val)
|
|
72
104
|
|
|
73
|
-
|
|
74
|
-
isInt(42) // true
|
|
75
|
-
```
|
|
105
|
+
> — 判断是否为字符串。
|
|
76
106
|
|
|
77
|
-
|
|
107
|
+
```ts
|
|
108
|
+
isString("hello"); // true
|
|
109
|
+
```
|
|
78
110
|
|
|
79
|
-
|
|
80
|
-
isFloat(3.14) // true
|
|
81
|
-
```
|
|
111
|
+
#### isBoolean(val)
|
|
82
112
|
|
|
83
|
-
|
|
113
|
+
> — 判断是否为布尔值。
|
|
84
114
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
115
|
+
```ts
|
|
116
|
+
isBoolean(true); // true
|
|
117
|
+
```
|
|
88
118
|
|
|
89
|
-
|
|
119
|
+
#### isSymbol(value)
|
|
90
120
|
|
|
91
|
-
|
|
92
|
-
isBoolean(true) // true
|
|
93
|
-
```
|
|
121
|
+
> — 判断是否为 Symbol。
|
|
94
122
|
|
|
95
|
-
|
|
123
|
+
```ts
|
|
124
|
+
isSymbol(Symbol("foo")); // true
|
|
125
|
+
```
|
|
96
126
|
|
|
97
|
-
|
|
98
|
-
isSymbol(Symbol('foo')) // true
|
|
99
|
-
```
|
|
127
|
+
#### isPrimitive(value)
|
|
100
128
|
|
|
101
|
-
|
|
129
|
+
> — 判断是否为原始类型。
|
|
102
130
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
131
|
+
```ts
|
|
132
|
+
isPrimitive(42); // true
|
|
133
|
+
```
|
|
106
134
|
|
|
107
|
-
|
|
135
|
+
#### isNull(val)
|
|
108
136
|
|
|
109
|
-
|
|
110
|
-
isNull(null) // true
|
|
111
|
-
```
|
|
137
|
+
> — 判断是否为 null。
|
|
112
138
|
|
|
113
|
-
|
|
139
|
+
```ts
|
|
140
|
+
isNull(null); // true
|
|
141
|
+
```
|
|
114
142
|
|
|
115
|
-
|
|
116
|
-
isDef('hello') // true
|
|
117
|
-
```
|
|
143
|
+
#### isDef(val)
|
|
118
144
|
|
|
119
|
-
|
|
145
|
+
> — 判断是否不是 undefined。
|
|
120
146
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
147
|
+
```ts
|
|
148
|
+
isDef("hello"); // true
|
|
149
|
+
```
|
|
124
150
|
|
|
125
|
-
|
|
151
|
+
#### isUnDef(val)
|
|
126
152
|
|
|
127
|
-
|
|
128
|
-
isNullOrUnDef(null) // true
|
|
129
|
-
```
|
|
153
|
+
> — 判断是否为 undefined。
|
|
130
154
|
|
|
131
|
-
|
|
155
|
+
```ts
|
|
156
|
+
isUnDef(undefined); // true
|
|
157
|
+
```
|
|
132
158
|
|
|
133
|
-
|
|
134
|
-
isEmpty('') // true
|
|
135
|
-
isEmpty([]) // true
|
|
136
|
-
isEmpty({}) // true
|
|
137
|
-
```
|
|
159
|
+
#### isNullOrUnDef(val)
|
|
138
160
|
|
|
139
|
-
|
|
161
|
+
> — 判断是否为 null 或 undefined。
|
|
140
162
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
163
|
+
```ts
|
|
164
|
+
isNullOrUnDef(null); // true
|
|
165
|
+
```
|
|
144
166
|
|
|
145
|
-
|
|
167
|
+
#### isEmpty(value)
|
|
146
168
|
|
|
147
|
-
|
|
148
|
-
isEqual({ a: 1 }, { a: 1 }) // true
|
|
149
|
-
```
|
|
169
|
+
> — 判断是否为空(完备版:支持 Date/Map/Set 等)。
|
|
150
170
|
|
|
151
|
-
|
|
171
|
+
```ts
|
|
172
|
+
isEmpty(""); // true
|
|
173
|
+
isEmpty([]); // true
|
|
174
|
+
isEmpty({}); // true
|
|
175
|
+
```
|
|
152
176
|
|
|
153
|
-
|
|
154
|
-
isHexColor('#fff') // true
|
|
155
|
-
```
|
|
177
|
+
#### isEmptySv(value)
|
|
156
178
|
|
|
157
|
-
|
|
179
|
+
> — 判断是否为空(简化版)。
|
|
158
180
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
181
|
+
```ts
|
|
182
|
+
isEmptySv([]); // true
|
|
183
|
+
```
|
|
162
184
|
|
|
163
|
-
|
|
185
|
+
#### isEqual(x, y)
|
|
164
186
|
|
|
165
|
-
|
|
166
|
-
isPC() // true
|
|
167
|
-
```
|
|
187
|
+
> — 深度相等比较(支持 Date/RegExp)。
|
|
168
188
|
|
|
169
|
-
|
|
189
|
+
```ts
|
|
190
|
+
isEqual({ a: 1 }, { a: 1 }); // true
|
|
191
|
+
```
|
|
170
192
|
|
|
171
|
-
|
|
172
|
-
isWindow(window) // true
|
|
173
|
-
```
|
|
193
|
+
#### isHexColor(str)
|
|
174
194
|
|
|
175
|
-
|
|
195
|
+
> — 判断是否为十六进制颜色。
|
|
176
196
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
197
|
+
```ts
|
|
198
|
+
isHexColor("#fff"); // true
|
|
199
|
+
```
|
|
180
200
|
|
|
181
|
-
|
|
201
|
+
#### isValidEmail(email)
|
|
182
202
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
203
|
+
> — 判断是否为有效邮箱。
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
isValidEmail("a@b.com"); // true
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### isPC()
|
|
210
|
+
|
|
211
|
+
> — 判断是否为浏览器环境。
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
isPC(); // true
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
#### isWindow(val)
|
|
218
|
+
|
|
219
|
+
> — 判断是否为 window 对象。
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
isWindow(window); // true
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
#### isElement(val)
|
|
226
|
+
|
|
227
|
+
> — 判断是否为 DOM 元素。
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
isElement(document.body); // true
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### isIOS()
|
|
234
|
+
|
|
235
|
+
> — 判断设备是否为 iOS。
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
isIOS(); // true
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### 时间日期格式化
|
|
186
242
|
|
|
187
243
|
---
|
|
188
244
|
|
|
189
|
-
|
|
245
|
+
#### formatFull(date)
|
|
190
246
|
|
|
191
|
-
|
|
247
|
+
> — 完整日期时间(斜杠分隔)。
|
|
192
248
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
249
|
+
```ts
|
|
250
|
+
formatFull(new Date()); // "2026/06/03 14:30:45"
|
|
251
|
+
```
|
|
196
252
|
|
|
197
|
-
|
|
253
|
+
#### formatFullReplace(date)
|
|
198
254
|
|
|
199
|
-
|
|
200
|
-
formatFullReplace(new Date()) // "2026-06-03 14:30:45"
|
|
201
|
-
```
|
|
255
|
+
> — 完整日期时间(短横线分隔)。
|
|
202
256
|
|
|
203
|
-
|
|
257
|
+
```ts
|
|
258
|
+
formatFullReplace(new Date()); // "2026-06-03 14:30:45"
|
|
259
|
+
```
|
|
204
260
|
|
|
205
|
-
|
|
206
|
-
formatYMD(new Date()) // "2026年6月3日"
|
|
207
|
-
```
|
|
261
|
+
#### formatYMD(date)
|
|
208
262
|
|
|
209
|
-
|
|
263
|
+
> — 中文年月日。
|
|
210
264
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
265
|
+
```ts
|
|
266
|
+
formatYMD(new Date()); // "2026年6月3日"
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### formatWeek(date)
|
|
270
|
+
|
|
271
|
+
> — 星期几。
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
formatWeek(new Date()); // "星期三"
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### 数字与货币格式化
|
|
214
278
|
|
|
215
279
|
---
|
|
216
280
|
|
|
217
|
-
|
|
281
|
+
#### formatRmb(value, options)
|
|
282
|
+
|
|
283
|
+
> — 货币格式化(人民币)。
|
|
284
|
+
|
|
285
|
+
```ts
|
|
286
|
+
formatRmb(1234.56, { type: "zh-CN", currency: "CNY" }); // "¥1,234.56"
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
#### formatNum(value)
|
|
218
290
|
|
|
219
|
-
|
|
291
|
+
> — 千位分隔符。
|
|
220
292
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
293
|
+
```ts
|
|
294
|
+
formatNum(1234567); // "1,234,567"
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### percentCN(value, digit)
|
|
298
|
+
|
|
299
|
+
> — 百分比格式化。
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
percentCN(0.1234, 2); // "12.34%"
|
|
303
|
+
```
|
|
224
304
|
|
|
225
|
-
|
|
305
|
+
#### compactEN(value)
|
|
226
306
|
|
|
227
|
-
|
|
228
|
-
formatNum(1234567) // "1,234,567"
|
|
229
|
-
```
|
|
307
|
+
> — 大数简化(英文缩写)。
|
|
230
308
|
|
|
231
|
-
|
|
309
|
+
```ts
|
|
310
|
+
compactEN(12345); // "12K"
|
|
311
|
+
```
|
|
232
312
|
|
|
233
|
-
|
|
234
|
-
percentCN(0.1234, 2) // "12.34%"
|
|
235
|
-
```
|
|
313
|
+
#### compactCN(value)
|
|
236
314
|
|
|
237
|
-
|
|
315
|
+
> — 大数简化(中文缩写)。
|
|
238
316
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
317
|
+
```ts
|
|
318
|
+
compactCN(12345); // "1.2万"
|
|
319
|
+
```
|
|
242
320
|
|
|
243
|
-
|
|
321
|
+
#### signed(value, digit)
|
|
244
322
|
|
|
245
|
-
|
|
246
|
-
compactCN(12345) // "1.2万"
|
|
247
|
-
```
|
|
323
|
+
> — 带正负号显示。
|
|
248
324
|
|
|
249
|
-
|
|
325
|
+
```ts
|
|
326
|
+
signed(42, 1); // "+42.0"
|
|
327
|
+
```
|
|
250
328
|
|
|
251
|
-
|
|
252
|
-
signed(42, 1) // "+42.0"
|
|
253
|
-
```
|
|
329
|
+
### 字符串处理
|
|
254
330
|
|
|
255
331
|
---
|
|
256
332
|
|
|
257
|
-
|
|
333
|
+
#### maskPhone(phone)
|
|
258
334
|
|
|
259
|
-
|
|
335
|
+
> — 手机号脱敏(隐藏中间4位)。
|
|
260
336
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
337
|
+
```ts
|
|
338
|
+
maskPhone("13812345678"); // "138****5678"
|
|
339
|
+
```
|
|
264
340
|
|
|
265
|
-
|
|
341
|
+
#### spacePhone(phone)
|
|
266
342
|
|
|
267
|
-
|
|
268
|
-
spacePhone('13812345678') // "138 1234 5678"
|
|
269
|
-
```
|
|
343
|
+
> — 手机号空格分隔。
|
|
270
344
|
|
|
271
|
-
|
|
345
|
+
```ts
|
|
346
|
+
spacePhone("13812345678"); // "138 1234 5678"
|
|
347
|
+
```
|
|
272
348
|
|
|
273
|
-
|
|
274
|
-
capitalize('hello world') // "Hello World"
|
|
275
|
-
```
|
|
349
|
+
#### capitalize(str)
|
|
276
350
|
|
|
277
|
-
|
|
351
|
+
> — 每个单词首字母大写。
|
|
278
352
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
353
|
+
```ts
|
|
354
|
+
capitalize("hello world"); // "Hello World"
|
|
355
|
+
```
|
|
282
356
|
|
|
283
|
-
|
|
357
|
+
#### kebabToCamel(str)
|
|
284
358
|
|
|
285
|
-
|
|
286
|
-
camelToKebab('helloWorld') // "hello-world"
|
|
287
|
-
```
|
|
359
|
+
> — 短横线转小驼峰。
|
|
288
360
|
|
|
289
|
-
|
|
361
|
+
```ts
|
|
362
|
+
kebabToCamel("hello-world"); // "helloWorld"
|
|
363
|
+
```
|
|
290
364
|
|
|
291
|
-
|
|
292
|
-
toCamel('hello_world') // "helloWorld"
|
|
293
|
-
```
|
|
365
|
+
#### camelToKebab(str)
|
|
294
366
|
|
|
295
|
-
|
|
367
|
+
> — 驼峰转短横线。
|
|
296
368
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
369
|
+
```ts
|
|
370
|
+
camelToKebab("helloWorld"); // "hello-world"
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
#### toCamel(str)
|
|
374
|
+
|
|
375
|
+
> — 下划线转驼峰。
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
toCamel("hello_world"); // "helloWorld"
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
#### firstUpper(str)
|
|
382
|
+
|
|
383
|
+
> — 首字母大写。
|
|
300
384
|
|
|
301
|
-
|
|
385
|
+
```ts
|
|
386
|
+
firstUpper("hello"); // "Hello"
|
|
387
|
+
```
|
|
302
388
|
|
|
303
|
-
|
|
304
|
-
firstLower('Hello') // "hello"
|
|
305
|
-
```
|
|
389
|
+
#### firstLower(str)
|
|
306
390
|
|
|
307
|
-
|
|
391
|
+
> — 首字母小写。
|
|
308
392
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
393
|
+
```ts
|
|
394
|
+
firstLower("Hello"); // "hello"
|
|
395
|
+
```
|
|
312
396
|
|
|
313
|
-
|
|
397
|
+
#### reverse(str)
|
|
314
398
|
|
|
315
|
-
|
|
316
|
-
trimAll(' h e l lo ') // "hello"
|
|
317
|
-
```
|
|
399
|
+
> — 反转字符串。
|
|
318
400
|
|
|
319
|
-
|
|
401
|
+
```ts
|
|
402
|
+
reverse("hello"); // "olleh"
|
|
403
|
+
```
|
|
320
404
|
|
|
321
|
-
|
|
322
|
-
truncate('Hello World', 8) // "Hello..."
|
|
323
|
-
```
|
|
405
|
+
#### trimAll(str)
|
|
324
406
|
|
|
325
|
-
|
|
407
|
+
> — 去除所有空格。
|
|
326
408
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
409
|
+
```ts
|
|
410
|
+
trimAll(" h e l lo "); // "hello"
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
#### truncate(str, max, suffix?)
|
|
414
|
+
|
|
415
|
+
> — 超长文本截断。
|
|
416
|
+
|
|
417
|
+
```ts
|
|
418
|
+
truncate("Hello World", 8); // "Hello..."
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
#### truncateByWords(str, max, suffix?)
|
|
422
|
+
|
|
423
|
+
> — 按字数截断(中文友好)。
|
|
424
|
+
|
|
425
|
+
```ts
|
|
426
|
+
truncateByWords("你好世界欢迎你", 4); // "你好世界..."
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
### 存储
|
|
330
430
|
|
|
331
431
|
---
|
|
332
432
|
|
|
333
|
-
|
|
433
|
+
#### localGet<T>(key)
|
|
334
434
|
|
|
335
|
-
|
|
435
|
+
> — 获取 localStorage(自动 JSON 解析)。
|
|
336
436
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
437
|
+
```ts
|
|
438
|
+
localGet("user"); // { name: '张三' }
|
|
439
|
+
```
|
|
340
440
|
|
|
341
|
-
|
|
441
|
+
#### localSet(key, value)
|
|
342
442
|
|
|
343
|
-
|
|
344
|
-
localSet('user', { name: '张三' })
|
|
345
|
-
```
|
|
443
|
+
> — 设置 localStorage(自动 JSON 序列化)。
|
|
346
444
|
|
|
347
|
-
|
|
445
|
+
```ts
|
|
446
|
+
localSet("user", { name: "张三" });
|
|
447
|
+
```
|
|
348
448
|
|
|
349
|
-
|
|
350
|
-
localRm('user')
|
|
351
|
-
```
|
|
449
|
+
#### localRm(key)
|
|
352
450
|
|
|
353
|
-
|
|
451
|
+
> — 移除指定 localStorage。
|
|
354
452
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
453
|
+
```ts
|
|
454
|
+
localRm("user");
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
#### localClear()
|
|
458
|
+
|
|
459
|
+
> — 清除所有 localStorage。
|
|
460
|
+
|
|
461
|
+
```ts
|
|
462
|
+
localClear();
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
### 拷贝
|
|
358
466
|
|
|
359
467
|
---
|
|
360
468
|
|
|
361
|
-
|
|
469
|
+
#### deepClone(obj)
|
|
470
|
+
|
|
471
|
+
> — 递归深拷贝(支持 Date/RegExp/Map/Set/循环引用)。
|
|
472
|
+
|
|
473
|
+
```ts
|
|
474
|
+
deepClone({ a: 1, b: { c: 2 } });
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
#### deepCloneWithJSON(obj)
|
|
478
|
+
|
|
479
|
+
> — JSON 深拷贝(仅 JSON 安全类型)。
|
|
480
|
+
|
|
481
|
+
```ts
|
|
482
|
+
deepCloneWithJSON({ a: 1 });
|
|
483
|
+
```
|
|
362
484
|
|
|
363
|
-
|
|
485
|
+
#### structClone(obj, options?)
|
|
364
486
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
487
|
+
> — structuredClone 深拷贝(不支持函数/Symbol)。
|
|
488
|
+
|
|
489
|
+
```ts
|
|
490
|
+
structClone({ a: 1, b: { c: 2 } });
|
|
491
|
+
```
|
|
368
492
|
|
|
369
|
-
|
|
493
|
+
#### shallowClone(obj)
|
|
370
494
|
|
|
371
|
-
|
|
372
|
-
deepCloneWithJSON({ a: 1 })
|
|
373
|
-
```
|
|
495
|
+
> — 浅拷贝(仅第一层)。
|
|
374
496
|
|
|
375
|
-
|
|
497
|
+
```ts
|
|
498
|
+
shallowClone({ a: 1, b: { c: 2 } });
|
|
499
|
+
```
|
|
376
500
|
|
|
377
|
-
|
|
378
|
-
shallowClone({ a: 1, b: { c: 2 } })
|
|
379
|
-
```
|
|
501
|
+
### 数组
|
|
380
502
|
|
|
381
503
|
---
|
|
382
504
|
|
|
383
|
-
|
|
505
|
+
#### unique(arr)
|
|
506
|
+
|
|
507
|
+
> — Set 去重。
|
|
384
508
|
|
|
385
|
-
|
|
509
|
+
```ts
|
|
510
|
+
unique([1, 2, 2, 3]); // [1, 2, 3]
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
#### uniqueByKey(arr, key)
|
|
514
|
+
|
|
515
|
+
> — 对象数组按 key 去重。
|
|
516
|
+
|
|
517
|
+
```ts
|
|
518
|
+
uniqueByKey([{ id: 1 }, { id: 1 }], "id");
|
|
519
|
+
```
|
|
386
520
|
|
|
387
|
-
|
|
388
|
-
unique([1, 2, 2, 3]) // [1, 2, 3]
|
|
389
|
-
```
|
|
521
|
+
#### sortNumAsc(arr)
|
|
390
522
|
|
|
391
|
-
|
|
523
|
+
> — 数值升序。
|
|
392
524
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
525
|
+
```ts
|
|
526
|
+
sortNumAsc([3, 1, 2]); // [1, 2, 3]
|
|
527
|
+
```
|
|
396
528
|
|
|
397
|
-
|
|
529
|
+
#### sortNumDesc(arr)
|
|
398
530
|
|
|
399
|
-
|
|
400
|
-
sortNumAsc([3, 1, 2]) // [1, 2, 3]
|
|
401
|
-
```
|
|
531
|
+
> — 数值降序。
|
|
402
532
|
|
|
403
|
-
|
|
533
|
+
```ts
|
|
534
|
+
sortNumDesc([1, 3, 2]); // [3, 2, 1]
|
|
535
|
+
```
|
|
404
536
|
|
|
405
|
-
|
|
406
|
-
sortNumDesc([1, 3, 2]) // [3, 2, 1]
|
|
407
|
-
```
|
|
537
|
+
#### sortByKey(arr, key, order?)
|
|
408
538
|
|
|
409
|
-
|
|
539
|
+
> — 按对象属性排序。
|
|
410
540
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
541
|
+
```ts
|
|
542
|
+
sortByKey([{ age: 30 }, { age: 20 }], "age");
|
|
543
|
+
```
|
|
414
544
|
|
|
415
|
-
|
|
545
|
+
#### toArray(arrayLike)
|
|
416
546
|
|
|
417
|
-
|
|
418
|
-
toArray(document.querySelectorAll('div'))
|
|
419
|
-
```
|
|
547
|
+
> — 类数组转数组。
|
|
420
548
|
|
|
421
|
-
|
|
549
|
+
```ts
|
|
550
|
+
toArray(document.querySelectorAll("div"));
|
|
551
|
+
```
|
|
422
552
|
|
|
423
|
-
|
|
424
|
-
mergeArrays([1, 2], [3, 4], [5]) // [1, 2, 3, 4, 5]
|
|
425
|
-
```
|
|
553
|
+
#### mergeArrays(...arrays)
|
|
426
554
|
|
|
427
|
-
|
|
555
|
+
> — 合并多个数组。
|
|
428
556
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
```
|
|
557
|
+
```ts
|
|
558
|
+
mergeArrays([1, 2], [3, 4], [5]); // [1, 2, 3, 4, 5]
|
|
559
|
+
```
|
|
433
560
|
|
|
434
|
-
|
|
561
|
+
#### flatten(arr, depth?)
|
|
435
562
|
|
|
436
|
-
|
|
437
|
-
arrFind([{ id: 1 }, { id: 2 }], 'id', 2) // { id: 2 }
|
|
438
|
-
```
|
|
563
|
+
> — 多维数组扁平化到指定层级(默认 1 层,传 `Infinity` 完全展开)。
|
|
439
564
|
|
|
440
|
-
|
|
565
|
+
```ts
|
|
566
|
+
flatten([1, [2, [3, 4]], 5]); // [1, 2, [3, 4], 5]
|
|
567
|
+
flatten([1, [2, [3, 4]], 5], Infinity); // [1, 2, 3, 4, 5]
|
|
568
|
+
```
|
|
441
569
|
|
|
442
|
-
|
|
443
|
-
groupBy([{ type: 'fruit' }, { type: 'vegetable' }], 'type')
|
|
444
|
-
// => { fruit: [...], vegetable: [...] }
|
|
445
|
-
```
|
|
570
|
+
#### arrFind(arr, key, value)
|
|
446
571
|
|
|
447
|
-
|
|
572
|
+
> — 对象数组中按 key-value 查找第一个匹配项。
|
|
448
573
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
574
|
+
```ts
|
|
575
|
+
arrFind([{ id: 1 }, { id: 2 }], "id", 2); // { id: 2 }
|
|
576
|
+
```
|
|
452
577
|
|
|
453
|
-
|
|
578
|
+
#### groupBy(arr, key)
|
|
454
579
|
|
|
455
|
-
|
|
456
|
-
createRange(5) // [0, 1, 2, 3, 4]
|
|
457
|
-
createRange(3, (i) => i * 2) // [0, 2, 4]
|
|
458
|
-
```
|
|
580
|
+
> — 对象数组按指定属性分组。
|
|
459
581
|
|
|
460
|
-
|
|
582
|
+
```ts
|
|
583
|
+
groupBy([{ type: "fruit" }, { type: "vegetable" }], "type");
|
|
584
|
+
// => { fruit: [...], vegetable: [...] }
|
|
585
|
+
```
|
|
461
586
|
|
|
462
|
-
|
|
587
|
+
#### filterEmptyValues(obj)
|
|
463
588
|
|
|
464
|
-
|
|
589
|
+
> — 移除对象中值为空(null / undefined / 空字符串)的属性。
|
|
465
590
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
591
|
+
```ts
|
|
592
|
+
filterEmptyValues({ a: 1, b: "", c: null }); // { a: 1 }
|
|
593
|
+
```
|
|
469
594
|
|
|
470
|
-
|
|
595
|
+
#### createRange(length, mapFn?)
|
|
471
596
|
|
|
472
|
-
|
|
473
|
-
getCookie('token') // "abc123"
|
|
474
|
-
```
|
|
597
|
+
> — 快速生成范围数组。
|
|
475
598
|
|
|
476
|
-
|
|
599
|
+
```ts
|
|
600
|
+
createRange(5); // [0, 1, 2, 3, 4]
|
|
601
|
+
createRange(3, (i) => i * 2); // [0, 2, 4]
|
|
602
|
+
```
|
|
477
603
|
|
|
478
|
-
|
|
479
|
-
delCookie('token')
|
|
480
|
-
```
|
|
604
|
+
### Cookie
|
|
481
605
|
|
|
482
606
|
---
|
|
483
607
|
|
|
484
|
-
|
|
608
|
+
#### setCookie(name, value, days?)
|
|
485
609
|
|
|
486
|
-
|
|
610
|
+
> — 设置 Cookie(默认7天)。
|
|
487
611
|
|
|
488
|
-
|
|
612
|
+
```ts
|
|
613
|
+
setCookie("token", "abc123", 30);
|
|
614
|
+
```
|
|
489
615
|
|
|
490
|
-
|
|
491
|
-
getUrlParams('?a=1&b=2') // { a: '1', b: '2' }
|
|
492
|
-
```
|
|
616
|
+
#### getCookie(name)
|
|
493
617
|
|
|
494
|
-
|
|
618
|
+
> — 获取 Cookie。
|
|
495
619
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
620
|
+
```ts
|
|
621
|
+
getCookie("token"); // "abc123"
|
|
622
|
+
```
|
|
499
623
|
|
|
500
|
-
|
|
624
|
+
#### delCookie(name)
|
|
501
625
|
|
|
502
|
-
|
|
503
|
-
toQueryString({ a: 1, b: 'hello' }) // "a=1&b=hello"
|
|
504
|
-
```
|
|
626
|
+
> — 删除 Cookie。
|
|
505
627
|
|
|
506
|
-
|
|
628
|
+
```ts
|
|
629
|
+
delCookie("token");
|
|
630
|
+
```
|
|
507
631
|
|
|
508
|
-
|
|
632
|
+
### 浏览器
|
|
509
633
|
|
|
510
|
-
|
|
511
|
-
await copyToClipboard('Hello')
|
|
512
|
-
```
|
|
634
|
+
---
|
|
513
635
|
|
|
514
|
-
|
|
636
|
+
#### getUrlParams(url?)
|
|
515
637
|
|
|
516
|
-
|
|
517
|
-
downloadFile('Hello', 'hello.txt')
|
|
518
|
-
```
|
|
638
|
+
> — 获取 URL 参数对象。
|
|
519
639
|
|
|
520
|
-
|
|
640
|
+
```ts
|
|
641
|
+
getUrlParams("?a=1&b=2"); // { a: '1', b: '2' }
|
|
642
|
+
```
|
|
521
643
|
|
|
522
|
-
|
|
523
|
-
exportJSON({ name: '张三' })
|
|
524
|
-
```
|
|
644
|
+
#### getUrlParam(key, url?)
|
|
525
645
|
|
|
526
|
-
|
|
646
|
+
> — 获取单个 URL 参数。
|
|
527
647
|
|
|
528
|
-
|
|
648
|
+
```ts
|
|
649
|
+
getUrlParam("a"); // "1"
|
|
650
|
+
```
|
|
529
651
|
|
|
530
|
-
|
|
531
|
-
scrollToTop()
|
|
532
|
-
```
|
|
652
|
+
#### toQueryString(params)
|
|
533
653
|
|
|
534
|
-
|
|
654
|
+
> — 对象转 URL 参数字符串。
|
|
535
655
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
656
|
+
```ts
|
|
657
|
+
toQueryString({ a: 1, b: "hello" }); // "a=1&b=hello"
|
|
658
|
+
```
|
|
539
659
|
|
|
540
|
-
|
|
660
|
+
#### copyToClipboard(text)
|
|
541
661
|
|
|
542
|
-
|
|
543
|
-
const off = onScroll(y => console.log(y))
|
|
544
|
-
```
|
|
662
|
+
> — 复制文本到剪贴板(支持降级)。
|
|
545
663
|
|
|
546
|
-
|
|
664
|
+
```ts
|
|
665
|
+
await copyToClipboard("Hello");
|
|
666
|
+
```
|
|
547
667
|
|
|
548
|
-
|
|
668
|
+
#### downloadFile(content, filename, mimeType?)
|
|
549
669
|
|
|
550
|
-
|
|
551
|
-
const cleanup = observeIntersection(
|
|
552
|
-
document.querySelector('.footer')!,
|
|
553
|
-
() => loadMore(10),
|
|
554
|
-
);
|
|
555
|
-
```
|
|
670
|
+
> — 下载文件(Blob)。
|
|
556
671
|
|
|
557
|
-
|
|
672
|
+
```ts
|
|
673
|
+
downloadFile("Hello", "hello.txt");
|
|
674
|
+
```
|
|
558
675
|
|
|
559
|
-
|
|
676
|
+
#### exportJSON(data, filename?)
|
|
560
677
|
|
|
561
|
-
|
|
678
|
+
> — 导出 JSON 为文件。
|
|
562
679
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
// => 'c'
|
|
567
|
-
```
|
|
680
|
+
```ts
|
|
681
|
+
exportJSON({ name: "张三" });
|
|
682
|
+
```
|
|
568
683
|
|
|
569
|
-
|
|
684
|
+
#### scrollToTop(behavior?)
|
|
570
685
|
|
|
571
|
-
|
|
572
|
-
const fn = throttle((val: string) => console.log(val), 500)
|
|
573
|
-
fn('a'); fn('b'); fn('c')
|
|
574
|
-
// => 'a',500ms 后输出 'c'
|
|
575
|
-
```
|
|
686
|
+
> — 滚动到顶部(默认平滑)。
|
|
576
687
|
|
|
577
|
-
|
|
688
|
+
```ts
|
|
689
|
+
scrollToTop();
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
#### scrollToBottom(behavior?)
|
|
693
|
+
|
|
694
|
+
> — 滚动到底部(默认平滑)。
|
|
578
695
|
|
|
579
|
-
|
|
696
|
+
```ts
|
|
697
|
+
scrollToBottom();
|
|
698
|
+
```
|
|
580
699
|
|
|
581
|
-
|
|
700
|
+
#### onScroll(callback)
|
|
582
701
|
|
|
583
|
-
|
|
584
|
-
|
|
702
|
+
> — 监听滚动(rAF 节流),返回清理函数。
|
|
703
|
+
|
|
704
|
+
```ts
|
|
705
|
+
const off = onScroll((y) => console.log(y));
|
|
706
|
+
```
|
|
585
707
|
|
|
586
|
-
|
|
708
|
+
#### observeIntersection(target, onEnter, onLeave?, options?)
|
|
587
709
|
|
|
588
|
-
|
|
589
|
-
- **文档** — README 底部新增更新日志模块
|
|
710
|
+
> — 监听元素进入/离开可视区域,返回清理函数。
|
|
590
711
|
|
|
591
|
-
|
|
712
|
+
```ts
|
|
713
|
+
const cleanup = observeIntersection(document.querySelector(".footer")!, () =>
|
|
714
|
+
loadMore(10),
|
|
715
|
+
);
|
|
716
|
+
```
|
|
592
717
|
|
|
593
|
-
|
|
594
|
-
- **浏览器模块** — 新增 `observeIntersection` 可视区域检测(基于 IntersectionObserver)
|
|
718
|
+
### 防抖与节流
|
|
595
719
|
|
|
596
|
-
|
|
720
|
+
---
|
|
597
721
|
|
|
598
|
-
|
|
722
|
+
#### debounce(fn, delay?, options?)
|
|
599
723
|
|
|
600
|
-
|
|
724
|
+
> — 防抖,停止调用 delay 毫秒后才执行。
|
|
601
725
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
726
|
+
```ts
|
|
727
|
+
const fn = debounce((val: string) => console.log(val), 500);
|
|
728
|
+
fn("a");
|
|
729
|
+
fn("b");
|
|
730
|
+
fn("c");
|
|
731
|
+
// => 'c'
|
|
732
|
+
```
|
|
733
|
+
|
|
734
|
+
#### throttle(fn, interval?, options?)
|
|
735
|
+
|
|
736
|
+
> — 节流,固定间隔内最多执行一次。
|
|
737
|
+
|
|
738
|
+
```ts
|
|
739
|
+
const fn = throttle((val: string) => console.log(val), 500);
|
|
740
|
+
fn("a");
|
|
741
|
+
fn("b");
|
|
742
|
+
fn("c");
|
|
743
|
+
// => 'a',500ms 后输出 'c'
|
|
744
|
+
```
|
package/dist/copy/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare function deepClone<T>(obj: T, hash?: WeakMap<any, any>): T;
|
|
2
2
|
export declare function deepCloneWithJSON<T>(obj: T): T;
|
|
3
|
+
export declare function structClone<T>(obj: T, options?: StructuredSerializeOptions): T;
|
|
3
4
|
export declare function shallowClone<T>(obj: T): T;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=e=>Array.isArray(e),t=e=>typeof e==`object`&&!!e&&!Array.isArray(e),n=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,r=e=>n(e,`Function`)||!!(e&&e.constructor&&e.call&&e.apply),i=e=>n(e,`Date`)||!!e&&e.constructor===Date,a=e=>Number(e)===e,o=e=>a(e)&&Number.isFinite(e)&&e%1==0,s=e=>a(e)&&Number.isFinite(e)&&e%1!=0,c=e=>n(e,`AsyncFunction`),l=e=>!(!e||!e.then||!r(e.then)),u=e=>n(e,`String`)||typeof e==`string`||e instanceof String,d=e=>typeof e==`boolean`||n(e,`Boolean`),f=()=>typeof window<`u`,p=e=>typeof window<`u`&&n(e,`Window`),m=e=>t(e)&&!!e.tagName,h=e=>e===null,ee=e=>/^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(e),te=()=>/iPad|iPhone|iPod/.test(navigator.userAgent),ne=e=>/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(e),re=e=>e!==void 0,g=e=>e===void 0,_=e=>g(e)||h(e),v=e=>!!e&&e.constructor===Symbol,y=e=>e==null||typeof e!=`object`&&typeof e!=`function`,b=e=>{if(e==null)return!0;if(i(e))return isNaN(e.getTime());if(r(e)||v(e)||a(e))return!1;let t=e.length;if(a(t))return t===0;let n=e.size;return a(n)?n===0:Object.keys(e).length===0};function x(e){return e==null?!0:typeof e==`string`||Array.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:ArrayBuffer.isView(e)?e.byteLength===0:typeof e==`object`?Object.keys(e).length===0:!1}const S=(e,t)=>{if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;let n=Reflect.ownKeys(e),r=Reflect.ownKeys(t);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r++)if(!Reflect.has(t,n[r])||!S(e[n[r]],t[n[r]]))return!1;return!0},C=e=>new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}).format(e),w=e=>C(e).replace(/\//g,`-`),T=e=>new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`long`,day:`numeric`}).format(e),E=e=>new Intl.DateTimeFormat(`zh-CN`,{weekday:`long`}).format(e),D=(e,t)=>new Intl.NumberFormat(t.type,{style:`currency`,currency:t.currency}).format(e),O=e=>new Intl.NumberFormat(`zh-CN`).format(e),k=(e,t=0)=>new Intl.NumberFormat(`zh-CN`,{style:`percent`,minimumFractionDigits:t}).format(e),A=e=>new Intl.NumberFormat(`en-US`,{notation:`compact`,compactDisplay:`short`}).format(e),j=e=>new Intl.NumberFormat(`zh-CN`,{notation:`compact`,compactDisplay:`short`}).format(e),M=(e,t=0)=>new Intl.NumberFormat(`en-US`,{signDisplay:`always`,minimumFractionDigits:t}).format(e),N=e=>e.replace(/(\d{3})\d{4}(\d{4})/,`$1****$2`),P=e=>e.replace(/(\d{3})(\d{4})(\d{4})/,`$1 $2 $3`),F=e=>e.replace(/\b\w/g,e=>e.toUpperCase()),I=e=>e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),L=e=>e.replace(/([A-Z])/g,`-$1`).toLowerCase(),R=(e,t,n=`...`)=>e.length<=t?e:e.substring(0,t-n.length)+n,z=(e,t,n=`...`)=>{let r=e.split(``);return r.length<=t?e:r.slice(0,t).join(``)+n},B=e=>e.replace(/\s+/g,``),V=e=>e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase()),H=e=>e.charAt(0).toUpperCase()+e.slice(1),U=e=>e.charAt(0).toLowerCase()+e.slice(1),W=e=>e.split(``).reverse().join(``),G=e=>{let t=localStorage.getItem(e);if(t===null)return null;try{return JSON.parse(t)}catch{return t}},K=(e,t)=>{localStorage.setItem(e,JSON.stringify(t))},q=e=>{localStorage.removeItem(e)},J=()=>{localStorage.clear()};function Y(e,t=new WeakMap){if(typeof e!=`object`||!e)return e;if(t.has(e))return t.get(e);if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){let n=new Map;return t.set(e,n),e.forEach((e,r)=>{n.set(r,Y(e,t))}),n}if(e instanceof Set){let n=new Set;return t.set(e,n),e.forEach(e=>{n.add(Y(e,t))}),n}if(Array.isArray(e)){let n=[];return t.set(e,n),e.forEach((e,r)=>{n[r]=Y(e,t)}),n}let n={};return t.set(e,n),Object.keys(e).forEach(r=>{n[r]=Y(e[r],t)}),n}function X(e){return JSON.parse(JSON.stringify(e))}function ie(e){return typeof e!=`object`||!e?e:Array.isArray(e)?[...e]:{...e}}const
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=e=>Array.isArray(e),t=e=>typeof e==`object`&&!!e&&!Array.isArray(e),n=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,r=e=>n(e,`Function`)||!!(e&&e.constructor&&e.call&&e.apply),i=e=>n(e,`Date`)||!!e&&e.constructor===Date,a=e=>Number(e)===e,o=e=>a(e)&&Number.isFinite(e)&&e%1==0,s=e=>a(e)&&Number.isFinite(e)&&e%1!=0,c=e=>n(e,`AsyncFunction`),l=e=>!(!e||!e.then||!r(e.then)),u=e=>n(e,`String`)||typeof e==`string`||e instanceof String,d=e=>typeof e==`boolean`||n(e,`Boolean`),f=()=>typeof window<`u`,p=e=>typeof window<`u`&&n(e,`Window`),m=e=>t(e)&&!!e.tagName,h=e=>e===null,ee=e=>/^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(e),te=()=>/iPad|iPhone|iPod/.test(navigator.userAgent),ne=e=>/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(e),re=e=>e!==void 0,g=e=>e===void 0,_=e=>g(e)||h(e),v=e=>!!e&&e.constructor===Symbol,y=e=>e==null||typeof e!=`object`&&typeof e!=`function`,b=e=>{if(e==null)return!0;if(i(e))return isNaN(e.getTime());if(r(e)||v(e)||a(e))return!1;let t=e.length;if(a(t))return t===0;let n=e.size;return a(n)?n===0:Object.keys(e).length===0};function x(e){return e==null?!0:typeof e==`string`||Array.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:ArrayBuffer.isView(e)?e.byteLength===0:typeof e==`object`?Object.keys(e).length===0:!1}const S=(e,t)=>{if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;let n=Reflect.ownKeys(e),r=Reflect.ownKeys(t);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r++)if(!Reflect.has(t,n[r])||!S(e[n[r]],t[n[r]]))return!1;return!0},C=e=>new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}).format(e),w=e=>C(e).replace(/\//g,`-`),T=e=>new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`long`,day:`numeric`}).format(e),E=e=>new Intl.DateTimeFormat(`zh-CN`,{weekday:`long`}).format(e),D=(e,t)=>new Intl.NumberFormat(t.type,{style:`currency`,currency:t.currency}).format(e),O=e=>new Intl.NumberFormat(`zh-CN`).format(e),k=(e,t=0)=>new Intl.NumberFormat(`zh-CN`,{style:`percent`,minimumFractionDigits:t}).format(e),A=e=>new Intl.NumberFormat(`en-US`,{notation:`compact`,compactDisplay:`short`}).format(e),j=e=>new Intl.NumberFormat(`zh-CN`,{notation:`compact`,compactDisplay:`short`}).format(e),M=(e,t=0)=>new Intl.NumberFormat(`en-US`,{signDisplay:`always`,minimumFractionDigits:t}).format(e),N=e=>e.replace(/(\d{3})\d{4}(\d{4})/,`$1****$2`),P=e=>e.replace(/(\d{3})(\d{4})(\d{4})/,`$1 $2 $3`),F=e=>e.replace(/\b\w/g,e=>e.toUpperCase()),I=e=>e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),L=e=>e.replace(/([A-Z])/g,`-$1`).toLowerCase(),R=(e,t,n=`...`)=>e.length<=t?e:e.substring(0,t-n.length)+n,z=(e,t,n=`...`)=>{let r=e.split(``);return r.length<=t?e:r.slice(0,t).join(``)+n},B=e=>e.replace(/\s+/g,``),V=e=>e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase()),H=e=>e.charAt(0).toUpperCase()+e.slice(1),U=e=>e.charAt(0).toLowerCase()+e.slice(1),W=e=>e.split(``).reverse().join(``),G=e=>{let t=localStorage.getItem(e);if(t===null)return null;try{return JSON.parse(t)}catch{return t}},K=(e,t)=>{localStorage.setItem(e,JSON.stringify(t))},q=e=>{localStorage.removeItem(e)},J=()=>{localStorage.clear()};function Y(e,t=new WeakMap){if(typeof e!=`object`||!e)return e;if(t.has(e))return t.get(e);if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){let n=new Map;return t.set(e,n),e.forEach((e,r)=>{n.set(r,Y(e,t))}),n}if(e instanceof Set){let n=new Set;return t.set(e,n),e.forEach(e=>{n.add(Y(e,t))}),n}if(Array.isArray(e)){let n=[];return t.set(e,n),e.forEach((e,r)=>{n[r]=Y(e,t)}),n}let n={};return t.set(e,n),Object.keys(e).forEach(r=>{n[r]=Y(e[r],t)}),n}function X(e){return JSON.parse(JSON.stringify(e))}function ie(e,t){return structuredClone(e,t)}function ae(e){return typeof e!=`object`||!e?e:Array.isArray(e)?[...e]:{...e}}const oe=e=>[...new Set(e)],se=(e,t)=>[...new Map(e.map(e=>[e[t],e])).values()],ce=e=>[...e].sort((e,t)=>e-t),le=e=>[...e].sort((e,t)=>t-e),ue=(e,t,n=`asc`)=>[...e].sort((e,r)=>n===`asc`?e[t]-r[t]:r[t]-e[t]),de=e=>Array.from(e),fe=(...e)=>[].concat(...e),pe=(e,t=1)=>e.flat(t),me=(e,t,n)=>e.find(e=>e[t]===n),he=(e,t)=>e.reduce((e,n)=>{let r=String(n[t]);return e[r]||(e[r]=[]),e[r].push(n),e},{}),ge=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!=null&&e!==``)),_e=(e,t)=>Array.from({length:e},(e,n)=>t?t(n):n),Z=(e,t,n=0)=>{let r=new Date;r.setDate(r.getDate()+n),document.cookie=`${encodeURIComponent(e)}=${encodeURIComponent(t)}; expires=${r.toUTCString()}; path=/`},ve=e=>{let t=document.cookie.match(RegExp(`(^| )`+encodeURIComponent(e)+`=([^;]+)`));return t?decodeURIComponent(t[2]):null},ye=e=>{Z(e,``,-1)},be=e=>{let t={};return new URL(e||window.location.href).searchParams.forEach((e,n)=>{t[n]=e}),t},xe=(e,t)=>new URL(t||window.location.href).searchParams.get(e),Q=e=>Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join(`&`),Se=async e=>{if(navigator.clipboard)try{return await navigator.clipboard.writeText(e),!0}catch{return!1}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n},$=(e,t,n=`text/plain`)=>{let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,a.click(),URL.revokeObjectURL(i)},Ce=(e,t=`data.json`)=>{$(JSON.stringify(e,null,2),t,`application/json`)},we=(e=`smooth`)=>{window.scrollTo({top:0,behavior:e})},Te=(e=`smooth`)=>{window.scrollTo({top:document.documentElement.scrollHeight,behavior:e})},Ee=e=>{let t=!1,n=()=>{t||=(requestAnimationFrame(()=>{e(window.scrollY),t=!1}),!0)};return window.addEventListener(`scroll`,n),()=>window.removeEventListener(`scroll`,n)},De=(e,t,n,r)=>{let i=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting?t(e):n&&n(e)})},r);return i.observe(e),()=>i.disconnect()},Oe=(e,t=300,{leading:n=!1,trailing:r=!0}={})=>{let i=null,a=null,o=r,s=(...s)=>{a=s,i===null?n&&(e(...s),o=!1):(clearTimeout(i),o=r),i=setTimeout(()=>{o&&a&&e(...a),i=a=null,o=r},t)};return s.cancel=()=>{i&&=(clearTimeout(i),a=null),o=r},s},ke=(e,t=300,{leading:n=!0,trailing:r=!0}={})=>{let i=null,a=0,o=null,s=(...s)=>{let c=Date.now();!a&&!n&&(a=c);let l=t-(c-a);o=s,l<=0?(i&&=(clearTimeout(i),null),e(...s),a=c,o=null):r&&!i&&(i=setTimeout(()=>{i=null,a=n?Date.now():0,o&&e(...o),o=null},l))};return s.cancel=()=>{i&&=(clearTimeout(i),o=null)},s};exports.arrFind=me,exports.camelToKebab=L,exports.capitalize=F,exports.compactCN=j,exports.compactEN=A,exports.copyToClipboard=Se,exports.createRange=_e,exports.debounce=Oe,exports.deepClone=Y,exports.deepCloneWithJSON=X,exports.delCookie=ye,exports.downloadFile=$,exports.exportJSON=Ce,exports.filterEmptyValues=ge,exports.firstLower=U,exports.firstUpper=H,exports.flatten=pe,exports.formatFull=C,exports.formatFullReplace=w,exports.formatNum=O,exports.formatRmb=D,exports.formatWeek=E,exports.formatYMD=T,exports.getCookie=ve,exports.getUrlParam=xe,exports.getUrlParams=be,exports.groupBy=he,exports.is=n,exports.isArray=e,exports.isAsyncFunction=c,exports.isBoolean=d,exports.isDate=i,exports.isDef=re,exports.isElement=m,exports.isEmpty=b,exports.isEmptySv=x,exports.isEqual=S,exports.isFloat=s,exports.isFunction=r,exports.isHexColor=ee,exports.isIOS=te,exports.isInt=o,exports.isNull=h,exports.isNullOrUnDef=_,exports.isNumber=a,exports.isObject=t,exports.isPC=f,exports.isPrimitive=y,exports.isPromise=l,exports.isString=u,exports.isSymbol=v,exports.isUnDef=g,exports.isValidEmail=ne,exports.isWindow=p,exports.kebabToCamel=I,exports.localClear=J,exports.localGet=G,exports.localRm=q,exports.localSet=K,exports.maskPhone=N,exports.mergeArrays=fe,exports.observeIntersection=De,exports.onScroll=Ee,exports.percentCN=k,exports.reverse=W,exports.scrollToBottom=Te,exports.scrollToTop=we,exports.setCookie=Z,exports.shallowClone=ae,exports.signed=M,exports.sortByKey=ue,exports.sortNumAsc=ce,exports.sortNumDesc=le,exports.spacePhone=P,exports.structClone=ie,exports.throttle=ke,exports.toArray=de,exports.toCamel=V,exports.toQueryString=Q,exports.trimAll=B,exports.truncate=R,exports.truncateByWords=z,exports.unique=oe,exports.uniqueByKey=se;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>Array.isArray(e),t=e=>typeof e==`object`&&!!e&&!Array.isArray(e),n=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,r=e=>n(e,`Function`)||!!(e&&e.constructor&&e.call&&e.apply),i=e=>n(e,`Date`)||!!e&&e.constructor===Date,a=e=>Number(e)===e,o=e=>a(e)&&Number.isFinite(e)&&e%1==0,s=e=>a(e)&&Number.isFinite(e)&&e%1!=0,c=e=>n(e,`AsyncFunction`),l=e=>!(!e||!e.then||!r(e.then)),u=e=>n(e,`String`)||typeof e==`string`||e instanceof String,d=e=>typeof e==`boolean`||n(e,`Boolean`),f=()=>typeof window<`u`,p=e=>typeof window<`u`&&n(e,`Window`),m=e=>t(e)&&!!e.tagName,h=e=>e===null,ee=e=>/^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(e),te=()=>/iPad|iPhone|iPod/.test(navigator.userAgent),ne=e=>/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(e),re=e=>e!==void 0,g=e=>e===void 0,_=e=>g(e)||h(e),v=e=>!!e&&e.constructor===Symbol,y=e=>e==null||typeof e!=`object`&&typeof e!=`function`,b=e=>{if(e==null)return!0;if(i(e))return isNaN(e.getTime());if(r(e)||v(e)||a(e))return!1;let t=e.length;if(a(t))return t===0;let n=e.size;return a(n)?n===0:Object.keys(e).length===0};function x(e){return e==null?!0:typeof e==`string`||Array.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:ArrayBuffer.isView(e)?e.byteLength===0:typeof e==`object`?Object.keys(e).length===0:!1}const S=(e,t)=>{if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;let n=Reflect.ownKeys(e),r=Reflect.ownKeys(t);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r++)if(!Reflect.has(t,n[r])||!S(e[n[r]],t[n[r]]))return!1;return!0},C=e=>new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}).format(e),w=e=>C(e).replace(/\//g,`-`),T=e=>new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`long`,day:`numeric`}).format(e),E=e=>new Intl.DateTimeFormat(`zh-CN`,{weekday:`long`}).format(e),D=(e,t)=>new Intl.NumberFormat(t.type,{style:`currency`,currency:t.currency}).format(e),O=e=>new Intl.NumberFormat(`zh-CN`).format(e),k=(e,t=0)=>new Intl.NumberFormat(`zh-CN`,{style:`percent`,minimumFractionDigits:t}).format(e),A=e=>new Intl.NumberFormat(`en-US`,{notation:`compact`,compactDisplay:`short`}).format(e),j=e=>new Intl.NumberFormat(`zh-CN`,{notation:`compact`,compactDisplay:`short`}).format(e),M=(e,t=0)=>new Intl.NumberFormat(`en-US`,{signDisplay:`always`,minimumFractionDigits:t}).format(e),N=e=>e.replace(/(\d{3})\d{4}(\d{4})/,`$1****$2`),P=e=>e.replace(/(\d{3})(\d{4})(\d{4})/,`$1 $2 $3`),F=e=>e.replace(/\b\w/g,e=>e.toUpperCase()),I=e=>e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),L=e=>e.replace(/([A-Z])/g,`-$1`).toLowerCase(),R=(e,t,n=`...`)=>e.length<=t?e:e.substring(0,t-n.length)+n,z=(e,t,n=`...`)=>{let r=e.split(``);return r.length<=t?e:r.slice(0,t).join(``)+n},B=e=>e.replace(/\s+/g,``),V=e=>e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase()),H=e=>e.charAt(0).toUpperCase()+e.slice(1),U=e=>e.charAt(0).toLowerCase()+e.slice(1),W=e=>e.split(``).reverse().join(``),G=e=>{let t=localStorage.getItem(e);if(t===null)return null;try{return JSON.parse(t)}catch{return t}},K=(e,t)=>{localStorage.setItem(e,JSON.stringify(t))},q=e=>{localStorage.removeItem(e)},J=()=>{localStorage.clear()};function Y(e,t=new WeakMap){if(typeof e!=`object`||!e)return e;if(t.has(e))return t.get(e);if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){let n=new Map;return t.set(e,n),e.forEach((e,r)=>{n.set(r,Y(e,t))}),n}if(e instanceof Set){let n=new Set;return t.set(e,n),e.forEach(e=>{n.add(Y(e,t))}),n}if(Array.isArray(e)){let n=[];return t.set(e,n),e.forEach((e,r)=>{n[r]=Y(e,t)}),n}let n={};return t.set(e,n),Object.keys(e).forEach(r=>{n[r]=Y(e[r],t)}),n}function X(e){return JSON.parse(JSON.stringify(e))}function ie(e){return typeof e!=`object`||!e?e:Array.isArray(e)?[...e]:{...e}}const
|
|
1
|
+
const e=e=>Array.isArray(e),t=e=>typeof e==`object`&&!!e&&!Array.isArray(e),n=(e,t)=>Object.prototype.toString.call(e)===`[object ${t}]`,r=e=>n(e,`Function`)||!!(e&&e.constructor&&e.call&&e.apply),i=e=>n(e,`Date`)||!!e&&e.constructor===Date,a=e=>Number(e)===e,o=e=>a(e)&&Number.isFinite(e)&&e%1==0,s=e=>a(e)&&Number.isFinite(e)&&e%1!=0,c=e=>n(e,`AsyncFunction`),l=e=>!(!e||!e.then||!r(e.then)),u=e=>n(e,`String`)||typeof e==`string`||e instanceof String,d=e=>typeof e==`boolean`||n(e,`Boolean`),f=()=>typeof window<`u`,p=e=>typeof window<`u`&&n(e,`Window`),m=e=>t(e)&&!!e.tagName,h=e=>e===null,ee=e=>/^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(e),te=()=>/iPad|iPhone|iPod/.test(navigator.userAgent),ne=e=>/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(e),re=e=>e!==void 0,g=e=>e===void 0,_=e=>g(e)||h(e),v=e=>!!e&&e.constructor===Symbol,y=e=>e==null||typeof e!=`object`&&typeof e!=`function`,b=e=>{if(e==null)return!0;if(i(e))return isNaN(e.getTime());if(r(e)||v(e)||a(e))return!1;let t=e.length;if(a(t))return t===0;let n=e.size;return a(n)?n===0:Object.keys(e).length===0};function x(e){return e==null?!0:typeof e==`string`||Array.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:ArrayBuffer.isView(e)?e.byteLength===0:typeof e==`object`?Object.keys(e).length===0:!1}const S=(e,t)=>{if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;let n=Reflect.ownKeys(e),r=Reflect.ownKeys(t);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r++)if(!Reflect.has(t,n[r])||!S(e[n[r]],t[n[r]]))return!1;return!0},C=e=>new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}).format(e),w=e=>C(e).replace(/\//g,`-`),T=e=>new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`long`,day:`numeric`}).format(e),E=e=>new Intl.DateTimeFormat(`zh-CN`,{weekday:`long`}).format(e),D=(e,t)=>new Intl.NumberFormat(t.type,{style:`currency`,currency:t.currency}).format(e),O=e=>new Intl.NumberFormat(`zh-CN`).format(e),k=(e,t=0)=>new Intl.NumberFormat(`zh-CN`,{style:`percent`,minimumFractionDigits:t}).format(e),A=e=>new Intl.NumberFormat(`en-US`,{notation:`compact`,compactDisplay:`short`}).format(e),j=e=>new Intl.NumberFormat(`zh-CN`,{notation:`compact`,compactDisplay:`short`}).format(e),M=(e,t=0)=>new Intl.NumberFormat(`en-US`,{signDisplay:`always`,minimumFractionDigits:t}).format(e),N=e=>e.replace(/(\d{3})\d{4}(\d{4})/,`$1****$2`),P=e=>e.replace(/(\d{3})(\d{4})(\d{4})/,`$1 $2 $3`),F=e=>e.replace(/\b\w/g,e=>e.toUpperCase()),I=e=>e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),L=e=>e.replace(/([A-Z])/g,`-$1`).toLowerCase(),R=(e,t,n=`...`)=>e.length<=t?e:e.substring(0,t-n.length)+n,z=(e,t,n=`...`)=>{let r=e.split(``);return r.length<=t?e:r.slice(0,t).join(``)+n},B=e=>e.replace(/\s+/g,``),V=e=>e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase()),H=e=>e.charAt(0).toUpperCase()+e.slice(1),U=e=>e.charAt(0).toLowerCase()+e.slice(1),W=e=>e.split(``).reverse().join(``),G=e=>{let t=localStorage.getItem(e);if(t===null)return null;try{return JSON.parse(t)}catch{return t}},K=(e,t)=>{localStorage.setItem(e,JSON.stringify(t))},q=e=>{localStorage.removeItem(e)},J=()=>{localStorage.clear()};function Y(e,t=new WeakMap){if(typeof e!=`object`||!e)return e;if(t.has(e))return t.get(e);if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){let n=new Map;return t.set(e,n),e.forEach((e,r)=>{n.set(r,Y(e,t))}),n}if(e instanceof Set){let n=new Set;return t.set(e,n),e.forEach(e=>{n.add(Y(e,t))}),n}if(Array.isArray(e)){let n=[];return t.set(e,n),e.forEach((e,r)=>{n[r]=Y(e,t)}),n}let n={};return t.set(e,n),Object.keys(e).forEach(r=>{n[r]=Y(e[r],t)}),n}function X(e){return JSON.parse(JSON.stringify(e))}function ie(e,t){return structuredClone(e,t)}function ae(e){return typeof e!=`object`||!e?e:Array.isArray(e)?[...e]:{...e}}const oe=e=>[...new Set(e)],se=(e,t)=>[...new Map(e.map(e=>[e[t],e])).values()],ce=e=>[...e].sort((e,t)=>e-t),le=e=>[...e].sort((e,t)=>t-e),ue=(e,t,n=`asc`)=>[...e].sort((e,r)=>n===`asc`?e[t]-r[t]:r[t]-e[t]),de=e=>Array.from(e),fe=(...e)=>[].concat(...e),pe=(e,t=1)=>e.flat(t),me=(e,t,n)=>e.find(e=>e[t]===n),he=(e,t)=>e.reduce((e,n)=>{let r=String(n[t]);return e[r]||(e[r]=[]),e[r].push(n),e},{}),ge=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!=null&&e!==``)),_e=(e,t)=>Array.from({length:e},(e,n)=>t?t(n):n),Z=(e,t,n=0)=>{let r=new Date;r.setDate(r.getDate()+n),document.cookie=`${encodeURIComponent(e)}=${encodeURIComponent(t)}; expires=${r.toUTCString()}; path=/`},ve=e=>{let t=document.cookie.match(RegExp(`(^| )`+encodeURIComponent(e)+`=([^;]+)`));return t?decodeURIComponent(t[2]):null},ye=e=>{Z(e,``,-1)},be=e=>{let t={};return new URL(e||window.location.href).searchParams.forEach((e,n)=>{t[n]=e}),t},xe=(e,t)=>new URL(t||window.location.href).searchParams.get(e),Q=e=>Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join(`&`),Se=async e=>{if(navigator.clipboard)try{return await navigator.clipboard.writeText(e),!0}catch{return!1}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n},$=(e,t,n=`text/plain`)=>{let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,a.click(),URL.revokeObjectURL(i)},Ce=(e,t=`data.json`)=>{$(JSON.stringify(e,null,2),t,`application/json`)},we=(e=`smooth`)=>{window.scrollTo({top:0,behavior:e})},Te=(e=`smooth`)=>{window.scrollTo({top:document.documentElement.scrollHeight,behavior:e})},Ee=e=>{let t=!1,n=()=>{t||=(requestAnimationFrame(()=>{e(window.scrollY),t=!1}),!0)};return window.addEventListener(`scroll`,n),()=>window.removeEventListener(`scroll`,n)},De=(e,t,n,r)=>{let i=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting?t(e):n&&n(e)})},r);return i.observe(e),()=>i.disconnect()},Oe=(e,t=300,{leading:n=!1,trailing:r=!0}={})=>{let i=null,a=null,o=r,s=(...s)=>{a=s,i===null?n&&(e(...s),o=!1):(clearTimeout(i),o=r),i=setTimeout(()=>{o&&a&&e(...a),i=a=null,o=r},t)};return s.cancel=()=>{i&&=(clearTimeout(i),a=null),o=r},s},ke=(e,t=300,{leading:n=!0,trailing:r=!0}={})=>{let i=null,a=0,o=null,s=(...s)=>{let c=Date.now();!a&&!n&&(a=c);let l=t-(c-a);o=s,l<=0?(i&&=(clearTimeout(i),null),e(...s),a=c,o=null):r&&!i&&(i=setTimeout(()=>{i=null,a=n?Date.now():0,o&&e(...o),o=null},l))};return s.cancel=()=>{i&&=(clearTimeout(i),o=null)},s};export{me as arrFind,L as camelToKebab,F as capitalize,j as compactCN,A as compactEN,Se as copyToClipboard,_e as createRange,Oe as debounce,Y as deepClone,X as deepCloneWithJSON,ye as delCookie,$ as downloadFile,Ce as exportJSON,ge as filterEmptyValues,U as firstLower,H as firstUpper,pe as flatten,C as formatFull,w as formatFullReplace,O as formatNum,D as formatRmb,E as formatWeek,T as formatYMD,ve as getCookie,xe as getUrlParam,be as getUrlParams,he as groupBy,n as is,e as isArray,c as isAsyncFunction,d as isBoolean,i as isDate,re as isDef,m as isElement,b as isEmpty,x as isEmptySv,S as isEqual,s as isFloat,r as isFunction,ee as isHexColor,te as isIOS,o as isInt,h as isNull,_ as isNullOrUnDef,a as isNumber,t as isObject,f as isPC,y as isPrimitive,l as isPromise,u as isString,v as isSymbol,g as isUnDef,ne as isValidEmail,p as isWindow,I as kebabToCamel,J as localClear,G as localGet,q as localRm,K as localSet,N as maskPhone,fe as mergeArrays,De as observeIntersection,Ee as onScroll,k as percentCN,W as reverse,Te as scrollToBottom,we as scrollToTop,Z as setCookie,ae as shallowClone,M as signed,ue as sortByKey,ce as sortNumAsc,le as sortNumDesc,P as spacePhone,ie as structClone,ke as throttle,de as toArray,V as toCamel,Q as toQueryString,B as trimAll,R as truncate,z as truncateByWords,oe as unique,se as uniqueByKey};
|