rx-util

rxliuli 在浏览器上使用的 js 工具集

Tính đến 24-07-2019. Xem phiên bản mới nhất.

Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta // @require https://update.greasyfork.org/scripts/382120/719746/rx-util.js

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).rx={})}(this,function(t){"use strict";function e(t,e="unknown"){const n=document.createElement("a");n.download=e,n.style.display="none",n.href=URL.createObjectURL(t),document.body.appendChild(n),n.click(),document.body.removeChild(n)}function n(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(s,c)}a((r=r.apply(t,e||[])).next())})}const r=(new Map).set("http",80).set("https",443).set("ssh",22).set("ftp",21);var o;function i(t,{type:e=i.DataURL,encoding:n="UTF-8"}={}){return new Promise((r,i)=>{t||i(new Error("file not exists"));const s=new FileReader;s.onload=(()=>{r(s.result)}),s.onerror=(t=>{i(t)}),(new Map).set(o.DataURL,()=>s.readAsDataURL(t)).set(o.Text,()=>s.readAsText(t,n)).set(o.BinaryString,()=>s.readAsBinaryString(t)).set(o.ArrayBuffer,()=>s.readAsArrayBuffer(t)).get(e)()})}function s(t,e){const n={"y+":t.getFullYear(),"M+":t.getMonth()+1,"d+":t.getDate(),"h+":t.getHours(),"m+":t.getMinutes(),"s+":t.getSeconds(),"q+":Math.floor((t.getMonth()+3)/3),"S+":t.getMilliseconds()};for(const t in n)if(new RegExp("("+t+")").test(e))if("y+"===t)e=e.replace(RegExp.$1,(""+n[t]).substr(4-RegExp.$1.length));else if("S+"===t){let r=RegExp.$1.length;r=1===r?3:r,e=e.replace(RegExp.$1,("00"+n[t]).substr((""+n[t]).length-1,r))}else{const r=Reflect.get(n,t);e=e.replace(RegExp.$1,1===RegExp.$1.length?r:("00"+r).substr((""+r).length))}return e}!function(t){t.DataURL="readAsDataURL",t.Text="readAsText",t.BinaryString="readAsBinaryString",t.ArrayBuffer="readAsArrayBuffer"}(o||(o={})),i.DataURL=o.DataURL,i.Text=o.Text,i.BinaryString=o.BinaryString,i.ArrayBuffer=o.ArrayBuffer;const c="yyyy-MM-ddThh:mm:ss.SSS",a=(t,e)=>encodeURIComponent(t)+"="+encodeURIComponent(e);function u(t){return new Promise(e=>{if("number"==typeof t)setTimeout(e,t);else if("function"==typeof t){const n=setInterval(()=>{t()&&(clearInterval(n),e())},100)}else e()})}function l(t,e){return Promise.race([t,u(e).then(()=>{throw new Error("timeout")})])}function f(t,e,n=((t,e)=>(t.push(e),t)),r=(()=>[])){return t.reduce((t,o,i,s)=>{const c=e(o,i,s);return t.has(c)||t.set(c,r()),t.set(c,n(t.get(c),o,i,s)),t},new Map)}function d(t,e,n=1){const r=[];for(let o=t;o<e;o+=n)r.push(o);return r}function h(t){return t}function p(t,e,n=h){const r=e instanceof Function?e:t=>Reflect.get(t,e),o=n instanceof Function?n:t=>Reflect.get(t,n);return t.reduce((t,e,n,i)=>t.set(r(e,n,i),o(e,n,i)),new Map)}function y(t,e){return e<=0?"":t+y(t,e-1)}class g{constructor(t,e,n,r){this.name=t,this.format=e,this.value=n,this.index=r}}const m=(new Map).set("year","y{4}|y{2}").set("month","M{1,2}").set("day","d{1,2}").set("hour","h{1,2}").set("minute","m{1,2}").set("second","s{1,2}").set("millieSecond","S{1,3}"),w=(new Map).set("month","01").set("day","01").set("hour","00").set("minute","00").set("second","00").set("millieSecond","000");function v(t,e){const n=new Date;w.set("year",n.getFullYear().toString());const r=[];for(const[t,n]of m){const o=new RegExp(n);if(o.test(e)){const n=o.exec(e)[0],i=y("`",n.length),s=e.indexOf(n);e=e.replace(n,i),r.push(new g(t,y("\\d",n.length),null,s))}else r.push(new g(t,null,w.get(t),-1))}if(e=e.replace(new RegExp("`","g"),"\\d"),!new RegExp(`^${e}$`).test(t))return null;r.filter(({format:t})=>t).sort(function(t,e){return t.index-e.index}).map(e=>{const n=new RegExp(e.format).exec(t);return null!==n&&n.length>0&&(t=t.replace(n[0],""),e.value=n[0]),e}).forEach(({format:e},n)=>{const o=new RegExp(e).exec(t);null!==o&&o.length>0&&(t=t.replace(o[0],""),r[n].value=o[0])});const o=p(r,t=>t.name,t=>t.value);2===o.get("year").length&&o.set("year",w.get("year").substr(0,2).concat(o.get("year")));const i=`${o.get("year")}-${o.get("month")}-${o.get("day")}T${o.get("hour")}:${o.get("minute")}:${o.get("second")}.${o.get("millieSecond")}`;return new Date(i)}function S(t){return t.selectionStart}function R(t,e,n=e){t.focus(),t.setSelectionRange(e,n)}function b(t){return null==t}function x(t){return b(t)||"string"!=typeof t?t:t.toLowerCase()}let _;document.addEventListener("focus",t=>{_=t.target},!0),document.addEventListener("blur",()=>{_=null},!0);class E{constructor(t,e,n,r){this.el=t,this.type=e,this.listener=n,this.options=r}}function T(t){return b(t)?"":t instanceof Date?t.toISOString():t.toString()}function M(t,e=null,...n){try{return t(...n)}catch(t){return e}}class O{constructor(){this.classMap=new Map}static getFactory(){return new O}register(t,e){return this.classMap.set(t,e),e}getInstance(t,...e){const n=this.classMap.get(t);return n?new n(...e):null}*[Symbol.iterator](){for(const t of this.classMap.entries())yield t}}function I(t,e){return t instanceof Promise?t.then(e):e(t)}function P(t){const e=performance.now();return I(t(),()=>performance.now()-e)}function k(t,e,n){return t>=e&&t<n}const A=/^(-?\d+)(.\d+)?$/,D=/^-?\d+$/,C=/^\w+((-\w+)|(\.\w+))*@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/,L=/^((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)$/,$=/^0[1-9][0-9]{1,2}-[2-8][0-9]{6,7}$/,j=/^(((13[0-9]{1})|15[0-9]{1}|18[0-9]{1}|)+\d{8})$/,F=/^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/,U=/^\d{6}$/;class B{static isEmpty(t){return b(t)||""===t}static isBlank(t){return B.isEmpty(t)||""===t.trim()}static isFloat(t){return!b(t)&&A.test(t)}static isInteger(t){return!b(t)&&D.test(t)}static isEmail(t){return!b(t)&&C.test(t)}static isIpv4(t){return!b(t)&&L.test(t)}static isPort(t){return B.isInteger(t)&&k(parseInt(t),1,65535)}static isTelephone(t){return!b(t)&&$.test(t)}static isMobile(t){return!b(t)&&j.test(t)}static isDomain(t){return!b(t)&&F.test(t)}static isPostcode(t){return!b(t)&&U.test(t)}}const N=B;function z(t){return b(t)||"string"!=typeof t?t:t.toUpperCase()}function Y(t){return N.isBlank(t)?null:t}function K(t,...e){const n=new Set(e);return Reflect.ownKeys(t).reduce((e,r)=>(n.has(r)||Reflect.set(e,r,Reflect.get(t,r)),e),{})}class J{static dayStart(t=new Date){return new Date(`${s(t,"yyyy-MM-dd")}T00:00:00.000`)}static dayEnd(t=new Date){return new Date(`${s(t,"yyyy-MM-dd")}T23:59:59.999`)}static yearStart(t=new Date){return new Date(`${t.getFullYear()}-01-01T00:00:00.000`)}static yearEnd(t=new Date){return new Date(`${t.getFullYear()}-12-31T23:59:59.999`)}}const Z=J,q=864e5;class W{constructor(t){this.date=t}year(){return this.date.getFullYear()}month(){return this.date.getMonth()}monthOfYear(){return this.date.getMonth()+1}dayOfYear(){return Math.ceil((this.date.getTime()-Z.yearStart(this.date).getTime())/q)}dayOfMonth(){return this.date.getDate()}dayOfWeek(){return this.date.getDay()}weekOfYear(){return Math.ceil(this.dayOfYear()/7)}weekOfMonth(){return Math.ceil(this.dayOfMonth()/7)}quarter(){const t=this.month();return k(t,0,3)?1:k(t,3,6)?2:k(t,6,9)?3:4}hour(){return this.date.getHours()}minute(){return this.date.getMinutes()}second(){return this.date.getSeconds()}milliSecond(){return this.date.getMilliseconds()}}function V(t){return new W(t)}class H{constructor(t,e){this.start=t,this.end=e}milliSecond(){return this.end.getTime()-this.start.getTime()}second(){return Math.floor(this.milliSecond()/1e3)}minute(){return Math.floor(this.second()/60)}hour(){return Math.floor(this.minute()/60)}day(){return Math.floor(this.hour()/24)}month(){return 12*this.year()+(this.end.getMonth()-this.start.getMonth())}year(){return this.end.getFullYear()-this.start.getFullYear()}}const G=function*(){for(let t=0;;t++)yield t}();class Q{from(t){throw new Error("子类必须重写 from 函数")}to(t){throw new Error("子类必须重写 to 函数")}}class X extends Q{from(t){const e=[],n=t.length;let r=0;for(let o=0;o<n;o++){const n=t.charAt(o);n>="A"&&n<="Z"&&(0!==o&&e.push(t.substring(r,o)),r=o)}return r!==t.length&&e.push(t.substring(r,t.length)),e}}class tt extends X{to(t){return t.reduce((t,e,n)=>{const r=x(e);return t+((0===n?x:z)(r.substring(0,1))+r.substring(1))},"")}}class et extends X{to(t){return t.reduce((t,e)=>{const n=x(e);return t+(z(n.substring(0,1))+n.substring(1))},"")}}class nt extends Q{from(t){return t.split("_")}}class rt extends nt{to(t){return t.map(x).join("_")}}class ot extends nt{to(t){return t.map(z).join("_")}}var it;(it=t.StringStyleType||(t.StringStyleType={}))[it.Camel=1]="Camel",it[it.Pascal=2]="Pascal",it[it.Snake=3]="Snake",it[it.ScreamingSnake=4]="ScreamingSnake";class st{static getInstance(e){switch(e){case t.StringStyleType.Camel:return new tt;case t.StringStyleType.Pascal:return new et;case t.StringStyleType.Snake:return new rt;case t.StringStyleType.ScreamingSnake:return new ot;default:throw new Error("No corresponding converter found")}}}class ct{constructor(t,e){this.fromConverter=st.getInstance(t),this.toConverter=st.getInstance(e)}convert(t){return N.isEmpty(t)?t:this.toConverter.to(this.fromConverter.from(t))}}function at(t,e=t.toString()){const n=new Map;return new Proxy(t,{apply(t,r,o){const i=(t=>`onceOfSameParam-${e}-${JSON.stringify(t)}`)(o),s=n.get(i);return void 0!==s?s:I(Reflect.apply(t,r,o),t=>(n.set(i,t),t))}})}const ut=at((t,e)=>new ct(t,e));class lt{static getConverter(t,e){return ut(t,e)}static convert(t,e,n){return lt.getConverter(t,e).convert(n)}}function ft(t){return b(t)?[]:Reflect.ownKeys(t)}function dt(t,...e){const n=e.filter(t=>t!==dt._);if(n.length>=t.length)return t(...n);function r(...n){const r=new Set;let o=0;const i=e.map(t=>t!==dt._||void 0===n[o]||n[o]===dt._?t:(r.add(o),n[o++])),s=n.filter((t,e)=>!r.has(e));return dt(t,...i,...s)}return r._length=t.length-e.filter(t=>t!==dt._).length,r.toString=(()=>`name: ${t.name}, args: [${e.map(t=>t.toString()).join(", ")}]`),r._curry=!0,r}dt._=Symbol("_");class ht{constructor(t){this.fmt=t}format(t){return b(t)?"":s(t,this.fmt)}parse(t){return N.isEmpty(t)?null:v(t,this.fmt)}strFormat(t,e){if(N.isEmpty(t))return"";return s(e?v(t,e):new Date(t),this.fmt)}}function pt(t,e,n=1){let r=0;for(let o=0,i=t.length;o<i;o++)if(e.call(t,t[o],o,t)&&++r>=n)return o;return-1}ht.dateFormatter=new ht("yyyy-MM-dd"),ht.timeFormatter=new ht("hh:mm:ss"),ht.dateTimeFormatter=new ht("yyyy-MM-dd hh:mm:ss");const yt=(t,e)=>(function(...n){const r=pt(n,t=>t!==dt._,t._length||t.length),o=dt(t,...n);return-1===r?yt(o,e):dt(e,o,...n.slice(r+1))});class gt{constructor(t={}){Object.assign(this,t)}}const mt="TimoutInfinite";function wt(t,...e){return[t,...e].reduce((t,e)=>b(e)?t:Reflect.ownKeys(e).reduce((t,n)=>{const r=Reflect.get(e,n);return b(r)?t:(Reflect.set(t,n,r),t)},t),{})}class vt{constructor({timeout:t=mt,serialize:e=JSON.stringify,deserialize:n=JSON.parse}={}){this.cacheOption={timeout:t,serialize:e,deserialize:n},this.localStorage=window.localStorage,this.clearExpired()}clearExpired(){return n(this,void 0,void 0,function*(){const t=this.localStorage,e=t.length,r=[];for(let n=0;n<e;n++){yield u(0);const e=t.key(n),o=t.getItem(e),i=M(JSON.parse,null,o);if(null===i)continue;const{timeStart:s,timeout:c}=i.cacheOption;c!==mt&&Date.now()-s>c&&r.push(e)}yield r.forEach(e=>n(this,void 0,void 0,function*(){return t.removeItem(e)}))})}add(t,e,n={}){null===this.get(t,n)&&this.set(t,e,n)}del(t){this.localStorage.removeItem(t)}set(t,e,n={}){const r=wt(this.cacheOption,n);this.localStorage.setItem(t,JSON.stringify(new gt({key:t,val:r.serialize(e),cacheOption:Object.assign({},r,{timeStart:r.timeStart||Date.now()})})))}get(t,e={}){const n=this.localStorage.getItem(t),r=M(JSON.parse,null,n);if(null===r)return null;const{timeStart:o,timeout:i,deserialize:s}=wt(this.cacheOption,r.cacheOption,e);if(i!==mt&&Date.now()-o>i)return this.del(t),null;try{return s(r.val)}catch(e){return this.del(t),null}}touch(t,e={}){const n=this.localStorage.getItem(t),r=M(JSON.parse,null,n);if(null===r)return null;const o=wt(this.cacheOption,r.cacheOption,e),{timeStart:i,timeout:s,deserialize:c}=o;if(s!==mt&&Date.now()-i>s)return this.del(t),null;try{const e=c(r.val);return this.set(t,e,wt(o,{timeStart:Date.now()})),e}catch(e){return this.del(t),null}}}const St=new vt;class Rt{static once(t,{identity:e=t.toString(),timeout:n=mt}={}){const r=()=>`CacheUtil.onceOfSameParam-${e}`,o=new Proxy(t,{apply(t,e,o){const i=r(),s={timeout:n},c=St.get(i);return null!==c?c:I(Reflect.apply(t,e,o),t=>(St.set(i,t,s),t))}});return Object.assign(o,{origin:t,clear(){St.del(r())}})}static onceOfSameParam(t,{identity:e=t.toString(),timeout:n=mt}={}){const r=t=>`CacheUtil.onceOfSameParam-${e}-${JSON.stringify(t)}`,o=new Proxy(t,{apply(t,e,o){const i=r(o),s={timeout:n},c=St.get(i);return null!==c?c:I(Reflect.apply(t,e,o),t=>(St.set(i,t,s),t))}});return Object.assign(o,{origin:t,clear(...t){St.del(r(t))}})}}const bt=Rt;function xt(...t){}class _t{static cyclingDebugger(){const t=setInterval(()=>{},100);return()=>clearInterval(t)}static checkDebug(t=(()=>window.location.reload())){const e=setInterval(()=>{const e=P(()=>{for(let t=0;t<1e3;t++)console.log(t),console.clear()});e>500&&(console.log(e),t())},1e3);return()=>clearInterval(e)}static disableConsoleOutput(){if(!window.console)return xt;const t=p(Object.keys(console),h,t=>{const e=console[t];return console[t]=xt,e});return()=>{for(const[e,n]of t)console[e]=n}}}const Et=_t;function Tt(t,e,n){return I((0,t[0])(...e),function(r){if(n(r))return r;const o=t.slice(1);return 0===o.length?r:Tt(o,e,n)})}class Mt{static and(...t){return function(...e){return Tt(t,e,t=>!t)}}static or(...t){return function(...e){return Tt(t,e,t=>t)}}static not(t){return new Proxy(t,{apply(t,e,n){return I(Reflect.apply(t,this,n),t=>!t)}})}}class Ot{static isEmpty(t){return b(t)||!(t instanceof Array)||0===t.length}}const It=Ot;class Pt{static join(...t){return t.reduce(Pt._join)}static _join(t,e){return t.endsWith(Pt.Separator)?(t+e).replace(Pt.Separator+Pt.Separator,Pt.Separator):e.startsWith(Pt.Separator)?t+e:t+Pt.Separator+e}}Pt.Separator="/";const kt=Pt;class At{constructor({enable:t=!0}={}){this.debug=console.debug,this.error=console.error,this.info=console.info,this.log=console.log,this.warn=console.warn,this.dir=console.dir,this.dirxml=console.dirxml,this.table=console.table,this.trace=console.trace,this.group=console.group,this.groupCollapsed=console.groupCollapsed,this.groupEnd=console.groupEnd,this.clear=console.clear,this.count=console.count,this.assert=console.assert,this.profile=console.profile,this.profileEnd=console.profileEnd,this.time=console.time,this.timeEnd=console.timeEnd,this.timeStamp=console.timeStamp,this._enable=t}set enable(t){this._enable=t,Object.keys(console).forEach(e=>this[e]=t?console[e]:xt)}}const Dt=new At;function Ct(t){return function(e){return new Proxy(e,{get:(e,n)=>Reflect.has(t,n)?Reflect.get(e,Reflect.get(t,n)):Reflect.get(e,n),set:(e,n,r)=>Reflect.has(t,n)?(Reflect.set(e,Reflect.get(t,n),r),!0):(Reflect.set(e,n,r),!0)})}}function Lt(t,{before:e=h,after:n=h,paramFn:r=((t,...e)=>[])}={}){return function t(o,...i){const s=e(o,...i),c=s.child;return It.isEmpty(c)||(s.child=c.map(e=>t(e,...r(s,...i)))),n(s,...i)}(t)}class $t{static bridge({id:t="id",parentId:e="parentId",child:n="child",path:r="path"}={}){return Ct({id:t,parentId:e,child:n,path:r})}static bridgeTree(t,e){return Lt(t,{before:this.bridge(e)})}static bridgeList(t,e){return t.map(this.bridge(e))}}const jt=$t;function Ft(t,e){const n=function(t){return t instanceof Function?/^(?:constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/:/^(?:toString|length)$/}(e);return Reflect.ownKeys(e).forEach(r=>{"string"==typeof r&&n.test(r)||Reflect.set(t,r,Reflect.get(e,r))}),t}const Ut=()=>!1;var Bt;!function(t){t.forEach="forEach",t.filter="filter",t.map="map",t.flatMap="flatMap",t.sort="sort",t.reduce="reduce",t.reduceRight="reduceRight",t.findIndex="findIndex",t.find="find",t.every="every",t.some="some",t.parallel="parallel",t.serial="serial"}(Bt||(Bt={}));class Nt{constructor(t,e){this.type=t,this.args=e,this.type=t,this.args=e}}Nt.Type=Bt;class zt{constructor(t=[]){this._arr=t}sort(t){return n(this,void 0,void 0,function*(){if(void 0===t)return new Yt(this._arr.sort());const e=this._arr.map((t,e)=>[t,e]);return new Yt(yield(yield function t(e,r){return n(this,void 0,void 0,function*(){if(e.length<=1)return e;const n=Math.floor(e.length/2),o=e[n],i=[],s=[];for(let t=0,c=e.length;t<c;t++){if(t===n)continue;const c=e[t];(yield r(c,o))<=0?i.push(c):s.push(c)}return(yield t(i,r)).concat([o]).concat(yield t(s,r))})}(e,([e],[n])=>t(e,n))).map(([t,e])=>this._arr[e]))})}find(t){return n(this,void 0,void 0,function*(){const e=yield this.findIndex(t);return-1===e?null:this._arr[e]})}every(t){return n(this,void 0,void 0,function*(){return-1===(yield this.findIndex(Mt.not(t)))})}some(t){return n(this,void 0,void 0,function*(){return-1!==(yield this.findIndex(t))})}parallel(){return new Kt(this._arr)}serial(){return new Yt(this._arr)}value(){return this._arr.slice()}}class Yt extends zt{constructor(t){super(t)}forEach(t){return n(this,void 0,void 0,function*(){for(let e=0,n=this._arr.length;e<n;e++)yield t.call(this,this._arr[e],e,this)})}filter(t){return n(this,void 0,void 0,function*(){const e=new Yt;for(let n=0,r=this._arr.length;n<r;n++)(yield t.call(this,this._arr[n],n,this))&&e._arr.push(this._arr[n]);return e})}map(t){return n(this,void 0,void 0,function*(){const e=new Yt;for(let n=0,r=this._arr.length;n<r;n++)e._arr.push(yield t.call(this,this._arr[n],n,this));return e})}flatMap(t){return n(this,void 0,void 0,function*(){const e=new Yt;for(let n=0,r=this._arr.length;n<r;n++)e._arr.push(...yield t.call(this,this._arr[n],n,this));return e})}reduce(t,e){return n(this,void 0,void 0,function*(){for(let n=0,r=this._arr.length;n<r;n++)e=e?yield t.call(this,e,this._arr[n],n,this):this._arr[n];return e})}reduceRight(t,e){return n(this,void 0,void 0,function*(){for(let n=this._arr.length-1;n>=0;n--)e=e?yield t.apply(this,[e,this._arr[n],n,this]):this._arr[n];return e})}findIndex(t){return n(this,void 0,void 0,function*(){for(let e=0,n=this._arr.length;e<n;e++){if(yield t.call(this,this._arr[e],e,this))return e}return-1})}}class Kt extends zt{constructor(t){super(t)}forEach(t){return n(this,void 0,void 0,function*(){yield this._all(t)})}filter(t){return n(this,void 0,void 0,function*(){const e=yield this._all(t),n=new Kt;for(let t=0,r=e.length;t<r;t++)e[t]&&n._arr.push(this._arr[t]);return n})}map(t){return n(this,void 0,void 0,function*(){return new Kt(yield this._all(t))})}flatMap(t){return n(this,void 0,void 0,function*(){const e=yield this._all(t);return new Kt(e.flat())})}sort(t){throw new Error("Method not implemented.")}reduce(t,e){return n(this,void 0,void 0,function*(){for(let n=0,r=this._arr.length;n<r;n++)e=e?yield t.call(this,e,this._arr[n],n,this):this._arr[n];return e})}reduceRight(t,e){return n(this,void 0,void 0,function*(){for(let n=this._arr.length-1;n>=0;n--)e=e?yield t.apply(this,[e,this._arr[n],n,this]):this._arr[n];return e})}findIndex(t){return n(this,void 0,void 0,function*(){return(yield this._all(t)).findIndex(h)})}_all(t){return n(this,void 0,void 0,function*(){return yield Promise.all(this._arr.map((e,n)=>t.apply(this,[e,n,this])))})}}class Jt{constructor(...t){this.length=0,this._arr=Array.from(t),this._tasks=[]}set _arr(t){this.__arr=t,this.length=this.__arr.length}get _arr(){return this.__arr}static from(t){const e=new Jt;return b(t)?e:(e._arr=Array.from(t),e)}filter(t){return this._addTask(new Nt(Nt.Type.filter,[t]))}map(t){return this._addTask(new Nt(Nt.Type.map,[t]))}flatMap(t){return this._addTask(new Nt(Nt.Type.flatMap,[t]))}sort(t){return this._addTask(new Nt(Nt.Type.sort,[t]))}parallel(){return this._addTask(new Nt(Nt.Type.parallel,[]))}serial(){return this._addTask(new Nt(Nt.Type.serial,[]))}forEach(t){return this._addTask(new Nt(Nt.Type.forEach,[t])).then()}some(t){return this._addTask(new Nt(Nt.Type.some,[t])).then()}every(t){return this._addTask(new Nt(Nt.Type.every,[t])).then()}find(t){return this._addTask(new Nt(Nt.Type.find,[t])).then()}findIndex(t){return this._addTask(new Nt(Nt.Type.findIndex,[t])).then()}reduce(t,e){return this._addTask(new Nt(Nt.Type.reduce,[t,e])).then()}reduceRight(t,e){return this._addTask(new Nt(Nt.Type.reduceRight,[t,e])).then()}then(t,e){return n(this,void 0,void 0,function*(){try{let n=new Yt(this._arr),r=this._arr;for(const e of this._tasks){if(!((n=yield Reflect.apply(Reflect.get(n,e.type),n,e.args))instanceof zt))return b(t)||t(r),n;r=n.value()}return b(t)||t(r),r}catch(t){b(e)||e(t)}})}value(){return this.then()}*[Symbol.iterator](){for(const t of this._arr)yield t}_addTask(t){const e=new Jt(...this._arr);return e._tasks=[...this._tasks,t],e}}t.AntiDebug=_t,t.ArrayValidator=Ot,t.AsyncArray=Jt,t.CacheUtil=Rt,t.CombinedPredicate=Mt,t.DateConstants=J,t.DateFormatter=ht,t.FetchLimiting=class{constructor({timeout:t=1e4,limit:e=10}={}){this.timeout=t,this.limit=e,this.execCount=0,this.waitArr=[]}fetch(t,e){return n(this,void 0,void 0,function*(){return this.waitArr.push([t,e]),yield u(()=>this.execCount<this.limit),(()=>n(this,void 0,void 0,function*(){this.execCount++;const t=this.waitArr.shift();try{return yield l(fetch(t[0],t[1]),this.timeout)}finally{this.execCount--}}))()})}},t.LocalStorageCache=vt,t.Locker=class{constructor({limit:t=1,timeout:e}={}){this.limit=t,this.timeout=e||Ut}isLocked(){return this.limit<=0}lock(t=this.timeout){return n(this,void 0,void 0,function*(){this.isLocked()?yield Promise.race([u(()=>{const t=!this.isLocked();return t&&this.limit--,t}),u(t)]):this.limit--})}unlock(){this.limit++}},t.Logger=At,t.NodeBridgeUtil=$t,t.PathUtil=Pt,t.StateMachine=O,t.StringStyleUtil=lt,t.StringValidator=B,t.aggregation=function(t){const e=Array.from(t);class n{constructor(...t){e.forEach(([e,n=h])=>Ft(this,new e(...n(t))))}}return e.forEach(([t])=>{Ft(n.prototype,t.prototype),Ft(n,t)}),n},t.antiDebug=Et,t.appends=function(t,e){for(const n in e){const r=e[n];t.append(n,T(r))}return t},t.arrayDiffBy=function(t,e,n=h){const r=new Set(t.map(n)),o=new Set(e.map(n)),i=t.filter((t,...e)=>!o.has(n(t,...e))),s=e.filter((t,...e)=>!r.has(n(t,...e))),c=new Set(i.map(n));return{left:i,right:s,common:t.filter((t,...e)=>!c.has(n(t,...e)))}},t.arrayToMap=p,t.arrayValidator=It,t.asIterator=function(t){const e=[];for(;;){const n=t.next();if(n.done)break;e.push(n.value)}return e},t.assign=wt,t.async=function(t){return new Proxy(t,{apply(t,e,r){return n(this,void 0,void 0,function*(){return yield Reflect.apply(t,e,r)})}})},t.asyncFlatMap=function(t,e){return n(this,void 0,void 0,function*(){const n=[];for(let r=0;r<t.length;r++)n.push(...yield e(t[r],r,t));return n})},t.asyncLimiting=function(t,{limit:e=1}={}){let r=0;const o=[];let i=!1;return new Proxy(t,{apply(t,s,c){return n(this,void 0,void 0,function*(){return o.push(c),yield u(()=>{const t=r<e;return t&&(i=!0,r++),t}),(()=>n(this,void 0,void 0,function*(){i||(r++,i=!1);const e=o.shift();try{return yield Reflect.apply(t,s,e)}finally{r--}}))()})}})},t.autoIncrement=function(){return G.next().value},t.blankToNull=Y,t.blankToNullField=function(t){return Reflect.ownKeys(t).reduce((e,n)=>{const r=Reflect.get(t,n);return Reflect.set(e,n,"string"==typeof r?Y(r):r),e},{})},t.bridge=Ct,t.cacheUtil=bt,t.compare=function t(e,n){if(("number"==typeof e||e instanceof Number)&&("number"==typeof n||n instanceof Number)){const t=+e,r=+n;if(isNaN(t)&&isNaN(r))return!0;if(t===r)return 1/t==1/r;if(Math.abs(t-r)<Number.EPSILON)return!0}if(e===n)return!0;if(e instanceof RegExp&&n instanceof RegExp||("string"==typeof e||e instanceof String)&&("string"==typeof n||n instanceof String))return e.toString()===n.toString();if(e instanceof Date&&n instanceof Date)return e.getTime()===n.getTime();if(!(e instanceof Object&&n instanceof Object))return!1;if(e.prototype!==n.prototype)return!1;if(e.constructor!==n.constructor)return!1;for(const t of Reflect.ownKeys(n))if(!Reflect.has(e,t))return!1;for(const r of Reflect.ownKeys(e)){if(!Reflect.has(n,r))return!1;if(typeof n[r]!=typeof e[r])return!1;if(!t(e[r],n[r]))return!1}return!0},t.compose=function(...t){return t.reduceRight((t,e)=>yt(e,t))},t.concatMap=function(t){let e=0;const r=new Set;return new Proxy(t,{apply(t,o,i){return n(this,void 0,void 0,function*(){const n=e;r.add(n),e++,yield u(()=>!r.has(n-1));const s=Reflect.apply(t,o,i);return r.delete(n),yield s})}})},t.copyText=function(t){const e=document.createElement("input");document.body.appendChild(e),e.setAttribute("value",t),e.select();const n=document.execCommand("copy");return document.body.removeChild(e),n},t.createElByString=function(t){const e=document.createElement("div");return e.innerHTML=t,e.querySelector("*")},t.curry=dt,t.dateBetween=function(t,e){return new H(t,e)},t.dateConstants=Z,t.dateEnhance=V,t.dateFormat=s,t.dateParse=v,t.debounce=function(t,e,n=null){let r,o=n;return new Proxy(e,{apply:(e,n,i)=>new Promise(s=>{r&&clearTimeout(r),r=setTimeout(()=>s(o=Reflect.apply(e,n,i)),t),setTimeout(()=>s(o),t)})})},t.deepFreeze=function t(e){return e instanceof Array?e.forEach(e=>{"object"==typeof e&&t(e)}):e instanceof Object&&function(t){return ft(t).map(e=>Reflect.get(t,e))}(e).forEach(e=>{"object"==typeof e&&t(e)}),Object.freeze(e)},t.deepProxy=function(t){const e={get(t,n){Reflect.set(t,n,Reflect.has(t,n)?Reflect.get(t,n):{});const r=Reflect.get(t,n);return"object"==typeof r?new Proxy(r,e):r}};return new Proxy(t,e)},t.deletes=function(t,e){return e.forEach(e=>t.delete(e)),t},t.deny=function(t){return Mt.not(t)},t.download=e,t.downloadString=function(t,r="unknown.txt"){return n(this,void 0,void 0,function*(){e(function(t){return new Blob([t],{type:"text/plain"})}(t),r)})},t.downloadUrl=function(t,r=t.substr(t.lastIndexOf("/"))){return n(this,void 0,void 0,function*(){try{const n=yield fetch(t);e(yield n.blob(),r)}catch(t){throw t}})},t.emptyAllField=function(t){return Reflect.ownKeys(t).reduce((t,e)=>(Reflect.set(t,e,null),t),{})},t.emptyFunc=xt,t.excludeFields=K,t.excludeFieldsDeep=function t(e,...n){return Reflect.ownKeys(e).reduce((r,o)=>{const i=Reflect.get(r,o);return i instanceof Object&&Reflect.set(e,o,t(i,...n)),r},e instanceof Array?e:K(e,...n))},t.fetchTimeout=l,t.fill=y,t.filterItems=function(t,e,n=h){const r=new Set(e.map(n));return t.filter((t,e,o)=>!r.has(n(t,e,o)))},t.findIndex=pt,t.flatMap=function(t,e=(t=>Array.from(t))){return t.reduce((t,n,r,o)=>(t.push(...e(n,r,o)),t),new Array)},t.floatEquals=function(t,e){return Math.abs(t-e)<Number.EPSILON},t.formDataToArray=function(t){return Array.from(t)},t.format=function(t,e){return Object.keys(e).reduce((t,n)=>t.replace(new RegExp(`{${n}}`,"g"),T(e[n])),t)},t.getCookies=function(){return document.cookie.split(";").reduce((t,e)=>{const[n,r]=e.split("=");return t.set(n,r),t},new Map)},t.getCusorPostion=S,t.getObjectEntries=function(t){return Reflect.ownKeys(t).map(e=>[e,Reflect.get(t,e)])},t.getObjectKeys=ft,t.getYearWeek=function(t){return V(t).weekOfYear()},t.groupBy=f,t.insertText=function(t,e,n=S(t)){const r=t.value;t.value=r.substr(0,n)+e+r.substr(n),R(t,n+e.length)},t.isBlank=function(t){return N.isBlank(t)},t.isEditable=function(t){return t&&(t.isContentEditable||["input","date","datetime","select","textarea"].includes(x(t.tagName)))},t.isEmpty=function(t){return N.isEmpty(t)},t.isFloat=function(t){return N.isFloat(t)},t.isNullOrUndefined=b,t.isNumber=function(t){return N.isInteger(t)},t.isRange=k,t.lastFocus=function(){return _},t.listToTree=function(t,{bridge:e=h,isRoot:n=(t=>!t.parentId)}={}){const r=t.reduce((r,o)=>{const i=e(o);if(n(i))return r.push(i),r;for(const n of t){const t=e(n);if(i.parentId===t.id)return t.child=t.child||[],t.child.push(i),r}return r},[]),o=r.length;return 0===o?{}:1===o?r[0]:r},t.loadResource=function(t,e,r={}){return n(this,void 0,void 0,function*(){const n=yield fetch(t,r),o=yield n.blob();e.src=window.URL.createObjectURL(o)})},t.loadScript=function(t){return new Promise((e,n)=>{const r=document.createElement("script");r.src=t,r.addEventListener("load",()=>e()),r.addEventListener("error",n),document.body.appendChild(r)})},t.logger=Dt,t.mapToObject=function(t){const e={};for(const[n,r]of t)Reflect.set(e,n,r);return e},t.mergeMap=function(t){let e=0;const r=new Set;return new Proxy(t,{apply(t,o,i){return n(this,void 0,void 0,function*(){const n=Reflect.apply(t,o,i),s=e;return r.add(s),e++,yield u(()=>!r.has(s-1)),r.delete(s),yield n})}})},t.nodeBridgeUtil=jt,t.objToFormData=function(t){return Object.entries(t).reduce((t,[e,n])=>(n instanceof Blob?t.append(e,n):t.append(e,n&&n.toString()),t),new FormData)},t.objectToMap=function(t){return Reflect.ownKeys(t).reduce((e,n)=>e.set(n,Reflect.get(t,n)),new Map)},t.once=function(t){let e,n=!0;return new Proxy(t,{apply:(t,r,o)=>!1===n?e:(n=!1,I(Reflect.apply(t,r,o),t=>e=t))})},t.onceOfSameParam=at,t.parseUrl=function(t){if(!t)throw new Error("Url cannot be empty");const e=new RegExp("^((\\w+)://([\\w\\.]*)(:(\\d+))?)(.*)").exec(t);if(null===e)return null;const n=e[1],o=e[2],i=e[3],s=e[5],c=e[6],a=t.substr(n.length),u=a.indexOf("?");if(-1===u){const e=a;return{url:t,website:n,protocol:o,domain:i,port:parseInt(s),href:c,accessPath:e,params:new Map}}let l=a.substr(0,u);return l.endsWith("/")&&(l=l.substring(0,l.length-1)),{url:t,website:n,protocol:o,domain:i,port:s||r.get(o)||0,href:c,accessPath:l,params:a.substr(u+1).split("&").map(t=>t.split("=")).filter(t=>""!==t[0]).reduce((t,e)=>{const n=decodeURIComponent(e[0]),r=decodeURIComponent(1===e.length?"":e[1]),o=t.get(n);return void 0===o?t.set(n,r):(Array.isArray(o)||t.set(n,[o]),void 0!==t.get(n).length&&t.get(n).push(r)),t},new Map)}},t.pathUtil=kt,t.randomInt=function(t,e){const n=e?t:0,r=e||t;return n+Math.floor(Math.random()*(r-n))},t.range=d,t.readLocal=i,t.removeEl=function(t){const e=t.parentElement;return null==e?null:e.removeChild(t)},t.removeText=function(t,e=t.selectionStart,n=t.selectionEnd){const r=S(t),o=t.value;t.value=o.substr(0,e)+o.substr(n,o.length),R(t,r)},t.returnItself=h,t.returnReasonableItself=function(...t){const e=t.length;return 0===e?null:1===e?t[0]:t},t.safeExec=M,t.setCusorPostion=R,t.sets=function(t,e){for(const n in e)t.set(n,e[n]);return t},t.singleModel=function(t){let e;return new Proxy(t,{construct:(t,n,r)=>(void 0===e&&(e=Reflect.construct(t,n,r)),e)})},t.sleep=function(t){const e=performance.now()+t;for(;performance.now()<=e;);},t.sortBy=function(t,e=h){return function t(e,n){if(e.length<=1)return e;const r=Math.floor(e.length/2),o=e[r],i=[],s=[];for(let t=0,c=e.length;t<c;t++){if(t===r)continue;const c=e[t];n(c,o)<=0?i.push(c):s.push(c)}return t(i,n).concat([o]).concat(t(s,n))}(t.map((t,e)=>[t,e]),([n,r],[o,i])=>{const s=e(n,r,t),c=e(o,i,t);return s===c?0:s<c?-1:1}).map(([e,n])=>t[n])},t.spliceParams=function(t={}){return Array.from(Object.entries(t)).reduce((t,[e,n])=>null==n?t:(n instanceof Date?t+=a(e,s(n,c)):n instanceof Array?t+=n.map(t=>a(e,t instanceof Date?s(t,c):t)).join("&"):t+=a(e,n),t+"&"),"")},t.strToArrayBuffer=function(t){const e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let e=0;e<t.length;++e)n[e]=255&t.charCodeAt(e);return e},t.strToDate=function(t,e){return v(t,e)},t.stringValidator=N,t.switchMap=function(t){let e,r=0,o=0;return new Proxy(t,{apply(t,i,s){return n(this,void 0,void 0,function*(){const n=r;r++;const c=yield Reflect.apply(t,i,s);return n<o?e:(e=c,o=n,c)})}})},t.throttle=function(t,e){let n,r=0;return new Proxy(e,{apply:(e,o,i)=>new Promise(s=>{const c=Date.now();if(c-r>t)return n=Reflect.apply(e,o,i),r=c,void s(n);s(n)})})},t.timing=P,t.toLowerCase=x,t.toObject=function(t,e,n=h){return t.reduce((t,r,o,i)=>{const s=e(r,o,i);return Reflect.has(t,s)||Reflect.set(t,s,n(r,o,i)),t},{})},t.toString=T,t.toUpperCase=z,t.treeMapping=Lt,t.treeToList=function(t,{calcPath:e=!1,bridge:n=h}={}){const r=[];return Lt(t,{before(t,o){const i=n(t);return e&&(i.path=(o?o+",":"")+i.id),r.push(i),i},paramFn:t=>e?[t.path]:[]}),r},t.trySometime=function(t,e=1,r=(t=>!0)){return new Proxy(t,{apply(t,o,i){return n(this,void 0,void 0,function*(){let n;for(let s=0;s<e;s++)try{const e=yield Reflect.apply(t,o,i);if(!0===r(e))return e;throw e}catch(t){n=t}throw n})}})},t.trySometimeParallel=function(t,e=1,r=(t=>!0)){return new Proxy(t,{apply(t,o,i){return n(this,void 0,void 0,function*(){return new Promise((s,c)=>n(this,void 0,void 0,function*(){let a;try{yield Promise.all(d(0,e).map(()=>n(this,void 0,void 0,function*(){try{const e=yield Reflect.apply(t,o,i);throw!0===r(e)&&s(e),e}catch(t){a=t}})))}catch(t){console.log(t)}c(a)}))})}})},t.uniqueBy=function(t,e=h){const n=new Set;return t.filter((t,...r)=>{const o=e(t,...r);return!n.has(o)&&(n.add(o),!0)})},t.wait=u,t.waitResource=function(t,{interval:e=100,max:n=10}={}){let r=0;return new Promise((o,i)=>{const s=setInterval(()=>{t()&&(clearInterval(s),o()),++r>=n&&(clearInterval(s),i(new Error("waitResource call timeout")))},e)})},t.watch=function(t,e,n=100){let r=t();const o=setInterval(()=>{const n=t();r!==n&&(e(n,r),r=n)},n);return()=>clearInterval(o)},t.watchEventListener=function(){const t=document.addEventListener,e=EventTarget.prototype.addEventListener,n=document.removeEventListener,r=EventTarget.prototype.removeEventListener;let o=[];document.addEventListener=EventTarget.prototype.addEventListener=function(n,r,i){const s=this===document?t:e;o.push(new E(this,n,r,i)),s.apply(this,n,r,i)},document.removeEventListenerByType=EventTarget.prototype.removeEventListenerByType=function(t){const e=this,i=e===document?n:r,s=f(o,n=>n.el===e&&n.type===t);s.get(!0).forEach(t=>{i.apply(t.el,[t.type,t.listener,t.useCapture])}),o=s.get(!1)}},t.watchObject=function(t,e){const n={get(t,e){try{return new Proxy(Reflect.get(t,e),n)}catch(n){return Reflect.get(t,e)}},set:(t,n,r)=>(e(t,n,r),Reflect.set(t,n,r))};return new Proxy(t,n)},Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=rx-util.min.js.map