-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.min.umd.js
6 lines (6 loc) · 18.2 KB
/
index.min.umd.js
1
2
3
4
5
6
/*!
* toolkit-use v0.1.4
* (c) 2023 ~ 至今 kennana
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("clipboard"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.set.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.array.from.js"),require("core-js/modules/es.array.includes.js"),require("core-js/modules/es.regexp.exec.js"),require("core-js/modules/es.regexp.test.js"),require("core-js/modules/es.string.replace.js"),require("core-js/modules/es.regexp.constructor.js"),require("core-js/modules/es.regexp.sticky.js"),require("core-js/modules/es.regexp.to-string.js"),require("core-js/modules/es.parse-int.js"),require("core-js/modules/es.number.constructor.js"),require("core-js/modules/es.array.slice.js"),require("core-js/modules/web.url.js"),require("core-js/modules/web.url-search-params.js"),require("core-js/modules/es.string.pad-start.js"),require("core-js/modules/es.parse-float.js"),require("core-js/modules/es.object.get-prototype-of.js"),require("core-js/modules/es.json.stringify.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.array.index-of.js"),require("core-js/modules/es.array.splice.js"),require("core-js/modules/es.object.define-property.js"),require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.string.split.js"),require("core-js/modules/es.array.filter.js"),require("crypto-js")):"function"==typeof define&&define.amd?define(["exports","clipboard","core-js/modules/es.array.iterator.js","core-js/modules/es.object.to-string.js","core-js/modules/es.set.js","core-js/modules/es.string.iterator.js","core-js/modules/web.dom-collections.iterator.js","core-js/modules/es.array.from.js","core-js/modules/es.array.includes.js","core-js/modules/es.regexp.exec.js","core-js/modules/es.regexp.test.js","core-js/modules/es.string.replace.js","core-js/modules/es.regexp.constructor.js","core-js/modules/es.regexp.sticky.js","core-js/modules/es.regexp.to-string.js","core-js/modules/es.parse-int.js","core-js/modules/es.number.constructor.js","core-js/modules/es.array.slice.js","core-js/modules/web.url.js","core-js/modules/web.url-search-params.js","core-js/modules/es.string.pad-start.js","core-js/modules/es.parse-float.js","core-js/modules/es.object.get-prototype-of.js","core-js/modules/es.json.stringify.js","core-js/modules/es.object.keys.js","core-js/modules/es.array.index-of.js","core-js/modules/es.array.splice.js","core-js/modules/es.object.define-property.js","core-js/modules/es.array.concat.js","core-js/modules/es.string.split.js","core-js/modules/es.array.filter.js","crypto-js"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["/src/index"]=e["/src/index"]||{},e["/src/index"].ts={}),e.Clipboard,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,e.CryptoJS)}(this,(function(e,t,r,n,o,s,a,i,u,l,c,f,d,p,g,m,y,j,h,b,v,w,S,E,x,k,D,A,T,R,q,O){"use strict";function C(e){return C="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},C(e)}function M(e){var t=function(e,t){if("object"!==C(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==C(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===C(t)?t:String(t)}function L(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,M(n.key),n)}}function N(e,t,r){return(t=M(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var P=function(){function e(r){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),N(this,"_data",""),N(this,"_class",""),N(this,"_clipboard",void 0),N(this,"_options",void 0),this._class=r.className,this._data=r.message,console.log("options",r,this._class),this._clipboard=new t(this._class,{text:function(){return n._data}}),this._options=r}var r,n,o;return r=e,(n=[{key:"copy",value:function(){var e=this;return this._clipboard.on("success",(function(){e._options.onSuccess&&e._options.onSuccess(),e._clipboard.destroy()})),this._clipboard.on("error",(function(){e._options.onError&&e._options.onError(),e._clipboard.destroy()})),this._clipboard}}])&&L(r.prototype,n),o&&L(r,o),Object.defineProperty(r,"prototype",{writable:!1}),e}(),$={uniqueOptionsArr:function(e,t){for(var r={},n=[],o=0;o<e.length;o++)r[e[o][t]]||(n.push(e[o]),r[e[o][t]]=!0);return n},uniqueValueArr:function(e){var t=new Set(e);return Array.from(t)},deepClone:function(e){if([null,void 0,NaN,!1].includes(e)||"object"!==C(e)&&"function"!=typeof e)return e;var t=Array.isArray(e)?[]:{};for(var r in e)t[r]="object"===C(e[r])?$.deepClone(e[r]):e[r];return t}},Z={formatDate:function(e,t){var r={"M+":(e=new Date(e)).getMonth()+1,"d+":e.getDate(),"h+":e.getHours()%12==0?12:e.getHours()%12,"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};for(var n in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,e.getFullYear().toString().substr(4-RegExp.$1.length))),/(E+)/.test(t)&&(t=t.replace(RegExp.$1,(RegExp.$1.length>1?RegExp.$1.length>2?"星期":"周":"")+{0:"日",1:"一",2:"二",3:"三",4:"四",5:"五",6:"六"}[e.getDay().toString()+""])),r)new RegExp("("+n+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?r[n]+"":("00"+r[n]).substr((""+r[n]).length)));return t},isLeap:function(e){return e%4==0&&e%100!=0||e%400==0},getWeek:function(e){return["日","一","二","三","四","五","六"][new Date(e).getDay()]},getMonthDays:function(e,t){if((t=parseInt(String(t))-1)<0||t>11)return 0;var r=[31,28,31,30,31,30,31,31,30,31,30,31];return Z.isLeap(e)&&(r[1]=29),r[t]},padLeftZero:function(e){var t=parseInt(String(e));return t>9?t:"0"+t},getToday:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"yyyy-mm-dd",r=new Date,n=r.getFullYear(),o=Z.padLeftZero(r.getMonth()+1),s=Z.padLeftZero(r.getDate()),a=Z.padLeftZero(r.getHours()),i=Z.padLeftZero(r.getMinutes()),u=Z.padLeftZero(r.getSeconds());switch(t){case"yyyy-mm-dd":e=n+"-"+o+"-"+s;break;case"mm-dd-yyyy":e=o+"-"+s+"-"+n;break;case"yyyy-mm-dd hh:MM:ss":e=n+"-"+o+"-"+s+" "+a+":"+i+":"+u;break;case"hh:MM:ss":e=a+":"+i+":"+u;break;case"yyyy":e=n;break;case"mm":e=o;break;case"dd":e=s;break;case"hh":e=a;break;case"MM":e=i;break;case"ss":e=u;break;case"mm-dd":e=o+"-"+s;break;default:e="参数错误"}return e},getYesterday:function(e){var t=e.split("-"),r=parseInt(t[0]),n=parseInt(t[1]),o=parseInt(t[2]);return n>12||n<1||o>Z.getMonthDays(r,n)?"日期不合法":(o-=1)>0?r+"-"+Z.padLeftZero(n)+"-"+Z.padLeftZero(o):(n-=1)>0?r+"-"+Z.padLeftZero(n)+"-"+Z.getMonthDays(r,n):(r-=1)+"-12-"+Z.getMonthDays(r,12)},getTomorrow:function(e){var t=e.split("-"),r=parseInt(t[0]),n=parseInt(t[1]),o=parseInt(t[2]);return n>12||n<1||o>Z.getMonthDays(r,n)?"日期不合法":(o+=1)<=Z.getMonthDays(r,n)?r+"-"+Z.padLeftZero(n)+"-"+Z.padLeftZero(o):(n+=1)<13?r+"-"+Z.padLeftZero(n)+"-01":(r+=1)+"-01-01"},beforeNDay:function(e,t){if(e.split("-").length<3)return"日期格式错误";var r=Z.formatDate(e,"yyyy-MM-dd HH:mm:ss");for(t=parseInt(String(t));t--;)r=Z.getYesterday(r);return r},afterNDay:function(e,t){if(e.split("-").length<3)return"日期格式错误";for(var r=Z.formatDate(e,"yyyy-MM-dd HH:mm:ss");t--;)r=Z.getTomorrow(r);return r}},_={transform:function(e,t){var r=0,n=Number(e);if(!isNaN(n)){var o=n.toString().split(".");if(o.length>1&&o[1].length>t)"5"===o[1].slice(t,t+1)&&(n+=Math.pow(.1,t+1)),r=n.toFixed(t);else r=n;r=Number(r)}return r},percent:function(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=_.transform(Number(100*e),t).toString();return r&&(n+="%"),n},point:function(e,t){var r=e.replace("%",""),n=Number(r)/100;return _.transform(n,t)}},U={frontUrlDownload:function(e,t){var r=document.createElement("a");r.href=e,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)},dataStreamDownloadExcelOrPdf:function(e,t,r,n){var o,s="";"pdf"===r&&(s=n||"application/pdf;chartset=utf-8",o="".concat(t,".pdf")),"excel"===r&&(s=n||"application/vnd.ms-excel;charset=utf-8",o="".concat(t,".xlsx"));var a=new Blob([e],{type:s});if("download"in document.createElement("a")){var i=document.createElement("a");i.download=o,i.style.display="none",i.href=URL.createObjectURL(a),document.body.appendChild(i),i.click(),URL.revokeObjectURL(i.href),document.body.removeChild(i)}else try{window.navigator.msSaveBlob(a,o)}catch(e){console.log(e)}}},H={padStartZero:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return String(e).padStart(t,"0")}},I={significantDigitsReg:/^[+-]?(0|([1-9]\d+))(\.\d+)?$/,chineseRealNameReg:/^[\u4E00-\u9FA5]{2,10}(·[\u4E00-\u9FA5]{2,10}){0,2}$/,identificationCardReg:/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{2})(\d)(\d|X)$/,identificationCardRegO:/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,phoneReg:/^1[34578]\d{9}$/,cryptographicStrengthReg:/^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/,emailReg:/^([a-z\d._-]+)@([a-z\d-]+)\.([a-z]{2,8})(\.[a-z]{2,8})?$/,emailRegO:/^\w+((-\w+)|(\.\w+))*@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/,urlReg:/^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/,ipV4Reg:/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,colorReg:/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,dateReg:/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/,qqReg:/^[1-9][0-9]{4,10}$/,wxReg:/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/,carReg:/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/,hanziReg:/^[\u4e00-\u9fa5]{0,}$/,hyphenateRE:/\B([A-Z])/g,camelizeRE:/-(\w)/g},z=function(e){return null!=e},F=function(e){return null!==e&&"object"===C(e)},B=Object.prototype.toString,J=Object.prototype.hasOwnProperty;function W(e){if("object"!==C(e)||null===e)return!1;var t=Object.getPrototypeOf(e);if(null===t)return!0;for(var r=t;null!==Object.getPrototypeOf(r);)r=Object.getPrototypeOf(r);return t===r}function V(e,t){for(var r in t)e[r]=t[r];return e}function Y(e){var t=Object.create(null);return function(r){return t[r]||(t[r]=e(r))}}var K=Y((function(e){return e.charAt(0).toUpperCase()+e.slice(1)})),X=Y((function(e){return e.replace(I.hyphenateRE,"-$1").toLowerCase()})),G=Y((function(e){return e.replace(I.camelizeRE,(function(e,t){return t?t.toUpperCase():""}))}));var Q=function e(t,r){if(t===r)return!0;var n=F(t),o=F(r);if(!n||!o)return!n&&!o&&String(t)===String(r);try{var s=Array.isArray(t),a=Array.isArray(r);if(s&&a)return t.length===r.length&&t.every((function(t,n){return e(t,r[n])}));if(t instanceof Date&&r instanceof Date)return t.getTime()===r.getTime();if(s||a)return!1;var i=Object.keys(t),u=Object.keys(r);return i.length===u.length&&i.every((function(n){return e(t[n],r[n])}))}catch(e){return!1}};var ee=Object.prototype.toString,te=function(e){return ee.call(e)},re=Array.isArray,ne=function(e){return"string"==typeof e},oe={isUndef:function(e){return null==e},isDef:z,isTrue:function(e){return!0===e},isFalse:function(e){return!1===e},isPrimitive:function(e){return"string"==typeof e||"number"==typeof e||"symbol"===C(e)||"boolean"==typeof e},isObject:F,isPromise:function(e){return z(e)&&"function"==typeof e.then&&"function"==typeof e.catch},toRawType:function(e){return B.call(e).slice(8,-1)},hasOwn:function(e,t){return J.call(e,t)},toNumber:function(e){var t=parseFloat(e);return isNaN(t)?e:t},isPlainObject:W,toString:function(e){return null==e?"":Array.isArray(e)||W(e)&&e.toString===B?JSON.stringify(e,null,2):String(e)},toArray:function(e,t){t=t||0;for(var r=e.length-t,n=new Array(r);r--;)n[r]=e[r+t];return n},extend:V,toObject:function(e){for(var t={},r=0;r<e.length;r++)e[r]&&V(t,e[r]);return t},cached:Y,capitalize:K,hyphenate:X,camelize:G,makeMap:function(e,t){for(var r=Object.create(null),n=e.split(","),o=0;o<n.length;o++)r[n[o]]=!0;return t?function(e){return r[e.toLowerCase()]}:function(e){return r[e]}},looseEqual:Q,remove:function(e,t){if(e.length){var r=e.indexOf(t);if(r>-1)return e.splice(r,1)}},looseCompareArrays:function(e,t){if(e.length!==t.length)return!1;for(var r=!0,n=0;r&&n<e.length;n++)r=Q(e[n],t[n]);return r},def:function(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,value:r})},objectToString:ee,toTypeString:te,isArray:re,isMap:function(e){return"[object Map]"===te(e)},isSet:function(e){return"[object Set]"===te(e)},isDate:function(e){return e instanceof Date},isFunction:function(e){return"function"==typeof e},isString:ne,isSymbol:function(e){return"symbol"===C(e)},isIntegerKey:function(e){return ne(e)&&"NaN"!==e&&"-"!==e[0]&&""+parseInt(e,10)===e},invokeArrayFns:function(e,t){for(var r=0;r<e.length;r++)e[r](t)},hasChanged:function(e,t){return!Object.is(e,t)}},se={addHandler:function(e,t,r){e.addEventListener?e.addEventListener(t,r,!1):e.attachEvent?e.attachEvent("on"+t,r):e["on"+t]=r},removeHandler:function(e,t,r){e.removeEventListener?e.removeEventListener(t,r,!1):e.detachEvent?e.detachEvent("on"+t,r):e["on"+t]=null},getEvent:function(e){return e||window.event},getTarget:function(e){return e.target||e.srcElement},preventDefault:function(e){e.preventDefault?e.preventDefault():e.returnValue=!1},stopPropagation:function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},getRelatedTarget:function(e){return e.relatedTarget?e.relatedTarget:e.toElement?e.toElement:e.fromElement?e.fromElement:null},getButton:function(e){if(document.implementation.hasFeature("MouseEvents","2.0"))return e.button;switch(e.button){case 0:case 1:case 3:case 5:case 7:return 0;case 2:case 6:return 2;case 4:return 1}},getWheelDelta:function(e){return e.wheelDelta?e.wheelDelta:40*-e.detail},getCharCode:function(e){return"number"==typeof e.charCode?e.charCode:e.keyCode}};var ae={getColor:function(){for(var e=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],t="",r=0;r<6;r++)t+=e[Math.floor(16*Math.random())];return t="#"+t},addHandler:se.addHandler,removeHandler:se.removeHandler,getEvent:se.getEvent,getTarget:se.getTarget,preventDefault:se.preventDefault,stopPropagation:se.stopPropagation,getRelatedTarget:se.getRelatedTarget,getButton:se.getButton,getWheelDelta:se.getWheelDelta,getCharCode:se.getCharCode,addClass:function(e,t){for(var r=e.className.split(" "),n=t.split(" "),o=r.concat(n),s=0;s<o.length;s++)for(var a=0;a<o.length-s-1;a++)o[s]==o[a]&&(o.splice(a,1),o.length--)},removeClass:function(e,t){var r,n,o=e.className.split(/\s+/),s=o.length;for(n=0;n<s;n++)if(o[n]==t){r=n;break}return o.splice(n,1),e.className=o.join(" "),r},getElementLeft:function(e){for(var t=e.offsetLeft,r=e.offsetParent;null!==r;)t+=r.offsetLeft,r=r.offsetParent;return t},getElementTop:function(e){for(var t=e.offsetTop,r=e.offsetParent;null!==r;)t+=r.offsetTop,r=r.offsetParent;return t},getOffset:function(e){for(var t={left:0,top:0};null!=e.offsetParent;)t.left+=e.offsetLeft,t.top+=e.offsetTop,e=e.offsetParent;return t},getViewport:function(){return"BackCompat"==document.compatMode?{width:document.body.clientWidth,height:document.body.clientHeight}:{width:document.documentElement.clientWidth,height:document.documentElement.clientHeight}},outputAttributes:function(e){for(var t,r,n=new Array,o=e.attributes.length,s=0;s<o;s++)e.attributes[s].specified&&(t=e.attributes[s].nodeName,r=e.attributes[s].nodeValue,n.push(t+'="'+r+'"'));return n.join(" ")},scrollToAims:function(e){var t=function(e){return Math.pow(e,3)},r=function(e){return e<.5?t(2*e)/2:1-t(2*(1-e))/2},n=document.documentElement,o=Date.now(),s=n.scrollTop,a=e?e.offsetTop-60:null,i=window.requestAnimationFrame||function(e){return setTimeout(e,16)};i((function e(){var t=(Date.now()-o)/500;t<1?(n.scrollTop=a?s+(a-s)*r(t):s*(1-r(t)),i(e)):n.scrollTop=a||0}))}},ie=O.enc.Utf8.parse("3333e6e143439161"),ue=O.enc.Utf8.parse("e3bbe7e3ba84431a"),le="localStorage",ce="SDF_0.0.1",fe=1,de=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(""!==t&&null!=t||(t=null),isNaN(r)||r<0)throw new Error("Expire must be a number");r=1e3*(r||fe);var n={value:t,time:Date.now(),expire:r},o=je(JSON.stringify(n));window[le].setItem(me(e),o)},pe=function(){for(var e=window[le].length,t=new Array,r=0;r<e;r++){var n=window[le].key(r),o=window[le].getItem(n);t[r]={key:n,val:o}}return t},ge=function(e){window[le].removeItem(me(e))},me=function(e){return ce+"_"+e},ye=function(e){var t=ce.length+1;return e.substr(t)},je=function(e){if("object"===C(e))try{e=JSON.stringify(e)}catch(e){console.log("encrypt error:",e)}var t=O.enc.Utf8.parse(e);return O.AES.encrypt(t,ie,{iv:ue,mode:O.mode.CBC,padding:O.pad.Pkcs7}).ciphertext.toString()},he=function(e){var t=O.enc.Hex.parse(e),r=O.enc.Base64.stringify(t),n=O.AES.decrypt(r,ie,{iv:ue,mode:O.mode.CBC,padding:O.pad.Pkcs7});return n.toString(O.enc.Utf8).toString()},be={isSupportStorage:function(){return"undefined"!=typeof Storage},setStorage:de,getStorage:function(e){if(e=me(e),!window[le].getItem(e)||"null"===JSON.stringify(window[le].getItem(e)))return null;var t=JSON.parse(he(window[le].getItem(e))),r=Date.now();return t.expire&&6e3*fe<r-t.time?(ge(e),null):(de(ye(e),t.value),t.value)},hasStorage:function(e){return e=me(e),!!pe().filter((function(t){return t.key===e})).length},getStorageKeys:function(){for(var e=pe(),t=[],r=0;r<e.length;r++){var n=e[r].key;t.push(n)}return t},getStorageForIndex:function(e){return window[le].key(e)},getStorageLength:function(){return window[le].length},getStorageAll:pe,removeStorage:ge,clearStorage:function(){window[le].clear()},autoAddPrefix:me,autoRemovePrefix:ye,encrypt:je,decrypt:he};e.ToolkitUseArray=$,e.ToolkitUseClipboard=P,e.ToolkitUseDate=Z,e.ToolkitUseDecimal=_,e.ToolkitUseDom=ae,e.ToolkitUseDownload=U,e.ToolkitUseRegex=I,e.ToolkitUseShared=oe,e.ToolkitUseStorage=be,e.ToolkitUseString=H}));