UNPKG

iking-utils-pro

Version:

金合前端工具库

2 lines (1 loc) 3.19 kB
function t(t,e){return Object.prototype.toString.call(t)===`[object ${e}]`}function e(t){return Object.prototype.toString.call(t)}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)}}function n(t={},e={}){if(!r.isObject(t)||!r.isObject(e))return console.warn("deepMerge: 两个参数都必须是对象"),e;const n=new WeakMap;return function t(e,i){if(n.has(i))return console.warn("deepMerge: 检测到循环引用,跳过合并"),e;n.set(i,!0);const s=Array.isArray(i)?[]:{};for(const t in e)e.hasOwnProperty(t)&&(s[t]=e[t]);for(const n in i)i.hasOwnProperty(n)&&(r.isObject(i[n])&&r.isObject(e[n])?s[n]=t(e[n],i[n]):s[n]=i[n]);return s}(t,e)}function i(t,e){if("string"!=typeof t)return console.error("setObjToUrlParams: baseUrl必须是字符串"),"";if(!r.isObject(e))return console.error("setObjToUrlParams: obj必须是对象"),t;let n="";for(const t in e)if(e.hasOwnProperty(t)){const r=null===e[t]||void 0===e[t]?"":e[t];n+=t+"="+encodeURIComponent(r)+"&"}return n=n.replace(/&$/,""),/\?$/.test(t)?t+n:t.replace(/\/?$/,"?")+n}function s(t,e){if("string"!=typeof t)return void console.error("openWindow: url必须是字符串");const{target:r="_blank",noopener:n=!0,noreferrer:i=!0}=e||{},s=[];n&&s.push("noopener=yes"),i&&s.push("noreferrer=yes"),window.open(t,r,s.join(","))}const o=t=>{if(!r.isObject(t))throw new Error("param must be an object");return t[Symbol.iterator]=a,t},c=t=>o(t);function a(){let t=-1,e=Object.entries(this),r=e.length;return{next:()=>(++t,r>t?{value:e[t],done:!1}:{value:e[t],done:!0})}}const u=(t,e)=>{if(!r.isObject(t)||!r.isObject(e))throw new Error("参数异常");Object.keys(t).forEach((r=>{Reflect.has(e,r)&&(t[r]=e[r])}))};export{n as deepMerge,c as forof,o as forofObj,s as openWindow,u as setKeyValue,i as setObjToUrlParams};