UNPKG

@kaobeimao/base

Version:

js base

17 lines (14 loc) 4.18 kB
import{cloneDeep as t}from"lodash";var n=Object.prototype.toString;function e(t,e){return n.call(t)==="[object "+e+"]"}function r(t){return e(t,"Function")}var o=function(t){return void 0!==t},i=function(t){return null!==t&&e(t,"Object")};var u="undefined"==typeof window;var c=Object.freeze({__proto__:null,isFunction:r,isDef:o,isUnDef:function(t){return!o(t)},isObject:i,isDate:function(t){return e(t,"Date")},isNumber:function(t){return e(t,"Number")},isAsyncFunction:function(t){return e(t,"AsyncFunction")},isPromise:function(t){return e(t,"Promise")&&i(t)&&r(t.then)&&r(t.catch)},isString:function(t){return e(t,"String")},isBoolean:function(t){return e(t,"Boolean")},isArray:function(t){return t&&Array.isArray(t)},isClient:function(){return"undefined"!=typeof window},isWindow:function(t){return"undefined"!=typeof window&&e(t,"Window")},isElement:function(t){return i(t)&&!!t.tagName},isServer:u,isImageDom:function(t){return t&&["IMAGE","IMG"].includes(t.tagName)}}),a=Object.freeze({__proto__:null,goToTop:function(){return window.scrollTo(0,0)},detectDeviceType:function(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?"Mobile":"Desktop"}}),s=Object.freeze({__proto__:null,smoothScroll:function(t){document.querySelector(t).scrollIntoView({behavior:"smooth"})}}),l=Object.freeze({__proto__:null,isWeekday:function(t){return t.getDay()%6!=0},cloneDeep:function(n){return t(n)}});var f=Object.freeze({__proto__:null,bubble:function(t){for(var n,e= /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ function(){for(var t=0,n=0,e=arguments.length;n<e;n++)t+=arguments[n].length;var r=Array(t),o=0;for(n=0;n<e;n++)for(var i=arguments[n],u=0,c=i.length;u<c;u++,o++)r[o]=i[u];return r}(t),r=e.length,o=0;o<r-1;o++)for(var i=0;i<r-1-o;i++)e[i]>e[i+1]&&(n=e[i],e[i]=e[i+1],e[i+1]=n);return e}});function p(t){return"string"!=typeof t&&(console.warn(t+" used as a key, but it is not a string."),t=String(t)),t}var g=function(){function t(t){this.KEY_PREFIX="__storage.",this.KEY_PREFIX=t}return t.prototype.ready=function(){return null==this.isSupport&&(this.isSupport=function(){var t="__localStorage_support_test",n="test",e=!1;try{return localStorage.setItem(t,n),localStorage.getItem(t)===n&&(e=!0),localStorage.removeItem(t),e}catch(t){return"QuotaExceededError"===t.name||"NS_ERROR_DOM_QUOTA_REACHED"===t.name?console.warn("localStorage 存储已达上限!"):console.warn("当前浏览器不支持 localStorage!"),e}}()),this.isSupport},t.prototype.setItem=function(t,n){var e=this;t=p(t),this.ready()&&(void 0===n&&(n=null),function(t,n){try{n(null,JSON.stringify(t))}catch(t){n(t)}}(n,(function(n,r){if(!n)try{var o=""+e.KEY_PREFIX+t;localStorage.setItem(o,r)}catch(t){console.log("e",t)}})))},t.prototype.getItem=function(t){t=p(t);var n=""+this.KEY_PREFIX+t;return JSON.parse(localStorage.getItem(n))},t}();function d(t){return new Promise((function(n){setTimeout(n,t)}))}var _=function(){function t(){}return t.getInstance=function(){return this.instance||(this.instance=new t),this.instance},t.prototype.sql=function(t,n){return void 0===t&&(t=[]),t.length?n&&n.fields&&n.fields.length?t.reduce((function(t,e){return t.push(n.fields.reduce((function(t,n){return t[n]=e[n],t}),{})),t}),[]):t:[]},t}().getInstance(),h=require("../package.json").version;export{a as B,s as D,c as I,f as S,g as StorageHandler,l as U,_ as processor,d as sleep,h as version};