UNPKG

iking-utils-pro

Version:

金合前端工具库

2 lines (1 loc) 2.08 kB
function t(t,i){return Object.prototype.toString.call(t)===`[object ${i}]`}function i(t){return Object.prototype.toString.call(t)}class e{static isJSON(t){try{return!!JSON.parse(t)}catch(t){return!1}}static getTypeLong(t){return i(t)}static getType(t){const e=i(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(i){return null!==i&&t(i,"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(i){return t(i,"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(i){return t(i,"Number")}static isPromise(i){return t(i,"Promise")&&this.isObject(i)&&this.isFunction(i.then)&&this.isFunction(i.catch)}static isString(i){return t(i,"String")}static isFunction(t){return"function"==typeof t}static isBoolean(i){return t(i,"Boolean")}static isRegExp(i){return t(i,"RegExp")}static isArray(t){return t&&Array.isArray(t)}static isWindow(i){return"undefined"!=typeof window&&t(i,"Window")}static isElement(t){return this.isObject(t)&&!!t.tagName}static isMap(i){return t(i,"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=()=>{if("Notification"in window){"default"===Notification.permission&&Notification.requestPermission().then((t=>{"granted"===t&&console.info("已获取通知权限")})).catch((t=>{console.error("获取通知权限失败:",t)}))}},n=(t,i)=>{if("Notification"in window&&"granted"===Notification.permission){const s={body:t.message,icon:t?.icon||"",data:t};new Notification(t.title,s).onclick=t=>{e.isFunction(i)&&i(t)}}};export{s as checkPermission,n as showNotification};