UNPKG

iking-utils-pro

Version:

金合前端工具库

2 lines (1 loc) 3.04 kB
import t from"cookiejs";import e from"localforage";function r(t,e){return Object.prototype.toString.call(t)===`[object ${e}]`}function s(t){return Object.prototype.toString.call(t)}class i{static isJSON(t){try{return!!JSON.parse(t)}catch(t){return!1}}static getTypeLong(t){return s(t)}static getType(t){const e=s(t);return e.substring(8,e.length-1).toLocaleLowerCase()}static isDef(t){return void 0!==t}static isUnDef(t){return!this.isDef(t)}static isObject(t){return null!==t&&r(t,"Object")}static isEmpty(t){return this.isArray(t)||this.isString(t)?0===t.length:t instanceof Map||t instanceof Set?0===t.size:!!this.isObject(t)&&0===Object.keys(t).length}static isDate(t){return r(t,"Date")}static isNull(t){return null===t}static isNullAndUnDef(t){return this.isUnDef(t)&&this.isNull(t)}static isNullOrUnDef(t){return this.isUnDef(t)||this.isNull(t)}static isNumber(t){return r(t,"Number")}static isPromise(t){return r(t,"Promise")&&this.isObject(t)&&this.isFunction(t.then)&&this.isFunction(t.catch)}static isString(t){return r(t,"String")}static isFunction(t){return"function"==typeof t}static isBoolean(t){return r(t,"Boolean")}static isRegExp(t){return r(t,"RegExp")}static isArray(t){return t&&Array.isArray(t)}static isWindow(t){return"undefined"!=typeof window&&r(t,"Window")}static isElement(t){return this.isObject(t)&&!!t.tagName}static isMap(t){return r(t,"Map")}static isServer="undefined"==typeof window;static isClient=!this.isServer;static isUrl(t){return/(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/.test(t)}}var n={local:{has:t=>Object.prototype.hasOwnProperty.call(localStorage,t),setItem:(t,e,r=0)=>{const s=(new Date).getTime(),n=i.isDate(r)?s+1e3*r:0;localStorage.setItem(t,JSON.stringify({value:e,overTime:n}))},getItem:t=>{const e=localStorage.getItem(t);if(!e)return null;const r=JSON.parse(e);return(new Date).getTime()>r.overTime&&0!==r.overTime?(localStorage.removeItem(t),null):r.value},removeItem:t=>{t&&localStorage.removeItem(t)},clear:t=>{t?localStorage.removeItem(t):localStorage.clear()},size:()=>{const t=Object.keys(localStorage);let e=0;for(let r=0;r<t.length;r++){const s=t[r],i=localStorage.getItem(s)||"";e+=2*(s.length+i.length)}return Math.round(e/1024)}},session:{has:t=>Object.prototype.hasOwnProperty.call(sessionStorage,t),setItem:(t,e,r=0)=>{const s=(new Date).getTime(),i=r?s+1e3*r:0;sessionStorage.setItem(t,JSON.stringify({value:e,overTime:i}))},getItem:t=>{const e=sessionStorage.getItem(t);if(!e)return null;const r=JSON.parse(e);return(new Date).getTime()>r.overTime&&0!==r.overTime?(sessionStorage.removeItem(t),null):r.value},removeItem:t=>{t&&sessionStorage.removeItem(t)},clear:t=>{t?sessionStorage.removeItem(t):sessionStorage.clear()},size:()=>{const t=Object.keys(sessionStorage);let e=0;for(let r=0;r<t.length;r++){const s=t[r],i=sessionStorage.getItem(s)||"";e+=2*(s.length+i.length)}return Math.round(e/1024)}},forage:e,cookie:t};export{n as default};