mu-utiljs
Version:
Web前端 JavaScript 常用函数库
1 lines • 4.78 kB
JavaScript
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.mu=t():n.mu=t()}(self,(function(){return function(){"use strict";var n={d:function(t,e){for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o:function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r:function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})}},t={};n.r(t),n.d(t,{countAudioTime:function(){return u},debounce:function(){return f},deepCopy:function(){return e},deepCopy2:function(){return r},getFileExt:function(){return p},getFileSize:function(){return y},getNowDate:function(){return o},is:function(){return g},isArray:function(){return b},isBoolean:function(){return N},isClient:function(){return U},isDate:function(){return S},isDef:function(){return w},isElement:function(){return $},isEmpty:function(){return m},isFunction:function(){return P},isMap:function(){return T},isNull:function(){return v},isNullAndUnDef:function(){return M},isNullOrUnDef:function(){return O},isNumber:function(){return A},isObject:function(){return h},isPad:function(){return z},isPromise:function(){return E},isRegExp:function(){return x},isServer:function(){return F},isString:function(){return B},isUnDef:function(){return j},isUrl:function(){return R},isWindow:function(){return D},offEvent:function(){return s},onEvent:function(){return a},query:function(){return l},throttle:function(){return i},throttle2:function(){return c}});const e=n=>{const t=(r=n,"[object Array]"===Object.prototype.toString.call(r)||Array.isArray(r)?[]:{});var r,o;for(const r in n)null!==(o=n[r])&&function(n,t){return"[object Object]"===toString.call(n)}(o)||"object"==typeof o&&null!==o?t[r]=e(n[r]):t[r]=n[r];return t};function r(n){return JSON.parse(JSON.stringify(n))}function o(n){const t=new Date;let e=Number.parseInt(t.getMonth())+1,r=t.getDate();return e=e.toString().length>1?e:`0${e}`,r=r.toString().length>1?r:`0${r}`,"yyyy"===n?t.getFullYear():"mm"===n?e:"dd"===n?r:`${t.getFullYear()}${e}${r}`}function u(n=0){const t="0"+Math.floor(n/60),e="0"+Math.floor(n-60*Number(t));return t.substr(-2)+":"+e.substr(-2)}const i=(n,t=300)=>{let e=null;return function(){const r=this,o=arguments;e||(e=setTimeout((function(){n.apply(r,o),e=null}),t))}},c=(n,t=300)=>{let e=0;return function(){const r=new Date,o=arguments;r-e>t&&(n.apply(this,o),e=r)}},f=(n,t=300)=>{let e=null;return function(){const r=this,o=arguments;clearTimeout(e),e=setTimeout((function(){n.apply(r,o)}),t)}},l=n=>{const t=window.location.search.substring(1);try{return new URLSearchParams(t).get(n||"")}catch(e){const r=new RegExp("(^|&)"+n+"=([^&]*)(&|$)"),o=t.match(r);return null!=o?decodeURI(o[2]):null}},a=(n,t,e,r=!1)=>{try{n.addEventListener(t,e,r)}catch(r){try{n.attachEvent("on"+t,e)}catch(r){console.error(r),n["on"+t]=e}}},s=(n,t,e,r=!1)=>{try{n.removeEventListener(t,e,r)}catch(r){try{n.detachEvent("on"+t,e.bind(n))}catch(e){console.error(e),n["on"+t]=null}}};function p(n){let t=n.split(".");return t[t.length-1]}function y(n){if(!n||""==n||null==n)return"0 Bytes";const t=parseFloat(n),e=new Array("Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"),r=Math.floor(Math.log(t)/Math.log(1024));return(t/Math.pow(1024,r)).toFixed(2)+e[r]}const d=Object.prototype.toString;function g(n,t){return d.call(n)===`[object ${t}]`}function b(n){return"[object Array]"===Object.prototype.toString.call(n)||Array.isArray(n)}function h(n){return null!==n&&g(n,"Object")||"object"==typeof n&&null!==n}function m(n){return b(n)||B(n)?0===n.length:n instanceof Map||n instanceof Set?0===n.size:!!h(n)&&0===Object.keys(n).length}function w(n){return void 0!==n}function j(n){return!w(n)}function S(n){return g(n,"Date")}function v(n){return null===n}function M(n){return j(n)&&v(n)}function O(n){return j(n)||v(n)}function A(n){return g(n,"Number")}function E(n){return g(n,"Promise")&&h(n)&&P(n.then)&&P(n.catch)}function B(n){return g(n,"String")}function P(n){return"function"==typeof n}function N(n){return g(n,"Boolean")}function x(n){return g(n,"RegExp")}function D(n){return"undefined"!=typeof window&&g(n,"Window")}function $(n){return h(n)&&!!n.tagName}function T(n){return g(n,"Map")}const F="undefined"==typeof window,U=!F;function R(n){return/(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/.test(n)}function z(){return!!(navigator.userAgent.match(/(pad|iPad|pod|iPod|Android|Mobile|Tablet)/i)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1)}return t}()}));