@daysnap/utils 0.0.31 → 0.0.33
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/docs/modules.md +154 -55
- package/es/base64ToBlob.d.ts +2 -0
- package/es/base64ToBlob.js +2 -0
- package/es/clone.d.ts +7 -0
- package/es/clone.js +9 -0
- package/es/index.d.ts +4 -0
- package/es/index.js +4 -0
- package/es/isIOS.js +1 -1
- package/es/isLan.d.ts +5 -0
- package/es/isLan.js +35 -0
- package/es/isNumber.d.ts +5 -0
- package/es/isNumber.js +7 -0
- package/es/parseQuery.js +0 -1
- package/es/round.d.ts +6 -0
- package/es/round.js +48 -0
- package/lib/base64ToBlob.d.ts +2 -0
- package/lib/base64ToBlob.js +2 -0
- package/lib/clone.d.ts +7 -0
- package/lib/clone.js +15 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +44 -0
- package/lib/isIOS.js +1 -1
- package/lib/isLan.d.ts +5 -0
- package/lib/isLan.js +41 -0
- package/lib/isNumber.d.ts +5 -0
- package/lib/isNumber.js +13 -0
- package/lib/parseQuery.js +0 -1
- package/lib/round.d.ts +6 -0
- package/lib/round.js +54 -0
- package/package.json +1 -1
package/docs/modules.md
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
- [base64ToBlob](modules.md#base64toblob)
|
|
10
10
|
- [blobToBase64](modules.md#blobtobase64)
|
|
11
|
+
- [clone](modules.md#clone)
|
|
11
12
|
- [colorGenByHash](modules.md#colorgenbyhash)
|
|
12
13
|
- [compareVersion](modules.md#compareversion)
|
|
13
14
|
- [compressImage](modules.md#compressimage)
|
|
@@ -36,9 +37,11 @@
|
|
|
36
37
|
- [isIOS](modules.md#isios)
|
|
37
38
|
- [isIdCard](modules.md#isidcard)
|
|
38
39
|
- [isJSONString](modules.md#isjsonstring)
|
|
40
|
+
- [isLan](modules.md#islan)
|
|
39
41
|
- [isLicenseCode](modules.md#islicensecode)
|
|
40
42
|
- [isMobile](modules.md#ismobile)
|
|
41
43
|
- [isNull](modules.md#isnull)
|
|
44
|
+
- [isNumber](modules.md#isnumber)
|
|
42
45
|
- [isObject](modules.md#isobject)
|
|
43
46
|
- [isPhone](modules.md#isphone)
|
|
44
47
|
- [isPromise](modules.md#ispromise)
|
|
@@ -54,6 +57,7 @@
|
|
|
54
57
|
- [pick](modules.md#pick)
|
|
55
58
|
- [replaceCrlf](modules.md#replacecrlf)
|
|
56
59
|
- [reserve](modules.md#reserve)
|
|
60
|
+
- [round](modules.md#round)
|
|
57
61
|
- [sleep](modules.md#sleep)
|
|
58
62
|
- [stringifyQuery](modules.md#stringifyquery)
|
|
59
63
|
|
|
@@ -67,10 +71,10 @@ base64 转 blob
|
|
|
67
71
|
|
|
68
72
|
#### Parameters
|
|
69
73
|
|
|
70
|
-
| Name | Type |
|
|
71
|
-
| :------ | :------ |
|
|
72
|
-
| `base64` | `string` |
|
|
73
|
-
| `contentType?` | `string` |
|
|
74
|
+
| Name | Type | Description |
|
|
75
|
+
| :------ | :------ | :------ |
|
|
76
|
+
| `base64` | `string` | base64字符串 |
|
|
77
|
+
| `contentType?` | `string` | 文件类型 |
|
|
74
78
|
|
|
75
79
|
#### Returns
|
|
76
80
|
|
|
@@ -78,7 +82,7 @@ base64 转 blob
|
|
|
78
82
|
|
|
79
83
|
#### Defined in
|
|
80
84
|
|
|
81
|
-
[base64ToBlob.ts:
|
|
85
|
+
[base64ToBlob.ts:6](https://github.com/daysnap/utils/blob/2be359b/src/base64ToBlob.ts#L6)
|
|
82
86
|
|
|
83
87
|
___
|
|
84
88
|
|
|
@@ -100,7 +104,35 @@ blob 转 base64
|
|
|
100
104
|
|
|
101
105
|
#### Defined in
|
|
102
106
|
|
|
103
|
-
[blobToBase64.ts:4](https://github.com/daysnap/utils/blob/
|
|
107
|
+
[blobToBase64.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/blobToBase64.ts#L4)
|
|
108
|
+
|
|
109
|
+
___
|
|
110
|
+
|
|
111
|
+
### clone
|
|
112
|
+
|
|
113
|
+
▸ **clone**<`T`\>(`target`): `T`
|
|
114
|
+
|
|
115
|
+
拷贝对象
|
|
116
|
+
|
|
117
|
+
#### Type parameters
|
|
118
|
+
|
|
119
|
+
| Name |
|
|
120
|
+
| :------ |
|
|
121
|
+
| `T` |
|
|
122
|
+
|
|
123
|
+
#### Parameters
|
|
124
|
+
|
|
125
|
+
| Name | Type | Description |
|
|
126
|
+
| :------ | :------ | :------ |
|
|
127
|
+
| `target` | `T` | 需要转换的值 需要注意 当值为 undefined、function、symbol 会在转换过程中被忽略 |
|
|
128
|
+
|
|
129
|
+
#### Returns
|
|
130
|
+
|
|
131
|
+
`T`
|
|
132
|
+
|
|
133
|
+
#### Defined in
|
|
134
|
+
|
|
135
|
+
clone.ts:7
|
|
104
136
|
|
|
105
137
|
___
|
|
106
138
|
|
|
@@ -122,7 +154,7 @@ ___
|
|
|
122
154
|
|
|
123
155
|
#### Defined in
|
|
124
156
|
|
|
125
|
-
[createHexColorByHash.ts:4](https://github.com/daysnap/utils/blob/
|
|
157
|
+
[createHexColorByHash.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/createHexColorByHash.ts#L4)
|
|
126
158
|
|
|
127
159
|
___
|
|
128
160
|
|
|
@@ -148,7 +180,7 @@ ___
|
|
|
148
180
|
|
|
149
181
|
#### Defined in
|
|
150
182
|
|
|
151
|
-
[compareVersion.ts:9](https://github.com/daysnap/utils/blob/
|
|
183
|
+
[compareVersion.ts:9](https://github.com/daysnap/utils/blob/2be359b/src/compareVersion.ts#L9)
|
|
152
184
|
|
|
153
185
|
___
|
|
154
186
|
|
|
@@ -170,7 +202,7 @@ ___
|
|
|
170
202
|
|
|
171
203
|
#### Defined in
|
|
172
204
|
|
|
173
|
-
[compressImage.ts:6](https://github.com/daysnap/utils/blob/
|
|
205
|
+
[compressImage.ts:6](https://github.com/daysnap/utils/blob/2be359b/src/compressImage.ts#L6)
|
|
174
206
|
|
|
175
207
|
___
|
|
176
208
|
|
|
@@ -194,7 +226,7 @@ ___
|
|
|
194
226
|
|
|
195
227
|
#### Defined in
|
|
196
228
|
|
|
197
|
-
[downloadFile.ts:4](https://github.com/daysnap/utils/blob/
|
|
229
|
+
[downloadFile.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/downloadFile.ts#L4)
|
|
198
230
|
|
|
199
231
|
___
|
|
200
232
|
|
|
@@ -223,7 +255,7 @@ ___
|
|
|
223
255
|
|
|
224
256
|
#### Defined in
|
|
225
257
|
|
|
226
|
-
[each.ts:4](https://github.com/daysnap/utils/blob/
|
|
258
|
+
[each.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/each.ts#L4)
|
|
227
259
|
|
|
228
260
|
▸ **each**<`T`\>(`data`, `callback`): `void`
|
|
229
261
|
|
|
@@ -246,7 +278,7 @@ ___
|
|
|
246
278
|
|
|
247
279
|
#### Defined in
|
|
248
280
|
|
|
249
|
-
[each.ts:8](https://github.com/daysnap/utils/blob/
|
|
281
|
+
[each.ts:8](https://github.com/daysnap/utils/blob/2be359b/src/each.ts#L8)
|
|
250
282
|
|
|
251
283
|
___
|
|
252
284
|
|
|
@@ -268,7 +300,7 @@ ___
|
|
|
268
300
|
|
|
269
301
|
#### Defined in
|
|
270
302
|
|
|
271
|
-
[filterBankCardNo.ts:4](https://github.com/daysnap/utils/blob/
|
|
303
|
+
[filterBankCardNo.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/filterBankCardNo.ts#L4)
|
|
272
304
|
|
|
273
305
|
___
|
|
274
306
|
|
|
@@ -290,7 +322,7 @@ ___
|
|
|
290
322
|
|
|
291
323
|
#### Defined in
|
|
292
324
|
|
|
293
|
-
[filterEmoji.ts:4](https://github.com/daysnap/utils/blob/
|
|
325
|
+
[filterEmoji.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/filterEmoji.ts#L4)
|
|
294
326
|
|
|
295
327
|
___
|
|
296
328
|
|
|
@@ -312,7 +344,7 @@ ___
|
|
|
312
344
|
|
|
313
345
|
#### Defined in
|
|
314
346
|
|
|
315
|
-
[filterIdCard.ts:4](https://github.com/daysnap/utils/blob/
|
|
347
|
+
[filterIdCard.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/filterIdCard.ts#L4)
|
|
316
348
|
|
|
317
349
|
___
|
|
318
350
|
|
|
@@ -334,7 +366,7 @@ ___
|
|
|
334
366
|
|
|
335
367
|
#### Defined in
|
|
336
368
|
|
|
337
|
-
[filterName.ts:4](https://github.com/daysnap/utils/blob/
|
|
369
|
+
[filterName.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/filterName.ts#L4)
|
|
338
370
|
|
|
339
371
|
___
|
|
340
372
|
|
|
@@ -359,7 +391,7 @@ filterPhone('13177778888', ' ') => 131 **** 8888
|
|
|
359
391
|
|
|
360
392
|
#### Defined in
|
|
361
393
|
|
|
362
|
-
[filterPhone.ts:6](https://github.com/daysnap/utils/blob/
|
|
394
|
+
[filterPhone.ts:6](https://github.com/daysnap/utils/blob/2be359b/src/filterPhone.ts#L6)
|
|
363
395
|
|
|
364
396
|
___
|
|
365
397
|
|
|
@@ -382,7 +414,7 @@ ___
|
|
|
382
414
|
|
|
383
415
|
#### Defined in
|
|
384
416
|
|
|
385
|
-
[formatAmount.ts:4](https://github.com/daysnap/utils/blob/
|
|
417
|
+
[formatAmount.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/formatAmount.ts#L4)
|
|
386
418
|
|
|
387
419
|
___
|
|
388
420
|
|
|
@@ -405,7 +437,7 @@ ___
|
|
|
405
437
|
|
|
406
438
|
#### Defined in
|
|
407
439
|
|
|
408
|
-
[formatDate.ts:6](https://github.com/daysnap/utils/blob/
|
|
440
|
+
[formatDate.ts:6](https://github.com/daysnap/utils/blob/2be359b/src/formatDate.ts#L6)
|
|
409
441
|
|
|
410
442
|
___
|
|
411
443
|
|
|
@@ -427,7 +459,7 @@ ___
|
|
|
427
459
|
|
|
428
460
|
#### Defined in
|
|
429
461
|
|
|
430
|
-
[getBlobByUrl.ts:4](https://github.com/daysnap/utils/blob/
|
|
462
|
+
[getBlobByUrl.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/getBlobByUrl.ts#L4)
|
|
431
463
|
|
|
432
464
|
___
|
|
433
465
|
|
|
@@ -450,7 +482,7 @@ ___
|
|
|
450
482
|
|
|
451
483
|
#### Defined in
|
|
452
484
|
|
|
453
|
-
[storage/index.ts:7](https://github.com/daysnap/utils/blob/
|
|
485
|
+
[storage/index.ts:7](https://github.com/daysnap/utils/blob/2be359b/src/storage/index.ts#L7)
|
|
454
486
|
|
|
455
487
|
___
|
|
456
488
|
|
|
@@ -472,7 +504,7 @@ ___
|
|
|
472
504
|
|
|
473
505
|
#### Defined in
|
|
474
506
|
|
|
475
|
-
[getDayMillisecond.ts:4](https://github.com/daysnap/utils/blob/
|
|
507
|
+
[getDayMillisecond.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/getDayMillisecond.ts#L4)
|
|
476
508
|
|
|
477
509
|
___
|
|
478
510
|
|
|
@@ -494,7 +526,7 @@ ___
|
|
|
494
526
|
|
|
495
527
|
#### Defined in
|
|
496
528
|
|
|
497
|
-
[getImageInfo.ts:4](https://github.com/daysnap/utils/blob/
|
|
529
|
+
[getImageInfo.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/getImageInfo.ts#L4)
|
|
498
530
|
|
|
499
531
|
___
|
|
500
532
|
|
|
@@ -517,7 +549,7 @@ ___
|
|
|
517
549
|
|
|
518
550
|
#### Defined in
|
|
519
551
|
|
|
520
|
-
[storage/index.ts:7](https://github.com/daysnap/utils/blob/
|
|
552
|
+
[storage/index.ts:7](https://github.com/daysnap/utils/blob/2be359b/src/storage/index.ts#L7)
|
|
521
553
|
|
|
522
554
|
___
|
|
523
555
|
|
|
@@ -539,7 +571,7 @@ ___
|
|
|
539
571
|
|
|
540
572
|
#### Defined in
|
|
541
573
|
|
|
542
|
-
[getVideoInfo.ts:4](https://github.com/daysnap/utils/blob/
|
|
574
|
+
[getVideoInfo.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/getVideoInfo.ts#L4)
|
|
543
575
|
|
|
544
576
|
___
|
|
545
577
|
|
|
@@ -555,7 +587,7 @@ ___
|
|
|
555
587
|
|
|
556
588
|
#### Defined in
|
|
557
589
|
|
|
558
|
-
[inBrowser.ts:4](https://github.com/daysnap/utils/blob/
|
|
590
|
+
[inBrowser.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/inBrowser.ts#L4)
|
|
559
591
|
|
|
560
592
|
___
|
|
561
593
|
|
|
@@ -571,7 +603,7 @@ ___
|
|
|
571
603
|
|
|
572
604
|
#### Defined in
|
|
573
605
|
|
|
574
|
-
[isAndroid.ts:4](https://github.com/daysnap/utils/blob/
|
|
606
|
+
[isAndroid.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isAndroid.ts#L4)
|
|
575
607
|
|
|
576
608
|
___
|
|
577
609
|
|
|
@@ -593,7 +625,7 @@ ___
|
|
|
593
625
|
|
|
594
626
|
#### Defined in
|
|
595
627
|
|
|
596
|
-
[isEmail.ts:4](https://github.com/daysnap/utils/blob/
|
|
628
|
+
[isEmail.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isEmail.ts#L4)
|
|
597
629
|
|
|
598
630
|
___
|
|
599
631
|
|
|
@@ -615,7 +647,7 @@ ___
|
|
|
615
647
|
|
|
616
648
|
#### Defined in
|
|
617
649
|
|
|
618
|
-
[isEmpty.ts:6](https://github.com/daysnap/utils/blob/
|
|
650
|
+
[isEmpty.ts:6](https://github.com/daysnap/utils/blob/2be359b/src/isEmpty.ts#L6)
|
|
619
651
|
|
|
620
652
|
___
|
|
621
653
|
|
|
@@ -637,7 +669,7 @@ ___
|
|
|
637
669
|
|
|
638
670
|
#### Defined in
|
|
639
671
|
|
|
640
|
-
[isEmptyObject.ts:5](https://github.com/daysnap/utils/blob/
|
|
672
|
+
[isEmptyObject.ts:5](https://github.com/daysnap/utils/blob/2be359b/src/isEmptyObject.ts#L5)
|
|
641
673
|
|
|
642
674
|
___
|
|
643
675
|
|
|
@@ -659,7 +691,7 @@ val is Error
|
|
|
659
691
|
|
|
660
692
|
#### Defined in
|
|
661
693
|
|
|
662
|
-
[isError.ts:4](https://github.com/daysnap/utils/blob/
|
|
694
|
+
[isError.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isError.ts#L4)
|
|
663
695
|
|
|
664
696
|
___
|
|
665
697
|
|
|
@@ -681,7 +713,7 @@ val is Function
|
|
|
681
713
|
|
|
682
714
|
#### Defined in
|
|
683
715
|
|
|
684
|
-
[isFunction.ts:4](https://github.com/daysnap/utils/blob/
|
|
716
|
+
[isFunction.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isFunction.ts#L4)
|
|
685
717
|
|
|
686
718
|
___
|
|
687
719
|
|
|
@@ -697,7 +729,7 @@ ___
|
|
|
697
729
|
|
|
698
730
|
#### Defined in
|
|
699
731
|
|
|
700
|
-
[isIOS.ts:4](https://github.com/daysnap/utils/blob/
|
|
732
|
+
[isIOS.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isIOS.ts#L4)
|
|
701
733
|
|
|
702
734
|
___
|
|
703
735
|
|
|
@@ -719,7 +751,7 @@ ___
|
|
|
719
751
|
|
|
720
752
|
#### Defined in
|
|
721
753
|
|
|
722
|
-
[isIdCard.ts:4](https://github.com/daysnap/utils/blob/
|
|
754
|
+
[isIdCard.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isIdCard.ts#L4)
|
|
723
755
|
|
|
724
756
|
___
|
|
725
757
|
|
|
@@ -741,7 +773,29 @@ ___
|
|
|
741
773
|
|
|
742
774
|
#### Defined in
|
|
743
775
|
|
|
744
|
-
[isJSONString.ts:7](https://github.com/daysnap/utils/blob/
|
|
776
|
+
[isJSONString.ts:7](https://github.com/daysnap/utils/blob/2be359b/src/isJSONString.ts#L7)
|
|
777
|
+
|
|
778
|
+
___
|
|
779
|
+
|
|
780
|
+
### isLan
|
|
781
|
+
|
|
782
|
+
▸ **isLan**(`ip`): `boolean`
|
|
783
|
+
|
|
784
|
+
判断 ip 是否是局域网 ip,仅支持 ipv4
|
|
785
|
+
|
|
786
|
+
#### Parameters
|
|
787
|
+
|
|
788
|
+
| Name | Type | Description |
|
|
789
|
+
| :------ | :------ | :------ |
|
|
790
|
+
| `ip` | `string` | ipv4 地址 |
|
|
791
|
+
|
|
792
|
+
#### Returns
|
|
793
|
+
|
|
794
|
+
`boolean`
|
|
795
|
+
|
|
796
|
+
#### Defined in
|
|
797
|
+
|
|
798
|
+
isLan.ts:5
|
|
745
799
|
|
|
746
800
|
___
|
|
747
801
|
|
|
@@ -763,7 +817,7 @@ ___
|
|
|
763
817
|
|
|
764
818
|
#### Defined in
|
|
765
819
|
|
|
766
|
-
[isLicenseCode.ts:5](https://github.com/daysnap/utils/blob/
|
|
820
|
+
[isLicenseCode.ts:5](https://github.com/daysnap/utils/blob/2be359b/src/isLicenseCode.ts#L5)
|
|
767
821
|
|
|
768
822
|
___
|
|
769
823
|
|
|
@@ -779,7 +833,7 @@ ___
|
|
|
779
833
|
|
|
780
834
|
#### Defined in
|
|
781
835
|
|
|
782
|
-
[isMobile.ts:4](https://github.com/daysnap/utils/blob/
|
|
836
|
+
[isMobile.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isMobile.ts#L4)
|
|
783
837
|
|
|
784
838
|
___
|
|
785
839
|
|
|
@@ -801,7 +855,29 @@ val is null
|
|
|
801
855
|
|
|
802
856
|
#### Defined in
|
|
803
857
|
|
|
804
|
-
[isNull.ts:4](https://github.com/daysnap/utils/blob/
|
|
858
|
+
[isNull.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isNull.ts#L4)
|
|
859
|
+
|
|
860
|
+
___
|
|
861
|
+
|
|
862
|
+
### isNumber
|
|
863
|
+
|
|
864
|
+
▸ **isNumber**(`val`): val is number
|
|
865
|
+
|
|
866
|
+
判断是否是数字
|
|
867
|
+
|
|
868
|
+
#### Parameters
|
|
869
|
+
|
|
870
|
+
| Name | Type | Description |
|
|
871
|
+
| :------ | :------ | :------ |
|
|
872
|
+
| `val` | `unknown` | 需要判断的值 |
|
|
873
|
+
|
|
874
|
+
#### Returns
|
|
875
|
+
|
|
876
|
+
val is number
|
|
877
|
+
|
|
878
|
+
#### Defined in
|
|
879
|
+
|
|
880
|
+
isNumber.ts:5
|
|
805
881
|
|
|
806
882
|
___
|
|
807
883
|
|
|
@@ -823,7 +899,7 @@ val is Record<string, any\>
|
|
|
823
899
|
|
|
824
900
|
#### Defined in
|
|
825
901
|
|
|
826
|
-
[isObject.ts:4](https://github.com/daysnap/utils/blob/
|
|
902
|
+
[isObject.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isObject.ts#L4)
|
|
827
903
|
|
|
828
904
|
___
|
|
829
905
|
|
|
@@ -845,7 +921,7 @@ ___
|
|
|
845
921
|
|
|
846
922
|
#### Defined in
|
|
847
923
|
|
|
848
|
-
[isPhone.ts:4](https://github.com/daysnap/utils/blob/
|
|
924
|
+
[isPhone.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isPhone.ts#L4)
|
|
849
925
|
|
|
850
926
|
___
|
|
851
927
|
|
|
@@ -873,7 +949,7 @@ val is Promise<T\>
|
|
|
873
949
|
|
|
874
950
|
#### Defined in
|
|
875
951
|
|
|
876
|
-
[isPromise.ts:4](https://github.com/daysnap/utils/blob/
|
|
952
|
+
[isPromise.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isPromise.ts#L4)
|
|
877
953
|
|
|
878
954
|
___
|
|
879
955
|
|
|
@@ -895,7 +971,7 @@ val is RegExp
|
|
|
895
971
|
|
|
896
972
|
#### Defined in
|
|
897
973
|
|
|
898
|
-
[isRegExp.ts:4](https://github.com/daysnap/utils/blob/
|
|
974
|
+
[isRegExp.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isRegExp.ts#L4)
|
|
899
975
|
|
|
900
976
|
___
|
|
901
977
|
|
|
@@ -917,7 +993,7 @@ val is string
|
|
|
917
993
|
|
|
918
994
|
#### Defined in
|
|
919
995
|
|
|
920
|
-
[isString.ts:4](https://github.com/daysnap/utils/blob/
|
|
996
|
+
[isString.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isString.ts#L4)
|
|
921
997
|
|
|
922
998
|
___
|
|
923
999
|
|
|
@@ -939,7 +1015,7 @@ val is undefined
|
|
|
939
1015
|
|
|
940
1016
|
#### Defined in
|
|
941
1017
|
|
|
942
|
-
[isUndefined.ts:4](https://github.com/daysnap/utils/blob/
|
|
1018
|
+
[isUndefined.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/isUndefined.ts#L4)
|
|
943
1019
|
|
|
944
1020
|
___
|
|
945
1021
|
|
|
@@ -961,7 +1037,7 @@ val is Window
|
|
|
961
1037
|
|
|
962
1038
|
#### Defined in
|
|
963
1039
|
|
|
964
|
-
[isWindow.ts:5](https://github.com/daysnap/utils/blob/
|
|
1040
|
+
[isWindow.ts:5](https://github.com/daysnap/utils/blob/2be359b/src/isWindow.ts#L5)
|
|
965
1041
|
|
|
966
1042
|
___
|
|
967
1043
|
|
|
@@ -991,7 +1067,7 @@ ___
|
|
|
991
1067
|
|
|
992
1068
|
#### Defined in
|
|
993
1069
|
|
|
994
|
-
[omit.ts:4](https://github.com/daysnap/utils/blob/
|
|
1070
|
+
[omit.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/omit.ts#L4)
|
|
995
1071
|
|
|
996
1072
|
___
|
|
997
1073
|
|
|
@@ -1013,7 +1089,7 @@ ___
|
|
|
1013
1089
|
|
|
1014
1090
|
#### Defined in
|
|
1015
1091
|
|
|
1016
|
-
[parseDate.ts:4](https://github.com/daysnap/utils/blob/
|
|
1092
|
+
[parseDate.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/parseDate.ts#L4)
|
|
1017
1093
|
|
|
1018
1094
|
___
|
|
1019
1095
|
|
|
@@ -1036,7 +1112,7 @@ ___
|
|
|
1036
1112
|
|
|
1037
1113
|
#### Defined in
|
|
1038
1114
|
|
|
1039
|
-
[parseError.ts:8](https://github.com/daysnap/utils/blob/
|
|
1115
|
+
[parseError.ts:8](https://github.com/daysnap/utils/blob/2be359b/src/parseError.ts#L8)
|
|
1040
1116
|
|
|
1041
1117
|
___
|
|
1042
1118
|
|
|
@@ -1059,7 +1135,7 @@ ___
|
|
|
1059
1135
|
|
|
1060
1136
|
#### Defined in
|
|
1061
1137
|
|
|
1062
|
-
[parsePath.ts:4](https://github.com/daysnap/utils/blob/
|
|
1138
|
+
[parsePath.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/parsePath.ts#L4)
|
|
1063
1139
|
|
|
1064
1140
|
___
|
|
1065
1141
|
|
|
@@ -1082,7 +1158,7 @@ ___
|
|
|
1082
1158
|
|
|
1083
1159
|
#### Defined in
|
|
1084
1160
|
|
|
1085
|
-
[parseQuery.ts:8](https://github.com/daysnap/utils/blob/
|
|
1161
|
+
[parseQuery.ts:8](https://github.com/daysnap/utils/blob/2be359b/src/parseQuery.ts#L8)
|
|
1086
1162
|
|
|
1087
1163
|
___
|
|
1088
1164
|
|
|
@@ -1112,7 +1188,7 @@ ___
|
|
|
1112
1188
|
|
|
1113
1189
|
#### Defined in
|
|
1114
1190
|
|
|
1115
|
-
[pick.ts:4](https://github.com/daysnap/utils/blob/
|
|
1191
|
+
[pick.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/pick.ts#L4)
|
|
1116
1192
|
|
|
1117
1193
|
___
|
|
1118
1194
|
|
|
@@ -1135,7 +1211,7 @@ ___
|
|
|
1135
1211
|
|
|
1136
1212
|
#### Defined in
|
|
1137
1213
|
|
|
1138
|
-
[replaceCrlf.ts:4](https://github.com/daysnap/utils/blob/
|
|
1214
|
+
[replaceCrlf.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/replaceCrlf.ts#L4)
|
|
1139
1215
|
|
|
1140
1216
|
___
|
|
1141
1217
|
|
|
@@ -1161,7 +1237,30 @@ reserve(0, '--') => 0
|
|
|
1161
1237
|
|
|
1162
1238
|
#### Defined in
|
|
1163
1239
|
|
|
1164
|
-
[reserve.ts:8](https://github.com/daysnap/utils/blob/
|
|
1240
|
+
[reserve.ts:8](https://github.com/daysnap/utils/blob/2be359b/src/reserve.ts#L8)
|
|
1241
|
+
|
|
1242
|
+
___
|
|
1243
|
+
|
|
1244
|
+
### round
|
|
1245
|
+
|
|
1246
|
+
▸ **round**(`val`, `fractionDigits`): `any`
|
|
1247
|
+
|
|
1248
|
+
四舍五入
|
|
1249
|
+
|
|
1250
|
+
#### Parameters
|
|
1251
|
+
|
|
1252
|
+
| Name | Type | Description |
|
|
1253
|
+
| :------ | :------ | :------ |
|
|
1254
|
+
| `val` | `number` | 需要四舍五入的值 |
|
|
1255
|
+
| `fractionDigits` | `number` | 需要保留的小数点位数 |
|
|
1256
|
+
|
|
1257
|
+
#### Returns
|
|
1258
|
+
|
|
1259
|
+
`any`
|
|
1260
|
+
|
|
1261
|
+
#### Defined in
|
|
1262
|
+
|
|
1263
|
+
round.ts:6
|
|
1165
1264
|
|
|
1166
1265
|
___
|
|
1167
1266
|
|
|
@@ -1184,7 +1283,7 @@ ___
|
|
|
1184
1283
|
|
|
1185
1284
|
#### Defined in
|
|
1186
1285
|
|
|
1187
|
-
[sleep.ts:4](https://github.com/daysnap/utils/blob/
|
|
1286
|
+
[sleep.ts:4](https://github.com/daysnap/utils/blob/2be359b/src/sleep.ts#L4)
|
|
1188
1287
|
|
|
1189
1288
|
___
|
|
1190
1289
|
|
|
@@ -1206,4 +1305,4 @@ ___
|
|
|
1206
1305
|
|
|
1207
1306
|
#### Defined in
|
|
1208
1307
|
|
|
1209
|
-
[stringifyQuery.ts:6](https://github.com/daysnap/utils/blob/
|
|
1308
|
+
[stringifyQuery.ts:6](https://github.com/daysnap/utils/blob/2be359b/src/stringifyQuery.ts#L6)
|
package/es/base64ToBlob.d.ts
CHANGED
package/es/base64ToBlob.js
CHANGED
package/es/clone.d.ts
ADDED
package/es/clone.js
ADDED
package/es/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './base64ToBlob';
|
|
2
2
|
export * from './blobToBase64';
|
|
3
|
+
export * from './clone';
|
|
3
4
|
export * from './compareVersion';
|
|
4
5
|
export * from './compressImage';
|
|
5
6
|
export * from './createHexColorByHash';
|
|
@@ -26,9 +27,11 @@ export * from './isFunction';
|
|
|
26
27
|
export * from './isIOS';
|
|
27
28
|
export * from './isIdCard';
|
|
28
29
|
export * from './isJSONString';
|
|
30
|
+
export * from './isLan';
|
|
29
31
|
export * from './isLicenseCode';
|
|
30
32
|
export * from './isMobile';
|
|
31
33
|
export * from './isNull';
|
|
34
|
+
export * from './isNumber';
|
|
32
35
|
export * from './isObject';
|
|
33
36
|
export * from './isPhone';
|
|
34
37
|
export * from './isPromise';
|
|
@@ -44,6 +47,7 @@ export * from './parseQuery';
|
|
|
44
47
|
export * from './pick';
|
|
45
48
|
export * from './replaceCrlf';
|
|
46
49
|
export * from './reserve';
|
|
50
|
+
export * from './round';
|
|
47
51
|
export * from './sleep';
|
|
48
52
|
export * from './storage';
|
|
49
53
|
export * from './stringifyQuery';
|
package/es/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* 本文件自动生成 './scripts/entry.js' */
|
|
2
2
|
export * from './base64ToBlob';
|
|
3
3
|
export * from './blobToBase64';
|
|
4
|
+
export * from './clone';
|
|
4
5
|
export * from './compareVersion';
|
|
5
6
|
export * from './compressImage';
|
|
6
7
|
export * from './createHexColorByHash';
|
|
@@ -27,9 +28,11 @@ export * from './isFunction';
|
|
|
27
28
|
export * from './isIOS';
|
|
28
29
|
export * from './isIdCard';
|
|
29
30
|
export * from './isJSONString';
|
|
31
|
+
export * from './isLan';
|
|
30
32
|
export * from './isLicenseCode';
|
|
31
33
|
export * from './isMobile';
|
|
32
34
|
export * from './isNull';
|
|
35
|
+
export * from './isNumber';
|
|
33
36
|
export * from './isObject';
|
|
34
37
|
export * from './isPhone';
|
|
35
38
|
export * from './isPromise';
|
|
@@ -45,6 +48,7 @@ export * from './parseQuery';
|
|
|
45
48
|
export * from './pick';
|
|
46
49
|
export * from './replaceCrlf';
|
|
47
50
|
export * from './reserve';
|
|
51
|
+
export * from './round';
|
|
48
52
|
export * from './sleep';
|
|
49
53
|
export * from './storage';
|
|
50
54
|
export * from './stringifyQuery';
|
package/es/isIOS.js
CHANGED
package/es/isLan.d.ts
ADDED
package/es/isLan.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断 ip 是否是局域网 ip,仅支持 ipv4
|
|
3
|
+
* @param ip ipv4 地址
|
|
4
|
+
*/
|
|
5
|
+
export function isLan(ip) {
|
|
6
|
+
// eslint-disable-next-line no-param-reassign
|
|
7
|
+
ip = ip.toLocaleLowerCase();
|
|
8
|
+
if (ip === 'localhost') {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (ip === '') {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
var v = 0;
|
|
15
|
+
var aNum = ip.split('.');
|
|
16
|
+
if (aNum.length !== 4) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
// eslint-disable-next-line no-bitwise
|
|
20
|
+
v += parseInt(aNum[0], 10) << 24;
|
|
21
|
+
// eslint-disable-next-line no-bitwise
|
|
22
|
+
v += parseInt(aNum[1], 10) << 16;
|
|
23
|
+
// eslint-disable-next-line no-bitwise
|
|
24
|
+
v += parseInt(aNum[2], 10) << 8;
|
|
25
|
+
// eslint-disable-next-line no-bitwise
|
|
26
|
+
v += parseInt(aNum[3], 10) << 0;
|
|
27
|
+
// eslint-disable-next-line no-bitwise
|
|
28
|
+
v = v >> 16 & 0xffff;
|
|
29
|
+
return (
|
|
30
|
+
// eslint-disable-next-line no-bitwise
|
|
31
|
+
v >> 8 === 0x7f ||
|
|
32
|
+
// eslint-disable-next-line no-bitwise
|
|
33
|
+
v >> 8 === 0xa || v === 0xc0a8 || v >= 0xac10 && v <= 0xac1f
|
|
34
|
+
);
|
|
35
|
+
}
|
package/es/isNumber.d.ts
ADDED
package/es/isNumber.js
ADDED
package/es/parseQuery.js
CHANGED
package/es/round.d.ts
ADDED
package/es/round.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 四舍五入
|
|
3
|
+
* @param val 需要四舍五入的值
|
|
4
|
+
* @param fractionDigits 需要保留的小数点位数
|
|
5
|
+
*/
|
|
6
|
+
export function round(val, fractionDigits) {
|
|
7
|
+
// todo
|
|
8
|
+
var number = val;
|
|
9
|
+
if (number >= Math.pow(10, 21)) {
|
|
10
|
+
return number.toString();
|
|
11
|
+
}
|
|
12
|
+
if (typeof fractionDigits === 'undefined' || fractionDigits === 0) {
|
|
13
|
+
return Math.round(number).toString();
|
|
14
|
+
}
|
|
15
|
+
var result = number.toString();
|
|
16
|
+
var arr = result.split('.');
|
|
17
|
+
// 整数的情况
|
|
18
|
+
if (arr.length < 2) {
|
|
19
|
+
result += '.';
|
|
20
|
+
for (var i = 0; i < fractionDigits; i += 1) {
|
|
21
|
+
result += '0';
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
var integer = arr[0];
|
|
26
|
+
var decimal = arr[1];
|
|
27
|
+
if (decimal.length === fractionDigits) {
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
if (decimal.length < fractionDigits) {
|
|
31
|
+
for (var _i = 0; _i < fractionDigits - decimal.length; _i += 1) {
|
|
32
|
+
result += '0';
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
result = "".concat(integer, ".").concat(decimal.substr(0, fractionDigits));
|
|
37
|
+
var last = decimal.substr(fractionDigits, 1);
|
|
38
|
+
if (/^\d(9){5,}[0-9]$/.test(decimal.substr(fractionDigits))) {
|
|
39
|
+
last = (+last + 1).toString();
|
|
40
|
+
}
|
|
41
|
+
// 四舍五入,转换为整数再处理,避免浮点数精度的损失
|
|
42
|
+
if (parseInt(last, 10) >= 5) {
|
|
43
|
+
var x = Math.pow(10, fractionDigits);
|
|
44
|
+
result = (Math.round(parseFloat(result) * x) + 1) / x;
|
|
45
|
+
result = round(result, fractionDigits);
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
package/lib/base64ToBlob.d.ts
CHANGED
package/lib/base64ToBlob.js
CHANGED
|
@@ -8,6 +8,8 @@ exports.base64ToBlob = base64ToBlob;
|
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
/**
|
|
10
10
|
* base64 转 blob
|
|
11
|
+
* @param base64 base64字符串
|
|
12
|
+
* @param contentType 文件类型
|
|
11
13
|
*/
|
|
12
14
|
function base64ToBlob(base64, contentType) {
|
|
13
15
|
var _prefix$match;
|
package/lib/clone.d.ts
ADDED
package/lib/clone.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.clone = clone;
|
|
7
|
+
/**
|
|
8
|
+
* 拷贝对象
|
|
9
|
+
* @param target 需要转换的值
|
|
10
|
+
*
|
|
11
|
+
* 需要注意 当值为 undefined、function、symbol 会在转换过程中被忽略
|
|
12
|
+
*/
|
|
13
|
+
function clone(target) {
|
|
14
|
+
return JSON.parse(JSON.stringify(target));
|
|
15
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './base64ToBlob';
|
|
2
2
|
export * from './blobToBase64';
|
|
3
|
+
export * from './clone';
|
|
3
4
|
export * from './compareVersion';
|
|
4
5
|
export * from './compressImage';
|
|
5
6
|
export * from './createHexColorByHash';
|
|
@@ -26,9 +27,11 @@ export * from './isFunction';
|
|
|
26
27
|
export * from './isIOS';
|
|
27
28
|
export * from './isIdCard';
|
|
28
29
|
export * from './isJSONString';
|
|
30
|
+
export * from './isLan';
|
|
29
31
|
export * from './isLicenseCode';
|
|
30
32
|
export * from './isMobile';
|
|
31
33
|
export * from './isNull';
|
|
34
|
+
export * from './isNumber';
|
|
32
35
|
export * from './isObject';
|
|
33
36
|
export * from './isPhone';
|
|
34
37
|
export * from './isPromise';
|
|
@@ -44,6 +47,7 @@ export * from './parseQuery';
|
|
|
44
47
|
export * from './pick';
|
|
45
48
|
export * from './replaceCrlf';
|
|
46
49
|
export * from './reserve';
|
|
50
|
+
export * from './round';
|
|
47
51
|
export * from './sleep';
|
|
48
52
|
export * from './storage';
|
|
49
53
|
export * from './stringifyQuery';
|
package/lib/index.js
CHANGED
|
@@ -25,6 +25,17 @@ Object.keys(_blobToBase).forEach(function (key) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
+
var _clone = require("./clone");
|
|
29
|
+
Object.keys(_clone).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _clone[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _clone[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
28
39
|
var _compareVersion = require("./compareVersion");
|
|
29
40
|
Object.keys(_compareVersion).forEach(function (key) {
|
|
30
41
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -311,6 +322,17 @@ Object.keys(_isJSONString).forEach(function (key) {
|
|
|
311
322
|
}
|
|
312
323
|
});
|
|
313
324
|
});
|
|
325
|
+
var _isLan = require("./isLan");
|
|
326
|
+
Object.keys(_isLan).forEach(function (key) {
|
|
327
|
+
if (key === "default" || key === "__esModule") return;
|
|
328
|
+
if (key in exports && exports[key] === _isLan[key]) return;
|
|
329
|
+
Object.defineProperty(exports, key, {
|
|
330
|
+
enumerable: true,
|
|
331
|
+
get: function get() {
|
|
332
|
+
return _isLan[key];
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
});
|
|
314
336
|
var _isLicenseCode = require("./isLicenseCode");
|
|
315
337
|
Object.keys(_isLicenseCode).forEach(function (key) {
|
|
316
338
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -344,6 +366,17 @@ Object.keys(_isNull).forEach(function (key) {
|
|
|
344
366
|
}
|
|
345
367
|
});
|
|
346
368
|
});
|
|
369
|
+
var _isNumber = require("./isNumber");
|
|
370
|
+
Object.keys(_isNumber).forEach(function (key) {
|
|
371
|
+
if (key === "default" || key === "__esModule") return;
|
|
372
|
+
if (key in exports && exports[key] === _isNumber[key]) return;
|
|
373
|
+
Object.defineProperty(exports, key, {
|
|
374
|
+
enumerable: true,
|
|
375
|
+
get: function get() {
|
|
376
|
+
return _isNumber[key];
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
});
|
|
347
380
|
var _isObject = require("./isObject");
|
|
348
381
|
Object.keys(_isObject).forEach(function (key) {
|
|
349
382
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -509,6 +542,17 @@ Object.keys(_reserve).forEach(function (key) {
|
|
|
509
542
|
}
|
|
510
543
|
});
|
|
511
544
|
});
|
|
545
|
+
var _round = require("./round");
|
|
546
|
+
Object.keys(_round).forEach(function (key) {
|
|
547
|
+
if (key === "default" || key === "__esModule") return;
|
|
548
|
+
if (key in exports && exports[key] === _round[key]) return;
|
|
549
|
+
Object.defineProperty(exports, key, {
|
|
550
|
+
enumerable: true,
|
|
551
|
+
get: function get() {
|
|
552
|
+
return _round[key];
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
});
|
|
512
556
|
var _sleep = require("./sleep");
|
|
513
557
|
Object.keys(_sleep).forEach(function (key) {
|
|
514
558
|
if (key === "default" || key === "__esModule") return;
|
package/lib/isIOS.js
CHANGED
package/lib/isLan.d.ts
ADDED
package/lib/isLan.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isLan = isLan;
|
|
7
|
+
/**
|
|
8
|
+
* 判断 ip 是否是局域网 ip,仅支持 ipv4
|
|
9
|
+
* @param ip ipv4 地址
|
|
10
|
+
*/
|
|
11
|
+
function isLan(ip) {
|
|
12
|
+
// eslint-disable-next-line no-param-reassign
|
|
13
|
+
ip = ip.toLocaleLowerCase();
|
|
14
|
+
if (ip === 'localhost') {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (ip === '') {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
var v = 0;
|
|
21
|
+
var aNum = ip.split('.');
|
|
22
|
+
if (aNum.length !== 4) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line no-bitwise
|
|
26
|
+
v += parseInt(aNum[0], 10) << 24;
|
|
27
|
+
// eslint-disable-next-line no-bitwise
|
|
28
|
+
v += parseInt(aNum[1], 10) << 16;
|
|
29
|
+
// eslint-disable-next-line no-bitwise
|
|
30
|
+
v += parseInt(aNum[2], 10) << 8;
|
|
31
|
+
// eslint-disable-next-line no-bitwise
|
|
32
|
+
v += parseInt(aNum[3], 10) << 0;
|
|
33
|
+
// eslint-disable-next-line no-bitwise
|
|
34
|
+
v = v >> 16 & 0xffff;
|
|
35
|
+
return (
|
|
36
|
+
// eslint-disable-next-line no-bitwise
|
|
37
|
+
v >> 8 === 0x7f ||
|
|
38
|
+
// eslint-disable-next-line no-bitwise
|
|
39
|
+
v >> 8 === 0xa || v === 0xc0a8 || v >= 0xac10 && v <= 0xac1f
|
|
40
|
+
);
|
|
41
|
+
}
|
package/lib/isNumber.js
ADDED
package/lib/parseQuery.js
CHANGED
|
@@ -28,7 +28,6 @@ function parseQuery(v, k) {
|
|
|
28
28
|
var _step$value = (0, _slicedToArray2["default"])(_step.value, 2),
|
|
29
29
|
key = _step$value[0],
|
|
30
30
|
value = _step$value[1];
|
|
31
|
-
console.log(key, value);
|
|
32
31
|
res[key] = (0, _isJSONString.isJSONString)(value) ? JSON.parse(value) : value;
|
|
33
32
|
}
|
|
34
33
|
} catch (err) {
|
package/lib/round.d.ts
ADDED
package/lib/round.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.round = round;
|
|
7
|
+
/**
|
|
8
|
+
* 四舍五入
|
|
9
|
+
* @param val 需要四舍五入的值
|
|
10
|
+
* @param fractionDigits 需要保留的小数点位数
|
|
11
|
+
*/
|
|
12
|
+
function round(val, fractionDigits) {
|
|
13
|
+
// todo
|
|
14
|
+
var number = val;
|
|
15
|
+
if (number >= Math.pow(10, 21)) {
|
|
16
|
+
return number.toString();
|
|
17
|
+
}
|
|
18
|
+
if (typeof fractionDigits === 'undefined' || fractionDigits === 0) {
|
|
19
|
+
return Math.round(number).toString();
|
|
20
|
+
}
|
|
21
|
+
var result = number.toString();
|
|
22
|
+
var arr = result.split('.');
|
|
23
|
+
// 整数的情况
|
|
24
|
+
if (arr.length < 2) {
|
|
25
|
+
result += '.';
|
|
26
|
+
for (var i = 0; i < fractionDigits; i += 1) {
|
|
27
|
+
result += '0';
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
var integer = arr[0];
|
|
32
|
+
var decimal = arr[1];
|
|
33
|
+
if (decimal.length === fractionDigits) {
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
if (decimal.length < fractionDigits) {
|
|
37
|
+
for (var _i = 0; _i < fractionDigits - decimal.length; _i += 1) {
|
|
38
|
+
result += '0';
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
result = "".concat(integer, ".").concat(decimal.substr(0, fractionDigits));
|
|
43
|
+
var last = decimal.substr(fractionDigits, 1);
|
|
44
|
+
if (/^\d(9){5,}[0-9]$/.test(decimal.substr(fractionDigits))) {
|
|
45
|
+
last = (+last + 1).toString();
|
|
46
|
+
}
|
|
47
|
+
// 四舍五入,转换为整数再处理,避免浮点数精度的损失
|
|
48
|
+
if (parseInt(last, 10) >= 5) {
|
|
49
|
+
var x = Math.pow(10, fractionDigits);
|
|
50
|
+
result = (Math.round(parseFloat(result) * x) + 1) / x;
|
|
51
|
+
result = round(result, fractionDigits);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|