lyb-js 1.1.5 → 1.1.6
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 +107 -45
- package/dist/Base/LibJsGetDataType/index.d.ts +1 -5
- package/dist/Base/LibJsGetDataType/index.js +1 -5
- package/dist/Base/LibJsPromiseTimeout/index.d.ts +1 -5
- package/dist/Base/LibJsPromiseTimeout/index.js +1 -5
- package/dist/Browser/LibJsColorConsole/index.d.ts +1 -7
- package/dist/Browser/LibJsColorConsole/index.js +1 -7
- package/dist/Browser/LibJsIsMobile/index.d.ts +1 -4
- package/dist/Browser/LibJsIsMobile/index.js +1 -4
- package/dist/Browser/LibJsIsPad/index.d.ts +1 -4
- package/dist/Browser/LibJsIsPad/index.js +1 -4
- package/dist/Browser/LibJsObjToUrlParams/index.d.ts +1 -4
- package/dist/Browser/LibJsObjToUrlParams/index.js +1 -4
- package/dist/Browser/LibJsPathParams/index.d.ts +1 -4
- package/dist/Browser/LibJsPathParams/index.js +1 -4
- package/dist/Browser/LibJsSetTitleIcon/index.d.ts +1 -3
- package/dist/Browser/LibJsSetTitleIcon/index.js +1 -3
- package/dist/Browser/LibJsTagTitleTip/index.d.ts +1 -3
- package/dist/Browser/LibJsTagTitleTip/index.js +1 -3
- package/dist/Data/LibJsChunkArray/index.d.ts +1 -4
- package/dist/Data/LibJsChunkArray/index.js +1 -4
- package/dist/Data/LibJsDeepJSONParse/index.d.ts +1 -4
- package/dist/Data/LibJsDeepJSONParse/index.js +1 -4
- package/dist/Data/LibJsGroupArrayByKey/index.d.ts +1 -4
- package/dist/Data/LibJsGroupArrayByKey/index.js +1 -4
- package/dist/Data/LibJsMatchEmail/index.d.ts +1 -4
- package/dist/Data/LibJsMatchEmail/index.js +1 -4
- package/dist/Data/LibJsShuffleArray/index.d.ts +1 -4
- package/dist/Data/LibJsShuffleArray/index.js +1 -4
- package/dist/Data/LibJsStepArray/index.d.ts +1 -4
- package/dist/Data/LibJsStepArray/index.js +1 -4
- package/dist/Data/LibReverseArrayFromIndex/index.d.ts +1 -4
- package/dist/Data/LibReverseArrayFromIndex/index.js +1 -4
- package/dist/File/LibJsDownloadImageLink/index.d.ts +1 -3
- package/dist/File/LibJsDownloadImageLink/index.js +1 -3
- package/dist/File/LibJsImageOptimizer/index.d.ts +1 -14
- package/dist/File/LibJsImageOptimizer/index.js +1 -14
- package/dist/File/LibJsSaveJson/index.d.ts +1 -4
- package/dist/File/LibJsSaveJson/index.js +1 -4
- package/dist/Formatter/LibJsFormatterByte/index.d.ts +1 -4
- package/dist/Formatter/LibJsFormatterByte/index.js +1 -4
- package/dist/Formatter/LibJsMaskPhoneNumber/index.d.ts +1 -4
- package/dist/Formatter/LibJsMaskPhoneNumber/index.js +1 -4
- package/dist/Formatter/LibJsNumComma/index.d.ts +1 -4
- package/dist/Formatter/LibJsNumComma/index.js +1 -4
- package/dist/Formatter/LibJsNumberUnit/index.d.ts +1 -4
- package/dist/Formatter/LibJsNumberUnit/index.js +1 -4
- package/dist/Formatter/LibJsSecondsFormatterChinese/index.d.ts +1 -6
- package/dist/Formatter/LibJsSecondsFormatterChinese/index.js +1 -6
- package/dist/Math/LibJsCalculateExpression/index.d.ts +1 -4
- package/dist/Math/LibJsCalculateExpression/index.js +16 -17
- package/dist/Math/LibJsConvertAngle/index.d.ts +1 -7
- package/dist/Math/LibJsConvertAngle/index.js +1 -7
- package/dist/Math/LibJsCoordsAngle/index.d.ts +1 -5
- package/dist/Math/LibJsCoordsAngle/index.js +1 -5
- package/dist/Math/LibJsCoordsDistance/index.d.ts +1 -5
- package/dist/Math/LibJsCoordsDistance/index.js +1 -5
- package/dist/Math/LibJsDecimal/index.d.ts +1 -5
- package/dist/Math/LibJsDecimal/index.js +1 -5
- package/dist/Misc/LibJsRegFormValidate/index.d.ts +1 -16
- package/dist/Misc/LibJsRegFormValidate/index.js +1 -16
- package/dist/Misc/LibJsRetryRequest/index.d.ts +1 -12
- package/dist/Misc/LibJsRetryRequest/index.js +1 -12
- package/dist/Misc/LibNumerStepper/index.d.ts +1 -6
- package/dist/Misc/LibNumerStepper/index.js +1 -6
- package/dist/Random/LibJsProbabilityResult/index.d.ts +1 -5
- package/dist/Random/LibJsProbabilityResult/index.js +1 -5
- package/dist/Random/LibJsRandom/index.d.ts +1 -4
- package/dist/Random/LibJsRandom/index.js +1 -4
- package/dist/Random/LibJsRandomColor/index.d.ts +1 -4
- package/dist/Random/LibJsRandomColor/index.js +1 -4
- package/dist/Random/LibJsUniqueRandomNumbers/index.d.ts +1 -4
- package/dist/Random/LibJsUniqueRandomNumbers/index.js +1 -4
- package/dist/Time/LibJsSameTimeCheck/index.d.ts +1 -5
- package/dist/Time/LibJsSameTimeCheck/index.js +1 -5
- package/dist/Time/LibJsTimeAgo/index.d.ts +1 -6
- package/dist/Time/LibJsTimeAgo/index.js +1 -6
- package/dist/Time/LibJsTimeGreeting/index.d.ts +1 -5
- package/dist/Time/LibJsTimeGreeting/index.js +1 -5
- package/dist/libJs.d.ts +39 -199
- package/dist/libJs.js +39 -199
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
> 该库为作者在写项目时收集的常用方法,代码简陋,没有严格的边缘处理
|
|
6
6
|
>
|
|
7
|
-
>
|
|
7
|
+
> 在通过`import`引入使用时,鼠标悬浮在每一个方法上都有较为完整的`Jsdoc`提示
|
|
8
8
|
|
|
9
9
|
## 起步
|
|
10
10
|
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
```ts
|
|
14
14
|
import { LibJs } from "lyb-js";
|
|
15
15
|
|
|
16
|
-
LibJs.Base.libJsGetDataType("Hellow World!");
|
|
16
|
+
const t = LibJs.Base.libJsGetDataType("Hellow World!");
|
|
17
|
+
console.log(t); //"string"
|
|
17
18
|
```
|
|
18
19
|
|
|
19
20
|
> 按需引入,打包时就不会把整个库打进去
|
|
@@ -21,7 +22,8 @@ LibJs.Base.libJsGetDataType("Hellow World!"); //"string"
|
|
|
21
22
|
```ts
|
|
22
23
|
import { libJsGetDataType } from "lyb-js/dist/Base/LibJsGetDataType";
|
|
23
24
|
|
|
24
|
-
libJsGetDataType("Hellow World!");
|
|
25
|
+
const t = libJsGetDataType("Hellow World!");
|
|
26
|
+
console.log(t); //"string"
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
> 如果在多个文件使用到同一个方法,建议采用按需引入聚合导出
|
|
@@ -34,8 +36,11 @@ export * from "lyb-js/dist/Math/LibJsCalculateExpression";
|
|
|
34
36
|
//你的项目文件 index.ts
|
|
35
37
|
import { libJsGetDataType,libJsCalculateExpression } from "utils";
|
|
36
38
|
|
|
37
|
-
libJsGetDataType("Hellow World!");
|
|
38
|
-
|
|
39
|
+
const t = libJsGetDataType("Hellow World!");
|
|
40
|
+
console.log(t); //"string"
|
|
41
|
+
|
|
42
|
+
const v = libJsCalculateExpression("(1+2)-(3*4)/5");
|
|
43
|
+
conosle.log(v); //0.6
|
|
39
44
|
```
|
|
40
45
|
|
|
41
46
|
**通过 `CDN ` 使用 `LibJs`**
|
|
@@ -46,7 +51,8 @@ libJsCalculateExpression("(1+2)-(3*4)/5"); //0.6
|
|
|
46
51
|
<script src="https://unpkg.com/lyb-js/umd/lyb.js"></script>
|
|
47
52
|
|
|
48
53
|
<script>
|
|
49
|
-
LibJs.Base.libJsGetDataType("Hellow World!");
|
|
54
|
+
const t = LibJs.Base.libJsGetDataType("Hellow World!");
|
|
55
|
+
console.log(t); //"string"
|
|
50
56
|
</script>
|
|
51
57
|
```
|
|
52
58
|
|
|
@@ -163,9 +169,14 @@ LibJs.Base.libJsGetDataType("Hellow World!"); //"string"
|
|
|
163
169
|
> 返回数据类型
|
|
164
170
|
|
|
165
171
|
```ts
|
|
166
|
-
libJsGetDataType(123);
|
|
167
|
-
|
|
168
|
-
|
|
172
|
+
const n = libJsGetDataType(123);
|
|
173
|
+
console.log(n); //"number"
|
|
174
|
+
|
|
175
|
+
const s = libJsGetDataType("hello");
|
|
176
|
+
console.log(s); //"string"
|
|
177
|
+
|
|
178
|
+
const a = libJsGetDataType([1, 2, 3]);
|
|
179
|
+
console.log(a); //"array"
|
|
169
180
|
```
|
|
170
181
|
|
|
171
182
|
### LibJsPromiseTimeout-延时执行
|
|
@@ -305,8 +316,8 @@ console.log(moved); //[4, 5, 1, 2, 3]
|
|
|
305
316
|
> 翻转指定索引后面的数组
|
|
306
317
|
|
|
307
318
|
```ts
|
|
308
|
-
libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
|
|
309
|
-
// [1, 2, 5, 4, 3]
|
|
319
|
+
const newArr = libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
|
|
320
|
+
console.log(newArr); // [1, 2, 5, 4, 3]
|
|
310
321
|
```
|
|
311
322
|
|
|
312
323
|
## File-文件
|
|
@@ -394,10 +405,17 @@ console.log(formatted); //1,234,567.89
|
|
|
394
405
|
> 将秒数格式化为中文时间描述,支持扩展到年
|
|
395
406
|
|
|
396
407
|
```ts
|
|
397
|
-
libJsSecondsFormatterChinese(100000);
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
libJsSecondsFormatterChinese(
|
|
408
|
+
const a = libJsSecondsFormatterChinese(100000);
|
|
409
|
+
console.log(a); //"1天3小时46分40秒"
|
|
410
|
+
|
|
411
|
+
const b = libJsSecondsFormatterChinese(31536000);
|
|
412
|
+
console.log(b); //"1年"
|
|
413
|
+
|
|
414
|
+
const c = libJsSecondsFormatterChinese(3600);
|
|
415
|
+
console.log(c); //"1小时"
|
|
416
|
+
|
|
417
|
+
const d = libJsSecondsFormatterChinese(90);
|
|
418
|
+
console.log(d); //"1分30秒"
|
|
401
419
|
```
|
|
402
420
|
|
|
403
421
|
## Math-数学
|
|
@@ -417,10 +435,12 @@ console.log(result); //0.6
|
|
|
417
435
|
|
|
418
436
|
```ts
|
|
419
437
|
//角度转弧度
|
|
420
|
-
libJsConvertAngle(90, "rad");
|
|
438
|
+
const rad = libJsConvertAngle(90, "rad");
|
|
439
|
+
console.log(rad); //1.5708... (π/2)
|
|
421
440
|
|
|
422
441
|
//弧度转角度
|
|
423
|
-
libJsConvertAngle(Math.PI, "deg");
|
|
442
|
+
const deg = libJsConvertAngle(Math.PI, "deg");
|
|
443
|
+
console.log(deg); //180
|
|
424
444
|
```
|
|
425
445
|
|
|
426
446
|
### LibJsCoordsAngle-两点角度
|
|
@@ -428,9 +448,14 @@ libJsConvertAngle(Math.PI, "deg"); //返回 180
|
|
|
428
448
|
> 计算两点角度
|
|
429
449
|
|
|
430
450
|
```ts
|
|
431
|
-
libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 });
|
|
432
|
-
|
|
433
|
-
|
|
451
|
+
const a = libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 });
|
|
452
|
+
console.log(a); //0
|
|
453
|
+
|
|
454
|
+
const b = libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 });
|
|
455
|
+
console.log(b); //45
|
|
456
|
+
|
|
457
|
+
const c = libJsCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 });
|
|
458
|
+
console.log(c); //90
|
|
434
459
|
```
|
|
435
460
|
|
|
436
461
|
### LibJsCoordsDistance-两点距离
|
|
@@ -438,9 +463,14 @@ libJsCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //90
|
|
|
438
463
|
> 计算两点距离
|
|
439
464
|
|
|
440
465
|
```ts
|
|
441
|
-
libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 });
|
|
442
|
-
|
|
443
|
-
|
|
466
|
+
const a = libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 });
|
|
467
|
+
console.log(a); //5
|
|
468
|
+
|
|
469
|
+
const b = libJsCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 });
|
|
470
|
+
console.log(b); //5
|
|
471
|
+
|
|
472
|
+
const c = libJsCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 });
|
|
473
|
+
console.log(c); //0
|
|
444
474
|
```
|
|
445
475
|
|
|
446
476
|
### LibJsDecimal-高精度计算
|
|
@@ -448,9 +478,14 @@ libJsCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //0
|
|
|
448
478
|
> 计算两个数的运算结果,并保留指定位数的小数
|
|
449
479
|
|
|
450
480
|
```ts
|
|
451
|
-
libJsDecimal(10, 3, "+");
|
|
452
|
-
|
|
453
|
-
|
|
481
|
+
const a = libJsDecimal(10, 3, "+");
|
|
482
|
+
console.log(a); //13
|
|
483
|
+
|
|
484
|
+
const b = libJsDecimal(10, 3, "-");
|
|
485
|
+
console.log(b); //7
|
|
486
|
+
|
|
487
|
+
const c = libJsDecimal(10, 3, "/", 2);
|
|
488
|
+
console.log(c); //3.33
|
|
454
489
|
```
|
|
455
490
|
|
|
456
491
|
## Misc-杂项
|
|
@@ -465,11 +500,12 @@ const rules = [
|
|
|
465
500
|
{ key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
|
|
466
501
|
{ key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
|
|
467
502
|
];
|
|
468
|
-
libJsRegFormValidate(form, rules);
|
|
469
|
-
//返回结果: []
|
|
503
|
+
const result1 = libJsRegFormValidate(form, rules);
|
|
504
|
+
console.log(result1); //返回结果: []
|
|
470
505
|
|
|
471
506
|
const invalidForm = { username: "jo", email: "invalid-email" };
|
|
472
|
-
libJsRegFormValidate(invalidForm, rules);
|
|
507
|
+
const result2 = libJsRegFormValidate(invalidForm, rules);
|
|
508
|
+
console.log(result2);
|
|
473
509
|
//返回结果: [
|
|
474
510
|
// { key: "username", msg: "用户名不合法", name: "用户名" },
|
|
475
511
|
// { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
|
|
@@ -511,9 +547,14 @@ stepper.down("sub"); // 索引减1
|
|
|
511
547
|
> 百分比概率结果
|
|
512
548
|
|
|
513
549
|
```ts
|
|
514
|
-
libJsProbabilityResult(50);
|
|
515
|
-
|
|
516
|
-
|
|
550
|
+
const result1 = libJsProbabilityResult(50);
|
|
551
|
+
console.log(result1); //50% 概率为 true
|
|
552
|
+
|
|
553
|
+
const result2 = libJsProbabilityResult(80); //80% 概率为 true
|
|
554
|
+
console.log(result2); //50% 概率为 true
|
|
555
|
+
|
|
556
|
+
const result3 = libJsProbabilityResult(100); //100% 概率为 true
|
|
557
|
+
console.log(result3); //50% 概率为 true
|
|
517
558
|
```
|
|
518
559
|
|
|
519
560
|
### LibJsRandom-随机数
|
|
@@ -521,8 +562,11 @@ libJsProbabilityResult(100); //100% 概率为 true
|
|
|
521
562
|
> 随机获取两个数之间的值,包含两数自身
|
|
522
563
|
|
|
523
564
|
```ts
|
|
524
|
-
libJsRandom(1, 10); //1 到 10 之间的随机整数
|
|
525
|
-
|
|
565
|
+
const result1 = libJsRandom(1, 10); //1 到 10 之间的随机整数
|
|
566
|
+
console.log(result1); //50% 概率为 true
|
|
567
|
+
|
|
568
|
+
const result2 = libJsRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
569
|
+
console.log(result2); //50% 概率为 true
|
|
526
570
|
```
|
|
527
571
|
|
|
528
572
|
### LibJsRandomColor-随机色
|
|
@@ -530,8 +574,11 @@ libJsRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
|
530
574
|
> 随机 RGBA 颜色
|
|
531
575
|
|
|
532
576
|
```ts
|
|
533
|
-
libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
534
|
-
|
|
577
|
+
const result1 = libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
578
|
+
console.log(result1); //50% 概率为 true
|
|
579
|
+
|
|
580
|
+
const result2 = libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
581
|
+
console.log(result2); //50% 概率为 true
|
|
535
582
|
```
|
|
536
583
|
|
|
537
584
|
### LibJsUniqueRandomNumbers-随机数数组
|
|
@@ -539,8 +586,11 @@ libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
|
539
586
|
> 随机生成指定个数、指定范围不重复的随机数数组
|
|
540
587
|
|
|
541
588
|
```ts
|
|
542
|
-
libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
543
|
-
|
|
589
|
+
const result1 = libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
590
|
+
console.log(result1); //50% 概率为 true
|
|
591
|
+
|
|
592
|
+
const result2 = libJsUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
593
|
+
console.log(result2); //50% 概率为 true
|
|
544
594
|
```
|
|
545
595
|
|
|
546
596
|
## Time-时间
|
|
@@ -560,10 +610,17 @@ console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前
|
|
|
560
610
|
> 时间差计算
|
|
561
611
|
|
|
562
612
|
```ts
|
|
563
|
-
libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
libJsTimeAgotamp(Date.now() -
|
|
613
|
+
const result1 = libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
614
|
+
console.log(result1); //50% 概率为 true
|
|
615
|
+
|
|
616
|
+
const result2 = libJsTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
617
|
+
console.log(result2); //50% 概率为 true
|
|
618
|
+
|
|
619
|
+
const result3 = libJsTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
620
|
+
console.log(result3); //50% 概率为 true
|
|
621
|
+
|
|
622
|
+
const result4 = libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
623
|
+
console.log(result4); //50% 概率为 true
|
|
567
624
|
```
|
|
568
625
|
|
|
569
626
|
### LibJsTimeGreeting-时间问候
|
|
@@ -571,8 +628,13 @@ libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
|
571
628
|
> 根据当前时间返回问候语
|
|
572
629
|
|
|
573
630
|
```ts
|
|
574
|
-
libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
575
|
-
|
|
576
|
-
|
|
631
|
+
const result1 = libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
632
|
+
console.log(result1); //50% 概率为 true
|
|
633
|
+
|
|
634
|
+
const result2 = libJsTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
635
|
+
console.log(result2); //50% 概率为 true
|
|
636
|
+
|
|
637
|
+
const result3 = libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
638
|
+
console.log(result3); //50% 概率为 true
|
|
577
639
|
```
|
|
578
640
|
|
|
@@ -2,10 +2,6 @@ export type LibJsGetDataTypeReturnType = "string" | "number" | "boolean" | "arra
|
|
|
2
2
|
/**
|
|
3
3
|
* @description 返回数据类型
|
|
4
4
|
* @param v 需要判断类型的数据
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* libJsGetDataType(123); //"number"
|
|
8
|
-
* libJsGetDataType("hello"); //"string"
|
|
9
|
-
* libJsGetDataType([1, 2, 3]); //"array"
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsColorConsole-有色打印
|
|
10
6
|
*/
|
|
11
7
|
export declare const libJsGetDataType: (v: any) => LibJsGetDataTypeReturnType;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description 返回数据类型
|
|
3
3
|
* @param v 需要判断类型的数据
|
|
4
|
-
* @link
|
|
5
|
-
* @example
|
|
6
|
-
* libJsGetDataType(123); //"number"
|
|
7
|
-
* libJsGetDataType("hello"); //"string"
|
|
8
|
-
* libJsGetDataType([1, 2, 3]); //"array"
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsColorConsole-有色打印
|
|
9
5
|
*/
|
|
10
6
|
export const libJsGetDataType = (v) => {
|
|
11
7
|
return Object.prototype.toString
|
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
* @description 延时执行,切换到其他页面会暂停
|
|
3
3
|
* @param delay 延时毫秒数
|
|
4
4
|
* @param fn 延时执行函数
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* libJsPromiseTimeout(3000, () => {
|
|
8
|
-
* console.log("执行延时函数");
|
|
9
|
-
* });
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPromiseTimeout-延时执行
|
|
10
6
|
*/
|
|
11
7
|
export declare const libJsPromiseTimeout: (delay?: number, fn?: () => void) => Promise<void>;
|
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
* @description 延时执行,切换到其他页面会暂停
|
|
3
3
|
* @param delay 延时毫秒数
|
|
4
4
|
* @param fn 延时执行函数
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* libJsPromiseTimeout(3000, () => {
|
|
8
|
-
* console.log("执行延时函数");
|
|
9
|
-
* });
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPromiseTimeout-延时执行
|
|
10
6
|
*/
|
|
11
7
|
export const libJsPromiseTimeout = (delay = 1, fn) => {
|
|
12
8
|
let timeoutId;
|
|
@@ -2,13 +2,7 @@
|
|
|
2
2
|
* @param title 标题
|
|
3
3
|
* @param color 颜色
|
|
4
4
|
* @param logs 信息
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* //使用红色打印日志
|
|
8
|
-
* libJsColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
|
|
9
|
-
*
|
|
10
|
-
* //使用蓝色打印简单日志
|
|
11
|
-
* libJsColorConsole("信息", "blue", "操作成功");
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsColorConsole-有色打印
|
|
12
6
|
*/
|
|
13
7
|
export declare const libJsColorConsole: (title: string, color: "red" | "orange" | "yellow" | "green" | "blue" | "purple", logs?: {
|
|
14
8
|
label: string;
|
|
@@ -2,13 +2,7 @@
|
|
|
2
2
|
* @param title 标题
|
|
3
3
|
* @param color 颜色
|
|
4
4
|
* @param logs 信息
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* //使用红色打印日志
|
|
8
|
-
* libJsColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
|
|
9
|
-
*
|
|
10
|
-
* //使用蓝色打印简单日志
|
|
11
|
-
* libJsColorConsole("信息", "blue", "操作成功");
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsColorConsole-有色打印
|
|
12
6
|
*/
|
|
13
7
|
export const libJsColorConsole = (title, color, logs = []) => {
|
|
14
8
|
const colors = {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
/** @description 判断是否为移动设备
|
|
2
|
-
* @link
|
|
3
|
-
* @example
|
|
4
|
-
* const isMobile = libIsMobile();
|
|
5
|
-
* console.log(isMobile); //true 或 false
|
|
2
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsIsMobile-判断手机
|
|
6
3
|
*/
|
|
7
4
|
export declare const libJsIsMobile: () => boolean;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/** @description 判断是否为移动设备
|
|
2
|
-
* @link
|
|
3
|
-
* @example
|
|
4
|
-
* const isMobile = libIsMobile();
|
|
5
|
-
* console.log(isMobile); //true 或 false
|
|
2
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsIsMobile-判断手机
|
|
6
3
|
*/
|
|
7
4
|
export const libJsIsMobile = () => {
|
|
8
5
|
const ua = navigator.userAgent.toLowerCase();
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
/** @description 判断是否为平板
|
|
2
|
-
* @link
|
|
3
|
-
* @example
|
|
4
|
-
* const isPad = libJsIsPad();
|
|
5
|
-
* console.log(isPad); //true 或 false
|
|
2
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsIsPad-判断平板
|
|
6
3
|
*/
|
|
7
4
|
export declare const libJsIsPad: () => boolean;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/** @description 判断是否为平板
|
|
2
|
-
* @link
|
|
3
|
-
* @example
|
|
4
|
-
* const isPad = libJsIsPad();
|
|
5
|
-
* console.log(isPad); //true 或 false
|
|
2
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsIsPad-判断平板
|
|
6
3
|
*/
|
|
7
4
|
export const libJsIsPad = () => {
|
|
8
5
|
const ua = navigator.userAgent.toLowerCase();
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/** @description 将对象转为地址栏参数
|
|
2
2
|
* @param params 对象参数
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsObjToUrlParams({ name: "John", age: 30, active: true });
|
|
6
|
-
* // "name=John&age=30&active=true"
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsObjToUrlParams-对象转Url参数
|
|
7
4
|
*/
|
|
8
5
|
export declare const libJsObjToUrlParams: (params: Record<string, string | number | boolean>) => string;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/** @description 将对象转为地址栏参数
|
|
2
2
|
* @param params 对象参数
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsObjToUrlParams({ name: "John", age: 30, active: true });
|
|
6
|
-
* // "name=John&age=30&active=true"
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsObjToUrlParams-对象转Url参数
|
|
7
4
|
*/
|
|
8
5
|
export const libJsObjToUrlParams = (params) => {
|
|
9
6
|
return Object.entries(params)
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
/** @description 获取浏览器地址栏参数
|
|
2
|
-
* @link
|
|
3
|
-
* @example
|
|
4
|
-
* const params = libJsPathParams();
|
|
5
|
-
* console.log(params); //{ param1: "value1", param2: "value2" }
|
|
2
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPathParams-地址栏参数
|
|
6
3
|
*/
|
|
7
4
|
export declare const libJsPathParams: () => Record<string, string>;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/** @description 获取浏览器地址栏参数
|
|
2
|
-
* @link
|
|
3
|
-
* @example
|
|
4
|
-
* const params = libJsPathParams();
|
|
5
|
-
* console.log(params); //{ param1: "value1", param2: "value2" }
|
|
2
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPathParams-地址栏参数
|
|
6
3
|
*/
|
|
7
4
|
export const libJsPathParams = () => {
|
|
8
5
|
const v = location.href;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/** @description 动态设置网站标题及图标
|
|
2
2
|
* @param title 网站标题
|
|
3
3
|
* @param url 网站图标地址
|
|
4
|
-
* @link
|
|
5
|
-
* @example
|
|
6
|
-
* libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSetTitleIcon-网站标题图标
|
|
7
5
|
*/
|
|
8
6
|
export declare const libJsSetTitleIcon: (title: string, url: string) => void;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/** @description 动态设置网站标题及图标
|
|
2
2
|
* @param title 网站标题
|
|
3
3
|
* @param url 网站图标地址
|
|
4
|
-
* @link
|
|
5
|
-
* @example
|
|
6
|
-
* libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSetTitleIcon-网站标题图标
|
|
7
5
|
*/
|
|
8
6
|
export const libJsSetTitleIcon = (title, url) => {
|
|
9
7
|
document.title = title;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
|
|
2
2
|
* @param backTitle 从其他网页返回时显示的标题
|
|
3
3
|
* @param leaveTitle 从当前网页离开时显示的标题
|
|
4
|
-
* @link
|
|
5
|
-
* @example
|
|
6
|
-
* libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTagTitleTip-网站标题交互
|
|
7
5
|
*/
|
|
8
6
|
export declare const libJsTagTitleTip: (backTitle: string, leaveTitle: string) => void;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
|
|
2
2
|
* @param backTitle 从其他网页返回时显示的标题
|
|
3
3
|
* @param leaveTitle 从当前网页离开时显示的标题
|
|
4
|
-
* @link
|
|
5
|
-
* @example
|
|
6
|
-
* libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTagTitleTip-网站标题交互
|
|
7
5
|
*/
|
|
8
6
|
export const libJsTagTitleTip = (backTitle, leaveTitle) => {
|
|
9
7
|
let document_title = "";
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
* @description 将数组拆分成指定数组元素数量的多个数组
|
|
3
3
|
* @param arr 需要拆分的数组
|
|
4
4
|
* @param chunkSize 每个数组的元素数量
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* const chunks = libJsChunkArray([1, 2, 3, 4, 5, 6], 2);
|
|
8
|
-
* console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsChunkArray-数组拆分
|
|
9
6
|
*/
|
|
10
7
|
export declare const libJsChunkArray: <T>(arr: T[], chunkSize: number) => T[][];
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
* @description 将数组拆分成指定数组元素数量的多个数组
|
|
3
3
|
* @param arr 需要拆分的数组
|
|
4
4
|
* @param chunkSize 每个数组的元素数量
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* const chunks = libJsChunkArray([1, 2, 3, 4, 5, 6], 2);
|
|
8
|
-
* console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsChunkArray-数组拆分
|
|
9
6
|
*/
|
|
10
7
|
export const libJsChunkArray = (arr, chunkSize) => {
|
|
11
8
|
const result = [];
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
/** @description 递归将JSON字符串深度解析为对象
|
|
2
|
-
* @link
|
|
3
|
-
* @example
|
|
4
|
-
* const obj = libJsDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
|
|
5
|
-
* console.log(obj); //{ a: 1, b: { c: 2 } }
|
|
2
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsDeepJSONParse-深度解析JSON
|
|
6
3
|
*/
|
|
7
4
|
export declare const libJsDeepJSONParse: <T>(data: any) => T;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/** @description 递归将JSON字符串深度解析为对象
|
|
2
|
-
* @link
|
|
3
|
-
* @example
|
|
4
|
-
* const obj = libJsDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
|
|
5
|
-
* console.log(obj); //{ a: 1, b: { c: 2 } }
|
|
2
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsDeepJSONParse-深度解析JSON
|
|
6
3
|
*/
|
|
7
4
|
export const libJsDeepJSONParse = (data) => {
|
|
8
5
|
//检查是否为字符串并尝试解析
|
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
* @param arr 要分组的数组
|
|
4
4
|
* @param key 分组的键
|
|
5
5
|
* @returns 分组后的对象
|
|
6
|
-
* @link
|
|
7
|
-
* @example
|
|
8
|
-
* const grouped = libJsGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
|
|
9
|
-
* console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
|
|
6
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsGroupArrayByKey-分类汇总
|
|
10
7
|
*/
|
|
11
8
|
export declare const libJsGroupArrayByKey: (arr: any[] | undefined, key: string) => any;
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
* @param arr 要分组的数组
|
|
4
4
|
* @param key 分组的键
|
|
5
5
|
* @returns 分组后的对象
|
|
6
|
-
* @link
|
|
7
|
-
* @example
|
|
8
|
-
* const grouped = libJsGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
|
|
9
|
-
* console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
|
|
6
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsGroupArrayByKey-分类汇总
|
|
10
7
|
*/
|
|
11
8
|
export const libJsGroupArrayByKey = (arr = [], key) => {
|
|
12
9
|
return key
|
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
* @param str 要匹配的字符串
|
|
4
4
|
* @param emailList 电子邮件后缀列表
|
|
5
5
|
* @returns 匹配结果数组
|
|
6
|
-
* @link
|
|
7
|
-
* @example
|
|
8
|
-
* const emails = libJsMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
|
|
9
|
-
* console.log(emails); //["user@gmail.com", "user@yahoo.com"]
|
|
6
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsMatchEmail-匹配E-Mail
|
|
10
7
|
*/
|
|
11
8
|
export declare const libJsMatchEmail: (str: string, emailList: string[]) => string[];
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
* @param str 要匹配的字符串
|
|
4
4
|
* @param emailList 电子邮件后缀列表
|
|
5
5
|
* @returns 匹配结果数组
|
|
6
|
-
* @link
|
|
7
|
-
* @example
|
|
8
|
-
* const emails = libJsMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
|
|
9
|
-
* console.log(emails); //["user@gmail.com", "user@yahoo.com"]
|
|
6
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsMatchEmail-匹配E-Mail
|
|
10
7
|
*/
|
|
11
8
|
export const libJsMatchEmail = (str, emailList) => {
|
|
12
9
|
return str.includes("@")
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/** @description 将数组打乱顺序
|
|
2
2
|
* @param arr 需要乱序的数组
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* const shuffled = libJsShuffleArray([1, 2, 3, 4, 5]);
|
|
6
|
-
* console.log(shuffled); //[3, 5, 2, 1, 4] (结果每次不同)
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsShuffleArray-数组乱序
|
|
7
4
|
*/
|
|
8
5
|
export declare const libJsShuffleArray: <T>(arr: T[]) => T[];
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/** @description 将数组打乱顺序
|
|
2
2
|
* @param arr 需要乱序的数组
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* const shuffled = libJsShuffleArray([1, 2, 3, 4, 5]);
|
|
6
|
-
* console.log(shuffled); //[3, 5, 2, 1, 4] (结果每次不同)
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsShuffleArray-数组乱序
|
|
7
4
|
*/
|
|
8
5
|
export const libJsShuffleArray = (arr) => {
|
|
9
6
|
const newArr = [...arr];
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/** @description 数组元素整体步数移动
|
|
2
2
|
* @param arr 移动的数组
|
|
3
3
|
* @param step 负数为向后移动,正数为向前移动
|
|
4
|
-
|
|
5
|
-
* @example
|
|
6
|
-
* const moved = libJsStepArray([1, 2, 3, 4, 5], 2);
|
|
7
|
-
* console.log(moved); //[4, 5, 1, 2, 3]
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsStepArray-数组偏移
|
|
8
5
|
*/
|
|
9
6
|
export declare const libJsStepArray: <T>(arr: T[], step: number) => T[];
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/** @description 数组元素整体步数移动
|
|
2
2
|
* @param arr 移动的数组
|
|
3
3
|
* @param step 负数为向后移动,正数为向前移动
|
|
4
|
-
|
|
5
|
-
* @example
|
|
6
|
-
* const moved = libJsStepArray([1, 2, 3, 4, 5], 2);
|
|
7
|
-
* console.log(moved); //[4, 5, 1, 2, 3]
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsStepArray-数组偏移
|
|
8
5
|
*/
|
|
9
6
|
export const libJsStepArray = (arr, step) => {
|
|
10
7
|
const length = arr.length;
|