UNPKG

iking-utils-pro

Version:

金合前端工具库

2 lines (1 loc) 2.1 kB
"use strict";function t(t,e){return Object.prototype.toString.call(t)===`[object ${e}]`}function e(t){return Object.prototype.toString.call(t)}Object.defineProperty(exports,"__esModule",{value:!0});class r{static isJSON(t){try{return!!JSON.parse(t)}catch(t){return!1}}static getTypeLong(t){return e(t)}static getType(t){const r=e(t);return r.substring(8,r.length-1).toLocaleLowerCase()}static isDef(t){return void 0!==t}static isUnDef(t){return!this.isDef(t)}static isObject(e){return null!==e&&t(e,"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(e){return t(e,"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(e){return t(e,"Number")}static isPromise(e){return t(e,"Promise")&&this.isObject(e)&&this.isFunction(e.then)&&this.isFunction(e.catch)}static isString(e){return t(e,"String")}static isFunction(t){return"function"==typeof t}static isBoolean(e){return t(e,"Boolean")}static isRegExp(e){return t(e,"RegExp")}static isArray(t){return t&&Array.isArray(t)}static isWindow(e){return"undefined"!=typeof window&&t(e,"Window")}static isElement(t){return this.isObject(t)&&!!t.tagName}static isMap(e){return t(e,"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)}}const s=t=>{if(!t)return{};const e=new URL(t),r=new URLSearchParams(e.search);return Object.fromEntries(r.entries())};exports.assembleUrl=(t,e)=>t&&e?e.startsWith("http")?e:`${t}${e}`:"",exports.getUrlKeyData=(t,e)=>s(t)[e],exports.parseUrl=s,exports.replaceTemplateVar=(t,e)=>{const s=/\$\{([^\}]+)\}/g;let i;for(;null!==(i=s.exec(t));){const s=i[1];r.isObject(e)&&e.hasOwnProperty(s)&&(t=t.replace(i[0],String(e[s])))}return t};