@wxhccc/es-util 2.1.2 → 2.1.4
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 +221 -0
- package/dist/array-tree-switch.js +2 -2
- package/dist/event-target-emitter.js +2 -2
- package/dist/index.esm.js +14 -6
- package/dist/index.js +14 -6
- package/dist/index.min.js +3 -3
- package/dist/object-array.js +2 -2
- package/dist/optional.js +2 -2
- package/dist/page-communicate.js +2 -2
- package/dist/promise.js +2 -2
- package/dist/raf-timer.js +2 -2
- package/dist/utils.js +2 -2
- package/dist/validate.js +2 -2
- package/dist/value-string-switch/uri-b64.d.ts +2 -2
- package/dist/value-string-switch.d.ts +1 -0
- package/dist/value-string-switch.js +14 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -478,6 +478,89 @@ byteStringify(1234, { detail: true, standard: 'metric', precision: 3 })
|
|
|
478
478
|
|
|
479
479
|
```
|
|
480
480
|
|
|
481
|
+
### `maskData(data, options)`
|
|
482
|
+
|
|
483
|
+
mask the string for privacy, such as phone number and id card, returns `''` if `data` is not a non-empty string
|
|
484
|
+
|
|
485
|
+
**parameters:**
|
|
486
|
+
- **data** {string} The string need to mask.
|
|
487
|
+
- **options** {object} The options.
|
|
488
|
+
- **maskWith** {string} the char used to replace, default `'*'`
|
|
489
|
+
- **startCharIndex** {number} the start index of the masked part, negative counts from the end of string
|
|
490
|
+
- **endCharIndex** {number} the end index (inclusive) of the masked part, default to the end of string, negative counts from the end of string
|
|
491
|
+
- **startFrom** {string} the masked part starts after this substring, the substring itself is kept
|
|
492
|
+
- **endUntil** {string} the masked part ends before the last occurrence of this substring, the substring and the text after it are kept
|
|
493
|
+
- **mode** {string} built-in presets, support `'telphone'` and `'idcard'`, all the options above can override the preset
|
|
494
|
+
|
|
495
|
+
**returns**: string
|
|
496
|
+
|
|
497
|
+
Example
|
|
498
|
+
|
|
499
|
+
```javascript
|
|
500
|
+
import { maskData } from '@wxhccc/es-util'
|
|
501
|
+
|
|
502
|
+
maskData('123456789')
|
|
503
|
+
/*log '*********'*/
|
|
504
|
+
maskData('123456789', { startCharIndex: 3 })
|
|
505
|
+
/*log '123******'*/
|
|
506
|
+
maskData('123456789', { startCharIndex: 3, endCharIndex: 5 })
|
|
507
|
+
/*log '123***789'*/
|
|
508
|
+
maskData('123456789', { startCharIndex: -2 })
|
|
509
|
+
/*log '1234567**'*/
|
|
510
|
+
maskData('13888888888', { mode: 'telphone' })
|
|
511
|
+
/*log '138****8888'*/
|
|
512
|
+
maskData('abcd1234@sine.com', { startCharIndex: 2, endCharIndex: -3, endUntil: '@' })
|
|
513
|
+
/*log 'ab****34@sine.com'*/
|
|
514
|
+
maskData(undefined)
|
|
515
|
+
/*log ''*/
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### `b64UriEncode(str)`
|
|
519
|
+
|
|
520
|
+
encode a string to base64, implemented with `encodeURIComponent` + `window.btoa`, mainly to solve the problem that `btoa` throws on special characters, slower than the `Buffer` solution, suitable for simple scenes
|
|
521
|
+
|
|
522
|
+
**parameters:**
|
|
523
|
+
- **str** {string} The string need to encode, returns `''` if a non-string value is passed.
|
|
524
|
+
|
|
525
|
+
**returns**: string
|
|
526
|
+
|
|
527
|
+
Example
|
|
528
|
+
|
|
529
|
+
```javascript
|
|
530
|
+
import { b64UriEncode } from '@wxhccc/es-util'
|
|
531
|
+
|
|
532
|
+
b64UriEncode('123456')
|
|
533
|
+
/*log 'MTIzNDU2'*/
|
|
534
|
+
b64UriEncode(undefined)
|
|
535
|
+
/*log ''*/
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
### `b64UriDecode(str)`
|
|
539
|
+
|
|
540
|
+
decode a base64 string created by `b64UriEncode`
|
|
541
|
+
|
|
542
|
+
**parameters:**
|
|
543
|
+
- **str** {string} The base64 string need to decode, returns `''` if a non-string value is passed.
|
|
544
|
+
|
|
545
|
+
**returns**: string
|
|
546
|
+
|
|
547
|
+
> throws `InvalidCharacterError` if the string is not valid base64, throws `URIError` if the decoded result is not valid UTF-8
|
|
548
|
+
|
|
549
|
+
Example
|
|
550
|
+
|
|
551
|
+
```javascript
|
|
552
|
+
import { b64UriDecode } from '@wxhccc/es-util'
|
|
553
|
+
|
|
554
|
+
b64UriDecode('MTIzNDU2')
|
|
555
|
+
/*log '123456'*/
|
|
556
|
+
b64UriDecode(undefined)
|
|
557
|
+
/*log ''*/
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
> these two methods rely on `window.btoa` / `window.atob`, so they only work in browser environments
|
|
561
|
+
|
|
562
|
+
> since v2.1.4, non-string arguments no longer throw or produce a wrong result, they return `''` instead
|
|
563
|
+
|
|
481
564
|
> these methods remove from v1.2.0 you can use lodash instead
|
|
482
565
|
### ~~`camelize(string)`~~
|
|
483
566
|
|
|
@@ -596,6 +679,144 @@ runTask()
|
|
|
596
679
|
|
|
597
680
|
```
|
|
598
681
|
|
|
682
|
+
## optional module
|
|
683
|
+
|
|
684
|
+
### `safeJsonParse(json, faileValue)`
|
|
685
|
+
|
|
686
|
+
`JSON.parse` wrapped with try/catch, returns `faileValue` (default `undefined`) when the string is not valid JSON
|
|
687
|
+
|
|
688
|
+
**parameters:**
|
|
689
|
+
- **json** {string} the json string need to parse, default `''`
|
|
690
|
+
- **faileValue** {any} the value returned when parsing fails, default `undefined`
|
|
691
|
+
|
|
692
|
+
**returns**: any
|
|
693
|
+
|
|
694
|
+
Example
|
|
695
|
+
|
|
696
|
+
```javascript
|
|
697
|
+
import { safeJsonParse } from '@wxhccc/es-util'
|
|
698
|
+
|
|
699
|
+
safeJsonParse('{"a":1}')
|
|
700
|
+
/*log { a: 1 }*/
|
|
701
|
+
safeJsonParse('{"a":}', [])
|
|
702
|
+
/*log []*/
|
|
703
|
+
safeJsonParse('{"a":}')
|
|
704
|
+
/*log undefined */
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
### `isNullable(value)`
|
|
708
|
+
|
|
709
|
+
check whether the value is literally empty (`''`, `null` or `undefined`), it also works as a type guard
|
|
710
|
+
|
|
711
|
+
**parameters:**
|
|
712
|
+
- **value** {any} the value need to check
|
|
713
|
+
|
|
714
|
+
**returns**: boolean
|
|
715
|
+
|
|
716
|
+
Example
|
|
717
|
+
|
|
718
|
+
```javascript
|
|
719
|
+
import { isNullable } from '@wxhccc/es-util'
|
|
720
|
+
|
|
721
|
+
isNullable('') /*log true*/
|
|
722
|
+
isNullable(null) /*log true*/
|
|
723
|
+
isNullable(undefined) /*log true*/
|
|
724
|
+
isNullable(0) /*log false*/
|
|
725
|
+
isNullable('0') /*log false*/
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
### `filterNullable(obj, deep)`
|
|
729
|
+
|
|
730
|
+
return a new object with the empty properties (`''`, `null`, `undefined`) removed
|
|
731
|
+
|
|
732
|
+
**parameters:**
|
|
733
|
+
- **obj** {object} the object need to filter
|
|
734
|
+
- **deep** {boolean} filter the nested objects and the objects inside arrays as well, default `false`
|
|
735
|
+
|
|
736
|
+
**returns**: object
|
|
737
|
+
|
|
738
|
+
Example
|
|
739
|
+
|
|
740
|
+
```javascript
|
|
741
|
+
import { filterNullable } from '@wxhccc/es-util'
|
|
742
|
+
|
|
743
|
+
filterNullable({ a: 1, b: null, c: '', d: undefined })
|
|
744
|
+
/*log { a: 1 }*/
|
|
745
|
+
filterNullable({ a: 1, b: { c: undefined, d: 2 }, e: [{ f: null, g: 3 }] }, true)
|
|
746
|
+
/*log { a: 1, b: { d: 2 }, e: [{ g: 3 }] }*/
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
### `switchNullToUndefined(data)`
|
|
750
|
+
|
|
751
|
+
return a new copy where all the `null` values are replaced by `undefined`, nested objects and arrays are handled recursively
|
|
752
|
+
|
|
753
|
+
**parameters:**
|
|
754
|
+
- **data** {any} the data need to switch
|
|
755
|
+
|
|
756
|
+
**returns**: any
|
|
757
|
+
|
|
758
|
+
Example
|
|
759
|
+
|
|
760
|
+
```javascript
|
|
761
|
+
import { switchNullToUndefined } from '@wxhccc/es-util'
|
|
762
|
+
|
|
763
|
+
switchNullToUndefined({ a: null, b: 1, c: [null, 2] })
|
|
764
|
+
/*log { a: undefined, b: 1, c: [undefined, 2] }*/
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
### `formParamsSwitch(formData, maps, options)`
|
|
768
|
+
|
|
769
|
+
switch the array fields of a form data to the format needed by a request, usually used before sending search params
|
|
770
|
+
|
|
771
|
+
**parameters:**
|
|
772
|
+
- **formData** {object} the form data
|
|
773
|
+
- **maps** {object} the switch rules, the key is the field name in `formData`, the value can be:
|
|
774
|
+
- `[startKey, endKey]` or `[startKey, endKey, format]`: split the two-item array into two fields, `format` will be passed to `dateFormat`
|
|
775
|
+
- `'join'`: join the array with `,`
|
|
776
|
+
- `'pop'`: take the last item of the array
|
|
777
|
+
- **options** {object} the options
|
|
778
|
+
- **filterNullable** {boolean} remove the empty fields from the result, default `true`
|
|
779
|
+
- **dateFormat** {(date, format) => string} the formatter used when the rule contains a `format`
|
|
780
|
+
|
|
781
|
+
**returns**: object
|
|
782
|
+
|
|
783
|
+
Example
|
|
784
|
+
|
|
785
|
+
```javascript
|
|
786
|
+
import { formParamsSwitch } from '@wxhccc/es-util'
|
|
787
|
+
|
|
788
|
+
formParamsSwitch(
|
|
789
|
+
{ keyword: 'abc', createTime: ['2022-01-01', '2022-01-31'], status: null },
|
|
790
|
+
{ createTime: ['startTime', 'endTime'] }
|
|
791
|
+
)
|
|
792
|
+
/*log { keyword: 'abc', startTime: '2022-01-01', endTime: '2022-01-31' } */
|
|
793
|
+
|
|
794
|
+
formParamsSwitch({ ids: [1, 2, 3] }, { ids: 'join' })
|
|
795
|
+
/*log { ids: '1,2,3' } */
|
|
796
|
+
formParamsSwitch({ ids: [1, 2, 3] }, { ids: 'pop' })
|
|
797
|
+
/*log { ids: 3 } */
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
### `formParamsSwitchCreator(dateFormat)`
|
|
801
|
+
|
|
802
|
+
create a `formParamsSwitch` with the `dateFormat` bound
|
|
803
|
+
|
|
804
|
+
**parameters:**
|
|
805
|
+
- **dateFormat** {(date, format) => string} the formatter
|
|
806
|
+
|
|
807
|
+
**returns**: the `formParamsSwitch` function
|
|
808
|
+
|
|
809
|
+
Example
|
|
810
|
+
|
|
811
|
+
```javascript
|
|
812
|
+
import { formParamsSwitchCreator } from '@wxhccc/es-util'
|
|
813
|
+
|
|
814
|
+
const myFormParamsSwitch = formParamsSwitchCreator((date) => date.replace(/-/g, '/'))
|
|
815
|
+
|
|
816
|
+
myFormParamsSwitch({ createTime: ['2022-01-01', '2022-01-31'] }, { createTime: ['startTime', 'endTime'] })
|
|
817
|
+
/*log { startTime: '2022/01/01', endTime: '2022/01/31' } */
|
|
818
|
+
```
|
|
819
|
+
|
|
599
820
|
## event-target-emitter module
|
|
600
821
|
|
|
601
822
|
> v1.7.0 add
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @wxhccc/es-util v2.1.
|
|
3
|
-
* (c)
|
|
2
|
+
* @wxhccc/es-util v2.1.3
|
|
3
|
+
* (c) 2026 wxhccc
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
const { hasOwnProperty, toString } = Object.prototype;
|
|
@@ -429,12 +429,20 @@ function maskData(data, options) {
|
|
|
429
429
|
|
|
430
430
|
/**
|
|
431
431
|
* 将字符串编码为base64, 采用encodeURIComponent+window.btoa,主要为了解决atob/btoa处理特殊字符会报错的问题,性能不如buffer方案,适用于简单场景
|
|
432
|
-
* @param str
|
|
432
|
+
* @param str 待转换的字符串,非字符串类型返回空字符串
|
|
433
433
|
* @returns
|
|
434
434
|
*/
|
|
435
|
-
const b64UriEncode = (str) =>
|
|
436
|
-
|
|
437
|
-
|
|
435
|
+
const b64UriEncode = (str) => {
|
|
436
|
+
if (typeof str !== 'string')
|
|
437
|
+
return '';
|
|
438
|
+
return window.btoa(encodeURIComponent(str));
|
|
439
|
+
};
|
|
440
|
+
/** b64UriEncode对应的解码函数,非字符串类型返回空字符串 */
|
|
441
|
+
const b64UriDecode = (str) => {
|
|
442
|
+
if (typeof str !== 'string')
|
|
443
|
+
return '';
|
|
444
|
+
return decodeURIComponent(window.atob(str));
|
|
445
|
+
};
|
|
438
446
|
|
|
439
447
|
/**
|
|
440
448
|
* wrap promise and handle reject or err by return an array like [error, undefined]
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @wxhccc/es-util v2.1.
|
|
3
|
-
* (c)
|
|
2
|
+
* @wxhccc/es-util v2.1.3
|
|
3
|
+
* (c) 2026 wxhccc
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
@@ -433,12 +433,20 @@ function maskData(data, options) {
|
|
|
433
433
|
|
|
434
434
|
/**
|
|
435
435
|
* 将字符串编码为base64, 采用encodeURIComponent+window.btoa,主要为了解决atob/btoa处理特殊字符会报错的问题,性能不如buffer方案,适用于简单场景
|
|
436
|
-
* @param str
|
|
436
|
+
* @param str 待转换的字符串,非字符串类型返回空字符串
|
|
437
437
|
* @returns
|
|
438
438
|
*/
|
|
439
|
-
const b64UriEncode = (str) =>
|
|
440
|
-
|
|
441
|
-
|
|
439
|
+
const b64UriEncode = (str) => {
|
|
440
|
+
if (typeof str !== 'string')
|
|
441
|
+
return '';
|
|
442
|
+
return window.btoa(encodeURIComponent(str));
|
|
443
|
+
};
|
|
444
|
+
/** b64UriEncode对应的解码函数,非字符串类型返回空字符串 */
|
|
445
|
+
const b64UriDecode = (str) => {
|
|
446
|
+
if (typeof str !== 'string')
|
|
447
|
+
return '';
|
|
448
|
+
return decodeURIComponent(window.atob(str));
|
|
449
|
+
};
|
|
442
450
|
|
|
443
451
|
/**
|
|
444
452
|
* wrap promise and handle reject or err by return an array like [error, undefined]
|
package/dist/index.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @wxhccc/es-util v2.1.
|
|
3
|
-
* (c)
|
|
2
|
+
* @wxhccc/es-util v2.1.3
|
|
3
|
+
* (c) 2026 wxhccc
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).EsUtil={})}(this,(function(e){"use strict";const{hasOwnProperty:t,toString:n}=Object.prototype,r=(e,t)=>{Object.keys(e).forEach(((n,r)=>t(n,e[n],r)))},s=e=>"function"==typeof e,i=Array.isArray,o=e=>{const t=(r=e,n.call(r)).match(/^\[object (.*)\]$/);var r;return t?t[1]:""},a=e=>"Object"===o(e),c=(e,n)=>t.call(e,n);function l(e,t=[]){return{[e]:t}}const d=/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;const u={telphone:{startCharIndex:-8,endCharIndex:-5},idcard:{startCharIndex:-12,endCharIndex:-5}};async function f(e){try{return[null,await e]}catch(e){return[e,void 0]}}const p=function(e,t){const{wrap:n,lock:r,syncRefHandle:o}={...t};let a,c,l=!1,d=!1;const u=e=>{if(c){const[t,n]=c;t[n]=e}a&&a(e)};if(r){const e=e=>i(e)&&2===e.length;e(r)?c=r:s(r)&&(a=r,e(o)&&(c=o)),l=!(!a&&!c),l&&(d=!!c&&!!c[0][c[1]])}let p;if(s(e)){const t=d?Promise.resolve(void 0):e();p=n?f(t):t}else p=n?f(e):e;return p instanceof Promise&&l&&!d&&(u(!0),p.finally((()=>u(!1)))),p};function m(e="",t){try{return JSON.parse(e)}catch(e){return t}}const h=e=>""===e||null==e,y=(e,t)=>{const n={};return r(e,((e,r)=>{h(r)||(t?i(r)?n[e]=r.map((e=>a(e)?y(e):e)):n[e]=a(r)?y(r):r:n[e]=r)})),n},g=e=>{if(null!==e){if(i(e))return e.map(g);if(a(e)){const t={};return r(e,((e,n)=>{t[e]=g(n)})),t}return e}},b=(e,t,n)=>{const o=Object.keys(t),a={},c={};r(e,(t=>{o.includes(t)?a[t]=e[t]:c[t]=e[t]}));const l=Object.keys(a);if(0===l.length)return e;const{filterNullable:d,dateFormat:u}={filterNullable:!0,...n},f=l.reduce(((e,n)=>{const r=a[n],o=t[n];if(!r||!o)return e;if("join"===o||"pop"===o)i(r)&&r.length&&(e[n]="join"===o?r.join(","):r.slice(-1)[0]);else if(2===o.length||3===o.length){if(!r||2!==r.length)return e;const[t,n,i]=o,[a,c]=r;Object.assign(e,{[t]:s(u)?u(a,i):a,[n]:s(u)?u(c,i):c})}return e}),{}),p={...c,...f};return d?y(p):p},M=e=>"string"==typeof e,j=Symbol("NOMETHOD");function x(e){const t=new Map([[j,new Set]]),{name:n,customHanlderCreator:r}=e||{},i=s(r)?r(t):null,o=/\|-[a-z]+-\|/,a=(e,...t)=>{try{e(...t)}catch(e){console.error(e)}},c=s(i)?i:e=>{const{method:r,data:s,originEmitterName:i,targetEmitterName:c}=e||[];if(r&&"string"==typeof r){const e=[];t.forEach(((t,n)=>{if("string"==typeof n&&n.startsWith(r)){const[,r]=n.split(o);r&&i&&r!==i||e.push(...t)}})),!e.length||n&&c&&n!==c||e.forEach((e=>a(e,s)))}const l=t.get(j);l&&l.forEach((t=>a(t,s,e)))},l=(e,t)=>{const{limitFrom:n="",namespace:r=""}=t||{};return(n||r)&&"string"==typeof e?`${e}|-from-|${n}|-ns-|${r}`:e},d=(e,t,r)=>M(e)?{method:e,data:t,...r&&M(r)?{targetEmitterName:r}:{},...n&&M(n)?{originEmitterName:n}:{}}:e;return{name:n,rootEventListener:c,on:(e,n,r)=>{if("symbol"==typeof e&&e!==j)return;const s=l(e,r);t.has(s)||t.set(s,new Set);const i=t.get(s);i?.add(n)},off:(e,n,r)=>{if("symbol"==typeof e&&e!==j)return;const{namespace:s}=r||{};if(s&&!e)return void t.forEach(((e,n)=>{"string"==typeof n&&n.endsWith(s)&&t.delete(n)}));const i=l(e,r);n?t.get(i)?.delete(n):t.delete(i)},emit:(...e)=>{const t=d(...e);c(t)},createPayload:d,removeAllListeners:()=>{t.clear()},getMethodNames:e=>{if(!e){const e=[];return t.forEach(((t,n)=>M(n)&&e.push(n.split(o)))),e}const n=[];return t.forEach(((e,t)=>M(t)&&n.push(t))),n},getListeners:(e,n)=>{if("symbol"==typeof e)return e===j?Array.from(t.get(j)||[]):[];const r=l(e,n),s=t.get(r);return s?Array.from(s):[]}}}e.ChinaIdCardValid=function(e){const t=e.toString().toUpperCase();return d.test(t)&&["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"].includes(t.substr(0,2))&&(()=>{if(18===t.length){const e=t.split(""),n=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],r=[1,0,"X",9,8,7,6,5,4,3,2];let s=0,i=0,o=0;for(let t=0;t<17;t++)i=parseInt(e[t]),o=n[t],s+=i*o;return r[s%11].toString()===e[17]}return!0})()},e.NOMETHOD=j,e.array2tree=function(e,t={}){const{primaryKey:n,parentKey:r,childrenKey:o,createRoot:a,parentRefKey:d}={primaryKey:"id",parentKey:"pid",childrenKey:"children",createRoot:!1,parentRefKey:!1,...t},u=d&&("string"==typeof d?d:"_parent"),f={},p=[];if(i(e)){const t=[],s=e=>{e.forEach((e=>{c(f,e[n])||(f[e[n]]={...e,...l(o)}),e[r]?c(f,e[r])?f[e[r]][o].push(Object.assign(f[e[n]],u?{[u]:f[e[r]]}:{})):t.push(e):p.push(f[e[n]])}))};s(e),t.length&&s(t)}return s(a)?a(p):a?{[o]:p}:p},e.awaitWrapper=f,e.b64UriDecode=e=>decodeURIComponent(window.atob(e)),e.b64UriEncode=e=>window.btoa(encodeURIComponent(e)),e.byteStringify=function(e,t){const n=Object.assign({standard:"jedec",unitLvl:"auto",precision:1,detail:!1},t),{standard:r,unitLvl:s,precision:o,detail:a}=n;let c=parseFloat(e);if(!Number.isFinite(c))return;const l=c<0?-1:1;c=Math.abs(c);const{base:d,unitMap:u}=((e,t)=>{const n={B:{expMax:0,units:{metric:"B",iec:"B",jedec:"B"}},K:{expMax:1,units:{metric:"kB",iec:"KiB",jedec:"KB"}},M:{expMax:2,units:{metric:"MB",iec:"MiB",jedec:"MB"}},G:{expMax:3,units:{metric:"GB",iec:"GiB",jedec:"GB"}},T:{expMax:4,units:{metric:"TB",iec:"TiB",jedec:"TB"}},P:{expMax:5,units:{metric:"PB",iec:"PiB",jedec:"PB"}},E:{expMax:6,units:{metric:"EB",iec:"EiB",jedec:"EB"}},Z:{expMax:7,units:{metric:"ZB",iec:"ZiB",jedec:"ZB"}},Y:{expMax:8,units:{metric:"YB",iec:"YiB",jedec:"YB"}}},r={metric:1e3,iec:1024,jedec:1024};return{base:r[e]||r.jedec,unitMap:n[t]||Object.values(n)}})(r,s),f=e=>Number.isInteger(e)?e:e.toFixed(o);let p="",m=0;if(i(u))u.some((e=>{const t=Math.pow(d,e.expMax),n=c/t;return!(n>d)&&(p=e.units[r],m=f(n*l),!0)}));else{const e=Math.pow(d,u.expMax);p=u.units[r];m=f(c/e*l)}return a?{value:m,unit:p}:`${m} ${p}`},e.checkoutBy=function(e,t,n){return a(e)?i(t)?t.map((t=>e[t])):t&&a(t)?Object.keys(t).map((r=>{const s=t[r];return a(e[r])&&a(s)?n?n({},e[r],s):Object.assign({},e[r],s):s||e[r]})):Object.values(e):[]},e.createRAFTimer=e=>{const{autoStopWhenNoTask:t,autoStartWhenAddTask:n}={...e};let r=0,s=!0,i=0,o=0,a=[],c=!1;const l=e=>{const n=e-(o||e);o=e,i+=n,c&&(a=a.filter((e=>!e.needClear)),c=!1),!t||a.length?(a.forEach((e=>{const{callback:t,maxTime:r,runTime:s,elapsed:o,interval:a,needClear:l}=e;if(!l){if(r&&s>=r)return e.needClear=!0,void(c=!0);if(o>=a){try{t(i)}catch(e){}e.elapsed=0,e.runTime+=1}else e.elapsed+=n}})),r=window.requestAnimationFrame(l)):s=!0},d=()=>{r=window.requestAnimationFrame(l),s=!1},u=()=>{window.cancelAnimationFrame(r),s=!0};return{start:d,stop:u,pauseToggle:()=>{s?d():u()},addTask:(e,t,r)=>{e&&(n&&s&&d(),a.push({callback:e,elapsed:0,interval:t,maxTime:r,runTime:0}))},removeTask:e=>{a=a.filter((t=>t.callback!==e))},isPaused:()=>s}},e.eventTargetEmitter=x,e.filterNullable=y,e.formParamsSwitch=b,e.formParamsSwitchCreator=e=>(t,n,r)=>b(t,n,{dateFormat:e,...r}),e.formulaValidate=function(e,t){return e=e.replace(/\s/g,""),!/[+\-*/]{2,}/.test(e)&&!/\(\)/.test(e)&&!/\([+\-*/]/.test(e)&&!/[+\-*/]\)/.test(e)&&!/[^+\-*/]\(/.test(e)&&!/\)[^+\-*/]/.test(e)&&(()=>{const t=[];for(let n,r=0;r<e.length;r++)if(n=e.charAt(r),"("===n)t.push("(");else if(")"===n){if(!(t.length>0))return!1;t.pop()}return!t.length})()&&(!i(t)||(n=t,e.replace(/[()+\-*/]{1,}/g,"`").split("`").every((e=>!/[A-Z]/i.test(e)||n.includes(e)))));var n},e.isNullable=h,e.mapToObject=function(e,t="key",n="value"){const r={};return i(e)&&t&&n&&[t,n].every((e=>["string","function"].includes(typeof e)))&&e.forEach(((e,s)=>{const i="string"==typeof t?e[t]:t(e,s),o="string"==typeof n?e[n]:n(e,s);["string","number"].includes(typeof i)&&(r[i]=o)})),r},e.maskData=function(e,t){if("string"!=typeof e||!e)return"";const n=t&&t.mode&&u[t.mode]?u[t.mode]:{},{maskWith:r,startCharIndex:s=0,endCharIndex:i,startFrom:o,endUntil:a}={maskWith:"*",...n,...t};let c=e,l="",d="";const f=o?e.indexOf(o):-1;if(f>-1){const t=f+o.length;c=c.slice(t),l=e.slice(0,t)}const p=a?e.lastIndexOf(a):-1;p>-1&&(c=c.slice(0,p),d=e.slice(p));const m=c.split(""),h=[l],y=m.length,g=[s>=0?s:y+s,void 0!==i?i>=0?i:y+i:y-1];let[b,M]=g;return M=M>0&&M<y?M:y-1,b=b>=0&&b<=M?b:0,m.forEach(((e,t)=>{h.push(t>=b&&t<=M?r:e)})),h.push(d),h.join("")},e.pageCommunicate=function(e){const{messageHanlder:t,currentPage:n}=e||{},{emit:r,on:s,off:i,createPayload:o,removeAllListeners:a}=x({name:n,customHanlderCreator:t}),c=e=>r(e.data);let l;const d=window.localStorage,u="PAGE_COMMUNICATE_CHANNEL";if(void 0!==typeof window.BroadcastChannel)l=new BroadcastChannel(u),l.addEventListener("message",c);else{const e=()=>{const e=m(d.getItem(u)||"");e&&r(e)};window.addEventListener("storage",e)}return{on:s,off:i,send:(...e)=>{const t=o(...e);if(l)l.postMessage(t);else{const e=JSON.stringify({...t,ts:+new Date});d.setItem(u,e)}},destory:()=>{a(),l?l.close():d.removeItem(u)}}},e.pickRenameKeys=function(e,t){if(!(e&&a(e)&&t&&a(t)))return;const n={};for(const r in e)r in t&&(n[t[r]]=e[r]);return n},e.safeJsonParse=m,e.secondsToDuration=(e,t="h")=>{const n=Number.isInteger(e)?e:Math.round(e),r={s:n%60};switch(t){case"m":r.m=Math.floor(n/60);break;case"h":r.m=Math.floor(n%3600/60),r.h=Math.floor(n/3600);break;case"d":r.m=Math.floor(n%3600/60),r.h=Math.floor(n%86400/3600),r.d=Math.floor(n/3600/24)}return r},e.switchNullToUndefined=g,e.tree2array=function(e,t={}){const{primaryKey:n,parentKey:r,childrenKey:s,hasParentKey:o,returnObject:a}=Object.assign({hasParentKey:!0,primaryKey:"id",parentKey:"pid",childrenKey:"children",returnObject:!1},t),c=a?{}:[];return i(e)||"object"==typeof e?(function e(t,l,d=!1){const u=o?{}:{[r]:l};if(!d){const e=Object.assign(u,function(e,t){const n={};for(const r in e)r!==t&&(n[r]=e[r]);return n}(t,s));a?c[t[n]]=e:c.push(e)}i(t[s])&&t[s].length&&t[s].forEach((r=>e(r,t[n])))}(i(e)?l(s,e):e,null,!0),c):c},e.treeAnalyse=function(e,t,n){const r={nodes:[],childKeysMaps:{},keyNodeMap:{},disabledKeys:[]},s=Array.isArray(n)?n:["nodes","keyNodeMap","childKeysMaps","disabledKeys"],{primaryKey:i,labelKey:o,disabledKey:a,childrenKey:c}={primaryKey:"id",labelKey:"name",childrenKey:"children",disabledKey:"disabled",...t},[l,d,u,f]=Object.keys(r).map((e=>s.includes(e))),p=(e,t)=>{e.forEach((e=>{const{[i]:n,[o]:s,[c]:m,[a]:h}=e;let y;l&&r.nodes.push(e),u&&void 0!==n&&(y={keyVlaue:n,keyLabel:s,parent:t,children:[]},t?.children.push(y),r.keyNodeMap[n]=y),f&&h&&void 0!==n&&r.disabledKeys.push(n),Array.isArray(m)&&m.length&&(d&&(r.childKeysMaps[n]=m.map((e=>e[i]))),p(m,y))}))};return e&&p(e),r},e.wp=p,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
6
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).EsUtil={})}(this,(function(e){"use strict";const{hasOwnProperty:t,toString:n}=Object.prototype,r=(e,t)=>{Object.keys(e).forEach(((n,r)=>t(n,e[n],r)))},s=e=>"function"==typeof e,i=Array.isArray,o=e=>{const t=(r=e,n.call(r)).match(/^\[object (.*)\]$/);var r;return t?t[1]:""},a=e=>"Object"===o(e),c=(e,n)=>t.call(e,n);function l(e,t=[]){return{[e]:t}}const d=/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;const u={telphone:{startCharIndex:-8,endCharIndex:-5},idcard:{startCharIndex:-12,endCharIndex:-5}};async function f(e){try{return[null,await e]}catch(e){return[e,void 0]}}const p=function(e,t){const{wrap:n,lock:r,syncRefHandle:o}={...t};let a,c,l=!1,d=!1;const u=e=>{if(c){const[t,n]=c;t[n]=e}a&&a(e)};if(r){const e=e=>i(e)&&2===e.length;e(r)?c=r:s(r)&&(a=r,e(o)&&(c=o)),l=!(!a&&!c),l&&(d=!!c&&!!c[0][c[1]])}let p;if(s(e)){const t=d?Promise.resolve(void 0):e();p=n?f(t):t}else p=n?f(e):e;return p instanceof Promise&&l&&!d&&(u(!0),p.finally((()=>u(!1)))),p};function m(e="",t){try{return JSON.parse(e)}catch(e){return t}}const h=e=>""===e||null==e,y=(e,t)=>{const n={};return r(e,((e,r)=>{h(r)||(t?i(r)?n[e]=r.map((e=>a(e)?y(e):e)):n[e]=a(r)?y(r):r:n[e]=r)})),n},g=e=>{if(null!==e){if(i(e))return e.map(g);if(a(e)){const t={};return r(e,((e,n)=>{t[e]=g(n)})),t}return e}},b=(e,t,n)=>{const o=Object.keys(t),a={},c={};r(e,(t=>{o.includes(t)?a[t]=e[t]:c[t]=e[t]}));const l=Object.keys(a);if(0===l.length)return e;const{filterNullable:d,dateFormat:u}={filterNullable:!0,...n},f=l.reduce(((e,n)=>{const r=a[n],o=t[n];if(!r||!o)return e;if("join"===o||"pop"===o)i(r)&&r.length&&(e[n]="join"===o?r.join(","):r.slice(-1)[0]);else if(2===o.length||3===o.length){if(!r||2!==r.length)return e;const[t,n,i]=o,[a,c]=r;Object.assign(e,{[t]:s(u)?u(a,i):a,[n]:s(u)?u(c,i):c})}return e}),{}),p={...c,...f};return d?y(p):p},M=e=>"string"==typeof e,j=Symbol("NOMETHOD");function x(e){const t=new Map([[j,new Set]]),{name:n,customHanlderCreator:r}=e||{},i=s(r)?r(t):null,o=/\|-[a-z]+-\|/,a=(e,...t)=>{try{e(...t)}catch(e){console.error(e)}},c=s(i)?i:e=>{const{method:r,data:s,originEmitterName:i,targetEmitterName:c}=e||[];if(r&&"string"==typeof r){const e=[];t.forEach(((t,n)=>{if("string"==typeof n&&n.startsWith(r)){const[,r]=n.split(o);r&&i&&r!==i||e.push(...t)}})),!e.length||n&&c&&n!==c||e.forEach((e=>a(e,s)))}const l=t.get(j);l&&l.forEach((t=>a(t,s,e)))},l=(e,t)=>{const{limitFrom:n="",namespace:r=""}=t||{};return(n||r)&&"string"==typeof e?`${e}|-from-|${n}|-ns-|${r}`:e},d=(e,t,r)=>M(e)?{method:e,data:t,...r&&M(r)?{targetEmitterName:r}:{},...n&&M(n)?{originEmitterName:n}:{}}:e;return{name:n,rootEventListener:c,on:(e,n,r)=>{if("symbol"==typeof e&&e!==j)return;const s=l(e,r);t.has(s)||t.set(s,new Set);const i=t.get(s);i?.add(n)},off:(e,n,r)=>{if("symbol"==typeof e&&e!==j)return;const{namespace:s}=r||{};if(s&&!e)return void t.forEach(((e,n)=>{"string"==typeof n&&n.endsWith(s)&&t.delete(n)}));const i=l(e,r);n?t.get(i)?.delete(n):t.delete(i)},emit:(...e)=>{const t=d(...e);c(t)},createPayload:d,removeAllListeners:()=>{t.clear()},getMethodNames:e=>{if(!e){const e=[];return t.forEach(((t,n)=>M(n)&&e.push(n.split(o)))),e}const n=[];return t.forEach(((e,t)=>M(t)&&n.push(t))),n},getListeners:(e,n)=>{if("symbol"==typeof e)return e===j?Array.from(t.get(j)||[]):[];const r=l(e,n),s=t.get(r);return s?Array.from(s):[]}}}e.ChinaIdCardValid=function(e){const t=e.toString().toUpperCase();return d.test(t)&&["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"].includes(t.substr(0,2))&&(()=>{if(18===t.length){const e=t.split(""),n=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],r=[1,0,"X",9,8,7,6,5,4,3,2];let s=0,i=0,o=0;for(let t=0;t<17;t++)i=parseInt(e[t]),o=n[t],s+=i*o;return r[s%11].toString()===e[17]}return!0})()},e.NOMETHOD=j,e.array2tree=function(e,t={}){const{primaryKey:n,parentKey:r,childrenKey:o,createRoot:a,parentRefKey:d}={primaryKey:"id",parentKey:"pid",childrenKey:"children",createRoot:!1,parentRefKey:!1,...t},u=d&&("string"==typeof d?d:"_parent"),f={},p=[];if(i(e)){const t=[],s=e=>{e.forEach((e=>{c(f,e[n])||(f[e[n]]={...e,...l(o)}),e[r]?c(f,e[r])?f[e[r]][o].push(Object.assign(f[e[n]],u?{[u]:f[e[r]]}:{})):t.push(e):p.push(f[e[n]])}))};s(e),t.length&&s(t)}return s(a)?a(p):a?{[o]:p}:p},e.awaitWrapper=f,e.b64UriDecode=e=>"string"!=typeof e?"":decodeURIComponent(window.atob(e)),e.b64UriEncode=e=>"string"!=typeof e?"":window.btoa(encodeURIComponent(e)),e.byteStringify=function(e,t){const n=Object.assign({standard:"jedec",unitLvl:"auto",precision:1,detail:!1},t),{standard:r,unitLvl:s,precision:o,detail:a}=n;let c=parseFloat(e);if(!Number.isFinite(c))return;const l=c<0?-1:1;c=Math.abs(c);const{base:d,unitMap:u}=((e,t)=>{const n={B:{expMax:0,units:{metric:"B",iec:"B",jedec:"B"}},K:{expMax:1,units:{metric:"kB",iec:"KiB",jedec:"KB"}},M:{expMax:2,units:{metric:"MB",iec:"MiB",jedec:"MB"}},G:{expMax:3,units:{metric:"GB",iec:"GiB",jedec:"GB"}},T:{expMax:4,units:{metric:"TB",iec:"TiB",jedec:"TB"}},P:{expMax:5,units:{metric:"PB",iec:"PiB",jedec:"PB"}},E:{expMax:6,units:{metric:"EB",iec:"EiB",jedec:"EB"}},Z:{expMax:7,units:{metric:"ZB",iec:"ZiB",jedec:"ZB"}},Y:{expMax:8,units:{metric:"YB",iec:"YiB",jedec:"YB"}}},r={metric:1e3,iec:1024,jedec:1024};return{base:r[e]||r.jedec,unitMap:n[t]||Object.values(n)}})(r,s),f=e=>Number.isInteger(e)?e:e.toFixed(o);let p="",m=0;if(i(u))u.some((e=>{const t=Math.pow(d,e.expMax),n=c/t;return!(n>d)&&(p=e.units[r],m=f(n*l),!0)}));else{const e=Math.pow(d,u.expMax);p=u.units[r];m=f(c/e*l)}return a?{value:m,unit:p}:`${m} ${p}`},e.checkoutBy=function(e,t,n){return a(e)?i(t)?t.map((t=>e[t])):t&&a(t)?Object.keys(t).map((r=>{const s=t[r];return a(e[r])&&a(s)?n?n({},e[r],s):Object.assign({},e[r],s):s||e[r]})):Object.values(e):[]},e.createRAFTimer=e=>{const{autoStopWhenNoTask:t,autoStartWhenAddTask:n}={...e};let r=0,s=!0,i=0,o=0,a=[],c=!1;const l=e=>{const n=e-(o||e);o=e,i+=n,c&&(a=a.filter((e=>!e.needClear)),c=!1),!t||a.length?(a.forEach((e=>{const{callback:t,maxTime:r,runTime:s,elapsed:o,interval:a,needClear:l}=e;if(!l){if(r&&s>=r)return e.needClear=!0,void(c=!0);if(o>=a){try{t(i)}catch(e){}e.elapsed=0,e.runTime+=1}else e.elapsed+=n}})),r=window.requestAnimationFrame(l)):s=!0},d=()=>{r=window.requestAnimationFrame(l),s=!1},u=()=>{window.cancelAnimationFrame(r),s=!0};return{start:d,stop:u,pauseToggle:()=>{s?d():u()},addTask:(e,t,r)=>{e&&(n&&s&&d(),a.push({callback:e,elapsed:0,interval:t,maxTime:r,runTime:0}))},removeTask:e=>{a=a.filter((t=>t.callback!==e))},isPaused:()=>s}},e.eventTargetEmitter=x,e.filterNullable=y,e.formParamsSwitch=b,e.formParamsSwitchCreator=e=>(t,n,r)=>b(t,n,{dateFormat:e,...r}),e.formulaValidate=function(e,t){return e=e.replace(/\s/g,""),!/[+\-*/]{2,}/.test(e)&&!/\(\)/.test(e)&&!/\([+\-*/]/.test(e)&&!/[+\-*/]\)/.test(e)&&!/[^+\-*/]\(/.test(e)&&!/\)[^+\-*/]/.test(e)&&(()=>{const t=[];for(let n,r=0;r<e.length;r++)if(n=e.charAt(r),"("===n)t.push("(");else if(")"===n){if(!(t.length>0))return!1;t.pop()}return!t.length})()&&(!i(t)||(n=t,e.replace(/[()+\-*/]{1,}/g,"`").split("`").every((e=>!/[A-Z]/i.test(e)||n.includes(e)))));var n},e.isNullable=h,e.mapToObject=function(e,t="key",n="value"){const r={};return i(e)&&t&&n&&[t,n].every((e=>["string","function"].includes(typeof e)))&&e.forEach(((e,s)=>{const i="string"==typeof t?e[t]:t(e,s),o="string"==typeof n?e[n]:n(e,s);["string","number"].includes(typeof i)&&(r[i]=o)})),r},e.maskData=function(e,t){if("string"!=typeof e||!e)return"";const n=t&&t.mode&&u[t.mode]?u[t.mode]:{},{maskWith:r,startCharIndex:s=0,endCharIndex:i,startFrom:o,endUntil:a}={maskWith:"*",...n,...t};let c=e,l="",d="";const f=o?e.indexOf(o):-1;if(f>-1){const t=f+o.length;c=c.slice(t),l=e.slice(0,t)}const p=a?e.lastIndexOf(a):-1;p>-1&&(c=c.slice(0,p),d=e.slice(p));const m=c.split(""),h=[l],y=m.length,g=[s>=0?s:y+s,void 0!==i?i>=0?i:y+i:y-1];let[b,M]=g;return M=M>0&&M<y?M:y-1,b=b>=0&&b<=M?b:0,m.forEach(((e,t)=>{h.push(t>=b&&t<=M?r:e)})),h.push(d),h.join("")},e.pageCommunicate=function(e){const{messageHanlder:t,currentPage:n}=e||{},{emit:r,on:s,off:i,createPayload:o,removeAllListeners:a}=x({name:n,customHanlderCreator:t}),c=e=>r(e.data);let l;const d=window.localStorage,u="PAGE_COMMUNICATE_CHANNEL";if(void 0!==typeof window.BroadcastChannel)l=new BroadcastChannel(u),l.addEventListener("message",c);else{const e=()=>{const e=m(d.getItem(u)||"");e&&r(e)};window.addEventListener("storage",e)}return{on:s,off:i,send:(...e)=>{const t=o(...e);if(l)l.postMessage(t);else{const e=JSON.stringify({...t,ts:+new Date});d.setItem(u,e)}},destory:()=>{a(),l?l.close():d.removeItem(u)}}},e.pickRenameKeys=function(e,t){if(!(e&&a(e)&&t&&a(t)))return;const n={};for(const r in e)r in t&&(n[t[r]]=e[r]);return n},e.safeJsonParse=m,e.secondsToDuration=(e,t="h")=>{const n=Number.isInteger(e)?e:Math.round(e),r={s:n%60};switch(t){case"m":r.m=Math.floor(n/60);break;case"h":r.m=Math.floor(n%3600/60),r.h=Math.floor(n/3600);break;case"d":r.m=Math.floor(n%3600/60),r.h=Math.floor(n%86400/3600),r.d=Math.floor(n/3600/24)}return r},e.switchNullToUndefined=g,e.tree2array=function(e,t={}){const{primaryKey:n,parentKey:r,childrenKey:s,hasParentKey:o,returnObject:a}=Object.assign({hasParentKey:!0,primaryKey:"id",parentKey:"pid",childrenKey:"children",returnObject:!1},t),c=a?{}:[];return i(e)||"object"==typeof e?(function e(t,l,d=!1){const u=o?{}:{[r]:l};if(!d){const e=Object.assign(u,function(e,t){const n={};for(const r in e)r!==t&&(n[r]=e[r]);return n}(t,s));a?c[t[n]]=e:c.push(e)}i(t[s])&&t[s].length&&t[s].forEach((r=>e(r,t[n])))}(i(e)?l(s,e):e,null,!0),c):c},e.treeAnalyse=function(e,t,n){const r={nodes:[],childKeysMaps:{},keyNodeMap:{},disabledKeys:[]},s=Array.isArray(n)?n:["nodes","keyNodeMap","childKeysMaps","disabledKeys"],{primaryKey:i,labelKey:o,disabledKey:a,childrenKey:c}={primaryKey:"id",labelKey:"name",childrenKey:"children",disabledKey:"disabled",...t},[l,d,u,f]=Object.keys(r).map((e=>s.includes(e))),p=(e,t)=>{e.forEach((e=>{const{[i]:n,[o]:s,[c]:m,[a]:h}=e;let y;l&&r.nodes.push(e),u&&void 0!==n&&(y={keyVlaue:n,keyLabel:s,parent:t,children:[]},t?.children.push(y),r.keyNodeMap[n]=y),f&&h&&void 0!==n&&r.disabledKeys.push(n),Array.isArray(m)&&m.length&&(d&&(r.childKeysMaps[n]=m.map((e=>e[i]))),p(m,y))}))};return e&&p(e),r},e.wp=p,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/dist/object-array.js
CHANGED
package/dist/optional.js
CHANGED
package/dist/page-communicate.js
CHANGED
package/dist/promise.js
CHANGED
package/dist/raf-timer.js
CHANGED
package/dist/utils.js
CHANGED
package/dist/validate.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 将字符串编码为base64, 采用encodeURIComponent+window.btoa,主要为了解决atob/btoa处理特殊字符会报错的问题,性能不如buffer方案,适用于简单场景
|
|
3
|
-
* @param str
|
|
3
|
+
* @param str 待转换的字符串,非字符串类型返回空字符串
|
|
4
4
|
* @returns
|
|
5
5
|
*/
|
|
6
6
|
export declare const b64UriEncode: (str: string) => string;
|
|
7
|
-
/** b64UriEncode
|
|
7
|
+
/** b64UriEncode对应的解码函数,非字符串类型返回空字符串 */
|
|
8
8
|
export declare const b64UriDecode: (str: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './value-string-switch/index';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @wxhccc/es-util v2.1.
|
|
3
|
-
* (c)
|
|
2
|
+
* @wxhccc/es-util v2.1.3
|
|
3
|
+
* (c) 2026 wxhccc
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
@@ -120,12 +120,20 @@ function maskData(data, options) {
|
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* 将字符串编码为base64, 采用encodeURIComponent+window.btoa,主要为了解决atob/btoa处理特殊字符会报错的问题,性能不如buffer方案,适用于简单场景
|
|
123
|
-
* @param str
|
|
123
|
+
* @param str 待转换的字符串,非字符串类型返回空字符串
|
|
124
124
|
* @returns
|
|
125
125
|
*/
|
|
126
|
-
const b64UriEncode = (str) =>
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
const b64UriEncode = (str) => {
|
|
127
|
+
if (typeof str !== 'string')
|
|
128
|
+
return '';
|
|
129
|
+
return window.btoa(encodeURIComponent(str));
|
|
130
|
+
};
|
|
131
|
+
/** b64UriEncode对应的解码函数,非字符串类型返回空字符串 */
|
|
132
|
+
const b64UriDecode = (str) => {
|
|
133
|
+
if (typeof str !== 'string')
|
|
134
|
+
return '';
|
|
135
|
+
return decodeURIComponent(window.atob(str));
|
|
136
|
+
};
|
|
129
137
|
|
|
130
138
|
exports.b64UriDecode = b64UriDecode;
|
|
131
139
|
exports.b64UriEncode = b64UriEncode;
|