jcommon
Version:
JavaScript 常用纯函数工具库
2 lines (1 loc) • 34.7 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jcommon={})}(this,(function(e){"use strict";function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function r(e,t,r,n,o,i,a){try{var u=e[i](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,o)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,h(n.key),n)}}function i(e,t,r){return t&&o(e.prototype,t),r&&o(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function a(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=p(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){u=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw i}}}}function u(e,t,r){return(t=h(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function c(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?c(Object(r),!0).forEach((function(t){u(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function l(){l=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var i=t&&t.prototype instanceof y?t:y,a=Object.create(i.prototype),u=new N(n||[]);return o(a,"_invoke",{value:A(e,r,u)}),a}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var d="suspendedStart",p="suspendedYield",v="executing",g="completed",m={};function y(){}function b(){}function w(){}var S={};s(S,a,(function(){return this}));var O=Object.getPrototypeOf,E=O&&O(O(M([])));E&&E!==r&&n.call(E,a)&&(S=E);var x=w.prototype=y.prototype=Object.create(S);function T(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function j(e,t){function r(o,i,a,u){var c=h(e[o],e,i);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,a,u)}),(function(e){r("throw",e,a,u)})):t.resolve(l).then((function(e){s.value=e,a(s)}),(function(e){return r("throw",e,a,u)}))}u(c.arg)}var i;o(this,"_invoke",{value:function(e,n){function o(){return new t((function(t,o){r(e,n,t,o)}))}return i=i?i.then(o,o):o()}})}function A(t,r,n){var o=d;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:e,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=D(u,n);if(c){if(c===m)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===d)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var s=h(t,r,n);if("normal"===s.type){if(o=n.done?g:p,s.arg===m)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=g,n.method="throw",n.arg=s.arg)}}}function D(t,r){var n=r.method,o=t.iterator[n];if(o===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,D(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=h(o,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,m;var a=i.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,m):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function L(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function N(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(L,this),this.reset(!0)}function M(t){if(t||""===t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(typeof t+" is not iterable")}return b.prototype=w,o(x,"constructor",{value:w,configurable:!0}),o(w,"constructor",{value:b,configurable:!0}),b.displayName=s(w,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===b||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,w):(e.__proto__=w,s(e,c,"GeneratorFunction")),e.prototype=Object.create(x),e},t.awrap=function(e){return{__await:e}},T(j.prototype),s(j.prototype,u,(function(){return this})),t.AsyncIterator=j,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new j(f(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},T(x),s(x,c,"Generator"),s(x,a,(function(){return this})),s(x,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=M,N.prototype={constructor:N,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(k),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return u.type="throw",u.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,m):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),m},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),k(r),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;k(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:M(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),m}},t}function f(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||p(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function d(e){return d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},d(e)}function p(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}var v=function(e,t){return e.toString().padStart(t,"0")},g=function(e,t){return t.replace(/yyyy|YYYY/,e.getFullYear().toString()).replace(/yy|YY/,v(e.getFullYear()%100,2)).replace(/mm|MM/,v(e.getMonth()+1,2)).replace(/m|M/g,(e.getMonth()+1).toString()).replace(/dd|DD/,v(e.getDate(),2)).replace(/d|D/g,e.getDate().toString()).replace(/hh|HH/,v(e.getHours(),2)).replace(/h|H/g,e.getHours().toString()).replace(/ii|II/,v(e.getMinutes(),2)).replace(/i|I/g,e.getMinutes().toString()).replace(/ss|SS/,v(e.getSeconds(),2)).replace(/s|S/g,e.getSeconds().toString()).replace(/w/g,e.getDay().toString()).replace(/W/g,["日","一","二","三","四","五","六"][e.getDay()])},m=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"YYYY-MM-DD HH:II:SS";if(!e)return arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";try{return"string"==typeof e&&(e=isNaN(Number(e))?new Date(e):Number(e)),"number"==typeof e&&(e=new Date(e)),e instanceof Date?g(e,t):""}catch(e){return""}},y=function(e){return m(e)},b=function(e,t){return Object.prototype.toString.call(e)==="[object ".concat(t,"]")},w=function(e){return b(e,"Undefined")},S=function(e){return b(e,"Null")},O=function(e){return b(e,"Function")},E=function(e){return b(e,"Array")},x=function(e){return b(e,"Object")},T=function(e){return null==e||""===e},j=function(e){if(S(e)||w(e))return"";var t,r=e.constructor===Array?[]:{};if("object"===d(e)){if(JSON)t=JSON.stringify(e),r=JSON.parse(t);else for(var n in e)r[n]="object"===d(e[n])?j(e[n]):e[n];return r}},A=function(e,t,r){for(var n in t)if(x(t[n])&&x(e[n]))e[n]=A(e[n],t[n],r);else{if(Object.keys(e).includes(n)&&!r.includes(n))continue;e[n]=t[n]}for(var o in e)void 0===t[o]&&delete e[o];return e},D=function(e){var t;if("object"===d(e))if(Array.isArray(e))for(var r in t=[],e)t.push(D(e[r]));else if(null===e)t=null;else if(e.constructor===RegExp)t=e;else for(var n in t={},e)t[n]=D(e[n]);else t=e;return t},L=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=e.replace(/(^\s+)|(\s+$)/g,"");return t&&(r=r.replace(/\s/g,"")),r},k=function(e){var t=j(e);for(var r in t)"object"===d(t[r])?t[r]=k(t[r]):"string"==typeof t[r]&&(t[r]=L(t[r]));return t},N=function(e,t){t||(t=e.slice(e.lastIndexOf("/")+1));var r=document.createElement("a");r.download=t,r.style.display="none",r.href=e,document.body.appendChild(r),r.click(),document.body.removeChild(r)},M=function(e){return new Promise((function(t){return setTimeout(t,e)}))},I=function(e,t){var r=s(s({},{format:["阴性","阳性"],default:"未知",negative:["阴性","-"],positive:["阳性","+"]}),t),n=r.negative,o=r.positive,i=r.format,a=r.default;return n.includes(e)?i[0]:o.includes(e)?i[1]:e.includes("d")?i[0]:e.includes("D")?i[1]:a},P=function(){var e,t=(e=l().mark((function e(t,r){var n,o,i,u,c,s,f,h,d,p,v,g,m;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=new TextDecoder("utf-8"),o=t.body.getReader(),e.prev=2;case 3:return e.next=6,o.read();case 6:if(i=e.sent,u=i.done,c=i.value,!u){e.next=12;break}return r.done(),e.abrupt("break",19);case 12:s=n.decode(c),f=s.split(/(\n){2}/),h=f.map((function(e){return e.replace(/(\n)?^data:\s*/,"").trim()})).filter((function(e){return""!==e&&"[DONE]"!==e})).map((function(e){try{return JSON.parse(e)}catch(e){return console.log(e),{choices:[{delta:{content:""}}]}}})),d=a(h);try{for(d.s();!(p=d.n()).done;)g=p.value,m=(m=null!==(v=g.choices[0].delta.content)&&void 0!==v?v:"").replace(/^`\s*/,"`"),r.add(m)}catch(e){d.e(e)}finally{d.f()}e.next=3;break;case 19:e.next=24;break;case 21:e.prev=21,e.t0=e.catch(2),console.log(e.t0);case 24:case"end":return e.stop()}}),e,null,[[2,21]])})),function(){var t=this,n=arguments;return new Promise((function(o,i){var a=e.apply(t,n);function u(e){r(a,o,i,u,c,"next",e)}function c(e){r(a,o,i,u,c,"throw",e)}u(void 0)}))});return function(e,r){return t.apply(this,arguments)}}(),C=function(){return i((function e(t){n(this,e),u(this,"items",[]),this.items=t||[]}),[{key:"enqueue",value:function(e){E(e)?this.items=this.items.concat(e):this.items.push(e)}},{key:"dequeue",value:function(){return this.items.shift()}},{key:"front",value:function(){return this.items[0]}},{key:"isEmpty",value:function(){return 0===this.items.length}},{key:"size",value:function(){return this.items.length}},{key:"clear",value:function(){this.items=[]}},{key:"print",value:function(){console.log(this.items.toString())}}])}();"function"==typeof SuppressedError&&SuppressedError;var B=function(){return i((function e(){n(this,e),u(this,"listeners",void 0),u(this,"maxListener",void 0),this.listeners={},this.maxListener=5}),[{key:"addListener",value:function(e,t){var r=this.listeners;if(r[e]&&r[e].length>=this.maxListener)throw new Error("监听器的最大数量是".concat(this.maxListener,",您已超出限制"));r[e]instanceof Array?-1===r[e].indexOf(t)&&r[e].push(t):r[e]=[t]}},{key:"emit",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];this.listeners[e]&&this.listeners[e].forEach((function(e){e.apply(void 0,r)}))}},{key:"getListeners",value:function(e){return this.listeners[e]}},{key:"setMaxListeners",value:function(e){this.maxListener=e}},{key:"removeListener",value:function(e,t){var r=this.listeners,n=(r[e]||[]).indexOf(t);n>=0&&r[e].splice(n,1)}},{key:"removeAllListener",value:function(e){delete this.listeners[e]}},{key:"once",value:function(e,t){var r=this,n=function(){t.apply(void 0,arguments),r.removeListener(e,n)};this.addListener(e,n)}}])}();!function(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var u=e.length-1;u>=0;u--)(o=e[u])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);i>3&&a&&Object.defineProperty(t,r,a)}([function(e,t,r){return r.enumerable=!1,r}],B.prototype,"emit",null);var R=function(){return i((function e(t,r){n(this,e),u(this,"onConsume",void 0),u(this,"onDone",void 0),u(this,"queue",[]),u(this,"consuming",!1),u(this,"timer",void 0),u(this,"strTemp",""),this.onConsume=t,this.onDone=r}),[{key:"dynamicSpeed",value:function(){var e=2e3/this.queue.length;return e>200?200:e}},{key:"add",value:function(e){var t;e&&(t=this.queue).push.apply(t,f(e.split("")))}},{key:"consume",value:function(){if(this.queue.length>0){var e=this.queue.shift();e&&(this.strTemp+=e,this.onConsume(this.strTemp))}}},{key:"next",value:function(){var e=this;this.consume(),this.timer=setTimeout((function(){e.consume(),e.consuming&&e.next()}),this.dynamicSpeed())}},{key:"start",value:function(){this.consuming=!0,this.next()}},{key:"done",value:function(){this.consuming=!1,clearTimeout(this.timer),this.strTemp+=this.queue.join(""),this.onConsume(this.strTemp),this.onDone(this.strTemp),this.queue=[]}}])}(),Y=function(){function e(){n(this,e),u(this,"cache",void 0),this.cache=new Map}return i(e,[{key:"set",value:function(e,t){this.cache.set(e,t)}},{key:"get",value:function(e){return this.cache.get(e)}},{key:"has",value:function(e){return this.cache.has(e)}},{key:"delete",value:function(e){this.cache.delete(e)}},{key:"clear",value:function(){this.cache.clear()}}],[{key:"getInstance",value:function(){return e.instance}}])}();u(Y,"instance",new Y);var F=Y.getInstance();Object.freeze(F),e.EventBus=B,e.Queue=C,e.Typewriter=R,e.addZero=v,e.arrByObj=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";if("[object Array]"!==Object.prototype.toString.call(e))return console.error("arrByObj 参数错误,请检查:",e),{};var n={};return e.forEach((function(e){n[e[t]]=r?e[r]:e})),n},e.arrayCompare=function(e,t){return e.length===t.length&&e.every((function(e){return t.some((function(t){return e===t}))}))&&t.every((function(t){return e.some((function(e){return e===t}))}))},e.cleanObject=function(e){if(!e)return{};var t=s({},e);return Object.keys(t).forEach((function(e){var r=t[e];T(r)&&delete t[e]})),t},e.cloneJson=function(e){return"object"!=d(e)||null==e?e:JSON.parse(JSON.stringify(e))},e.cloneObj=j,e.convertDataToTree=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"pid",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"children",o=[];if(!Array.isArray(e))return o;var i={};return e.forEach((function(e){i[e[t]]=e})),e.forEach((function(e){var t=i[e[r]];t?(t[n]||(t[n]=[])).push(e):o.push(e)})),o},e.convertDateToStandard=y,e.convertDateToStandardDay=function(e){return m(e,"YYYY-MM-DD")},e.convertDateToStandardHours=function(e){return m(e,"YYYY-MM-DD HH")},e.convertDateToView=m,e.convertTreeToList=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"children",r=[],n=1;return function e(o){o.forEach((function(o){r.push(s(s({},o),{},u(u({},t,void 0),"index",n))),n++,o[t]&&e(o[t])}))}(e),r},e.copyToBoar=function(e){var t=document.createElement("textarea");return document.body.appendChild(t),t.value=e,t.select(),document.execCommand("copy")?(document.execCommand("copy"),document.body.removeChild(t),!0):(document.body.removeChild(t),!1)},e.cutNumber=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return"number"!=typeof e&&(e=Number(e)),Number(e.toFixed(t))},e.dateFormat=g,e.dateInterval=function(e,t){var r=[0,0,0,0],n="",o=t>e?parseInt(((t-e)/1e3).toString()):0;return r[0]=o>86400?parseInt((o/86400).toString()):0,o-=86400*r[0],r[1]=o>3600?parseInt((o/3600).toString()):0,o-=3600*r[1],r[2]=o>60?parseInt((o/60).toString()):0,r[3]=o-60*r[2],n=r[0]>0?r[0]+"天":"",n+=r[0]<=0&&r[1]<=0?"":r[1]+"小时",n+=r[0]<=0&&r[1]<=0&&r[2]<=0?"":r[2]+"分钟",n+=r[0]<=0&&r[1]<=0&&r[2]<=0&&r[3]<=0?"":r[3]+"秒"},e.dateMonthDays=function(e){var t=e?new Date(e):new Date,r=t.getMonth();return t.setMonth(r+1),t.setDate(0),t.getDate()},e.debounce=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=null,o=function(){for(var o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];if(n&&clearTimeout(n),r){var u=!n;n=setTimeout((function(){n=null}),t),u&&e.apply(void 0,i)}else n=setTimeout((function(){e.apply(void 0,i)}),t)};return o.cancel=function(){clearTimeout(n),n=null},o},e.deepClone=D,e.difference=function(e,t){var r=new Set(e),n=new Set(t);return[].concat(f(new Set(f(r).filter((function(e){return!n.has(e)})))),f(new Set(f(n).filter((function(e){return!r.has(e)})))))},e.doubleRanking=function(e,t){var r=s(s({},{filterRuleKey:"",rule:[],sortKey:"",sortOrder:1}),t),n=r.sortKey,o=void 0===n?"":n,i=r.filterRuleKey,u=void 0===i?"":i,c=r.rule,l=void 0===c?[]:c,f=r.sortOrder,h=void 0===f?1:f;if(0===l.length)return e;var d,p={},v=a(e=e.filter((function(e){return!l||-1!==l.indexOf(e[u])})));try{for(v.s();!(d=v.n()).done;){var g=d.value;Object.prototype.hasOwnProperty.call(p,g[u])?p[g[u]].push(g):p[g[u]]=[g]}}catch(e){v.e(e)}finally{v.f()}for(var m in p)p[m]=p[m].sort((function(e,t){return e[o]>t[o]?1*h:-1*h}));for(var y=[],b=0;b<l.length;b++)Object.prototype.hasOwnProperty.call(p,l[b])&&(y=y.concat(p[l[b]]));return y},e.download=N,e.downloadFile=function(e,t){if(void 0===e)throw new Error("The first parameter name is a must");if(void 0===t)throw new Error("The second parameter content is a must");t instanceof Blob||(t=new Blob([t]));var r=URL.createObjectURL(t);N(r,e)},e.dragScroll=function(e){var t=0,r=0,n=0,o=0;function i(i){return 0===i.button&&(n=i.clientX,o=i.clientY,t=e.scrollLeft||0,r=e.scrollTop||0,document.addEventListener("mousemove",a),document.addEventListener("mouseup",u),e.style.cursor="grab"),!1}function a(i){return e.scrollTo(t-(i.clientX-n),r-(i.clientY-o)),!1}function u(){document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",u)}return e.addEventListener("mousedown",i),{destroy:function(){e.removeEventListener("mousedown",i),e.style.cursor=""}}},e.endWith=function(e,t){var r=e.length-t.length;return r>=0&&e.lastIndexOf(t)==r},e.everyTrim=k,e.exportJson=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"data",r=document.createElement("a");try{r.href=URL.createObjectURL(new Blob([JSON.stringify(e)],{type:"application/json"})),r.download="".concat(t,".json"),r.click(),r=null}catch(e){r=null}},e.fetchToSlow=function(e){return function(t){return new Promise((function(r){Promise.all([t,M(e)]).then((function(e){r(e[0])}))}))}},e.formatQueryParam=function(e){e=k(e);var t="";if("[object Object]"===Object.prototype.toString.call(e)){var r=function(r){Array.isArray(e[r])?e[r].forEach((function(e){t+="".concat(r,"=").concat(e,"&")})):null!==e[r]&&(t+="".concat(r,"=").concat(e[r],"&"))};for(var n in e)r(n)}return t.length>0?(t="?".concat(t)).substring(0,t.length-1):""},e.formatRhBloodGroup=I,e.getBase64=function(e){return new Promise((function(t,r){var n=new FileReader;n.readAsDataURL(e),n.onload=function(){return t(n.result)},n.onerror=function(e){return r(e)}}))},e.getBirthdatByIdNo=function(e){var t="";return t=15==e.length?(t="19"+(t=e.substring(6,12))).substring(0,4)+"-"+t.substring(4,6)+"-"+t.substring(6):(t=e.substring(6,14)).substring(0,4)+"-"+t.substring(4,6)+"-"+t.substring(6)},e.getBrowserInfo=function(){var e,t,r,n={name:"other",version:"0"},o=navigator.userAgent.toLowerCase();for(t=[["WeiXin",/micromessenger\/([^\s]+)/],["QQ",/qq\/([^\s]+)/],["QQBrowser",/(?:qqbrowser|qqlivebrowser)\/([^\s]+)/],["JDAPP",/jdapp;/],["QIHU",/qihu|360se/],["LieBao",/(?:lbbrowser|liebaofast)\/?([\d\.]+)?/],["Sogou",/(?:metasr|sogou[\w]*)[ \/]([\d\.]+)/],["Opera",/(?:opera|opr|oupeng)\/([\d\.]+)/],["BaiduBrowser",/(?:bidubrowser|baidubrowser)[\/ ]?([\d\.\w]+)/],["BaiduBox",/baiduboxapp|baiduboxpad/],["UC",/(?:ucweb|ucbrowser)\/?([\d\.]+)/],["Maxthon",/maxthon\/([\d\.]+)/],["Samsung",/samsungbrowser\/([\d\.]+)/],["Dolphin",/aphone|apad/],["2345",/2345/],["Miui",/miuibrowser\/([\d\.]+)/],["OppoBrowser",/oppobrowser\/([\d\.]+)/],["MeiZu",/mz-/],["Weibo",/weibo/],["Youku",/youku/],["NewsApp",/newsapp/],["AliApp",/aliapp/],["Firefox",/firefox\/([\d\.\w]+)/],["Chrome",/chrome\/([\d\.]+)/],["IE",/msie[ ](\d+\.\d+)/],["Safari",/safari\/([\d\.]+)/]],e=0;e<t.length;e++)if(r=o.match(t[e][1])){n.name=t[e][0],n.version=r[1]||"0";break}return n},e.getCookie=function(e){var t=document.cookie.match(new RegExp("(^| )"+e+"=([^;]*)(;|$)"));return null!=t?unescape(t[2]):null},e.getCountDays=function(e){var t=new Date(e),r=t.getMonth();return t.setMonth(r+1),t.setDate(0),t.getDate()},e.getExt=function(e){if("string"==typeof e)return e.split(".").pop();throw new Error("filename must be a string type")},e.getFormData=function(e){var t=new FormData;return Object.keys(e).forEach((function(r){var n=e[r];Array.isArray(n)?n.forEach((function(e,n){return t.append(r+"[".concat(n,"]"),e)})):t.append(r,e[r])})),t},e.getSexByIdNO=function(e){return 18==e.length?Number(e.charAt(16))%2==0?"FEMALE":"MALE":15==e.length?Number(e.charAt(14))%2==0?"FEMALE":"MALE":""},e.getStorage=function(e){var t=window.localStorage.getItem(e)||"";return void 0===t||"function"==typeof t?"":JSON.parse(t)},e.getStringLen=function(e){if(!e)return 0;var t=e.length;e=e.toString();for(var r=0,n=0;n<t;n++)r+=e.charCodeAt(n)<0||e.charCodeAt(n)>255?2:1;return r},e.getUrlQuery=function(e){var t=window.location.search,r=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),n=t.substr(t.indexOf("?")+1).match(r);return null!=n?n[2]:""},e.getV=function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return r.length?r.reduce((function(t,r){var n;return null!==(n=null==t?void 0:t[r])&&void 0!==n?n:e})):e},e.globalCache=F,e.groupBy=function(e,t){return e.reduce((function(e,r){return(e[r[t]]=e[r[t]]||[]).push(r),e}),{})},e.hideIdNum=function(e){return"".concat(String(e).slice(0,1),"****************").concat(String(e).slice(17))},e.importJson=function(){return new Promise((function(e){var t=document.createElement("input");t.type="file",t.accept="application/json",t.onchange=function(r){var n=r.target.files;if(!n||!n.length)throw t=null,new Error("No files");var o=new FileReader;o.onload=function(r){try{var n=JSON.parse(r.target.result);console.log(n),t=null,e(n)}catch(r){t=null,e(!1)}},o.readAsText(n[0])},t.click()}))},e.isAndroidMobileDevice=function(){return/android/i.test(navigator.userAgent.toLowerCase())},e.isAppleMobileDevice=function(){return/iphone|ipod|ipad|Macintosh/i.test(navigator.userAgent.toLowerCase())},e.isArray=E,e.isBoolean=function(e){return b(e,"Boolean")},e.isDate=function(e){return b(e,"Date")},e.isEmail=function(e){return/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(e)},e.isEmptyObject=function(e){if(null==e)return!0;if(Array.isArray(e))return!e.length;for(var t in e)if(Object.hasOwnProperty.call(e,t))return!1;return!0},e.isEqual=function(e,t){return JSON.stringify(e)===JSON.stringify(t)},e.isError=function(e){return b(e,"Error")},e.isFalsy=function(e){return 0!==e&&!e},e.isFunc=O,e.isNull=S,e.isNumber=function(e){return b(e,"Number")},e.isObject=x,e.isPhone=function(e){if(!e)return!1;return/(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/.test(e)},e.isQQ=function(){return!!/qq\/([\d\.]+)*/i.test(navigator.userAgent)},e.isReg=function(e){return b(e,"RegExp")},e.isRhNegative=function(e){return I(e,{format:[!0,!1]})},e.isRhPositive=function(e){return I(e,{format:[!1,!0]})},e.isString=function(e){return b(e,"String")},e.isSupportStorage=function(){if(!window.localStorage)return!1;try{return window.localStorage.setItem("JUTILS_STOARGE_TEST","true"),window.localStorage.removeItem("JUTILS_STOARGE_TEST"),!0}catch(e){return!1}},e.isType=b,e.isUndefined=w,e.isUserId=function(e){var t,r,n,o,i,a,u,c;if(i=["1","0","x","9","8","7","6","5","4","3","2"],a=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],t="",!e)return"身份证号码不能为空";if(18!=e.length)return"身份证号码长度应该为18位";if(18==e.length?t=e.substring(0,17):15==e.length&&(t=e.substring(0,6)+"19"+e.substring(6,15)),!/^\d+$/.test(t))return"身份证格式错误";if(r=t.substring(6,10),n=t.substring(10,12),o=t.substring(12,14),!1===/[1-9]\d{3}-(0[1-9]|1[0-2])-([0-2]\d|3[0-1])/.test(r+"-"+n+"-"+o))return"身份证生日无效。";if((new Date).getFullYear()-Number(r)>150||(new Date).getTime()-new Date(Number(r),Number(n)-1,Number(o)).getTime()<0)return"身份证生日不在有效范围";if(Number(n)>12||0===Number(n))return"身份证月份无效";if(Number(o)>31||0==Number(o))return"身份证日期无效";if(!{11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}[t.substring(0,2)])return"身份证地区编码错误";for(c=0,u=0;u<17;u++)c+=Number(t.charAt(u))*Number(a[u]);return t+=i[c%11],18!=e.length?"":t!=e.toLowerCase()?"不是合法的身份证号码":""},e.isVoid=T,e.isWX=function(){return!!/MicroMessenger/i.test(navigator.userAgent)},e.mergeObj=A,e.moreClick=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:300,n=null,o=0,i=0;return function(){for(var a=arguments.length,u=new Array(a),c=0;c<a;c++)u[c]=arguments[c];clearTimeout(n);var s=(new Date).getTime();i=s-o<r?i+1:0,o=(new Date).getTime(),i===t&&(n=setTimeout((function(){i=0,o=0,O(e)&&e.apply(void 0,u)}),r))}},e.oneClickToMoreClick=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:300,t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];var o=null,i=0,a=0;return function(){for(var t=arguments.length,n=new Array(t),u=0;u<t;u++)n[u]=arguments[u];clearTimeout(o);var c=(new Date).getTime();a=c-i<e?a+1:0,i=(new Date).getTime(),r.forEach((function(t,r){r===a&&(o=setTimeout((function(){a=0,i=0,O(t)&&t.apply(void 0,n)}),e))}))}},e.operattelecom=function(e){var t=e||"",r=t.substring(0,3),n=t.substring(0,4);return!!/^1\d{10}$/.test(t)&&("130,131,132,155,156,185,186,145,176".indexOf(r)>=0?"联通":"133,153,180,181,189,177,173,170".indexOf(r)>=0||"1349"==n?"电信":"134,135,136,137,138,139,150,151,152,157,158,159,187,188,147,182,183,184,178".indexOf(r)>=0?"移动":"未知")},e.osInfo=function(e){e=e||navigator.userAgent;for(var t={os:"other",version:""},r=[["android",/Android;?[\s\/]+([\d.]+)?/],["android",/jdapp;android;[\d.]+;([\d.]+);/],["android",/[aA]ndroid;/],["ipad",/iPad;.*?OS\s([\d_]+)/],["ipod",/iPod(?:\stouch)?;.*?\sOS\s([\d_]+)?/],["iphone",/CPU\siPhone\s(?:OS\s)?([\d_]+)/],["windows",/Windows NT/],["mac",/Macintosh;.*?Mac OS X\s([\d._]+)/],["windows phone",/Windows Phone\s([\d.]+)?/],["symbianos",/SymbianOS\/([\d.]+)?/],["bb",/BlackBerry|BB10|RIM Tablet OS\s([\d.]+)?/],["linux",/linux/i]],n=0;n<r.length;n++){var o=r[n],i=e.match(o[1]);if(i){t.os=o[0],t.version=(i[1]||"").replace(/_/g,".");break}}return t},e.processStreamResponse=P,e.randomColor=function(){return"rgba(".concat(Math.floor(255*Math.random()),", ").concat(Math.floor(255*Math.random()),", ").concat(Math.floor(255*Math.random()),", 1)")},e.randomData=function(e,t){for(var r=[],n=0;n<e;n++){for(var o={},i=0;i<t.length;i++)o[t[i]]=t[i]+String(Math.random()).substr(15);r.push(o)}return r},e.reduceCallBackNumber=function(e){return function(t,r){var n=r[e]||0;return"string"==typeof n&&(n=isNaN(Number(n))?0:Number(n)),t+n}},e.removeStorage=function(e){window.localStorage.removeItem(e)},e.saveStorage=function(e,t){if(void 0===t||"function"==typeof t)window.localStorage.setItem(e,"");else try{window.localStorage.setItem(e,JSON.stringify(t))}catch(e){console.error(e)}},e.scaleLinear=function(e,t,r){return(e/t*r).toFixed(arguments.length>3&&void 0!==arguments[3]?arguments[3]:2)},e.scopeRandom=function(e,t){return Math.floor(Math.random()*(t-e)+e)},e.similar=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;if(!e||!t)return 0;if(e===t)return 100;var n,o,i,a,u,c,s,l=e.length>t.length?e.length:t.length,f=e.length,h=t.length,d=[];if(0===f)return h;if(0===h)return f;for(n=0;n<=f;n++)d[n]=[],d[n][0]=n;for(o=0;o<=h;o++)d[0][o]=o;for(n=1;n<=f;n++)for(i=e.charAt(n-1),o=1;o<=h;o++)a=i===t.charAt(o-1)?0:1,d[n][o]=(u=d[n-1][o]+1,c=d[n][o-1]+1,s=d[n-1][o-1]+a,u<c?u<s?u:s:c<s?c:s);var p=100*(1-d[f][h]/l);return Number(p.toFixed(r))},e.sleep=M,e.sortCallBackChinese=function(e){return function(t,r){return t[e].localeCompare(r[e],"zh")}},e.sortCallBackTime=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return function(r,n){var o=t?1:-1;return new Date(y(n[e])).getTime()-new Date(y(r[e])).getTime()>0?1*o:-1*o}},e.sorterCallBack=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return function(r,n){return r[e]>n[e]?t?1:-1:t?-1:1}},e.throttle=function(e){var t,r,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500,i=arguments.length>2?arguments[2]:void 0,a=0;i||(i={leading:!1,trailing:!0});var u=function(){a=!1===i.leading?0:(new Date).getTime(),t=null,e.apply(r,n),t||(r=n=null)};return function(){for(var n=arguments.length,c=new Array(n),s=0;s<n;s++)c[s]=arguments[s];var l=(new Date).getTime();a||!1!==i.leading||(a=l);var f=o-(l-a);r=null,f<=0||f>o?(t&&(clearTimeout(t),t=null),a=l,e.apply(r,c),t||(r=c=null)):t||!1===i.trailing||(t=setTimeout(u,f))}},e.timeFormat=function(e){var t,r=new Date(e),n=new Date,o=r.getFullYear(),i=r.getMonth()+10,a=r.getDate(),u=r.getHours(),c=r.getMinutes(),s=n.getFullYear(),l=n.getHours();if(o<s)t=o+"年"+i+"月"+a+"日 "+u+":"+c;else{var f=(n.getTime()-r.getTime())/36e5;if(f>l)t=i+"月"+a+"日 "+u+":"+c;else if(f>=1)t="今天 "+u+":"+c+"分";else{var h=n.getMinutes()-c;t=h>1?h+"分钟前":"刚刚"}}return t},e.trim=L,e.uniqueArray=function(e){if(!Array.isArray(e))throw new Error("The first parameter must be an array");return 1==e.length?e:f(new Set(e))},e.uniqueId=function(){var e=Math.random,t=parseInt;return Number(new Date).toString()+t((10*e()).toString())+t((10*e()).toString())+t((10*e()).toString())},e.urlByObj=function(e){var t={},r=e.match(/[?&][^?&]+=[^?&]+/g);return r&&r.forEach((function(e){var r=e.substring(1).split("="),n=decodeURIComponent(r[0]),o=decodeURIComponent(r[1]);t[n]=o})),t},e.uuid=function(e,t){t=t||"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";for(var r="",n=e=e||8;n>0;--n)r+=t[Math.floor(Math.random()*t.length)];return r},e.versionCount=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:99,r=e.split(".").map((function(e){return Number(e)})),n=r.some((function(e){return isNaN(e)})),o=!0;return n?e:((r=r.reverse()).forEach((function(e,n){o&&(e>=t?r[n]=0:(o=!1,r[n]=r[n]+1))})),r.reverse().join("."))}}));