wangs-utils
Version:
``` npm i wangs-utils ```
2 lines (1 loc) • 21.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).wang={})}(this,function(t){"use strict";function r(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function u(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t){return function(t){if(Array.isArray(t))return c(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return c(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Map"===(n="Object"===n&&t.constructor?t.constructor.name:n)||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(t,e):void 0}}(t)||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 c(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function f(t,e){(e=null==e?window:e).tempFn=t;for(var n=arguments.length,r=new Array(2<n?n-2:0),o=2;o<n;o++)r[o-2]=arguments[o];t=e.tempFn.apply(e,r);return delete e.tempFn,t}function e(t,e,n){for(var r=n,o=0;o<t.length;o++)r=e(r,t[o],o);return r}function s(t,e){for(var n=[],r=0;r<t.length;r++){var o=t[r];e(o,r)&&n.push(o)}return n}function n(t,e){for(var n=0;n<t.length;n++)if(e(t[n],n))return!0;return!1}function l(t){for(var e=a(t),n=arguments.length,r=new Array(1<n?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return r.forEach(function(t){Array.isArray(t)?e.push.apply(e,a(t)):e.push(t)}),e}function p(t){switch(Object.prototype.toString.call(t)){case"[object Boolean]":return"bool";case"[object Number]":return"number";case"[object String]":return"string";case"[object Undefined]":return"undefined";case"[object Null]":return"null";case"[object Array]":return"array";case"[object Object]":return"object";case"[object Function]":return"function";case"[object Date]":return"date";case"[object RegExp]":return"regExp";case"[object Error]":return"error";case"[object Symbol]":return"symbol";case"[object Promise]":return"promise";case"[object Set]":return"set";default:return"sorry! unrecognized"}}function h(t,e){var n,r,o,u;if(arguments.length<1)return!0;for(n=1,r=arguments.length;n<r;n++)if(o=[],u=[],!function t(e,n){if(isNaN(e)&&isNaN(n)&&"number"==typeof e&&"number"==typeof n)return 1;if(e===n)return 1;if("function"==typeof e&&"function"==typeof n||e instanceof Date&&n instanceof Date||e instanceof RegExp&&n instanceof RegExp||e instanceof String&&n instanceof String||e instanceof Number&&n instanceof Number)return e.toString()===n.toString();if(e instanceof Object&&n instanceof Object&&!e.isPrototypeOf(n)&&!n.isPrototypeOf(e)&&e.constructor===n.constructor&&e.prototype===n.prototype&&!(-1<o.indexOf(e)||-1<u.indexOf(n))){for(var r in n){if(n.hasOwnProperty(r)!==e.hasOwnProperty(r))return;if(i(n[r])!==i(e[r]))return}for(r in e){if(n.hasOwnProperty(r)!==e.hasOwnProperty(r))return;if(i(n[r])!==i(e[r]))return;switch(i(e[r])){case"object":case"function":if(o.push(e),u.push(n),!t(e[r],n[r]))return;o.pop(),u.pop();break;default:if(e[r]!==n[r])return}}return 1}}(t,arguments[n]))return!1;return!0}function g(t){for(var e=[],n=arguments.length,r=new Array(1<n?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];for(var u=0;u<t.length;u++){var i=t[u];-1!==r.indexOf(i)&&(t.splice(u,1),e.push(i),u--)}return e}function y(t){return t.split("").reverse().join("")}function v(t){var u=t.url,e=t.method,i=void 0===e?"GET":e,e=t.params,a=void 0===e?{}:e,t=t.data,c=void 0===t?{}:t;return new Promise(function(n,r){i=i.toUpperCase();var e="";Object.keys(a).forEach(function(t){e+="".concat(t,"=").concat(a[t],"&")}),e&&(e=e.substring(0,e.length-1),u+="?"+e);var o=new XMLHttpRequest;o.open(i,u,!0),"GET"===i?o.send():"POST"!==i&&"PUT"!==i&&"DELETE"!==i||(o.setRequestHeader("Content-Type","application/json;charset=utf-8"),o.send(JSON.stringify(c))),o.onreadystatechange=function(){var t,e;4===o.readyState&&(t=o.status,e=o.statusText,200<=t&&t<=299?(e={data:JSON.parse(o.response),status:t,statusText:e},n(e)):r(new Error("request error status is "+t)))}})}v.get=function(t,e){return v(Object.assign(e,{url:t,method:"GET"}))},v.delete=function(t,e){return v(Object.assign(e,{url:t,method:"DELETE"}))},v.post=function(t,e,n){return v(Object.assign(n,{url:t,data:e,method:"POST"}))},v.put=function(t,e,n){return v(Object.assign(n,{url:t,data:e,method:"PUT"}))};var d={},b={};d.on=function(t,e){var n=b[t];n?n.push(e):b[t]=[e]},d.emit=function(t,e){t=b[t];t&&0<t.length&&t.forEach(function(t){t(e)})},d.off=function(t){t?delete b[t]:b={}};var m="pending",O="resolved",w="rejected";function j(t){var n=this;function e(e){n.status===m&&(n.status=w,n.data=e,0<n.callbacks.length&&setTimeout(function(){n.callbacks.forEach(function(t){t.onRejected(e)})}))}n.status=m,n.data=void 0,n.callbacks=[];try{t(function(e){n.status===m&&(n.status=O,n.data=e,0<n.callbacks.length&&setTimeout(function(){n.callbacks.forEach(function(t){t.onResolved(e)})}))},e)}catch(t){console.log("-----"),e(t)}}j.prototype.then=function(o,u){var i=this;return o="function"==typeof o?o:function(t){return t},u="function"==typeof u?u:function(t){throw t},new j(function(n,r){function e(t){try{var e=t(i.data);e instanceof j?e.then(function(t){return n(t)},function(t){return r(t)}):n(e)}catch(t){r(t)}}i.status===O?setTimeout(function(){e(o)}):i.status===w?setTimeout(function(){e(u)}):i.callbacks.push({onResolved:function(t){e(o)},onRejected:function(t){e(u)}})})},j.prototype.catch=function(t){return this.then(void 0,t)},j.resolve=function(n){return new j(function(t,e){n instanceof j?n.then(t,e):t(n)})},j.reject=function(n){return new j(function(t,e){e(n)})},j.all=function(i){return new j(function(n,r){var o=0,u=new Array(i.length);i.forEach(function(t,e){t.then(function(t){o++,u[e]=t,o===i.length&&n(u)},function(t){return r(t)})})})},j.race=function(t){return new j(function(e,n){t.forEach(function(t){t.then(e,n)})})},j.resolveDelay=function(n,r){return new j(function(t,e){setTimeout(function(){n instanceof j?n.then(t,e):t(n)},r)})},j.rejectDelay=function(n,r){return new j(function(t,e){setTimeout(function(){e(n)},r)})};var S={},E={},A=0;function k(t){for(var e=t.length,n=e;1<n;){n=Math.floor(n/2),console.log(n);for(var r=n;r<e;r++){for(var o=t[r],u=r-n;0<=u&&t[u]>o;)t[u+n]=t[u],u-=n;t[u+n]=o}}return t}S.subscribe=function(t,e){var n="token_"+ ++A,r=E[t];return r?r[n]=e:E[t]=u({},n,e),n},S.publish=function(t,e){var n=E[t];n&&setTimeout(function(){Object.values(n).forEach(function(t){t(e)})},0)},S.publishSync=function(t,e){t=E[t];t&&Object.values(t).forEach(function(t){t(e)})},S.unsubscribe=function(e){if(void 0===e)E={};else{if("string"!=typeof e)throw new Error("如果传入参数, 必须是字符串类型");var t;0===e.indexOf("token_")?(t=Object.values(E).find(function(t){return t.hasOwnProperty(e)}))&&delete t[e]:delete E[e]}},console.log(k([5,7,9,3,2,6,10,1]));var x=new(function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.ls=window.localStorage,this.ss=window.sessionStorage}var e,n,r;return e=t,(n=[{key:"setCookie",value:function(t,e,n){var r,o=t;if("Object"===Object.prototype.toString.call(o).slice(8,-1))for(var u in o)(r=new Date).setDate(r.getDate()+n),document.cookie=u+"="+o[u]+";expires="+r;else(r=new Date).setDate(r.getDate()+n),document.cookie=t+"="+e+";expires="+r}},{key:"getCookie",value:function(t){for(var e=document.cookie.split("; "),n=0;n<e.length;n++){var r=e[n].split("=");if(r[0]==t)return r[1]}return""}},{key:"removeCookie",value:function(t){this.setCookie(t,1,-1)}},{key:"setLocal",value:function(t,e){var n=t;if("Object"===Object.prototype.toString.call(n).slice(8,-1))for(var r in n)this.ls.setItem(r,JSON.stringify(n[r]));else this.ls.setItem(t,JSON.stringify(e))}},{key:"getLocal",value:function(t){return t?JSON.parse(this.ls.getItem(t)):null}},{key:"removeLocal",value:function(t){this.ls.removeItem(t)}},{key:"clearLocal",value:function(){this.ls.clear()}},{key:"setSession",value:function(t,e){var n=t;if("Object"===Object.prototype.toString.call(n).slice(8,-1))for(var r in n)this.ss.setItem(r,JSON.stringify(n[r]));else this.ss.setItem(t,JSON.stringify(e))}},{key:"getSession",value:function(t){return t?JSON.parse(this.ss.getItem(t)):null}},{key:"removeSession",value:function(t){this.ss.removeItem(t)}},{key:"clearSession",value:function(){this.ss.clear()}}])&&o(e.prototype,n),r&&o(e,r),t}());t.PriorityQueue=function(){var o=[];function u(t,e){this.data=t,this.priority=e}this.enqueue=function(t,e){if(e<0||100<e)throw new Error("优先级值必须在0到100之间");var n=new u(t,e);if(0===o.length)o.push(n);else{for(var r=0;r<o.length;r++)if(o[r].priority>e)return void o.splice(r,0,n);o.push(n)}},this.dequeue=function(){return o.shift()},this.front=function(){return o[0]},this.size=function(){return o.length},this.isEmpty=function(){return 0===o.length}},t.Promise=j,t.PubSub=S,t.Queue=function(){var e=[];this.enqueue=function(t){e.push(t)},this.dequeue=function(){return e.shift()},this.front=function(){return e[0]},this.size=function(){return e.length},this.isEmpty=function(){return 0===e.length}},t.Stack=function(){var e=[];this.push=function(t){e.push(t)},this.pop=function(){return e.pop()},this.peek=function(){return e[e.length-1]},this.size=function(){return e.length},this.isEmpty=function(){return 0===e.length},this.clear=function(){e=[]}},t.amountToChinese=function(t){var e,n,r,o=Math.round(100*t)+"",u="",i="",a="零壹贰叁肆伍陆柒捌玖",c="万仟佰拾亿仟佰拾万仟佰拾元角分",f=o.length,s=0;if("-"===o.substr(0,1)?(u="负",o=o.substr(1,o.length)):"+"===o.substr(0,1)&&(o=o.substr(1,o.length)),15<f)return t;if("0"===o)return i="零元整";for(var c=c.substr(c.length-f,f),l=0;l<c.length;l++)r=parseInt(o.substr(l,1),10),l!==f-3&&l!==f-7&&l!==f-11&&l!==f-15?0===r?(n=e="",s+=1):s=(n=(e=0!==r&&0!==s?"零"+a.substr(r,1):a.substr(r,1),c.substr(l,1)),0):(0!==r&&0!==s?(e="零"+a.substr(r,1),n=c.substr(l,1),s=0):0!==r&&0===s?(e=a.substr(r,1),n=c.substr(l,1),s=0):(n=0===r&&3<=s?e="":(e="",c.substr(l,1)),s+=1),l!==f-11&&l!==f-3||(n=c.substr(l,1))),i=i+e+n;return 0===r&&(i+="整"),u+i},t.apply=function(t,e,n){return(e=null==e?window:e).tempFn=t,n=e.tempFn.apply(e,a(n)),delete e.tempFn,n},t.axios=v,t.bind=function(r,o){for(var t=arguments.length,u=new Array(2<t?t-2:0),e=2;e<t;e++)u[e-2]=arguments[e];return function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return f.apply(void 0,[r,o].concat(u,e))}},t.browserType=function(){var t=navigator.userAgent,e=-1<t.indexOf("Opera"),n=-1<t.indexOf("compatible")&&-1<t.indexOf("MSIE")&&!e,r=-1<t.indexOf("Trident")&&-1<t.indexOf("rv:11.0"),o=-1<t.indexOf("Edge")&&!n,u=-1<t.indexOf("Firefox"),i=-1<t.indexOf("Safari")&&-1==t.indexOf("Chrome"),a=-1<t.indexOf("Chrome")&&-1<t.indexOf("Safari");if(n){new RegExp("MSIE (\\d+\\.\\d+);").test(t);t=parseFloat(RegExp.$1);return 7==t?"IE7":8==t?"IE8":9==t?"IE9":10==t?"IE10":"IE7以下"}return r?"IE11":o?"Edge":u?"FF":e?"Opera":i?"Safari":a?"Chrome":void 0},t.bubbleSort=function(t){for(var e=t.length-1;0<e;e--)for(var n,r=0;r<e;r++)t[r]>t[r+1]&&(n=[t[r],t[r+1]],t[r+1]=n[0],t[r]=n[1]);return t},t.call=f,t.changeCase=function(t,e){switch(e=e||4){case 1:return t.replace(/\b\w+\b/g,function(t){return t.substring(0,1).toUpperCase()+t.substring(1).toLowerCase()});case 2:return t.replace(/\b\w+\b/g,function(t){return t.substring(0,1).toLowerCase()+t.substring(1).toUpperCase()});case 3:return t.split("").map(function(t){return/[a-z]/.test(t)?t.toUpperCase():t.toLowerCase()}).join("");case 4:return t.toUpperCase();case 5:return t.toLowerCase();default:return t}},t.chunk=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1,n=[],r=[];return 0===t.length||(e<1&&(e=1),t.forEach(function(t){0===r.length&&n.push(r),r.push(t),r.length===e&&(r=[])})),n},t.clone=function(t){return t instanceof Array?t.reduce(function(t,e){return t.push(e),t},[]):null!==t&&"object"===i(t)?function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach(function(t){u(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({},t):t},t.compact=function(t){return s(t,function(t){return t})},t.compareArr=function t(e,n){if("array"!=p(e)||"array"!=p(n))return"参数错误";if(e===n)return!0;if(e.length!=n.length)return!1;for(var r in e){if(p(e[r])!=p(n[r]))return!1;if("object".includes(p(e[r]))){if(!h(e[r],n[r]))return!1}else if("array"==p(e[r]))t(e[r],n[r]);else if(e[r]!=n[r])return!1}return!0},t.compareObj=h,t.concat=l,t.dateByday=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"-",n=new Date,r=n.getTime();return n.setTime(parseInt(r+864e5*t)),r=n.getFullYear(),(t=(n.getMonth()+1).toString()).length<=1&&(t="0"+t),n=n.getDate().toString(),r+e+t+e+(n=n.length<=1?"0"+n:n)},t.debounce=function(n,r){return function(t){var e=this;n.hasOwnProperty("timeoutId")&&clearTimeout(n.timeoutId),n.timeoutId=setTimeout(function(){n.call(e,t),delete n.timeoutId},r)}},t.deepClone=function n(t){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:new Map;if(t instanceof Array||null!==t&&"object"===i(t)){var o=r.get(t);if(o)return o;if(t instanceof Array)o=[],r.set(t,o),t.forEach(function(t,e){o[e]=n(t,r)});else for(var e in o={},r.set(t,o),t)t.hasOwnProperty(e)&&(o[e]=n(t[e],r));return o}return t},t.deepClone1=function(t){return JSON.parse(JSON.stringify(t))},t.deepClone2=function t(e){if(e instanceof Array||null!==e&&"object"===i(e)){var n,r=e instanceof Array?[]:{};for(n in e)e.hasOwnProperty(n)&&(r[n]=t(e[n]));return r}return e},t.deepClone3=function t(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:new Map;if(e instanceof Array||null!==e&&"object"===i(e)){var r,o=n.get(e);if(o)return o;for(r in o=e instanceof Array?[]:{},n.set(e,o),e)e.hasOwnProperty(r)&&(o[r]=t(e[r],n));return o}return e},t.deepFlatten=function(t){var e,n=this;return Array.isArray(t)?(e=t.map(function(t){return Array.isArray(t)?n.deepFlatten(t):t}),(t=[]).concat.apply(t,a(e))):[]},t.difference=function(t,e){return 0===t.length?[]:0===e.length?a(t):s(t,function(t){return-1===e.indexOf(t)})},t.differences=function(t){for(var e=arguments.length,r=new Array(1<e?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];return 0===t.length?[]:0===r.length?a(t):s(t,function(t){for(var e=!0,n=0;n<r.length;n++)if(-1!==r[n].indexOf(t)){e=!1;break}return e})},t.drop=function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1;return 0==t.length?[]:(n<1&&(n=1),t.filter(function(t,e){return n<=e}))},t.dropRight=function(n){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1;return 0==n.length?[]:(r<1&&(r=1),n.filter(function(t,e){return e<n.length-r}))},t.eventBus=d,t.every=function(t,e){for(var n=0;n<t.length;n++)if(!e(t[n],n))return!1;return!0},t.extractTree=function(t,r,e){var o=[];if(!Array.isArray(t)&&!t.length)return[];if("string"!=typeof r)return[];!Array.isArray(e)||Array.isArray(e)&&!e.length?(o=Object.keys(t[0])).splice(o.indexOf(r),1):o=e;var u=[];return function t(e){return e.forEach(function(e){var n={};o.forEach(function(t){n[t]=e[t]}),u.push(n),e[r]&&t(e[r])}),u}(t)},t.filter=s,t.find=function(t,e){for(var n=0;n<t.length;n++){var r=t[n];if(e(r,n))return r}},t.findIndex=function(t,e){for(var n=0;n<t.length;n++)if(e(t[n],n))return n;return-1},t.flatten1=function n(t){return e(t,function(t,e){return Array.isArray(e)?t=l(t,n(e)):t.push(e),t},[])},t.flatten2=function(t){for(var e=l.apply(void 0,[[]].concat(a(t)));n(e,function(t){return Array.isArray(t)});)e=l.apply(void 0,[[]].concat(a(e)));return e},t.formatAmount=function(t){if(isNaN(t))return!1;amounts=Math.abs(t),amounts=""+Number(amounts).toFixed(2);for(var e=(n=amounts.split("."))[0],n="."+n[1],r=/(\d+)(\d{3})/;r.test(e);)e=e.replace(r,"$1,$2");return 0<t?e+n:"-"+e+n},t.formatFloat=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1,n=2<arguments.length?arguments[2]:void 0,r=parseFloat(t);if(isNaN(r))return!1;var o=(r="ceil"===n?Math.ceil(t*Math.pow(10,e))/Math.pow(10,e):"floor"===n?Math.floor(t*Math.pow(10,e))/Math.pow(10,e):Math.round(t*Math.pow(10,e))/Math.pow(10,e)).toString(),u=o.indexOf(".");for(u<0&&(u=o.length,o+=".");o.length<=u+e;)o+="0";return o},t.getDate=function(t,e){if(t&&isNaN(t))return!1;if((t+"").includes("."))return!1;function n(t){return t<10?"0"+t:t}t=t||(new Date).getTime();var r=(t=new Date(Number(t))).getFullYear(),o=t.getMonth()+1,u=t.getDate(),i=t.getHours(),a=t.getMinutes(),c=t.getSeconds();switch(e){case"year":return r;case"month":return r+"-"+n(o);case"day":return r+"-"+n(o)+"-"+n(u);case"hour":return r+"-"+n(o)+"-"+n(u)+" "+n(i);case"minute":return r+"-"+n(o)+"-"+n(u)+" "+n(i)+":"+n(a);default:return r+"-"+n(o)+"-"+n(u)+" "+n(i)+":"+n(a)+":"+n(c)}},t.getQuery=function(t){var e={};arr=t.split("?")[1].split("&");for(var n=0;n<arr.length;n++){var r=arr[n].split("="),o=r[0],r=r[1];e[o]=r}return e},t.insertSort=function(t){for(var e=t.length,n=1;n<e;n++){for(var r=t[n],o=n-1;0<=o&&t[o]>r;)t[o+1]=t[o],o--;t[o+1]=r}return t},t.makeTree=function(t,i,a){var e=t.filter(function(t){return 0===t[i]});return function o(t,u){t.map(function(r){u.map(function(t,e){var n;t[i]===r.id&&((n=JSON.parse(JSON.stringify(u))).splice(e,1),o([t],n),r[a]?r[a].push(t):r[a]=[t])})})}(e,t.filter(function(t){return 0!==t[i]})),e},t.map=function(t,e){for(var n=[],r=0;r<t.length;r++){var o=e(t[r],r);n.push(o)}return n},t.mergeArray=function(t){for(var e=a(t),n=arguments.length,r=new Array(1<n?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return 0===r.length||r.forEach(function(t){t.forEach(function(t){-1===e.indexOf(t)&&e.push(t)})}),e},t.mergeObject=function(){for(var r={},t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return e.forEach(function(n){Object.keys(n).forEach(function(t){var e=n[t];r.hasOwnProperty(t)?r[t]=l([],r[t],e):r[t]=e})}),r},t.myInstanceOf=function(t,e){for(var n=t.__proto__;null!==n;){if(n===e.prototype)return!0;n=n.__proto__}return!1},t.newInstance=function(t){for(var e={},n=arguments.length,r=new Array(1<n?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];var u=t.apply(e,r);return u instanceof Object?u:(e.__proto__=t.prototype,e)},t.numToChinese=function(t){for(var e=new Array("零","一","二","三","四","五","六","七","八","九","十"),n=new Array("","十","百","仟","萬","億","点",""),r=(""+t).replace(/(^0*)/g,"").split("."),o=0,u="",i=r[0].length-1;0<=i;i--){switch(o){case 0:u=n[7]+u;break;case 4:new RegExp("0{4}//d{"+(r[0].length-i-1)+"}$").test(r[0])||(u=n[4]+u);break;case 8:u=n[5]+u,n[7]=n[5],o=0}o%4==2&&0!=r[0].charAt(i+2)&&0==r[0].charAt(i+1)&&(u=e[0]+u),0!=r[0].charAt(i)&&(u=e[r[0].charAt(i)]+n[o%4]+u),o++}if(1<r.length){u+=n[6];for(i=0;i<r[1].length;i++)u+=e[r[1].charAt(i)]}return u=(u="一十"==u?"十":u).match(/^一/)&&3==u.length?u.replace("一",""):u},t.palindrome=function(t){return t===y(t)},t.pull=g,t.pullAll=function(t,e){return g.apply(void 0,[t].concat(a(e)))},t.random=function(t,e){return 2===arguments.length?Math.floor(t+Math.random()*(e+1-t)):null},t.reduce=e,t.reverseString=y,t.selectSort=function(t){for(var e=t.length,n=0;n<e-1;n++){for(var r,o=n,u=n+1;u<e;u++)t[o]>t[u]&&(o=u);o!==n&&(r=[t[o],t[n]],t[n]=r[0],t[o]=r[1])}return t},t.shellSort=k,t.slice=function(t,e,n){var r=[];if(0===t.length)return r;(n=n||t.length)>t.length&&(n=t.length);for(var o=e=(e=e||0)<0?0:e;o<n;o++)r.push(t[o]);return r},t.some=n,t.stampInterval=function(t,e){var n=e<t?t:e,r=e<t?e:t,e=[0,0,0,0],t="",r=r<n?parseInt((n-r)/1e3):0;return e[0]=86400<r?parseInt(r/86400):0,r-=86400*e[0],e[1]=3600<r?parseInt(r/3600):0,r-=3600*e[1],e[2]=60<r?parseInt(r/60):0,e[3]=r-60*e[2],t=0<e[0]?e[0]+"天":"",t+=e[0]<=0&&e[1]<=0?"":e[1]+"小时",(t+=e[0]<=0&&e[1]<=0&&e[2]<=0?"":e[2]+"分钟")+(e[0]<=0&&e[1]<=0&&e[2]<=0&&e[3]<=0?"":e[3]+"秒")},t.storage=x,t.sumBigNumber=function(t,e){var n="",r=0;for(t=t.split(""),e=e.split("");t.length||e.length||r;)n=(r+=~~t.pop()+~~e.pop())%10+n,r=9<r;return n.replace(/^0+/,"")},t.throttle=function(n,r){var o=0;return function(t){console.log("事件 throttle");var e=Date.now();r<e-o&&(n.call(this,t),o=e)}},t.trim=function(t,e){switch(e=e||1){case 1:return t.replace(/\s+/g,"");case 2:return t.replace(/(^\s*)|(\s*$)/g,"");case 3:return t.replace(/(^\s*)/g,"");case 4:return t.replace(/(\s*$)/g,"");default:return t}},t.truncate=function(t,e){return t.length>e?t.substring(0,e)+"...":t},t.unique=function(t){var e=[],n={};return t.forEach(function(t){n.hasOwnProperty(t)||(e.push(t),n[t]=!0)}),e},t.uniqueByAttr=function(t,n){var r={};return t.reduce(function(t,e){return r[e[n]]||(r[e[n]]=t.push(e)),t},[])},Object.defineProperty(t,"__esModule",{value:!0})});