@bestime/utils_base 1.0.3 → 1.0.5

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 CHANGED
@@ -1,15 +1,15 @@
1
- ### 不同git项目,使用不同用户名和邮箱
2
-
3
- 修改配置文件 ~/.gitconfig
4
-
5
- ```cmd
6
- [core]
7
- autocrlf = false
8
- [includeIf "gitdir:D:/bestime/git/"]
9
- path = D:/bestime/config/.gitconfig
10
- [includeIf "gitdir:D:/work-qssoft/git/qs-t/"]
11
- path = D:/bestime/config/qssoft.gitconfig
12
- [includeIf "gitdir:D:/work-qssoft/git/rdc-cq/"]
13
- path = D:/bestime/config/sitian.gitconfig
14
-
1
+ ### 不同git项目,使用不同用户名和邮箱
2
+
3
+ 修改配置文件 ~/.gitconfig
4
+
5
+ ```cmd
6
+ [core]
7
+ autocrlf = false
8
+ [includeIf "gitdir:D:/bestime/git/"]
9
+ path = D:/bestime/config/.gitconfig
10
+ [includeIf "gitdir:D:/work-qssoft/git/qs-t/"]
11
+ path = D:/bestime/config/qssoft.gitconfig
12
+ [includeIf "gitdir:D:/work-qssoft/git/rdc-cq/"]
13
+ path = D:/bestime/config/sitian.gitconfig
14
+
15
15
  ```
@@ -422,9 +422,26 @@ declare function randomColor(): string;
422
422
 
423
423
  type VoidFunc = () => void;
424
424
  interface PollingOption {
425
+ /**
426
+ * 多少毫秒一次
427
+ */
425
428
  interval: number;
426
- timeout: number;
429
+ /**
430
+ * 过期时间。不填则永不过期
431
+ */
432
+ timeout?: number;
433
+ /**
434
+ *
435
+ * @param remainTime 剩余时间回调(需要设置了timeout大于0)
436
+ * @returns
437
+ */
427
438
  onMessage?: (remainTime: number) => void;
439
+ /**
440
+ *
441
+ * @param next 继续轮询
442
+ * @param done 完成并停止
443
+ * @returns
444
+ */
428
445
  handler: (next: VoidFunc, done: VoidFunc) => void;
429
446
  }
430
447
  /**
@@ -457,13 +474,14 @@ declare class Polling {
457
474
  private _timer;
458
475
  private _timer_info;
459
476
  private _stamp;
477
+ private _isMount;
460
478
  private _passStamp;
461
479
  private _option;
462
480
  constructor(setting: Partial<PollingOption>);
463
481
  private _next;
464
482
  private _doOnce;
465
483
  /** 开始 */
466
- start(): this;
484
+ start(): this | undefined;
467
485
  /** 完成 */
468
486
  done(): this;
469
487
  /** 销毁 */
@@ -1,7 +1,8 @@
1
1
  /**
2
- * 基础工具库 => jUtilsBase
2
+ * 纯JS工具库 => jUtilsBase
3
+ * 可在nodejs和小程序中使用
3
4
  * @QQ 1174295440
4
5
  * @author IT0909
5
- * @update 2023-11-05 17:28:15
6
+ * @update 2023-11-24 17:11:14
6
7
  */
7
- function isNull(e){return null===e||e===undefined}function _String(e){return isNull(e)?"":String(e)}var $letters=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],$ArrayTypeNameBig="Array",$FunctionTypeNameBig="Function",$ObjectTypeNameBig="Object",$stringTypeNameBig="String",$numberTypeNameBig="Number",$undefinedValue=void 0,$zeroString="0",$falseString="false",$trueString="true",$ObjectTypeNameBigPrototypeToString=Object.prototype.toString,$encodeURI=encodeURI,$decodeURIComponent=decodeURIComponent,$regSpaceStr="\\s\\uFEFF\\xA0",$isBroswer="undefined"!=typeof document&&document.getElementById!==undefined,$browserGlobal="undefined"!=typeof window?window:$undefinedValue;function getType(e){return $ObjectTypeNameBigPrototypeToString.call(e).slice(8,-1)}function isArray(e){return getType(e)===$ArrayTypeNameBig}function isKvPair(e){return getType(e)===$ObjectTypeNameBig}function isString(e){return getType(e)===$stringTypeNameBig}function hpJsonParse(e,n){var t;try{t=JSON.parse(e)}catch(r){t=n}return t}function _KvPair(e){return e=isKvPair(e)||isKvPair(e=hpJsonParse(e))?e:{}}function isEmpty(e){return isNull(e)||""===e}function isFunction(e){return"function"==typeof e}function param(e){var t=[];function i(e,n){null!=e&&""!==e&&(n=null==(n=isFunction(n)?n():n)?"":n,t[t.length]=$encodeURI(e)+"="+$encodeURI(n))}return function a(e,n){var t,r;if(e)switch(getType(n)){case $ArrayTypeNameBig:for(t=0;t<n.length;t++)a(e+"["+("object"==typeof n[t]&&n[t]?t:"")+"]",n[t]);break;case $ObjectTypeNameBig:for(r in n)a(e+"["+r+"]",n[r]);break;default:i(e,n)}else switch(getType(n)){case $stringTypeNameBig:case $ObjectTypeNameBig:for(r in n)a(r,n[r]);break;case $ArrayTypeNameBig:for(t=0;t<n.length;t++)i(n[t].name,n[t].value)}}("",e),t.join("&")}function urlToGet(e,n){e=_String(e).replace(/&*$/g,"").replace(/\?*$/,"");var t="";return(t=isKvPair(n)||isArray(n)?param(n):_String(n).replace(/^&*/,""))&&(e+=(/\?/.test(e)?"&":"?")+t),e}$isBroswer?document.getElementsByTagName("head")[0]:undefined;var baseReg="["+$regSpaceStr+"]+";function trim(e,n){var t=getType(e),r=(t===$numberTypeNameBig&&(e=String(e),t=$stringTypeNameBig),"");if(t!==$stringTypeNameBig)return"";switch(n){case 1:r="^"+baseReg;break;case-1:r=baseReg+"$";break;case"*":r=baseReg;break;default:r="^"+baseReg+"|"+baseReg+"$"}return e.replace(new RegExp(r,"g"),"")}function hpIsEmptyMap(e){var n,t=!0;for(n in e)if(n!==undefined){t=!1;break}return t}function clean(e,n,t){if(t=!1!==t,isKvPair(e)){var r,i,a={};for(i in e)_filterData(isArray(r=e[i])||isKvPair(r)?clean(r,n):r,n,t,function(e){a[i]=e})}else if(isArray(e)){a=[];for(var o=0,s=e.length;o<s;o++)_filterData(clean(e[o],n),n,t,function(e){a.push(e)})}else a=e;return a}function _filterData(e,n,t,r){isString(e)?n&&""==trim(e,"*")||r(e):null!=e&&(t&&isKvPair(e)&&hpIsEmptyMap(e),r(e))}function cloneEasy(e){switch(getType(e)){case $ArrayTypeNameBig:for(var n=[],t=0;t<e.length;t++)n.push(cloneEasy(e[t]));break;case $ObjectTypeNameBig:for(var r in n={},e)n[r]=cloneEasy(e[r]);break;case $FunctionTypeNameBig:function i(){e.apply(this,arguments)}for(var a in e.prototype)i.prototype[a]=e.prototype[a];n=i;break;default:n=e}return n}function isNoData(e,n){var t=!1;return t=isArray(e)&&n.array&&0===e.length||isKvPair(e)&&n.kvPair&&hpIsEmptyMap(e)||isString(e)&&n.string&&""===e||isNull(e)?!0:t}function hander(e,n){if(isKvPair(e))for(var t in e){var r=e[t];(isArray(r)||isKvPair(r))&&hander(r,n),isNoData(r,n)&&delete e[t]}}function shake(e,n){n=Object.assign({string:!0,array:!0,kvPair:!0},n);return hander(e=cloneEasy(e),n),e}function _Array(e){return e=isArray(e)||isArray(e=hpJsonParse(e))?e:[]}function variableHasValue(e,n,t){var r;t=null==t?60:t,e()?n():(clearTimeout(r),setTimeout(function(){variableHasValue(e,n,t)},t))}variableHasValue["async"]=function(n,t){return new Promise(function(e){variableHasValue(n,e,t)})};var DEFAULT_CONFIG={id:"id",children:"children"};function deepFindTreePath(e,n,t){t=Object.assign(DEFAULT_CONFIG,t);for(var r=[],i=cloneEasy(e),a=new Set,o=t["children"];i.length;){var s=i[0];if(a.has(s))r.pop(),i.shift();else if(a.add(s),s[o]&&i.unshift.apply(i,s[o]),r.push(s),n(s))return r}return undefined}function _Number(e){return(e=Number(e))===Math.abs(Infinity)||isNaN(e)?0:e}function defaultValue(e,n){return isNull(e)?n:e}function repeatString(e,n){var t="";if((e=_String(e)).length*n<1<<28)for(;1==(1&n)&&(t+=e),0!=(n>>>=1);)e+=e;return t}function hpPadString(e,n,t,r){return(e=_String(e)).length>(n>>=0)?e:(n-=e.length,t.length<n&&(t+=repeatString(t,n/t.length)),-1===r?t.slice(0,n)+e:e+t.slice(0,n))}function padStart(e,n,t){return hpPadString(e,n,t,-1)}function padEnd(e,n,t){return hpPadString(e,n,t,1)}function split(e,n){return""!==e?e.split(n):[]}function floorFixed(e,n,t){var e=split(e=trim(_Number(e)),"."),r=e[1]||"";return r.length<n&&(r=padEnd(r,n,$zeroString),t&&(r=r.replace(/0+$/,""))),n<1||!r?e[0]:e[0]+"."+r.substring(0,n)}function roundFixed(e,n,t){e=_Number(e);var r,i=Math.pow(10,n),e=_String(Math.round(e*i)/i);return 0<n&&(r=(i=split(e,"."))[0],(i=i[1]||"").length<n&&(i=padEnd(i,n,$zeroString),e=(i=t?i.replace(/0+$/,""):i)?r+"."+i:r)),e}function deepFindItem(e,t,n){var r,i,a=isNull(n)?"children":n;return function o(e){if(e)for(var n=0;n<e.length;n++){if(i=t(e[n])){r=e[n];break}if(o(e[n][a]),i)break}}(e),r}function flatArrayToTree(e,n){for(var t=(n=_KvPair(n)).id||"id",r=n.pid||"pid",i=n.children||"children",a=0;a<e.length;a++){var o,s=e[a];(o=deepFindItem(e,function(e){return null!=e[t]&&e[t]!=s[t]&&e[t]===s[r]},i))&&(o[i]=_Array(o[i]),o[i].push(s),e.splice(a--,1))}return e}function changeIndex(e,n,t){if(e<0)return n;e+=1;return(n=(n+t)%e)<0&&(n+=e),-0===n?0:n}function getRandom(e,n,t){t=!1===t?0:1;return e=Math.random()*(n-e+t)+e,t?Math.floor(e):e}function getRandomWord(){return $letters[getRandom(0,$letters.length-1)][0]}function uuid(e){e=_Number(e);for(var n="",t=0;t<13;t++)n+=getRandom(1,9);e=(new Date).getTime()*getRandom(1,100);return padEnd(getRandomWord()+Number(n).toString(32)+e.toString(32),20,getRandomWord()+getRandomWord()+getRandomWord())}function _Boolean(e){return!0===e||"true"===e||"1"===e||1===e}function flatTree(e,r){var i=[];return r=defaultValue(r,"children"),function a(e){if(isArray(e))for(var n,t=0;t<e.length;t++)n=e[t],i.push(n),a(n[r])}(e),i}function main(e,r,i,a){a=a||"children";var n=[];return function o(e,n){for(var t=0;t<e.length;t++)n[t]=cloneEasy(i(e[t])),e[t][a]&&(n[t][r]=[],o(e[t][a],n[t][r]))}(e,n),n}var events={};function defineEventBus(i){if(events[i])throw'"'+i+'" Has already been registered!';return events[i]=events[i]||[],{on:function(e){events[i].push(e)},emit:function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];for(var r=0;r<events[i].length;r++)events[i][r].apply($undefinedValue,n)},off:function(e){if(!e)throw"the hander of off is required!";for(var n=0;n<events[i].length;n++)events[i][n]===e&&events[i].splice(n--,1)},dispose:function(){for(var e=0;e<events[i].length;e++)events[i].splice(e--,1);delete events[i]}}}function forEachTree(e,t,r){r=r||"children",function i(e){for(var n=0;n<e.length;n++)t(e[n]),isArray(e[n][r])&&i(e[n][r])}(e)}function forEach(e,n){for(var t=0;t<e.length;t++)n(e[t],t,e)}function randomColor(){return"rgba("+getRandom(0,255,!0)+","+getRandom(0,255,!0)+","+getRandom(0,255,!0)+",1)"}function emptyFunc(e,n){}var Polling=function(){function e(e){this._timer=void 0,this._timer_info=void 0,this._stamp=0,this._passStamp=0,this._option=void 0,this._option=Object.assign({timeout:6e3,interval:1e3,handler:emptyFunc},e),this._next=this._next.bind(this),this._doOnce=this._doOnce.bind(this),this.done=this.done.bind(this)}var n=e.prototype;return n._next=function(){return clearInterval(this._timer),this._passStamp=+new Date-this._stamp,this._timer=setTimeout(this._doOnce,this._option.interval),this},n._doOnce=function(){if(this._passStamp>=this._option.timeout)return this._option.onMessage&&this._option.onMessage(0),this.done(),this;this._option.handler(this._next,this.done)},n.start=function(){var e,n=this;this._stamp=+new Date,this.done(),this._doOnce();return this._option.onMessage&&(clearInterval(this._timer_info),this._timer_info=setInterval(function(){e=+new Date-n._stamp,0===(e=Math.max(n._option.timeout-e,0))&&n.done(),n._option.onMessage(e)},100)),this},n.done=function(){return clearTimeout(this._timer),clearTimeout(this._timer_info),this},n.dispose=function(){return this.done(),this},e}();function dataPage(e,n,t){if(t<1)throw"页码必须大于0";var r=(t-1)*n,i=r+n;return{current:t,total:e.length,size:n,pages:Math.ceil(e.length/n),data:cloneEasy(e.slice(r,i))}}function hpTryToParseStringToBasicType(e){return null==e?undefined:$falseString!==e&&($trueString===e||hpJsonParse(e,e))}var defaultSplitArr=[$undefinedValue,$undefinedValue];function handleDeepKey(e,n,t){var n=splitSymbol(n),r=n[0];isPreLikeArray(r)?(r=_Number(r),n[1]==$undefinedValue?e.push(t):(/^\[[\D]+\]/.test(n[1])?e[r]=_KvPair(e[r]):e[r]=_Array(e[r]),handleDeepKey(e[r],n[1],t))):n[1]==$undefinedValue?e[r]=t:(/^\[[\D]+\]/.test(n[1])?e[r]=_KvPair(e[r]):e[r]=_Array(e[r]),handleDeepKey(e[r],n[1],t))}function splitSymbol(e){if(e==$undefinedValue)return defaultSplitArr;var r,i=e;return e.replace(/^\[(.*?)\](.*)?/,function(e,n,t){return i=n,r=t,""}),[i,r]}function isPreLikeArray(e){return""===e||/^\d+$/.test(e)}function parseQuery(e){var a,t,o={};return(e=e||$isBroswer&&$browserGlobal.location.href||"").replace(/([^=&?/#]*?)=([^=&?/#]*)/g,function(e,n,i){i=hpTryToParseStringToBasicType($decodeURIComponent(i)),t=$decodeURIComponent(n),a=!1,""!==t&&(t.replace(/(.*?)(\[.*)/,function(e,n,t){var r=splitSymbol(t);a=!0,isPreLikeArray(r[0])?o[n]=_Array(o[n]):o[n]=_KvPair(o[n]),handleDeepKey(o[n],t,i)}),a||(o[t]=i))}),o}export{Polling,_Array,_Boolean,_KvPair,_Number,_String,changeIndex,clean,cloneEasy,dataPage,deepFindItem,deepFindTreePath,defaultValue,defineEventBus,flatTree,floorFixed,forEach,forEachTree,getRandom,getType,isArray,isEmpty,isFunction,isKvPair,isNull,isString,main as mapTree,padEnd,padStart,param,parseQuery,randomColor,repeatString,roundFixed,shake,split,flatArrayToTree as tree,trim,urlToGet,uuid,variableHasValue};
8
+ function isNull(e){return null===e||e===undefined}function _String(e){return isNull(e)?"":String(e)}var $letters=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],$ArrayTypeNameBig="Array",$FunctionTypeNameBig="Function",$ObjectTypeNameBig="Object",$stringTypeNameBig="String",$numberTypeNameBig="Number",$undefinedValue=void 0,$zeroString="0",$falseString="false",$trueString="true",$ObjectTypeNameBigPrototypeToString=Object.prototype.toString,$encodeURI=encodeURI,$decodeURIComponent=decodeURIComponent,$regSpaceStr="\\s\\uFEFF\\xA0",$isBroswer="undefined"!=typeof document&&document.getElementById!==undefined,$browserGlobal="undefined"!=typeof window?window:$undefinedValue;function getType(e){return $ObjectTypeNameBigPrototypeToString.call(e).slice(8,-1)}function isArray(e){return getType(e)===$ArrayTypeNameBig}function isKvPair(e){return getType(e)===$ObjectTypeNameBig}function isString(e){return getType(e)===$stringTypeNameBig}function hpJsonParse(e,n){var t;try{t=JSON.parse(e)}catch(r){t=n}return t}function _KvPair(e){return e=isKvPair(e)||isKvPair(e=hpJsonParse(e))?e:{}}function isEmpty(e){return isNull(e)||""===e}function isFunction(e){return"function"==typeof e}function param(e){var t=[];function i(e,n){null!=e&&""!==e&&(n=null==(n=isFunction(n)?n():n)?"":n,t[t.length]=$encodeURI(e)+"="+$encodeURI(n))}return function a(e,n){var t,r;if(e)switch(getType(n)){case $ArrayTypeNameBig:for(t=0;t<n.length;t++)a(e+"["+("object"==typeof n[t]&&n[t]?t:"")+"]",n[t]);break;case $ObjectTypeNameBig:for(r in n)a(e+"["+r+"]",n[r]);break;default:i(e,n)}else switch(getType(n)){case $stringTypeNameBig:case $ObjectTypeNameBig:for(r in n)a(r,n[r]);break;case $ArrayTypeNameBig:for(t=0;t<n.length;t++)i(n[t].name,n[t].value)}}("",e),t.join("&")}function urlToGet(e,n){e=_String(e).replace(/&*$/g,"").replace(/\?*$/,"");var t="";return(t=isKvPair(n)||isArray(n)?param(n):_String(n).replace(/^&*/,""))&&(e+=(/\?/.test(e)?"&":"?")+t),e}$isBroswer?document.getElementsByTagName("head")[0]:undefined;var baseReg="["+$regSpaceStr+"]+";function trim(e,n){var t=getType(e),r=(t===$numberTypeNameBig&&(e=String(e),t=$stringTypeNameBig),"");if(t!==$stringTypeNameBig)return"";switch(n){case 1:r="^"+baseReg;break;case-1:r=baseReg+"$";break;case"*":r=baseReg;break;default:r="^"+baseReg+"|"+baseReg+"$"}return e.replace(new RegExp(r,"g"),"")}function hpIsEmptyMap(e){var n,t=!0;for(n in e)if(n!==undefined){t=!1;break}return t}function clean(e,n,t){if(t=!1!==t,isKvPair(e)){var r,i,a={};for(i in e)_filterData(isArray(r=e[i])||isKvPair(r)?clean(r,n):r,n,t,function(e){a[i]=e})}else if(isArray(e)){a=[];for(var o=0,s=e.length;o<s;o++)_filterData(clean(e[o],n),n,t,function(e){a.push(e)})}else a=e;return a}function _filterData(e,n,t,r){isString(e)?n&&""==trim(e,"*")||r(e):null!=e&&(t&&isKvPair(e)&&hpIsEmptyMap(e),r(e))}function cloneEasy(e){switch(getType(e)){case $ArrayTypeNameBig:for(var n=[],t=0;t<e.length;t++)n.push(cloneEasy(e[t]));break;case $ObjectTypeNameBig:for(var r in n={},e)n[r]=cloneEasy(e[r]);break;case $FunctionTypeNameBig:function i(){e.apply(this,arguments)}for(var a in e.prototype)i.prototype[a]=e.prototype[a];n=i;break;default:n=e}return n}function isNoData(e,n){var t=!1;return t=isArray(e)&&n.array&&0===e.length||isKvPair(e)&&n.kvPair&&hpIsEmptyMap(e)||isString(e)&&n.string&&""===e||isNull(e)?!0:t}function hander(e,n){if(isKvPair(e))for(var t in e){var r=e[t];(isArray(r)||isKvPair(r))&&hander(r,n),isNoData(r,n)&&delete e[t]}}function shake(e,n){n=Object.assign({string:!0,array:!0,kvPair:!0},n);return hander(e=cloneEasy(e),n),e}function _Array(e){return e=isArray(e)||isArray(e=hpJsonParse(e))?e:[]}function variableHasValue(e,n,t){var r;t=null==t?60:t,e()?n():(clearTimeout(r),setTimeout(function(){variableHasValue(e,n,t)},t))}variableHasValue["async"]=function(n,t){return new Promise(function(e){variableHasValue(n,e,t)})};var DEFAULT_CONFIG={id:"id",children:"children"};function deepFindTreePath(e,n,t){t=Object.assign(DEFAULT_CONFIG,t);for(var r=[],i=cloneEasy(e),a=new Set,o=t["children"];i.length;){var s=i[0];if(a.has(s))r.pop(),i.shift();else if(a.add(s),s[o]&&i.unshift.apply(i,s[o]),r.push(s),n(s))return r}return undefined}function _Number(e){return(e=Number(e))===Math.abs(Infinity)||isNaN(e)?0:e}function defaultValue(e,n){return isNull(e)?n:e}function repeatString(e,n){var t="";if((e=_String(e)).length*n<1<<28)for(;1==(1&n)&&(t+=e),0!=(n>>>=1);)e+=e;return t}function hpPadString(e,n,t,r){return(e=_String(e)).length>(n>>=0)?e:(n-=e.length,t.length<n&&(t+=repeatString(t,n/t.length)),-1===r?t.slice(0,n)+e:e+t.slice(0,n))}function padStart(e,n,t){return hpPadString(e,n,t,-1)}function padEnd(e,n,t){return hpPadString(e,n,t,1)}function split(e,n){return""!==e?e.split(n):[]}function floorFixed(e,n,t){var e=split(e=trim(_Number(e)),"."),r=e[1]||"";return r.length<n&&(r=padEnd(r,n,$zeroString),t&&(r=r.replace(/0+$/,""))),n<1||!r?e[0]:e[0]+"."+r.substring(0,n)}function roundFixed(e,n,t){e=_Number(e);var r,i=Math.pow(10,n),e=_String(Math.round(e*i)/i);return 0<n&&(r=(i=split(e,"."))[0],(i=i[1]||"").length<n&&(i=padEnd(i,n,$zeroString),e=(i=t?i.replace(/0+$/,""):i)?r+"."+i:r)),e}function deepFindItem(e,t,n){var r,i,a=isNull(n)?"children":n;return function o(e){if(e)for(var n=0;n<e.length;n++){if(i=t(e[n])){r=e[n];break}if(o(e[n][a]),i)break}}(e),r}function flatArrayToTree(e,n){for(var t=(n=_KvPair(n)).id||"id",r=n.pid||"pid",i=n.children||"children",a=0;a<e.length;a++){var o,s=e[a];(o=deepFindItem(e,function(e){return null!=e[t]&&e[t]!=s[t]&&e[t]===s[r]},i))&&(o[i]=_Array(o[i]),o[i].push(s),e.splice(a--,1))}return e}function changeIndex(e,n,t){if(e<0)return n;e+=1;return(n=(n+t)%e)<0&&(n+=e),-0===n?0:n}function getRandom(e,n,t){t=!1===t?0:1;return e=Math.random()*(n-e+t)+e,t?Math.floor(e):e}function getRandomWord(){return $letters[getRandom(0,$letters.length-1)][0]}function uuid(e){e=_Number(e);for(var n="",t=0;t<13;t++)n+=getRandom(1,9);e=(new Date).getTime()*getRandom(1,100);return padEnd(getRandomWord()+Number(n).toString(32)+e.toString(32),20,getRandomWord()+getRandomWord()+getRandomWord())}function _Boolean(e){return!0===e||"true"===e||"1"===e||1===e}function flatTree(e,r){var i=[];return r=defaultValue(r,"children"),function a(e){if(isArray(e))for(var n,t=0;t<e.length;t++)n=e[t],i.push(n),a(n[r])}(e),i}function main(e,r,i,a){a=a||"children";var n=[];return function o(e,n){for(var t=0;t<e.length;t++)n[t]=cloneEasy(i(e[t])),e[t][a]&&(n[t][r]=[],o(e[t][a],n[t][r]))}(e,n),n}var events={};function defineEventBus(i){if(events[i])throw'"'+i+'" Has already been registered!';return events[i]=events[i]||[],{on:function(e){events[i].push(e)},emit:function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];for(var r=0;r<events[i].length;r++)events[i][r].apply($undefinedValue,n)},off:function(e){if(!e)throw"the hander of off is required!";for(var n=0;n<events[i].length;n++)events[i][n]===e&&events[i].splice(n--,1)},dispose:function(){for(var e=0;e<events[i].length;e++)events[i].splice(e--,1);delete events[i]}}}function forEachTree(e,t,r){r=r||"children",function i(e){for(var n=0;n<e.length;n++)t(e[n]),isArray(e[n][r])&&i(e[n][r])}(e)}function forEach(e,n){for(var t=0;t<e.length;t++)n(e[t],t,e)}function randomColor(){return"rgba("+getRandom(0,255,!0)+","+getRandom(0,255,!0)+","+getRandom(0,255,!0)+",1)"}function emptyFunc(e,n){}var Polling=function(){function e(e){this._timer=void 0,this._timer_info=void 0,this._stamp=0,this._isMount=!0,this._passStamp=0,this._option=void 0,this._option=Object.assign({interval:1e3,handler:emptyFunc},e),this._next=this._next.bind(this),this._doOnce=this._doOnce.bind(this),this.done=this.done.bind(this)}var n=e.prototype;return n._next=function(){return clearInterval(this._timer),this._passStamp=+new Date-this._stamp,this._timer=setTimeout(this._doOnce,this._option.interval),this},n._doOnce=function(){if(this._option.timeout&&this._passStamp>=this._option.timeout)return this._option.onMessage&&this._option.onMessage(0),this.done(),this;this._option.handler(this._next,this.done)},n.start=function(){var e,n,t=this;if(this._isMount)return this._stamp=+new Date,this.done(),this._doOnce(),e=0,n=0,this._option.onMessage&&this._option.timeout&&(clearInterval(this._timer_info),this._timer_info=setInterval(function(){e=+new Date-t._stamp,0===(n=Math.max(t._option.timeout-e,0))&&t.done(),t._option.onMessage(n)},100)),this},n.done=function(){return clearTimeout(this._timer),clearTimeout(this._timer_info),this},n.dispose=function(){return this._isMount=!1,this.done(),this},e}();function dataPage(e,n,t){if(t<1)throw"页码必须大于0";var r=(t-1)*n,i=r+n;return{current:t,total:e.length,size:n,pages:Math.ceil(e.length/n),data:cloneEasy(e.slice(r,i))}}function hpTryToParseStringToBasicType(e){return null==e?undefined:$falseString!==e&&($trueString===e||hpJsonParse(e,e))}var defaultSplitArr=[$undefinedValue,$undefinedValue];function handleDeepKey(e,n,t){var n=splitSymbol(n),r=n[0];isPreLikeArray(r)?(r=_Number(r),n[1]==$undefinedValue?e.push(t):(/^\[[\D]+\]/.test(n[1])?e[r]=_KvPair(e[r]):e[r]=_Array(e[r]),handleDeepKey(e[r],n[1],t))):n[1]==$undefinedValue?e[r]=t:(/^\[[\D]+\]/.test(n[1])?e[r]=_KvPair(e[r]):e[r]=_Array(e[r]),handleDeepKey(e[r],n[1],t))}function splitSymbol(e){if(e==$undefinedValue)return defaultSplitArr;var r,i=e;return e.replace(/^\[(.*?)\](.*)?/,function(e,n,t){return i=n,r=t,""}),[i,r]}function isPreLikeArray(e){return""===e||/^\d+$/.test(e)}function parseQuery(e){var a,t,o={};return(e=e||$isBroswer&&$browserGlobal.location.href||"").replace(/([^=&?/#]*?)=([^=&?/#]*)/g,function(e,n,i){i=hpTryToParseStringToBasicType($decodeURIComponent(i)),t=$decodeURIComponent(n),a=!1,""!==t&&(t.replace(/(.*?)(\[.*)/,function(e,n,t){var r=splitSymbol(t);a=!0,isPreLikeArray(r[0])?o[n]=_Array(o[n]):o[n]=_KvPair(o[n]),handleDeepKey(o[n],t,i)}),a||(o[t]=i))}),o}export{Polling,_Array,_Boolean,_KvPair,_Number,_String,changeIndex,clean,cloneEasy,dataPage,deepFindItem,deepFindTreePath,defaultValue,defineEventBus,flatTree,floorFixed,forEach,forEachTree,getRandom,getType,isArray,isEmpty,isFunction,isKvPair,isNull,isString,main as mapTree,padEnd,padStart,param,parseQuery,randomColor,repeatString,roundFixed,shake,split,flatArrayToTree as tree,trim,urlToGet,uuid,variableHasValue};
@@ -422,9 +422,26 @@ declare function randomColor(): string;
422
422
 
423
423
  type VoidFunc = () => void;
424
424
  interface PollingOption {
425
+ /**
426
+ * 多少毫秒一次
427
+ */
425
428
  interval: number;
426
- timeout: number;
429
+ /**
430
+ * 过期时间。不填则永不过期
431
+ */
432
+ timeout?: number;
433
+ /**
434
+ *
435
+ * @param remainTime 剩余时间回调(需要设置了timeout大于0)
436
+ * @returns
437
+ */
427
438
  onMessage?: (remainTime: number) => void;
439
+ /**
440
+ *
441
+ * @param next 继续轮询
442
+ * @param done 完成并停止
443
+ * @returns
444
+ */
428
445
  handler: (next: VoidFunc, done: VoidFunc) => void;
429
446
  }
430
447
  /**
@@ -457,13 +474,14 @@ declare class Polling {
457
474
  private _timer;
458
475
  private _timer_info;
459
476
  private _stamp;
477
+ private _isMount;
460
478
  private _passStamp;
461
479
  private _option;
462
480
  constructor(setting: Partial<PollingOption>);
463
481
  private _next;
464
482
  private _doOnce;
465
483
  /** 开始 */
466
- start(): this;
484
+ start(): this | undefined;
467
485
  /** 完成 */
468
486
  done(): this;
469
487
  /** 销毁 */
@@ -1,7 +1,8 @@
1
1
  /**
2
- * 基础工具库 => jUtilsBase
2
+ * 纯JS工具库 => jUtilsBase
3
+ * 可在nodejs和小程序中使用
3
4
  * @QQ 1174295440
4
5
  * @author IT0909
5
- * @update 2023-11-05 17:28:15
6
+ * @update 2023-11-24 17:11:14
6
7
  */
7
- !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).jUtilsBase={})}(this,function(n){"use strict";function a(n){return null===n||n===undefined}function o(n){return a(n)?"":String(n)}var t=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],u="Array",f="Object",c="String",A="Number",s=void 0,B="false",R="true",U=Object.prototype.toString,r=encodeURI,i=decodeURIComponent,e="undefined"!=typeof document&&document.getElementById!==undefined,C="undefined"!=typeof window?window:s;function l(n){return U.call(n).slice(8,-1)}function h(n){return l(n)===u}function d(n){return l(n)===f}function p(n){return l(n)===c}function g(n,t){var e;try{e=JSON.parse(n)}catch(r){e=t}return e}function v(n){return n=d(n)||d(n=g(n))?n:{}}function m(n){return"function"==typeof n}function _(n){var e=[];function i(n,t){null!=n&&""!==n&&(t=null==(t=m(t)?t():t)?"":t,e[e.length]=r(n)+"="+r(t))}return function o(n,t){var e,r;if(n)switch(l(t)){case u:for(e=0;e<t.length;e++)o(n+"["+("object"==typeof t[e]&&t[e]?e:"")+"]",t[e]);break;case f:for(r in t)o(n+"["+r+"]",t[r]);break;default:i(n,t)}else switch(l(t)){case c:case f:for(r in t)o(r,t[r]);break;case u:for(e=0;e<t.length;e++)i(t[e].name,t[e].value)}}("",n),e.join("&")}e?document.getElementsByTagName("head")[0]:undefined;var b="[\\s\\uFEFF\\xA0]+";function y(n,t){var e=l(n),r=(e===A&&(n=String(n),e=c),"");if(e!==c)return"";switch(t){case 1:r="^"+b;break;case-1:r=b+"$";break;case"*":r=b;break;default:r="^"+b+"|"+b+"$"}return n.replace(new RegExp(r,"g"),"")}function w(n){var t,e=!0;for(t in n)if(t!==undefined){e=!1;break}return e}function S(n,t,e,r){p(n)?t&&""==y(n,"*")||r(n):null!=n&&(e&&d(n)&&w(n),r(n))}function T(n){switch(l(n)){case u:for(var t=[],e=0;e<n.length;e++)t.push(T(n[e]));break;case f:for(var r in t={},n)t[r]=T(n[r]);break;case"Function":function i(){n.apply(this,arguments)}for(var o in n.prototype)i.prototype[o]=n.prototype[o];t=i;break;default:t=n}return t}function k(n,t){if(d(n))for(var e in n){var r=n[e];(h(r)||d(r))&&k(r,t),i=t,o=!1,(o=!!(h(r=r)&&i.array&&0===r.length||d(r)&&i.kvPair&&w(r)||p(r)&&i.string&&""===r||a(r))||o)&&delete n[e]}var i,o}function x(n){return n=h(n)||h(n=g(n))?n:[]}function M(n,t,e){var r;e=null==e?60:e,n()?t():(clearTimeout(r),setTimeout(function(){M(n,t,e)},e))}M["async"]=function(t,e){return new Promise(function(n){M(t,n,e)})};var H={id:"id",children:"children"};function O(n){return(n=Number(n))===Math.abs(Infinity)||isNaN(n)?0:n}function E(n,t){return a(n)?t:n}function F(n,t){var e="";if((n=o(n)).length*t<1<<28)for(;1==(1&t)&&(e+=n),0!=(t>>>=1);)n+=n;return e}function K(n,t,e,r){return(n=o(n)).length>(t>>=0)?n:(t-=n.length,e.length<t&&(e+=F(e,t/e.length)),-1===r?e.slice(0,t)+n:n+e.slice(0,t))}function I(n,t,e){return K(n,t,e,1)}function N(n,t){return""!==n?n.split(t):[]}function V(n,e,t){var r,i,o=a(t)?"children":t;return function u(n){if(n)for(var t=0;t<n.length;t++){if(i=e(n[t])){r=n[t];break}if(u(n[t][o]),i)break}}(n),r}function j(n,t,e){e=!1===e?0:1;return n=Math.random()*(t-n+e)+n,e?Math.floor(n):n}function P(){return t[j(0,t.length-1)][0]}var D={};function G(n,t){}var J=[s,s];function Q(n){if(n==s)return J;var r,i=n;return n.replace(/^\[(.*?)\](.*)?/,function(n,t,e){return i=t,r=e,""}),[i,r]}function q(n){return""===n||/^\d+$/.test(n)}n.Polling=function(){function n(n){this._timer=void 0,this._timer_info=void 0,this._stamp=0,this._passStamp=0,this._option=void 0,this._option=Object.assign({timeout:6e3,interval:1e3,handler:G},n),this._next=this._next.bind(this),this._doOnce=this._doOnce.bind(this),this.done=this.done.bind(this)}var t=n.prototype;return t._next=function(){return clearInterval(this._timer),this._passStamp=+new Date-this._stamp,this._timer=setTimeout(this._doOnce,this._option.interval),this},t._doOnce=function(){if(this._passStamp>=this._option.timeout)return this._option.onMessage&&this._option.onMessage(0),this.done(),this;this._option.handler(this._next,this.done)},t.start=function(){var n,t=this;this._stamp=+new Date,this.done(),this._doOnce();return this._option.onMessage&&(clearInterval(this._timer_info),this._timer_info=setInterval(function(){n=+new Date-t._stamp,0===(n=Math.max(t._option.timeout-n,0))&&t.done(),t._option.onMessage(n)},100)),this},t.done=function(){return clearTimeout(this._timer),clearTimeout(this._timer_info),this},t.dispose=function(){return this.done(),this},n}(),n._Array=x,n._Boolean=function(n){return!0===n||"true"===n||"1"===n||1===n},n._KvPair=v,n._Number=O,n._String=o,n.changeIndex=function(n,t,e){return n<0?t:((t=(t+e)%(n+=1))<0&&(t+=n),-0===t?0:t)},n.clean=function $(n,t,e){if(e=!1!==e,d(n)){var r,i,o={};for(i in n)S(h(r=n[i])||d(r)?$(r,t):r,t,e,function(n){o[i]=n})}else if(h(n)){o=[];for(var u=0,a=n.length;u<a;u++)S($(n[u],t),t,e,function(n){o.push(n)})}else o=n;return o},n.cloneEasy=T,n.dataPage=function(n,t,e){if(e<1)throw"页码必须大于0";var r=(e-1)*t,i=r+t;return{current:e,total:n.length,size:t,pages:Math.ceil(n.length/t),data:T(n.slice(r,i))}},n.deepFindItem=V,n.deepFindTreePath=function(n,t,e){e=Object.assign(H,e);for(var r=[],i=T(n),o=new Set,u=e["children"];i.length;){var a=i[0];if(o.has(a))r.pop(),i.shift();else if(o.add(a),a[u]&&i.unshift.apply(i,a[u]),r.push(a),t(a))return r}return undefined},n.defaultValue=E,n.defineEventBus=function(i){if(D[i])throw'"'+i+'" Has already been registered!';return D[i]=D[i]||[],{on:function(n){D[i].push(n)},emit:function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];for(var r=0;r<D[i].length;r++)D[i][r].apply(s,t)},off:function(n){if(!n)throw"the hander of off is required!";for(var t=0;t<D[i].length;t++)D[i][t]===n&&D[i].splice(t--,1)},dispose:function(){for(var n=0;n<D[i].length;n++)D[i].splice(n--,1);delete D[i]}}},n.flatTree=function(n,r){var i=[];return r=E(r,"children"),function o(n){if(h(n))for(var t,e=0;e<n.length;e++)t=n[e],i.push(t),o(t[r])}(n),i},n.floorFixed=function(n,t,e){var r=(n=N(n=y(O(n)),"."))[1]||"";return r.length<t&&(r=I(r,t,"0"),e&&(r=r.replace(/0+$/,""))),t<1||!r?n[0]:n[0]+"."+r.substring(0,t)},n.forEach=function(n,t){for(var e=0;e<n.length;e++)t(n[e],e,n)},n.forEachTree=function(n,e,r){r=r||"children",function i(n){for(var t=0;t<n.length;t++)e(n[t]),h(n[t][r])&&i(n[t][r])}(n)},n.getRandom=j,n.getType=l,n.isArray=h,n.isEmpty=function(n){return a(n)||""===n},n.isFunction=m,n.isKvPair=d,n.isNull=a,n.isString=p,n.mapTree=function(n,r,i,o){o=o||"children";var t=[];return function u(n,t){for(var e=0;e<n.length;e++)t[e]=T(i(n[e])),n[e][o]&&(t[e][r]=[],u(n[e][o],t[e][r]))}(n,t),t},n.padEnd=I,n.padStart=function(n,t,e){return K(n,t,e,-1)},n.param=_,n.parseQuery=function(n){var u,r,a={};return(n=n||e&&C.location.href||"").replace(/([^=&?/#]*?)=([^=&?/#]*)/g,function(n,t,o){var e;e=i(o),o=null==e?undefined:B!==e&&(R===e||g(e,e)),r=i(t),u=!1,""!==r&&(r.replace(/(.*?)(\[.*)/,function(n,t,e){var r=Q(e);u=!0,q(r[0])?a[t]=x(a[t]):a[t]=v(a[t]),function i(n,t,e){var t=Q(t),r=t[0];q(r)?(r=O(r),t[1]==s?n.push(e):(/^\[[\D]+\]/.test(t[1])?n[r]=v(n[r]):n[r]=x(n[r]),i(n[r],t[1],e))):t[1]==s?n[r]=e:(/^\[[\D]+\]/.test(t[1])?n[r]=v(n[r]):n[r]=x(n[r]),i(n[r],t[1],e))}(a[t],e,o)}),u||(a[r]=o))}),a},n.randomColor=function(){return"rgba("+j(0,255,!0)+","+j(0,255,!0)+","+j(0,255,!0)+",1)"},n.repeatString=F,n.roundFixed=function(n,t,e){n=O(n);var r,i=Math.pow(10,t),n=o(Math.round(n*i)/i);return 0<t&&(r=(i=N(n,"."))[0],(i=i[1]||"").length<t&&(i=I(i,t,"0"),n=(i=e?i.replace(/0+$/,""):i)?r+"."+i:r)),n},n.shake=function(n,t){return t=Object.assign({string:!0,array:!0,kvPair:!0},t),k(n=T(n),t),n},n.split=N,n.tree=function(n,t){for(var e=(t=v(t)).id||"id",r=t.pid||"pid",i=t.children||"children",o=0;o<n.length;o++){var u,a=n[o];(u=V(n,function(n){return null!=n[e]&&n[e]!=a[e]&&n[e]===a[r]},i))&&(u[i]=x(u[i]),u[i].push(a),n.splice(o--,1))}return n},n.trim=y,n.urlToGet=function(n,t){n=o(n).replace(/&*$/g,"").replace(/\?*$/,"");var e="";return(e=d(t)||h(t)?_(t):o(t).replace(/^&*/,""))&&(n+=(/\?/.test(n)?"&":"?")+e),n},n.uuid=function(n){n=O(n);for(var t="",e=0;e<13;e++)t+=j(1,9);return n=(new Date).getTime()*j(1,100),I(P()+Number(t).toString(32)+n.toString(32),20,P()+P()+P())},n.variableHasValue=M});
8
+ !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).jUtilsBase={})}(this,function(n){"use strict";function a(n){return null===n||n===undefined}function o(n){return a(n)?"":String(n)}var t=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],u="Array",f="Object",s="String",A="Number",c=void 0,B="false",R="true",U=Object.prototype.toString,r=encodeURI,i=decodeURIComponent,e="undefined"!=typeof document&&document.getElementById!==undefined,C="undefined"!=typeof window?window:c;function h(n){return U.call(n).slice(8,-1)}function l(n){return h(n)===u}function d(n){return h(n)===f}function p(n){return h(n)===s}function g(n,t){var e;try{e=JSON.parse(n)}catch(r){e=t}return e}function v(n){return n=d(n)||d(n=g(n))?n:{}}function m(n){return"function"==typeof n}function _(n){var e=[];function i(n,t){null!=n&&""!==n&&(t=null==(t=m(t)?t():t)?"":t,e[e.length]=r(n)+"="+r(t))}return function o(n,t){var e,r;if(n)switch(h(t)){case u:for(e=0;e<t.length;e++)o(n+"["+("object"==typeof t[e]&&t[e]?e:"")+"]",t[e]);break;case f:for(r in t)o(n+"["+r+"]",t[r]);break;default:i(n,t)}else switch(h(t)){case s:case f:for(r in t)o(r,t[r]);break;case u:for(e=0;e<t.length;e++)i(t[e].name,t[e].value)}}("",n),e.join("&")}e?document.getElementsByTagName("head")[0]:undefined;var b="[\\s\\uFEFF\\xA0]+";function y(n,t){var e=h(n),r=(e===A&&(n=String(n),e=s),"");if(e!==s)return"";switch(t){case 1:r="^"+b;break;case-1:r=b+"$";break;case"*":r=b;break;default:r="^"+b+"|"+b+"$"}return n.replace(new RegExp(r,"g"),"")}function w(n){var t,e=!0;for(t in n)if(t!==undefined){e=!1;break}return e}function S(n,t,e,r){p(n)?t&&""==y(n,"*")||r(n):null!=n&&(e&&d(n)&&w(n),r(n))}function T(n){switch(h(n)){case u:for(var t=[],e=0;e<n.length;e++)t.push(T(n[e]));break;case f:for(var r in t={},n)t[r]=T(n[r]);break;case"Function":function i(){n.apply(this,arguments)}for(var o in n.prototype)i.prototype[o]=n.prototype[o];t=i;break;default:t=n}return t}function k(n,t){if(d(n))for(var e in n){var r=n[e];(l(r)||d(r))&&k(r,t),i=t,o=!1,(o=!!(l(r=r)&&i.array&&0===r.length||d(r)&&i.kvPair&&w(r)||p(r)&&i.string&&""===r||a(r))||o)&&delete n[e]}var i,o}function M(n){return n=l(n)||l(n=g(n))?n:[]}function x(n,t,e){var r;e=null==e?60:e,n()?t():(clearTimeout(r),setTimeout(function(){x(n,t,e)},e))}x["async"]=function(t,e){return new Promise(function(n){x(t,n,e)})};var H={id:"id",children:"children"};function O(n){return(n=Number(n))===Math.abs(Infinity)||isNaN(n)?0:n}function E(n,t){return a(n)?t:n}function F(n,t){var e="";if((n=o(n)).length*t<1<<28)for(;1==(1&t)&&(e+=n),0!=(t>>>=1);)n+=n;return e}function K(n,t,e,r){return(n=o(n)).length>(t>>=0)?n:(t-=n.length,e.length<t&&(e+=F(e,t/e.length)),-1===r?e.slice(0,t)+n:n+e.slice(0,t))}function I(n,t,e){return K(n,t,e,1)}function N(n,t){return""!==n?n.split(t):[]}function V(n,e,t){var r,i,o=a(t)?"children":t;return function u(n){if(n)for(var t=0;t<n.length;t++){if(i=e(n[t])){r=n[t];break}if(u(n[t][o]),i)break}}(n),r}function j(n,t,e){e=!1===e?0:1;return n=Math.random()*(t-n+e)+n,e?Math.floor(n):n}function P(){return t[j(0,t.length-1)][0]}var D={};function G(n,t){}var J=[c,c];function Q(n){if(n==c)return J;var r,i=n;return n.replace(/^\[(.*?)\](.*)?/,function(n,t,e){return i=t,r=e,""}),[i,r]}function q(n){return""===n||/^\d+$/.test(n)}n.Polling=function(){function n(n){this._timer=void 0,this._timer_info=void 0,this._stamp=0,this._isMount=!0,this._passStamp=0,this._option=void 0,this._option=Object.assign({interval:1e3,handler:G},n),this._next=this._next.bind(this),this._doOnce=this._doOnce.bind(this),this.done=this.done.bind(this)}var t=n.prototype;return t._next=function(){return clearInterval(this._timer),this._passStamp=+new Date-this._stamp,this._timer=setTimeout(this._doOnce,this._option.interval),this},t._doOnce=function(){if(this._option.timeout&&this._passStamp>=this._option.timeout)return this._option.onMessage&&this._option.onMessage(0),this.done(),this;this._option.handler(this._next,this.done)},t.start=function(){var n,t,e=this;if(this._isMount)return this._stamp=+new Date,this.done(),this._doOnce(),n=0,t=0,this._option.onMessage&&this._option.timeout&&(clearInterval(this._timer_info),this._timer_info=setInterval(function(){n=+new Date-e._stamp,0===(t=Math.max(e._option.timeout-n,0))&&e.done(),e._option.onMessage(t)},100)),this},t.done=function(){return clearTimeout(this._timer),clearTimeout(this._timer_info),this},t.dispose=function(){return this._isMount=!1,this.done(),this},n}(),n._Array=M,n._Boolean=function(n){return!0===n||"true"===n||"1"===n||1===n},n._KvPair=v,n._Number=O,n._String=o,n.changeIndex=function(n,t,e){return n<0?t:((t=(t+e)%(n+=1))<0&&(t+=n),-0===t?0:t)},n.clean=function $(n,t,e){if(e=!1!==e,d(n)){var r,i,o={};for(i in n)S(l(r=n[i])||d(r)?$(r,t):r,t,e,function(n){o[i]=n})}else if(l(n)){o=[];for(var u=0,a=n.length;u<a;u++)S($(n[u],t),t,e,function(n){o.push(n)})}else o=n;return o},n.cloneEasy=T,n.dataPage=function(n,t,e){if(e<1)throw"页码必须大于0";var r=(e-1)*t,i=r+t;return{current:e,total:n.length,size:t,pages:Math.ceil(n.length/t),data:T(n.slice(r,i))}},n.deepFindItem=V,n.deepFindTreePath=function(n,t,e){e=Object.assign(H,e);for(var r=[],i=T(n),o=new Set,u=e["children"];i.length;){var a=i[0];if(o.has(a))r.pop(),i.shift();else if(o.add(a),a[u]&&i.unshift.apply(i,a[u]),r.push(a),t(a))return r}return undefined},n.defaultValue=E,n.defineEventBus=function(i){if(D[i])throw'"'+i+'" Has already been registered!';return D[i]=D[i]||[],{on:function(n){D[i].push(n)},emit:function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];for(var r=0;r<D[i].length;r++)D[i][r].apply(c,t)},off:function(n){if(!n)throw"the hander of off is required!";for(var t=0;t<D[i].length;t++)D[i][t]===n&&D[i].splice(t--,1)},dispose:function(){for(var n=0;n<D[i].length;n++)D[i].splice(n--,1);delete D[i]}}},n.flatTree=function(n,r){var i=[];return r=E(r,"children"),function o(n){if(l(n))for(var t,e=0;e<n.length;e++)t=n[e],i.push(t),o(t[r])}(n),i},n.floorFixed=function(n,t,e){var r=(n=N(n=y(O(n)),"."))[1]||"";return r.length<t&&(r=I(r,t,"0"),e&&(r=r.replace(/0+$/,""))),t<1||!r?n[0]:n[0]+"."+r.substring(0,t)},n.forEach=function(n,t){for(var e=0;e<n.length;e++)t(n[e],e,n)},n.forEachTree=function(n,e,r){r=r||"children",function i(n){for(var t=0;t<n.length;t++)e(n[t]),l(n[t][r])&&i(n[t][r])}(n)},n.getRandom=j,n.getType=h,n.isArray=l,n.isEmpty=function(n){return a(n)||""===n},n.isFunction=m,n.isKvPair=d,n.isNull=a,n.isString=p,n.mapTree=function(n,r,i,o){o=o||"children";var t=[];return function u(n,t){for(var e=0;e<n.length;e++)t[e]=T(i(n[e])),n[e][o]&&(t[e][r]=[],u(n[e][o],t[e][r]))}(n,t),t},n.padEnd=I,n.padStart=function(n,t,e){return K(n,t,e,-1)},n.param=_,n.parseQuery=function(n){var u,r,a={};return(n=n||e&&C.location.href||"").replace(/([^=&?/#]*?)=([^=&?/#]*)/g,function(n,t,o){var e;e=i(o),o=null==e?undefined:B!==e&&(R===e||g(e,e)),r=i(t),u=!1,""!==r&&(r.replace(/(.*?)(\[.*)/,function(n,t,e){var r=Q(e);u=!0,q(r[0])?a[t]=M(a[t]):a[t]=v(a[t]),function i(n,t,e){var t=Q(t),r=t[0];q(r)?(r=O(r),t[1]==c?n.push(e):(/^\[[\D]+\]/.test(t[1])?n[r]=v(n[r]):n[r]=M(n[r]),i(n[r],t[1],e))):t[1]==c?n[r]=e:(/^\[[\D]+\]/.test(t[1])?n[r]=v(n[r]):n[r]=M(n[r]),i(n[r],t[1],e))}(a[t],e,o)}),u||(a[r]=o))}),a},n.randomColor=function(){return"rgba("+j(0,255,!0)+","+j(0,255,!0)+","+j(0,255,!0)+",1)"},n.repeatString=F,n.roundFixed=function(n,t,e){n=O(n);var r,i=Math.pow(10,t),n=o(Math.round(n*i)/i);return 0<t&&(r=(i=N(n,"."))[0],(i=i[1]||"").length<t&&(i=I(i,t,"0"),n=(i=e?i.replace(/0+$/,""):i)?r+"."+i:r)),n},n.shake=function(n,t){return t=Object.assign({string:!0,array:!0,kvPair:!0},t),k(n=T(n),t),n},n.split=N,n.tree=function(n,t){for(var e=(t=v(t)).id||"id",r=t.pid||"pid",i=t.children||"children",o=0;o<n.length;o++){var u,a=n[o];(u=V(n,function(n){return null!=n[e]&&n[e]!=a[e]&&n[e]===a[r]},i))&&(u[i]=M(u[i]),u[i].push(a),n.splice(o--,1))}return n},n.trim=y,n.urlToGet=function(n,t){n=o(n).replace(/&*$/g,"").replace(/\?*$/,"");var e="";return(e=d(t)||l(t)?_(t):o(t).replace(/^&*/,""))&&(n+=(/\?/.test(n)?"&":"?")+e),n},n.uuid=function(n){n=O(n);for(var t="",e=0;e<13;e++)t+=j(1,9);return n=(new Date).getTime()*j(1,100),I(P()+Number(t).toString(32)+n.toString(32),20,P()+P()+P())},n.variableHasValue=x});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bestime/utils_base",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "./dist/jUtilsBase.umd.min.cjs",
5
5
  "module": "./dist/jUtilsBase.esm.min.mjs",
6
6
  "types": "./dist/jUtilsBase.esm.d.ts",