rx-util

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

Verzia zo dňa 12.06.2019. Pozri najnovšiu verziu.

Tento skript by nemal byť nainštalovaný priamo. Je to knižnica pre ďalšie skripty, ktorú by mali používať cez meta príkaz // @require https://update.greasyfork.org/scripts/382120/708199/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){return t}function h(t,e,n=f((t,e)=>(t.push(e),t)),r=f(()=>[])){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 p(t){return f(t)}function y(t,e,n=p){return t.reduce((t,r,o,i)=>t.set(e(r,o,i),n(r,o,i)),new Map)}function g(t,e){return e<=0?"":t+g(t,e-1)}class m{constructor(t,e,n,r){this.name=t,this.format=e,this.value=n,this.index=r}}const w=(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}"),v=(new Map).set("month","01").set("day","01").set("hour","00").set("minute","00").set("second","00").set("millieSecond","000");function S(t,e){const n=new Date;v.set("year",n.getFullYear().toString());const r=[];for(const[t,n]of w){const o=new RegExp(n);if(o.test(e)){const n=o.exec(e)[0],i=g("`",n.length),s=e.indexOf(n);e=e.replace(n,i),r.push(new m(t,g("\\d",n.length),null,s))}else r.push(new m(t,null,v.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=y(r,t=>t.name,t=>t.value);2===o.get("year").length&&o.set("year",v.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 b(t){return t.selectionStart}function R(t,e,n=e){t.focus(),t.setSelectionRange(e,n)}function x(t){return null==t}function E(t){return x(t)||"string"!=typeof t?t:f(t.toLowerCase())}let M;document.addEventListener("focus",t=>{M=t.target},!0),document.addEventListener("blur",()=>{M=null},!0);class O{constructor(t,e,n,r){this.el=t,this.type=e,this.listener=n,this.options=r}}function T(t){return x(t)?"":t instanceof Date?t.toISOString():t.toString()}function P(t,e=null,...n){try{return t(...n)}catch(t){return e}}class A{constructor(){this.classMap=new Map}static getFactory(){return new A}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](){const t=this.classMap.entries();return{next:()=>t.next()}}}function I(t){const e=performance.now(),n=t();return n instanceof Promise?n.then(()=>performance.now()-e):performance.now()-e}const D=/^(-?\d+)(.\d+)?$/,L=/^-?\d+$/,_=/^\w+((-\w+)|(\.\w+))*@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/,C=/^((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)$/,k=/^0[1-9][0-9]{1,2}-[2-8][0-9]{6,7}$/,$=/^(((13[0-9]{1})|15[0-9]{1}|18[0-9]{1}|)+\d{8})$/,j=/^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/,F=/^\d{6}$/;const B=new class{isEmpty(t){return x(t)||""===t}isBlank(t){return B.isEmpty(t)||""===t.trim()}isFloat(t){return!x(t)&&D.test(t)}isInteger(t){return L.test(t)}isEmail(t){return _.test(t)}isIpv4(t){return C.test(t)}isTelephone(t){return k.test(t)}isMoblie(t){return $.test(t)}isDomain(t){return j.test(t)}isPostcode(t){return F.test(t)}};function U(t){return x(t)||"string"!=typeof t?t:f(t.toUpperCase())}function N(t){return B.isBlank(t)?null:t}function z(t,...e){const n=new Set(e);return f(Reflect.ownKeys(t).reduce((e,r)=>(n.has(r)||Reflect.set(e,r,Reflect.get(t,r)),e),{}))}function Y(t,e,n){return t>=e&&t<n}const K=new class{dayStart(t=new Date){return new Date(`${s(t,"yyyy-MM-dd")}T00:00:00.000`)}dayEnd(t=new Date){return new Date(`${s(t,"yyyy-MM-dd")}T23:59:59.999`)}yearStart(t=new Date){return new Date(`${t.getFullYear()}-01-01T00:00:00.000`)}yearEnd(t=new Date){return new Date(`${t.getFullYear()}-12-31T23:59:59.999`)}},J=864e5;class Z{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()-K.yearStart(this.date).getTime())/J)}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 Y(t,0,3)?1:Y(t,3,6)?2:Y(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 q(t){return new Z(t)}class W{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()}}function H(t,e=((...t)=>JSON.stringify(t))){const n=new Map;return new Proxy(t,{apply(t,r,o){const i=e(...o),s=n.get(i);if(void 0!==s)return s;const c=Reflect.apply(t,r,o);return c instanceof Promise?c.then(t=>(n.set(i,t),t)):(n.set(i,c),c)}})}const V=function*(){for(let t=0;;t++)yield t}();class G{from(t){throw new Error("子类必须重写 from 函数")}to(t){throw new Error("子类必须重写 to 函数")}}class Q extends G{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 X extends Q{to(t){return t.reduce((t,e,n)=>{const r=E(e);return t+((0===n?E:U)(r.substring(0,1))+r.substring(1))},"")}}class tt extends Q{to(t){return t.reduce((t,e)=>{const n=E(e);return t+(U(n.substring(0,1))+n.substring(1))},"")}}class et extends G{from(t){return t.split("_")}}class nt extends et{to(t){return t.map(E).join("_")}}class rt extends et{to(t){return t.map(U).join("_")}}var ot;(ot=t.StringStyleType||(t.StringStyleType={}))[ot.Camel=1]="Camel",ot[ot.Pascal=2]="Pascal",ot[ot.Snake=3]="Snake",ot[ot.ScreamingSnake=4]="ScreamingSnake";class it{static getInstance(e){switch(e){case t.StringStyleType.Camel:return new X;case t.StringStyleType.Pascal:return new tt;case t.StringStyleType.Snake:return new nt;case t.StringStyleType.ScreamingSnake:return new rt;default:throw new Error("No corresponding converter found")}}}class st{constructor(t,e){this.fromConverter=it.getInstance(t),this.toConverter=it.getInstance(e)}convert(t){return B.isEmpty(t)?t:this.toConverter.to(this.fromConverter.from(t))}}const ct=H((t,e)=>new st(t,e),(t,e)=>t.toString()+e.toString());class at{static getConverter(t,e){return ct(t,e)}static convert(t,e,n){return at.getConverter(t,e).convert(n)}}function ut(t){return x(t)?[]:Reflect.ownKeys(t)}function lt(t,...e){const n=e.filter(t=>t!==lt._);if(n.length>=t.length)return t(...n);function r(...n){const r=new Set;let o=0;const i=e.map(t=>t!==lt._||void 0===n[o]||n[o]===lt._?t:(r.add(o),n[o++])),s=n.filter((t,e)=>!r.has(e));return lt(t,...i,...s)}return r._length=t.length-e.filter(t=>t!==lt._).length,r.toString=(()=>`name: ${t.name}, args: [${e.map(t=>t.toString()).join(", ")}]`),r._curry=!0,r}lt._=Symbol("_");class ft{constructor(t){this.fmt=t}format(t){return x(t)?"":s(t,this.fmt)}parse(t){return B.isEmpty(t)?null:S(t,this.fmt)}strFormat(t,e){if(B.isEmpty(t))return"";return s(e?S(t,e):new Date(t),this.fmt)}}function ht(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}ft.dateFormatter=new ft("yyyy-MM-dd"),ft.timeFormatter=new ft("hh:mm:ss"),ft.dateTimeFormatter=new ft("yyyy-MM-dd hh:mm:ss");const dt=(t,e)=>(function(...n){const r=ht(n,t=>t!==lt._,t._length||t.length),o=lt(t,...n);return-1===r?dt(o,e):lt(e,o,...n.slice(r+1))});const pt="TimoutInfinite";class yt{constructor({timeout:t=pt,serialize:e=JSON.stringify,deserialize:n=JSON.parse}={}){this.cacheOption={timeout:t,serialize:e,deserialize:n}}add(t,e,n){}del(t){}set(t,e,n){}get(t,e){}touch(t,e){}}class gt{constructor(t={}){Object.assign(this,t)}}function mt(t,...e){return[t,...e].reduce((t,e)=>x(e)?t:Reflect.ownKeys(e).reduce((t,n)=>{const r=Reflect.get(e,n);return x(r)?t:(Reflect.set(t,n,r),t)},t),{})}class wt extends yt{constructor(t={}){super(t),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=P(JSON.parse,null,o);if(null===i)continue;const{timeStart:s,timeout:c}=i.cacheOption;c!==pt&&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=mt(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=P(JSON.parse,null,n);if(null===r)return null;const{timeStart:o,timeout:i,deserialize:s}=mt(this.cacheOption,r.cacheOption,e);if(i!==pt&&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=P(JSON.parse,null,n);if(null===r)return null;const o=mt(this.cacheOption,r.cacheOption,e),{timeStart:i,timeout:s,deserialize:c}=o;if(s!==pt&&Date.now()-i>s)return this.del(t),null;try{const e=c(r.val);return this.set(t,e,mt(o,{timeStart:Date.now()})),e}catch(e){return this.del(t),null}}}const vt=new wt;const St=new class{onceOfSameParam(t,{identity:e=t.toString(),timeout:n=pt}={}){const r=t=>`onceOfSameParam-${e}-${JSON.stringify(t)}`,o=function(...e){const o=r(e),i={timeout:n},s=vt.get(o);if(null!==s)return s;const c=t(...e);return c instanceof Promise?c.then(t=>(vt.set(o,t,i),t)):(vt.set(o,c,i),c)};return o.origin=t,o.clear=function(...t){const e=r(t);vt.del(e)},o}};function bt(...t){}const Rt={cyclingDebugger(){const t=setInterval(()=>{},100);return()=>clearInterval(t)},checkDebug(t=(()=>window.location.reload())){const e=setInterval(()=>{const e=I(()=>{for(let t=0;t<1e3;t++)console.log(t),console.clear()});e>500&&(console.log(e),t())},1e3);return()=>clearInterval(e)},disableConsoleOutput(){if(!window.console)return bt;const t=y(Object.keys(console),p,t=>{const e=console[t];return console[t]=bt,e});return()=>{for(const[e,n]of t)console[e]=n}}};const xt=new class{isEmpty(t){return x(t)||!(t instanceof Array)||0===t.length}};class Et{static _join(t,e){return t.endsWith(Et.Separator)?(t+e).replace(Et.Separator+Et.Separator,Et.Separator):e.startsWith(Et.Separator)?t+e:t+Et.Separator+e}join(...t){return t.reduce(Et._join)}}Et.Separator="/";const Mt=new Et;const Ot=new class{constructor({enable:t=!0}={}){this.reset=p,this.enable=t}set enable(t){this._enable=t,Object.keys(console).forEach(e=>this[e]=t?console[e]:bt)}get enable(){return this._enable}log(t,...e){}};function Tt(t){return function(e){return f(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 Pt(t,{before:e=p,after:n=p,paramFn:r=((t,...e)=>[])}={}){return function t(o,...i){const s=e(o,...i),c=s.child;return xt.isEmpty(c)||(s.child=c.map(e=>t(e,...r(s,...i)))),n(s,...i)}(t)}const At=new class{bridge({id:t="id",parentId:e="parentId",child:n="child",path:r="path"}={}){return f(Tt({id:t,parentId:e,child:n,path:r}))}bridgeTree(t,e){return Pt(t,{before:this.bridge(e)})}bridgeList(t,e){return t.map(this.bridge(e))}};function It(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 Dt=()=>!1;class Lt{constructor(...t){this._arr=t}get length(){return this._arr.length}static from(t){return x(t)?new Lt:new Lt(...Array.from(t))}forEach(t){return n(this,void 0,void 0,function*(){for(let e=0;e<this.length;e++)yield t.call(this,this._arr[e],e,this)})}filter(t){return n(this,void 0,void 0,function*(){const e=new Lt;for(let n=this.length-1;n>=0;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 Lt;for(let n=0;n<this.length;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 Lt;for(let n=0;n<this.length;n++)e._arr.push(...yield t.call(this,this._arr[n],n,this));return e})}every(t){return n(this,void 0,void 0,function*(){for(let e=0;e<this.length;e++)if(!(yield t.call(this,this._arr[e],e,this)))return!1;return!0})}find(t){return n(this,void 0,void 0,function*(){for(let e=0;e<this.length;e++){if(yield t.call(this,this._arr[e],e,this))return this._arr[e]}return null})}findIndex(t){return n(this,void 0,void 0,function*(){for(let e=0;e<this.length;e++){if(yield t.call(this,this._arr[e],e,this))return e}return null})}reduce(t,e){return n(this,void 0,void 0,function*(){for(let n=0;n<this.length;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.length-1;n>=0;n--)e=e?yield t.call(this,e,this._arr[n],n,this):this._arr[n];return e})}value(){return this._arr.slice()}[Symbol.iterator](){const t=this._arr.values();return{next:()=>t.next()}}}function _t(t,e,n){const r=(0,t[0])(...e);function o(r){if(n(r))return r;const o=t.slice(1);return 0===o.length?r:_t(o,e,n)}return r instanceof Promise?r.then(o):o(r)}t.AsyncArray=Lt,t.CombinedPredicate=class{static and(...t){return function(...e){return _t(t,e,t=>!t)}}static or(...t){return function(...e){return _t(t,e,t=>t)}}static not(t){return new Proxy(t,{apply(t,e,n){const r=Reflect.apply(t,this,n);return r instanceof Promise?r.then(t=>!t):!r}})}},t.DateFormatter=ft,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=wt,t.Locker=class{constructor({limit:t=1,timeout:e}={}){this.limit=t,this.timeout=e||Dt}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.StateMachine=A,t.StringStyleUtil=at,t.aggregation=function(t){const e=Array.from(t);class n{constructor(...t){e.forEach(([e,n=p])=>It(this,new e(...n(t))))}}return e.forEach(([t])=>{It(n.prototype,t.prototype),It(n,t)}),n},t.antiDebug=Rt,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=p){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=y,t.arrayValidator=xt,t.asIterator=function(t){const e=[];for(;;){const n=t.next();if(n.done)break;e.push(n.value)}return e},t.assign=mt,t.async=function(t){return f(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 V.next().value},t.blankToNull=N,t.blankToNullField=function(t){return f(Reflect.ownKeys(t).reduce((e,n)=>{const r=Reflect.get(t,n);return Reflect.set(e,n,"string"==typeof r?N(r):r),e},{}))},t.bridge=Tt,t.cacheUtil=St,t.compare=function t(e,n){if("number"==typeof e&&"number"==typeof n){if(isNaN(e)&&isNaN(n))return!0;if(Math.abs(e-n)<Number.EPSILON)return!0}if(e===n)return!0;if("function"==typeof e&&"function"==typeof n)return(e instanceof RegExp&&n instanceof RegExp||e instanceof String||n instanceof String||e instanceof Number||n instanceof Number)&&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)=>dt(e,t))},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=lt,t.dateBetween=function(t,e){return new W(t,e)},t.dateConstants=K,t.dateEnhance=q,t.dateFormat=s,t.dateParse=S,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 ut(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 f(new Proxy(t,e))},t.deletes=function(t,e){return e.forEach(e=>t.delete(e)),t},t.deny=function(t){return new Proxy(t,{apply(t,e,n){const r=Reflect.apply(t,this,n);return r instanceof Promise?r.then(t=>!t):!r}})},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 f(Reflect.ownKeys(t).reduce((t,e)=>(Reflect.set(t,e,null),t),{}))},t.emptyFunc=bt,t.excludeFields=z,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:z(e,...n))},t.fetchTimeout=l,t.fill=g,t.filterItems=function(t,e,n=p){const r=new Set(e.map(n));return t.filter((t,e,o)=>!r.has(n(t,e,o)))},t.findIndex=ht,t.flatMap=function(t,e=(t=>Array.from(f(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=b,t.getObjectEntries=function(t){return Reflect.ownKeys(t).map(e=>[e,Reflect.get(t,e)])},t.getObjectKeys=ut,t.getYearWeek=function(t){return q(t).weekOfYear()},t.groupBy=h,t.insertText=function(t,e,n=b(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 B.isBlank(t)},t.isEditable=function(t){return t&&(t.isContentEditable||["input","date","datetime","select","textarea"].includes(E(t.tagName)))},t.isEmpty=function(t){return B.isEmpty(t)},t.isFloat=function(t){return B.isFloat(t)},t.isNullOrUndefined=x,t.isNumber=function(t){return B.isInteger(t)},t.isRange=Y,t.lastFocus=function(){return M},t.listToTree=function(t,{bridge:e=p,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=Ot,t.mapToObject=function(t){const e={};for(const[n,r]of t)Reflect.set(e,n,r);return e},t.nodeBridgeUtil=At,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){if(!1===n)return e;n=!1;const i=Reflect.apply(t,r,o);return i instanceof Promise?i.then(t=>(e=t,t)):e=i}})},t.onceOfSameParam=H,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=Mt,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=b(t),o=t.value;t.value=o.substr(0,e)+o.substr(n,o.length),R(t,r)},t.returnItself=p,t.returnReasonableItself=function(...t){const e=t.length;return 0===e?null:1===e?t[0]:t},t.safeExec=P,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,n=p){if(e.length<=1)return e;const r=Math.floor(e.length/2),o=e.slice(),i=o.splice(r,1)[0],s=n(i,r,e),c=h(o,(t,...e)=>n(t,...e)<s);return[...t(c.get(!0)||[],n),i,...t(c.get(!1)||[],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 S(t,e)},t.stringValidator=B,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=I,t.toLowerCase=E,t.toObject=function(t,e,n=p){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=U,t.treeMapping=Pt,t.treeToList=function(t,{calcPath:e=!1,bridge:n=p}={}){const r=[];return Pt(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=p){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 O(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=h(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