lyb-js 1.1.5 → 1.1.7
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 +110 -47
- package/dist/Base/LibJsGetDataType/index.d.ts +1 -5
- package/dist/Base/LibJsGetDataType/index.js +2 -6
- package/dist/Base/LibJsPromiseTimeout/index.d.ts +1 -5
- package/dist/Base/LibJsPromiseTimeout/index.js +12 -15
- package/dist/Browser/LibJsColorConsole/index.d.ts +1 -7
- package/dist/Browser/LibJsColorConsole/index.js +23 -19
- package/dist/Browser/LibJsIsMobile/index.d.ts +1 -4
- package/dist/Browser/LibJsIsMobile/index.js +3 -6
- package/dist/Browser/LibJsIsPad/index.d.ts +1 -4
- package/dist/Browser/LibJsIsPad/index.js +9 -12
- package/dist/Browser/LibJsObjToUrlParams/index.d.ts +1 -4
- package/dist/Browser/LibJsObjToUrlParams/index.js +6 -6
- package/dist/Browser/LibJsPathParams/index.d.ts +1 -4
- package/dist/Browser/LibJsPathParams/index.js +6 -9
- package/dist/Browser/LibJsSetTitleIcon/index.d.ts +1 -3
- package/dist/Browser/LibJsSetTitleIcon/index.js +4 -6
- package/dist/Browser/LibJsTagTitleTip/index.d.ts +1 -3
- package/dist/Browser/LibJsTagTitleTip/index.js +6 -8
- package/dist/Data/LibJsChunkArray/index.d.ts +1 -4
- package/dist/Data/LibJsChunkArray/index.js +4 -7
- package/dist/Data/LibJsDeepJSONParse/index.d.ts +1 -4
- package/dist/Data/LibJsDeepJSONParse/index.js +6 -9
- package/dist/Data/LibJsGroupArrayByKey/index.d.ts +1 -4
- package/dist/Data/LibJsGroupArrayByKey/index.js +4 -6
- package/dist/Data/LibJsMatchEmail/index.d.ts +1 -4
- package/dist/Data/LibJsMatchEmail/index.js +5 -8
- package/dist/Data/LibJsShuffleArray/index.d.ts +1 -4
- package/dist/Data/LibJsShuffleArray/index.js +16 -9
- package/dist/Data/LibJsStepArray/index.d.ts +1 -4
- package/dist/Data/LibJsStepArray/index.js +4 -7
- package/dist/Data/LibReverseArrayFromIndex/index.d.ts +1 -4
- package/dist/Data/LibReverseArrayFromIndex/index.js +13 -7
- package/dist/File/LibJsDownloadImageLink/index.d.ts +1 -3
- package/dist/File/LibJsDownloadImageLink/index.js +6 -8
- package/dist/File/LibJsImageOptimizer/index.d.ts +1 -14
- package/dist/File/LibJsImageOptimizer/index.js +37 -50
- package/dist/File/LibJsSaveJson/index.d.ts +1 -4
- package/dist/File/LibJsSaveJson/index.js +5 -8
- package/dist/Formatter/LibJsFormatterByte/index.d.ts +1 -4
- package/dist/Formatter/LibJsFormatterByte/index.js +7 -10
- package/dist/Formatter/LibJsMaskPhoneNumber/index.d.ts +1 -4
- package/dist/Formatter/LibJsMaskPhoneNumber/index.js +3 -6
- package/dist/Formatter/LibJsNumComma/index.d.ts +1 -4
- package/dist/Formatter/LibJsNumComma/index.js +5 -7
- package/dist/Formatter/LibJsNumberUnit/index.d.ts +6 -9
- package/dist/Formatter/LibJsNumberUnit/index.js +18 -14
- package/dist/Formatter/LibJsSecondsFormatterChinese/index.d.ts +1 -6
- package/dist/Formatter/LibJsSecondsFormatterChinese/index.js +16 -21
- package/dist/Math/LibJsCalculateExpression/index.d.ts +1 -4
- package/dist/Math/LibJsCalculateExpression/index.js +33 -32
- package/dist/Math/LibJsConvertAngle/index.d.ts +1 -7
- package/dist/Math/LibJsConvertAngle/index.js +2 -8
- package/dist/Math/LibJsCoordsAngle/index.d.ts +1 -5
- package/dist/Math/LibJsCoordsAngle/index.js +6 -10
- package/dist/Math/LibJsCoordsDistance/index.d.ts +1 -5
- package/dist/Math/LibJsCoordsDistance/index.js +5 -9
- package/dist/Math/LibJsDecimal/index.d.ts +1 -5
- package/dist/Math/LibJsDecimal/index.js +9 -12
- package/dist/Misc/LibJsRegFormValidate/index.d.ts +1 -16
- package/dist/Misc/LibJsRegFormValidate/index.js +7 -22
- package/dist/Misc/LibJsRetryRequest/index.d.ts +1 -12
- package/dist/Misc/LibJsRetryRequest/index.js +8 -18
- package/dist/Misc/LibNumerStepper/index.d.ts +1 -6
- package/dist/Misc/LibNumerStepper/index.js +28 -35
- package/dist/Random/LibJsProbabilityResult/index.d.ts +1 -5
- package/dist/Random/LibJsProbabilityResult/index.js +4 -6
- package/dist/Random/LibJsRandom/index.d.ts +1 -4
- package/dist/Random/LibJsRandom/index.js +3 -5
- package/dist/Random/LibJsRandomColor/index.d.ts +1 -4
- package/dist/Random/LibJsRandomColor/index.js +7 -9
- package/dist/Random/LibJsUniqueRandomNumbers/index.d.ts +1 -4
- package/dist/Random/LibJsUniqueRandomNumbers/index.js +7 -9
- package/dist/Time/LibJsSameTimeCheck/index.d.ts +1 -5
- package/dist/Time/LibJsSameTimeCheck/index.js +4 -8
- package/dist/Time/LibJsTimeAgo/index.d.ts +1 -6
- package/dist/Time/LibJsTimeAgo/index.js +9 -13
- package/dist/Time/LibJsTimeGreeting/index.d.ts +1 -5
- package/dist/Time/LibJsTimeGreeting/index.js +5 -8
- package/dist/libJs.d.ts +42 -201
- package/dist/libJs.js +95 -256
- package/package.json +1 -1
- package/umd/lyb.js +3 -3
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,15 @@ LibJs.Base.libJsGetDataType("Hellow World!"); //"string"
|
|
|
163
169
|
> 返回数据类型
|
|
164
170
|
|
|
165
171
|
```ts
|
|
166
|
-
|
|
167
|
-
libJsGetDataType(
|
|
168
|
-
|
|
172
|
+
|
|
173
|
+
const n = libJsGetDataType(123);
|
|
174
|
+
console.log(n); //"number"
|
|
175
|
+
|
|
176
|
+
const s = libJsGetDataType("hello");
|
|
177
|
+
console.log(s); //"string"
|
|
178
|
+
|
|
179
|
+
const a = libJsGetDataType([1, 2, 3]);
|
|
180
|
+
console.log(a); //"array"
|
|
169
181
|
```
|
|
170
182
|
|
|
171
183
|
### LibJsPromiseTimeout-延时执行
|
|
@@ -305,8 +317,8 @@ console.log(moved); //[4, 5, 1, 2, 3]
|
|
|
305
317
|
> 翻转指定索引后面的数组
|
|
306
318
|
|
|
307
319
|
```ts
|
|
308
|
-
libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
|
|
309
|
-
// [1, 2, 5, 4, 3]
|
|
320
|
+
const newArr = libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
|
|
321
|
+
console.log(newArr); // [1, 2, 5, 4, 3]
|
|
310
322
|
```
|
|
311
323
|
|
|
312
324
|
## File-文件
|
|
@@ -373,8 +385,8 @@ console.log(masked); //138****5678
|
|
|
373
385
|
> 大于指定数字,用单位标识,你甚至可以用中文
|
|
374
386
|
|
|
375
387
|
```ts
|
|
376
|
-
const [value, unit] = libJsNumberUnit(1500, { K: 1000, M: 1000000 });
|
|
377
|
-
console.log(value, unit); //1.
|
|
388
|
+
const [value, unit, whole] = libJsNumberUnit(1500, { K: 1000, M: 1000000 }, 1);
|
|
389
|
+
console.log(value, unit, whole); //1.5 K 1.5K
|
|
378
390
|
|
|
379
391
|
const [value, unit] = libJsNumberUnit(0.05, { 分: 0.01, 角: 0.1, 元: 1 });
|
|
380
392
|
console.log(value, unit); //0.05 分
|
|
@@ -394,10 +406,17 @@ console.log(formatted); //1,234,567.89
|
|
|
394
406
|
> 将秒数格式化为中文时间描述,支持扩展到年
|
|
395
407
|
|
|
396
408
|
```ts
|
|
397
|
-
libJsSecondsFormatterChinese(100000);
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
libJsSecondsFormatterChinese(
|
|
409
|
+
const a = libJsSecondsFormatterChinese(100000);
|
|
410
|
+
console.log(a); //"1天3小时46分40秒"
|
|
411
|
+
|
|
412
|
+
const b = libJsSecondsFormatterChinese(31536000);
|
|
413
|
+
console.log(b); //"1年"
|
|
414
|
+
|
|
415
|
+
const c = libJsSecondsFormatterChinese(3600);
|
|
416
|
+
console.log(c); //"1小时"
|
|
417
|
+
|
|
418
|
+
const d = libJsSecondsFormatterChinese(90);
|
|
419
|
+
console.log(d); //"1分30秒"
|
|
401
420
|
```
|
|
402
421
|
|
|
403
422
|
## Math-数学
|
|
@@ -417,10 +436,12 @@ console.log(result); //0.6
|
|
|
417
436
|
|
|
418
437
|
```ts
|
|
419
438
|
//角度转弧度
|
|
420
|
-
libJsConvertAngle(90, "rad");
|
|
439
|
+
const rad = libJsConvertAngle(90, "rad");
|
|
440
|
+
console.log(rad); //1.5708... (π/2)
|
|
421
441
|
|
|
422
442
|
//弧度转角度
|
|
423
|
-
libJsConvertAngle(Math.PI, "deg");
|
|
443
|
+
const deg = libJsConvertAngle(Math.PI, "deg");
|
|
444
|
+
console.log(deg); //180
|
|
424
445
|
```
|
|
425
446
|
|
|
426
447
|
### LibJsCoordsAngle-两点角度
|
|
@@ -428,9 +449,14 @@ libJsConvertAngle(Math.PI, "deg"); //返回 180
|
|
|
428
449
|
> 计算两点角度
|
|
429
450
|
|
|
430
451
|
```ts
|
|
431
|
-
libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 });
|
|
432
|
-
|
|
433
|
-
|
|
452
|
+
const a = libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 });
|
|
453
|
+
console.log(a); //0
|
|
454
|
+
|
|
455
|
+
const b = libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 });
|
|
456
|
+
console.log(b); //45
|
|
457
|
+
|
|
458
|
+
const c = libJsCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 });
|
|
459
|
+
console.log(c); //90
|
|
434
460
|
```
|
|
435
461
|
|
|
436
462
|
### LibJsCoordsDistance-两点距离
|
|
@@ -438,9 +464,14 @@ libJsCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //90
|
|
|
438
464
|
> 计算两点距离
|
|
439
465
|
|
|
440
466
|
```ts
|
|
441
|
-
libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 });
|
|
442
|
-
|
|
443
|
-
|
|
467
|
+
const a = libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 });
|
|
468
|
+
console.log(a); //5
|
|
469
|
+
|
|
470
|
+
const b = libJsCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 });
|
|
471
|
+
console.log(b); //5
|
|
472
|
+
|
|
473
|
+
const c = libJsCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 });
|
|
474
|
+
console.log(c); //0
|
|
444
475
|
```
|
|
445
476
|
|
|
446
477
|
### LibJsDecimal-高精度计算
|
|
@@ -448,9 +479,14 @@ libJsCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //0
|
|
|
448
479
|
> 计算两个数的运算结果,并保留指定位数的小数
|
|
449
480
|
|
|
450
481
|
```ts
|
|
451
|
-
libJsDecimal(10, 3, "+");
|
|
452
|
-
|
|
453
|
-
|
|
482
|
+
const a = libJsDecimal(10, 3, "+");
|
|
483
|
+
console.log(a); //13
|
|
484
|
+
|
|
485
|
+
const b = libJsDecimal(10, 3, "-");
|
|
486
|
+
console.log(b); //7
|
|
487
|
+
|
|
488
|
+
const c = libJsDecimal(10, 3, "/", 2);
|
|
489
|
+
console.log(c); //3.33
|
|
454
490
|
```
|
|
455
491
|
|
|
456
492
|
## Misc-杂项
|
|
@@ -465,11 +501,12 @@ const rules = [
|
|
|
465
501
|
{ key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
|
|
466
502
|
{ key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
|
|
467
503
|
];
|
|
468
|
-
libJsRegFormValidate(form, rules);
|
|
469
|
-
//返回结果: []
|
|
504
|
+
const result1 = libJsRegFormValidate(form, rules);
|
|
505
|
+
console.log(result1); //返回结果: []
|
|
470
506
|
|
|
471
507
|
const invalidForm = { username: "jo", email: "invalid-email" };
|
|
472
|
-
libJsRegFormValidate(invalidForm, rules);
|
|
508
|
+
const result2 = libJsRegFormValidate(invalidForm, rules);
|
|
509
|
+
console.log(result2);
|
|
473
510
|
//返回结果: [
|
|
474
511
|
// { key: "username", msg: "用户名不合法", name: "用户名" },
|
|
475
512
|
// { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
|
|
@@ -511,9 +548,14 @@ stepper.down("sub"); // 索引减1
|
|
|
511
548
|
> 百分比概率结果
|
|
512
549
|
|
|
513
550
|
```ts
|
|
514
|
-
libJsProbabilityResult(50);
|
|
515
|
-
|
|
516
|
-
|
|
551
|
+
const result1 = libJsProbabilityResult(50);
|
|
552
|
+
console.log(result1); //50% 概率为 true
|
|
553
|
+
|
|
554
|
+
const result2 = libJsProbabilityResult(80); //80% 概率为 true
|
|
555
|
+
console.log(result2); //50% 概率为 true
|
|
556
|
+
|
|
557
|
+
const result3 = libJsProbabilityResult(100); //100% 概率为 true
|
|
558
|
+
console.log(result3); //50% 概率为 true
|
|
517
559
|
```
|
|
518
560
|
|
|
519
561
|
### LibJsRandom-随机数
|
|
@@ -521,8 +563,11 @@ libJsProbabilityResult(100); //100% 概率为 true
|
|
|
521
563
|
> 随机获取两个数之间的值,包含两数自身
|
|
522
564
|
|
|
523
565
|
```ts
|
|
524
|
-
libJsRandom(1, 10); //1 到 10 之间的随机整数
|
|
525
|
-
|
|
566
|
+
const result1 = libJsRandom(1, 10); //1 到 10 之间的随机整数
|
|
567
|
+
console.log(result1); //50% 概率为 true
|
|
568
|
+
|
|
569
|
+
const result2 = libJsRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
570
|
+
console.log(result2); //50% 概率为 true
|
|
526
571
|
```
|
|
527
572
|
|
|
528
573
|
### LibJsRandomColor-随机色
|
|
@@ -530,8 +575,11 @@ libJsRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
|
530
575
|
> 随机 RGBA 颜色
|
|
531
576
|
|
|
532
577
|
```ts
|
|
533
|
-
libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
534
|
-
|
|
578
|
+
const result1 = libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
579
|
+
console.log(result1); //50% 概率为 true
|
|
580
|
+
|
|
581
|
+
const result2 = libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
582
|
+
console.log(result2); //50% 概率为 true
|
|
535
583
|
```
|
|
536
584
|
|
|
537
585
|
### LibJsUniqueRandomNumbers-随机数数组
|
|
@@ -539,8 +587,11 @@ libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
|
539
587
|
> 随机生成指定个数、指定范围不重复的随机数数组
|
|
540
588
|
|
|
541
589
|
```ts
|
|
542
|
-
libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
543
|
-
|
|
590
|
+
const result1 = libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
591
|
+
console.log(result1); //50% 概率为 true
|
|
592
|
+
|
|
593
|
+
const result2 = libJsUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
594
|
+
console.log(result2); //50% 概率为 true
|
|
544
595
|
```
|
|
545
596
|
|
|
546
597
|
## Time-时间
|
|
@@ -560,10 +611,17 @@ console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前
|
|
|
560
611
|
> 时间差计算
|
|
561
612
|
|
|
562
613
|
```ts
|
|
563
|
-
libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
libJsTimeAgotamp(Date.now() -
|
|
614
|
+
const result1 = libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
615
|
+
console.log(result1); //50% 概率为 true
|
|
616
|
+
|
|
617
|
+
const result2 = libJsTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
618
|
+
console.log(result2); //50% 概率为 true
|
|
619
|
+
|
|
620
|
+
const result3 = libJsTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
621
|
+
console.log(result3); //50% 概率为 true
|
|
622
|
+
|
|
623
|
+
const result4 = libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
624
|
+
console.log(result4); //50% 概率为 true
|
|
567
625
|
```
|
|
568
626
|
|
|
569
627
|
### LibJsTimeGreeting-时间问候
|
|
@@ -571,8 +629,13 @@ libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
|
571
629
|
> 根据当前时间返回问候语
|
|
572
630
|
|
|
573
631
|
```ts
|
|
574
|
-
libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
575
|
-
|
|
576
|
-
|
|
632
|
+
const result1 = libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
633
|
+
console.log(result1); //50% 概率为 true
|
|
634
|
+
|
|
635
|
+
const result2 = libJsTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
636
|
+
console.log(result2); //50% 概率为 true
|
|
637
|
+
|
|
638
|
+
const result3 = libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
639
|
+
console.log(result3); //50% 概率为 true
|
|
577
640
|
```
|
|
578
641
|
|
|
@@ -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,13 +1,9 @@
|
|
|
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
|
-
export
|
|
6
|
+
export var libJsGetDataType = function (v) {
|
|
11
7
|
return Object.prototype.toString
|
|
12
8
|
.call(v)
|
|
13
9
|
.substring(8)
|
|
@@ -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,19 +2,16 @@
|
|
|
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
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
export var libJsPromiseTimeout = function (delay, fn) {
|
|
8
|
+
if (delay === void 0) { delay = 1; }
|
|
9
|
+
var timeoutId;
|
|
10
|
+
var remainingTime = delay;
|
|
11
|
+
var startTime = Date.now();
|
|
12
|
+
var isPaused = false;
|
|
13
|
+
return new Promise(function (resolve) {
|
|
14
|
+
var handleVisibilityChange = function () {
|
|
18
15
|
if (document.hidden) {
|
|
19
16
|
isPaused = true;
|
|
20
17
|
clearTimeout(timeoutId);
|
|
@@ -28,9 +25,9 @@ export const libJsPromiseTimeout = (delay = 1, fn) => {
|
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
};
|
|
31
|
-
|
|
32
|
-
timeoutId = setTimeout(()
|
|
33
|
-
fn
|
|
28
|
+
var startTimeout = function (resolve) {
|
|
29
|
+
timeoutId = setTimeout(function () {
|
|
30
|
+
fn === null || fn === void 0 ? void 0 : fn();
|
|
34
31
|
resolve();
|
|
35
32
|
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
36
33
|
}, remainingTime);
|
|
@@ -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;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
1
10
|
/** @description console颜色打印
|
|
2
11
|
* @param title 标题
|
|
3
12
|
* @param color 颜色
|
|
4
13
|
* @param logs 信息
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* //使用红色打印日志
|
|
8
|
-
* libJsColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
|
|
9
|
-
*
|
|
10
|
-
* //使用蓝色打印简单日志
|
|
11
|
-
* libJsColorConsole("信息", "blue", "操作成功");
|
|
14
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsColorConsole-有色打印
|
|
12
15
|
*/
|
|
13
|
-
export
|
|
14
|
-
|
|
16
|
+
export var libJsColorConsole = function (title, color, logs) {
|
|
17
|
+
if (logs === void 0) { logs = []; }
|
|
18
|
+
var colors = {
|
|
15
19
|
red: "#c0392b",
|
|
16
20
|
orange: "#d35400",
|
|
17
21
|
yellow: "#f1c40f",
|
|
@@ -20,20 +24,20 @@ export const libJsColorConsole = (title, color, logs = []) => {
|
|
|
20
24
|
purple: "#be2edd",
|
|
21
25
|
};
|
|
22
26
|
//时间戳生成函数
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
27
|
+
var getTimestamp = function () {
|
|
28
|
+
var now = new Date();
|
|
29
|
+
var hour = String(now.getHours()).padStart(2, "0");
|
|
30
|
+
var minutes = String(now.getMinutes()).padStart(2, "0");
|
|
31
|
+
var seconds = String(now.getSeconds()).padStart(2, "0");
|
|
32
|
+
return "[".concat(hour, ":").concat(minutes, ":").concat(seconds, "]");
|
|
29
33
|
};
|
|
30
34
|
if (Array.isArray(logs)) {
|
|
31
|
-
|
|
32
|
-
return [
|
|
35
|
+
var v = logs.map(function (log) {
|
|
36
|
+
return ["\n".concat(log.label, "\uFF1A"), log.value];
|
|
33
37
|
});
|
|
34
|
-
console.log(
|
|
38
|
+
console.log.apply(console, __spreadArray(["%c".concat(getTimestamp(), "-").concat(title), "color: #fff;background: ".concat(colors[color], "; font-size:14px;border-radius:5px;padding:0.25em;margin:0.5em 0")], v.flat(Infinity), false));
|
|
35
39
|
}
|
|
36
40
|
else {
|
|
37
|
-
console.log(
|
|
41
|
+
console.log("%c".concat(getTimestamp(), "-").concat(title), "color: #fff;background: ".concat(colors[color], "; font-size:14px;border-radius:5px;padding:0.25em;margin:0.5em 0"), logs);
|
|
38
42
|
}
|
|
39
43
|
};
|
|
@@ -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,10 +1,7 @@
|
|
|
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
|
-
export
|
|
8
|
-
|
|
4
|
+
export var libJsIsMobile = function () {
|
|
5
|
+
var ua = navigator.userAgent.toLowerCase();
|
|
9
6
|
return /mobile|android|iphone|ipod/.test(ua);
|
|
10
7
|
};
|
|
@@ -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,16 +1,13 @@
|
|
|
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
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
export var libJsIsPad = function () {
|
|
5
|
+
var ua = navigator.userAgent.toLowerCase();
|
|
6
|
+
var width = Math.max(window.screen.width, window.screen.height);
|
|
7
|
+
var height = Math.min(window.screen.width, window.screen.height);
|
|
8
|
+
var aspectRatio = width / height;
|
|
9
|
+
var isTabletUserAgent = /ipad|tablet|playbook|silk/.test(ua) && !/mobile/.test(ua);
|
|
10
|
+
var isTabletWidth = width >= 768 && width <= 1366;
|
|
11
|
+
var isTabletAspectRatio = aspectRatio >= 1.3 && aspectRatio <= 1.6;
|
|
15
12
|
return isTabletUserAgent || (isTabletWidth && isTabletAspectRatio);
|
|
16
13
|
};
|
|
@@ -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,12 +1,12 @@
|
|
|
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
|
-
export
|
|
5
|
+
export var libJsObjToUrlParams = function (params) {
|
|
9
6
|
return Object.entries(params)
|
|
10
|
-
.map((
|
|
7
|
+
.map(function (_a) {
|
|
8
|
+
var key = _a[0], value = _a[1];
|
|
9
|
+
return "".concat(key, "=").concat(value);
|
|
10
|
+
})
|
|
11
11
|
.join("&");
|
|
12
12
|
};
|
|
@@ -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,16 +1,13 @@
|
|
|
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
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export var libJsPathParams = function () {
|
|
5
|
+
var v = location.href;
|
|
6
|
+
var url = v.split("?")[1];
|
|
10
7
|
if (!url)
|
|
11
8
|
return {};
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
var params = url.split("&").reduce(function (pre, cur) {
|
|
10
|
+
var _a = cur.split(/=(.+)/), k = _a[0], v = _a[1];
|
|
14
11
|
return (pre[k] = v), pre;
|
|
15
12
|
}, {}) || {};
|
|
16
13
|
return params;
|
|
@@ -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,15 +1,13 @@
|
|
|
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
|
-
export
|
|
6
|
+
export var libJsSetTitleIcon = function (title, url) {
|
|
9
7
|
document.title = title;
|
|
10
|
-
|
|
8
|
+
var link = document.createElement("link");
|
|
11
9
|
link.setAttribute("rel", "icon");
|
|
12
10
|
link.setAttribute("href", url);
|
|
13
|
-
|
|
11
|
+
var head = document.head || document.getElementsByTagName("head")[0];
|
|
14
12
|
head.appendChild(link);
|
|
15
13
|
};
|
|
@@ -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;
|