d-utils
Version:
d-utils
856 lines (853 loc) • 51.4 kB
JavaScript
/**
* d-utils version: 4.0.3
* by ifmiss
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["[name]"]=e["[name]"]||{},e["[name]"].js={}))}(this,(function(e){"use strict";
/**
* @description 判断元素是否存在某个class类
* @param { HTMLElement } el dom元素
* @param { String } className class名称
* @example
* hasClass(document.body, 'd-utils')
*/function t(e,t){return e.classList.contains(t)}
/**
* @description 判断元素是否存在某个class类
* @param { HTMLElement } el dom元素
* @param { String } className class名称
* @example
* hasClass(document.body, 'd-utils')
*/
/**
* @description 检索数据类型并返回数据类型名称 object array string undefined bool number null 等等...
* @param { Any } data 要判断的数据
* @example
* checkType('1') // string
* @example
* checkType({}) // object
* @example
* checkType([]) // array
* @example
* checkType(localStorage) // storage
*/
function n(e){return Object.prototype.toString.call(e).match(/\[object (.*?)\]/)[1].toLowerCase()}
/*! *****************************************************************************
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.
***************************************************************************** */var o=function(){return(o=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function r(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{u(o.next(e))}catch(e){i(e)}}function c(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((o=o.apply(e,t||[])).next())}))}function i(e,t){var n,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,o=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function a(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],o=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function c(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a}function u(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(c(arguments[t]));return e}
/**
* @description 方法的从右往左执行
* @param { Function } fns 各种方法
* @example
* compose(a, b, c)(...query) // a, b, c 皆为方法
*
* const testCompose = (name, age) => {
* console.log('this name is: ', name)
* console.log('this age is: ', age)
* // 如果方法内部返回多个值作为后一个方法的参数,使用数组返回
* return [name, age]
* }
* const full = (name, age) => {
* console.log(`this is full: ${name} & ${age}`)
* }
*
* compose(full, testCompose)('d-utils', 1)
*
* // this name is: d-utils
* // this age is: 1
* // this is full: d-utils & 1
*/
/**
* 判断是否是 Object
*/
function s(e){return"object"===n(e)}
/**
* 日志的打印封装
*/var l=/** @class */function(){function e(){}
/**
* console提示信息
* @param { any } data 打印的数据信息
* @param { string } dataTitile 提示文案
* @param { string } color 颜色
* @example
* Log.console(window.screen, 'window:', 'red')
*/return e.console=function(t,n,r){void 0===n&&(n="数据信息"),void 0===r&&(r=e.defaultColor),s(t)?Array.isArray(t)?console.log("%c"+n,"color: "+r+"; font-weight: bold",t):console.log("%c"+n,"color: "+r+"; font-weight: bold",o({},t)):console.log("%c"+n,"color: "+r+"; font-weight: bold",t)},
/**
* default提示信息
* @param { any } data 打印的数据信息
* @param { string } dataTitile 提示文案
* @example
* Log.default('date', 'default')
*/
e.default=function(t,n){void 0===n&&(n="[d-utils] log_utils default => "),e.console(t,n,e.defaultColor)},
/**
* info提示信息
* @param { any } data 打印的数据信息
* @param { string } dataTitile 提示文案
* @example
* Log.info('date', 'info')
*/
e.info=function(t,n){void 0===n&&(n="[d-utils] log_utils info => "),e.console(t,n,e.infoColor)},
/**
* success成功信息
* @param { any } data 打印的数据信息
* @param { string } dataTitile 提示文案
* @example
* Log.info('date', 'success')
*/
e.success=function(t,n){void 0===n&&(n="[d-utils] log_utils success => "),e.console(t,n,e.successColor)},
/**
* error失败信息
* @param { any } data 打印的数据信息
* @param { string } dataTitile 提示文案
* @example
* Log.info('date', 'error')
*/
e.error=function(t,n){void 0===n&&(n="[d-utils] log_utils error => "),e.console(t,n,e.errorColor)},
/**
* warn警告信息
* @param { any } data 打印的数据信息
* @param { string } dataTitile 提示文案
* @example
* Log.info('date', 'warn')
*/
e.warn=function(t,n){void 0===n&&(n="[d-utils] log_utils warning => "),e.console(t,n,e.warningColor)},
/**
* @description console的美化样式
* @param { String } text 内容
* @param { Object } options 配置项,对象,大小背景,和背景颜色设置
* @property { Boolean } isMax 是否是较大显示console的高度,如果console的内容较多建议设置为false 默认为小格式
* @property { Array } colors 背景色列表,是一个从左向右渐变的过程
* @example
* Log.beauty('hello world')
* @example
* Log.beauty('这是一个console的方法,可以设置背景色的哦', {
* isMax: false,
* colors: ['#fa709a', '#fee140', '#ffb199']
* })
*/
e.beauty=function(e,t){if(void 0===e&&(e="未曾遗忘的青春"),t&&"object"!=typeof t)throw new TypeError("options is an object, but found "+typeof t);var n=Object.assign({},{isMax:!1,colors:["#a18cd1","#fbc2eb","#8ec5fc"]},t);n.isMax?console.log("%c"+e,"background-size: 100%;background-image: -moz-linear-gradient(left, "+n.colors.toString()+");background-image: -webkit-linear-gradient(left, "+n.colors.toString()+");background-image: linear-gradient(to right, "+n.colors.toString()+");padding:20px 40px;color:#fff;font-size:18px;"):console.log("%c"+e,"background-size: 100%;background-image: -moz-linear-gradient(left, "+n.colors.toString()+");background-image: -webkit-linear-gradient(left, "+n.colors.toString()+");background-image: linear-gradient(to right, "+n.colors.toString()+");padding:2px 5px;color:#fff;font-size:12px;")},
/**
* log打印一个group组 默认全部展示折叠
*/
e.group=function(t,n){void 0===t&&(t="[d-utils] log_utils group => "),void 0===n&&(n=e.defaultColor),console.group("%c"+t,"color: "+n+"; font-weight: bold")},
/**
* log打印一个group组 折叠的
*/
e.groupCollapsed=function(t,n){void 0===t&&(t="[d-utils] log_utils group_collapsed => "),void 0===n&&(n=e.defaultColor),console.groupCollapsed("%c"+t,"color: "+n+"; font-weight: bold")},
/**
* 关闭一个console.group
*/
e.groupEnd=function(){console.groupEnd()},
/**
* 打印一个table的表格数据
* @param data 数组对象数据
*/
e.table=function(e){console.table(e)},
/**
* 提示色 '#9E9E9E' 默认灰色
*/
e.defaultColor="#9E9E9E",
/**
* 提示色 '#0099FF' 蓝色
*/
e.infoColor="#0099FF",
/**
* 提示色 '#00CC99' 绿色
*/
e.successColor="#00CC99",
/**
* 提示色 '#CC3366' 红色
*/
e.errorColor="#CC0000",
/**
* 提示色 '#CC9966' 黄色
*/
e.warningColor="#FF9966",e}(),d=/** @class */function(){function e(){}
/**
* 装饰器,作用在类的方法上
* 方法的 log 信息
*/return e.log=function(e,t,n){var o=n.value;n.value=function(){for(var n,r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];l.groupCollapsed("[d-utils] DecoratorUtils "+t+"方法的执行信息",l.defaultColor),l.default(t+"("+r+")","方法准备执行:"),l.info(r,"详细的参数值: ");try{n=o.apply(e,r),l.success(n,"执行成功结果:")}catch(e){l.error(e,"执行失败结果:")}l.groupEnd()}},
/**
* 装饰器,作用在类的方法上
* 方法执行时间
*/
e.fnTime=function(e,t,n){var r=n.value;if("function"==typeof r)return o(o({},n),{value:function(){console.time("[d-utils] "+t+"方法执行时间: ");try{return r.apply(e,arguments)}finally{console.timeEnd("[d-utils] "+t+"方法执行时间: ")}}});l.error(t+"必须为方法","[d-utils] fnTime 执行失败结果: ")},e}();
/**
* @description 深拷贝
* @param { Object } obj 被拷贝的对象
* @return { Object } 返回新的对象
* @example
* let a = {
* a: 1,
* b: 2,
* c: 3,
* d: [1, 2]
* }
* let b = deepClone(a)
* a.d[0] = 3
* console.log(a)
* // a: {a: 1, b: 2, c: 3, d: [3, 2]}
* console.log(b)
* // b: {a: 1, b: 2, c: 3, d: [1, 2]}
* // 此时修改a.d[0]的值, a对象变化了,b对象没有随之改变
*/
function f(e){var t,o;console.warn("deepClone 方法暂时没有做对象引用的优化,可食用 lodash 的 cloneDeep 方法");var r={},i=Object.keys(e);try{for(var c=a(i),u=c.next();!u.done;u=c.next()){var s=u.value;switch(n(e[s])){case"object":r[s]=f(e[s]);break;case"array":r[s]=[].concat(e[s]);break;default:r[s]=e[s]}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(t)throw t.error}}return r}
/**
* @description 移除url的某一个参数
* @since 3.0.1
* @param { Array } paramNames 参数名称的数组
* @param { URL } url url地址
* @return { String } 返回一个新地址
* @example
* UrlUtils.deleteUrlParam(['code', 'name'], 'http://localhost:2008/#a?a=22&b=2&code=3')
* // 'http://localhost:2008/#a?a=22&b=2'
*/
/**
* 设备相关
*/
var h=/** @class */function(){function e(){}
/**
* @description 横竖屏的判断,如果是横屏幕显示,显示dom提示竖屏显示
* @param { String } 提示内容
* @example
* DeviceUtils.checkLayoutOrientation() // 横屏时候提示 请旋转屏幕,以达到更好的浏览效果
* @example
* DeviceUtils.checkLayoutOrientation('请竖直使用手机') // 横屏时候提示 请竖直使用手机
*/return e.checkLayoutOrientation=function(e){if(void 0===e&&(e="请旋转屏幕,以达到更好的浏览效果"),window.hasOwnProperty("orientation")){var t=null;
// 0 和 360 的时候是竖屏
n(),window.addEventListener("orientationchange",(function(){n()}))}function n(){var n=window.orientation;if(0===n||360===n)t&&(document.body.removeChild(t),t=null);else{if(t)return;(t=document.createElement("div")).style.cssText="position: fixed;\n top: 0;\n left: 0;\n right:0;\n bottom:0;\n display:flex;\n align-items:center;\n justify-content:center;\n font-size: 20px;\n background:#fff;\n z-index: 19940320;\n padding: 40px;",t.innerText=e,document.body.appendChild(t)}}},
/**
* @description 移动端REM的初始化js的方法,默认基于750的设计稿,可以限制最大显示宽度, 超出需要isFullOverMax 判断是否全屏幕显示, 不全屏则是body居中
* @param { number } BaseWidth 基础的设计稿宽度 默认750
* @param { number } MaxWidth 移动端最大的比例宽度点 默认document.body.clientWidth
* @param { boolean } isFullOverMax 超出{MaxWidth}最大宽度的时候是否居中显示(body居中的前提是超出设定的宽度以及isFullOverMax=false) 默认false
* @example
* DeviceUtils.initRem()
*/
e.initRem=function(e,t,n){void 0===e&&(e=750),void 0===t&&(t=document.body.clientWidth),void 0===n&&(n=!0);var o={},r=t/e;o.Html=document.getElementsByTagName("html")[0],o.intiFontSize=function(){var t=Math.min(document.body.clientWidth,document.body.clientHeight),o=parseFloat((t/e).toFixed(4)),i=o>r?r:o;return n&&(i=o),i},o.updateFontSize=function(){o.Html.setAttribute("style","font-size:"+100*o.intiFontSize()+"px"),!n&&document.body.clientWidth>=t&&document.body.setAttribute("style","margin: 0 auto; width: 7.5rem")},document.addEventListener&&(window.addEventListener("resize",o.updateFontSize,!1),document.addEventListener("DOMContentLoaded",o.updateFontSize,!1))},e}();
/**
* @description 返回两个数组之间的差集
* @param { Array } args 可以是多个数组,两个数组
* @return { Array } 返回数组
*/
/**
* 一个简单的发布订阅者模式
*/
var p=/** @class */function(){function e(){}
/**
* on 方法 添加监听事件
*/return e.on=function(t,n){var o={fn:n,type:"on",name:t};return Object.keys(e.handler).includes(t)?(e.handler[t].push(o),e):(e.handler[t]=[].concat(o),e)},
/**
* off 方法 移除监听事件
*/
e.off=function(t,n){var o=e.handler[t];if(o)for(var r=o.length-1;r>=0;r--)o[r].fn===n&&o.splice(r,1);return e},
/**
* emit 方法 触发监听的事件
*/
e.emit=function(t){for(var n=this,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var i=e.handler[t],a=[];i&&i.length&&i.forEach((function(e,t){var r;(r=e.fn).call.apply(r,u([n],o)),
// 如果有只监听一次的事件
"once"!==e.type&&a.push(i.slice(t,t+1))}));var c=i&&i.length&&i.some((function(e){return"once"===e.type}));
// 这里做一个执行完成之后的 once代码 off 的操作
return c&&(e.handler[t]=a),e},
/**
* once 方法 添加事件 只会被执行一次
*/
e.once=function(t,n){e.on(t,n),e.handler[t][0].type="once"},
/**
* 键值对 对应事件名称以及数组的值
*/
e.handler={},e}();
/**
* @description extend继承方法 Object.assign(...arg)的包装
* @param { Any } 参数为object对象
* @returns { Object } 返回一个新的对象
* @example
* extend({a: 1}, {a: 2}) // {a: 1}
* ⚠️ Object.assign属于浅拷贝,为了后续的操作不影响到之前的数据,最好在extend的第一个参数设置为{}
*/
/**
* @description 获取Cookie
* @param { String } name cookie名称
* @returns { (Array | Null) } 返回数据
* @example
* getCookie('test')
*/
function m(e){if(e){var t=new RegExp("(^| )"+e+"=([^;]*)(;|$)"),n=document.cookie.match(t);return n&&n[2]?n[2]:null}var o=[];if(document.cookie.length){var r=document.cookie.split("; ");for(var i in r)o.push({name:""+unescape(r[i].split("=")[0]),value:""+unescape(r[i].split("=")[1])});return o}return null}
/**
* @description object对象转化成get请求的字符串形式
* @param { Object } obj 需要操作的对象
* @return { String } 返回一个字符串 a=1&b=2
* @example
* // 'a=1&b=2'
* UrlUtils.stringifyUrl({a: 1, b: 2})
*/function g(e){return Object.entries(e).map((function(e){var t=c(u(e),2),n=t[0],o=t[1];return n+"="+encodeURIComponent(o)})).join("&")}
/**
* @description 判断是否是Android操作系统
* @return { Boolean } 返回是否是Android的布尔值
* @example
* isAndroid() // false
*/
function v(){var e=window.navigator.userAgent;return!!~e.indexOf("Android")||!!~e.indexOf("Adr")}
/**
* @description 正则表达式是否全部是
*/var y=/^[\u3220-\uFA29]+$/;
/**
* @description 判断字符串是否都是中文
* @param { String } str
* @return Boolean
* @example
* isChinese('你好,世界') // false
* isChinese('你好') // true
* isChinese('world') // false
*/
/**
* @description 正则表达式 邮箱是否合法
*/
var w=/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
/**
* @description 判断email格式是否正确
* @param { String } email 邮箱名称 字符串
* @return { Boolean } true是有效 false无效
* @example
* isEmail('185098535@qq.com') // true
*/
/**
* @description 正则表达式 判断是否为IOS设备
*/
var b=/(iPhone|iPad|iPod|iOS)/i;
/**
* @description 判断是否是IOS操作系统
* @return { Boolean } 返回是否是IOS的布尔值
* @example
* isIOS() // false
*/function T(){var e=window.navigator.userAgent;return b.test(e)}
/**
* 判断是否是JSON字符串
* @param str 需要校验的字符串
* @return Boolean 是否是JSON格式的字符串
*/
/**
* @description 正则表达式 判断是否为移动设备
*/
var S=/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i;
/**
* @description 判断是否是移动端
* @return { Boolean } 返回是否是移动端的布尔值
* @example
* isMobile() // false
*/
/**
* @description 正则表达式 手机的合法校验 /^1[3-9]\d{9}$/
*/
var x=/^1[3-9]\d{9}$/;
/**
* @description 判断手机格式是否正确
* @param { String } num 手机号 字符串
* @return { Boolean } true是有效 false无效
* @example
* isPhoneNum('13651971940') // true
*/
/**
* 获取url地址的参数信转化成键值对的对象格式
* @param { string } url 解析的url地址
* @example
* UrlUtils.parseUrl('http://www.daiwei.org/?a=1&b=2')
*/
function C(e){var t,n;void 0===e&&(e=window.location.search);var o=e.slice(e.indexOf("?")),r=new URLSearchParams(o),i={};try{for(var u=a(r.entries()),s=u.next();!s.done;s=u.next()){var l=c(s.value,2),d=l[0],f=l[1];i[d]=f}}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}return i}
/**
* 网页性能监测
*/var E,I,M=/** @class */function(){function e(){}
/**
* @description DNS查询耗时
* @description timing.domainLookupEnd - timing.domainLookupStart
* @returns { number } 时差 单位:ms
*/return e.dnsTime=function(){return e.timing.domainLookupEnd-e.timing.domainLookupStart},
/**
* @description 白屏时间
* @description timing.domLoading - timing.navigationStart
* @returns { number } 时差 单位:ms
*/
e.loadTime=function(){return e.timing.domLoading-e.timing.navigationStart},
/**
* @description request请求耗时
* @description timing.responseEnd - timing.responseStart
* @returns { number } 时差 单位:ms
*/
e.requestTime=function(){return e.timing.responseEnd-e.timing.responseStart},
/**
* @description TCP链接耗时
* @description timing.connectEnd - timing.connectStart
* @returns { number } 时差 单位:ms
*/
e.tcpTime=function(){return e.timing.connectEnd-e.timing.connectStart},
/**
* @description 解析dom树耗时
* @description timing.domComplete - timing.domInteractive
* @returns { number } 时差 单位:ms
*/
e.renderDomTime=function(){return e.timing.domComplete-e.timing.domInteractive},
/**
* @description domready时间(用户可操作时间节点)
* @description timing.domContentLoadedEventEnd - timing.navigationStart
* @returns { number } 时差 单位:ms
*/
e.readyDomTime=function(){return e.timing.domContentLoadedEventEnd-e.timing.navigationStart},
/**
* @description onload时间(总下载时间)
* @description timing.loadEventEnd - timing.navigationStart
* @returns { number } 时差 单位:ms
*/
e.loadFullTime=function(){return e.timing.loadEventEnd-e.timing.navigationStart},
/**
* @description 打印已知的所有数据信息
*/
e.logger=function(){window.addEventListener("load",(function(){setTimeout((function(){l.group("[d-utils] PerformanceUtils logger - list: ",l.infoColor),l.default(e.dnsTime(),"DNS查询耗时"),l.default(e.loadTime(),"白屏时间"),l.default(e.requestTime(),"request请求耗时"),l.default(e.tcpTime(),"TCP链接耗时"),l.default(e.renderDomTime(),"解析dom树耗时"),l.default(e.readyDomTime(),"用户可操作时间节点"),l.default(e.loadFullTime(),"onload时间"),l.groupEnd()}),300)}))},
/**
* @description window.performance对象
*/
e.performance=window.performance,
/**
* @description window.performance.timing对象
*/
e.timing=window.performance.timing,e}();
/**
* @description async / await 的错误处理 通过err的条件判断或者!res 的条件判断来走后续流程
* @param { Promise } promise
* @return { Array } array [0] 为err, array[1] 为data
*/!function(e){!function(e){
/** 去除首尾字符 */
e[e.LEFT_RIGHT=0]="LEFT_RIGHT",
/** 去除所有空格 */
e[e.ALL=1]="ALL",
/** 去除左边的空格 */
e[e.LEFT=2]="LEFT",
/** 去除右边课空格 */
e[e.RIGHT=3]="RIGHT"}(e.StrTrimType||(e.StrTrimType={}))}(E||(E={})),function(e){!function(e){e.fanmily="14px Arial",e.color="#d4546f"}(e.FontStyle||(e.FontStyle={})),function(e){e.Text="text",e.Image="image"}(e.TextType||(e.TextType={}))}(I||(I={}));var _=/** @class */function(){function e(e,t){
/**
* 基于当前屏幕的比例
*/
this.persent=1,
/**
* canvas的元素
*/
this.canvas=null,
/**
* context canvas 上下文
*/
this.context=null,
/**
* 合并的背景地址
*/
this.mainResource="",
/**
* canvas的宽度 实际上数合并背景的宽度
*/
this.canvasWidth=0,
/**
* canvas的高度 实际上数合并背景的高度
*/
this.canvasHeight=0,
/**
* 资源列表
*/
this.resourceList=[],this.mainResource=e,t&&(this.persent=t)}return e.prototype.addSourse=function(e){return this.resourceList.push(e),this},
/**
* 加载图片
*/
e.prototype.loadResourse=function(e,t){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){return(n=new Image).crossOrigin="anonymous",n.src=e,[2/*return*/,new Promise((function(r,i){n.onload=function(){var e=t?o({ref:n},t):n;r(e)},n.onerror=function(){l.error(e,"[d-utils] ImageUtils loadResourse 裁剪图片加载错误"),i()}}))]}))}))},e.prototype.composeMainResource=function(e){var t=e.width/e.height;this.canvasWidth=e.width*this.persent,this.canvasHeight=this.canvasWidth/t,
// 设置canvas的宽高
this.canvas.width=this.canvasWidth,this.canvas.height=this.canvasHeight,this.context.drawImage(e,0,0,this.canvasWidth,this.canvasHeight),this.context.restore()},
/**
* @description cavans绘制效果
* @param image addSourse 添加的数据信息
*/
e.prototype.renderResource=function(e){var t={left:e.left*this.canvasWidth,top:e.top*this.canvasHeight,width:e.width*this.canvasWidth,height:e.height*this.canvasHeight};this.context.save(),e.needRound?(
// 走圆形绘制图片 此时都视为正方形
this.context.arc(t.width/2+t.left,t.width/2+t.top,t.width/2,0,2*Math.PI,!1),this.context.clip(),this.context.drawImage(e.ref,t.left,t.top,t.width,t.width),this.context.restore()):(
// 走正常绘制
this.context.drawImage(e.ref,t.left,t.top,t.width,t.height),this.context.restore())},
/**
* @description 初始化canvas的设置
* @return { Promise } 返回合成成功的image对象信息
*/
e.prototype.compose=function(){return r(this,void 0,void 0,(function(){var e,t,n,o=this;return i(this,(function(r){switch(r.label){case 0:return this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),[4/*yield*/,this.loadResourse(this.mainResource)];case 1:return e=r.sent(),this.composeMainResource(e),t=[],n=this.resourceList.reduce((function(e,t,n){if(t.type===I.TextType.Image){var r=o.loadResourse(t.content,t);e.push(r)}else o.context.font=t.fanmily||I.FontStyle.fanmily,o.context.fillStyle=t.color||I.FontStyle.color,o.context.fillText(t.content,t.left*o.canvasWidth,t.top*o.canvasHeight);return e}),t),[4/*yield*/,Promise.all(n)];case 2:
// 再次绘制
return[4/*yield*/,r.sent().forEach((function(e){o.renderResource(e)}))];case 3:
// 再次绘制
return r.sent(),[2/*return*/,Promise.resolve(this.convertCanvasToImage())]}}))}))},
/**
* @description canvase转换成图片
* @return { Image } 返回一个new Image的实例
*/
e.prototype.convertCanvasToImage=function(){var e=new Image;return e.src=this.canvas.toDataURL("image/png",1),l.success(e,"[d-utils] ImageUtils convertCanvasToImage 图片对象创建成功"),e},e}();
/**
* @description 函数节流
* @param { Function } fn 需要节流的函数
* @param { Number } t 节流时间,多久以后执行一次方法 单位ms
* @example
* // 在鼠标resize的过程中,1秒触发一次,如果resize了10秒相当于console.log('resize')只执行了10次
* window.onresize = throttle(function () {
* // es5 获取参数
* let arg = Array.prototype.slice.call(arguments)
* // es6 获取参数
* let arg1 = Array.from(arguments)
* console.log('resize-throttle', arg)
* console.log('resize-throttle', arg1)
* }, 1000)
*/var k=require("weixin-js-sdk"),L=require("sha1"),O=/** @class */function(){function e(){}
/**
* ios 安卓需要验签的地址
* @returns { string } 浏览器url
*/return e.sdkUrlIosOrAndorid=function(){return(T()||v()&&!e.isUpThanWxVersion("6.3.31"))&&window.__D_UTILS_WX_FIRST_URL_HOOK__?window.__D_UTILS_WX_FIRST_URL_HOOK__:window.location.href.split("#")[0]},
/**
* @description IOS 或者 Android 微信版本小于6.3.31 需要种植首次进入页面的URL,用于解决微信签名错误
*/
e.plantSdkUrlIosOrAndorid=function(){window.__D_UTILS_WX_FIRST_URL_HOOK__||(window.__D_UTILS_WX_FIRST_URL_HOOK__=window.location.href.split("#")[0])},
/**
* @description wxSign 微信验签的动作
* @param { String } jsapi_ticket 公众号用于调用微信JS接口的临时票据
* @return { IWxSign } 返回 timestamp, nonceStr, signature
*/
e.wxSign=function(t){var n=e.randomWord(16),o=(Date.now()+"").substr(0,10),r=e.sdkUrlIosOrAndorid();return{timestamp:o,nonceStr:n,signature:L("jsapi_ticket="+t+"&noncestr="+n+"×tamp="+o+"&url="+r)}},
/**
* 跳转微信oauth2授权登录 非静默授权
* @param { String } appId
*/
e.routerAuthorized=function(e){var t=window.location.href;t=encodeURIComponent(t),window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+e+"&redirect_uri="+t+"&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect"},
/**
* randomWord 产生任意长度随机字母数字组合
* min-任意长度最小位[固定位数]
* max-任意长度最大位
*/
e.randomWord=function(e,t){var n="",o=e,r=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
// 随机产生
if(t&&t>e)o=Math.round(Math.random()*(t-e))+e;else for(var i=0;i<o;i++){n+=r[Math.round(Math.random()*(r.length-1))]}return n},
/**
* @description 是否高于微信某一个版本
* @param { String } version
* @returns { Boolean } 返回是否满足条件
*/
e.isUpThanWxVersion=function(e){void 0===e&&(e="6.3.31");var t=window.navigator.userAgent,n=e.split(".").map((function(e){return parseInt(e,10)})),o=/MicroMessenger\/([\d|\.]+)/;if(null===o.exec(t))return!1;var r=(o.exec(t)||[])[1].split(".");return r.length>=4&&(r=r.slice(0,3)),(r=r.map((function(e){return parseInt(e,10)})))[0]>n[0]||(r[0]===n[0]&&r[1]>n[1]||r[0]===n[0]&&r[1]===n[1]&&r[2]>=n[2])},
/**
* @description 初始化微信配置签名
* @param { Object } data 微信的签名配置
* @props { Boolean } data.debug 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
* @props { String } data.appId 必填,公众号的唯一标识
* @props { Number } data.timestamp 必填,生成签名的时间戳
* @props { String } data.nonceStr 必填,生成签名的随机串
* @props { String } data.signature 必填,签名
* @props { Array } data.jsApiList 必填,需要使用的JS接口列表
* @link 接口列表地址 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
*/
e.initWxConfig=function(e){k.config(Object.assign({},{debug:!1},e)),k.error((function(e){l.error(e,"[d-utils] wx.config error => ")}))},
/**
* 分享给朋友
* @param {Object} sharInfo
* @props { String } sharInfo.title 分享的title
* @props { String } sharInfo.desc 分享描述
* @props { String } sharInfo.link 分享链接
* @props { String } sharInfo.imgUrl 分享图标
* @props { Function } sharInfo.success 成功的回调
* @props { Function } sharInfo.cancel 取消的回调
* @props { Function } sharInfo.complete 完成的回调
* @return { Promise<IWxCallBackType> } 返回一个promise
*/
e.wxShareToFriend=function(e){var t=Object.assign({},this.defaultShareInfo,e);return new Promise((function(e,n){try{k.ready((function(){k.onMenuShareAppMessage({title:t.title,desc:t.desc,link:t.link,imgUrl:t.imgUrl,success:function(n){var o={type:"onMenuShareAppMessage",data:n};t.success(o),e(o)},cancel:function(n){var o={type:"onMenuShareAppMessage",data:n};t.cancel(o),e(o)},complete:function(n){var o={type:"onMenuShareAppMessage",data:n};t.complete(o),e(o)}})}))}catch(e){n({type:"onMenuShareAppMessage",data:e})}}))},
/**
* 分享到朋友圈
* @param {Object} sharInfo
* @props { String } sharInfo.title 分享的title
* @props { String } sharInfo.link 分享链接
* @props { String } sharInfo.imgUrl 分享图标
* @props { Function } sharInfo.success 成功的回调
* @props { Function } sharInfo.cancel 取消的回调
* @props { Function } sharInfo.complete 完成的回调
* @return { Promise<IWxCallBackType> } 返回一个promise
*/
e.wxShareToFriendCircle=function(e){var t=Object.assign({},this.defaultShareInfo,e);return new Promise((function(e,n){try{k.ready((function(){k.onMenuShareTimeline({title:t.title,link:t.link,imgUrl:t.imgUrl,success:function(n){var o={type:"onMenuShareTimeline",data:n};t.success(o),e(o)},cancel:function(n){var o={type:"onMenuShareTimeline",data:n};t.cancel(o),e(o)},complete:function(n){var o={type:"onMenuShareTimeline",data:n};t.complete(o),e(o)}})}))}catch(e){n({type:"onMenuShareTimeline",data:e})}}))},
/**
* 隐藏所有非基础按钮接口
* @return { Promise<IWxCallBackType> } 返回一个promise
*/
e.hideAllNonBaseMenuItem=function(){return new Promise((function(e,t){k.ready((function(){try{k.hideAllNonBaseMenuItem(),e({type:"hideAllNonBaseMenuItem",data:"成功"})}catch(e){t({type:"hideAllNonBaseMenuItem",data:e})}}))}))},
/**
* 批量隐藏功能按钮接口
* @param { array } arr // 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3
* @return { Promise<IWxCallBackType> } 返回一个promise
*/
e.hideMenuItems=function(e){return void 0===e&&(e=[]),new Promise((function(t,n){k.ready((function(){try{k.hideMenuItems({menuList:e}),t({type:"hideMenuItems",data:"成功, 隐藏的数组名称: "+e})}catch(e){n({type:"hideMenuItems",data:e})}}))}))},e.wx=k,
/**
* @description 初始化微信请求 js-sdk 的url地址 需要区分两种情况
* IOS 或者 Android 微信版本小于6.3.31, Android 微信版本大于6.3.31
* 当前这种只支持与VUE单页面模式
* @returns 返回获取jssdk的url参数值
*/
e.defaultShareInfo={title:"这是一个微信分享的title",desc:"这是一个微信分享的desc",link:"这是一个微信分享的link",imgUrl:"这是一个微信分享的imgUrl",success:function(){},cancel:function(){},complete:function(){}},
/**
* ios 手机在code过期之后会重新静默授权,会导致分享失败,通过url中是否存在code,针对ios用户执行reload的操作
* @since 3.0.1
*/
e.plantIosReloadShim=function(){var e=C();Object.keys(e).includes("code")&&T()&&localStorage.setItem("weixin-utils-reload","true")},
/**
* 在其他页面都需要添加改方法,用户在页面加载之后重新reload,已保证微信分享正常
* @since 3.0.1
*/
e.reloadIosWhenCode=function(){var e=window.location.href.split("?")[0],t=localStorage.getItem("weixin-utils-reload"),n=new URLSearchParams(window.location.search);n.delete("code");var o=n.toString()?e+"?"+n.toString():e;"true"===t&&(localStorage.removeItem("weixin-utils-reload"),setTimeout((function(){location.replace(o)}),88))},e}();e.Decorator=d,e.Device=h,e.Event=p,e.Http=function(e,t){return r(this,void 0,void 0,(function(){var n,o,r;return i(this,(function(i){var a;return n=e,console.log("url",e),t&&t.query&&Object.keys(t.query).length>0&&(n=e+"?"+g(t.query)),o=Object.assign({},{credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},showTip:!0},t),r=[(a=o.timeOut,void 0===a&&(a=12e3),new Promise((function(e,t){setTimeout((function(){e({msg:"可能由于网络状态等原因,暂无数据",status:0,result:null})}),a)}))),window.fetch(""+n,o)],[2/*return*/,new Promise((function(e,t){Promise.race(r).then((function(n){n.ok||n.status>=200&&n.status<300?n.json().then((function(n){n.status&&200===n.status?e(n):(o.showTip&&n.msg&&l.error(n.msg),t(n))})):(n&&n.msg&&l.error(n.msg),t(n))})).catch((function(e){t(e)}))}))]}))}))}
/**
* @description 返回两个数组之间的交集
* @param { Array } args 可以是多个数组,两个数组
* @return { Array } 返回数组
*/,e.Log=l,e.Performance=M,e.Synthesis=_,e.Wx=O,e.addClass=function(e,n){Array.isArray(n)?n.forEach((function(n){t(e,n)||e.classList.add(n)})):t(e,n)||e.classList.add(n)}
/**
* @description base64解码成字符串
* @param str base64字符串
* @return 返回str字符串
*/,e.base64Decode=function(e){return window.atob(decodeURIComponent(e))}
/**
* @description 字符串转成base64编码
* @param str 字符串
* @return str base64 字符串
*/,e.base64Encode=function(e){return window.btoa(e)}
/**
* @description 判断元素在数组或者字符串里存在的次数
* @param { Array | String } target 存在的数组或字符串
* @param { String | Number | ... } s 目标元素 值类型的元素
* @return { Number } 数量
*/,e.calcSameEleLength=function(e,t){if("string"==typeof t&&t.length>1)throw Error("元素只支持长度为1的字符查询");return("string"==typeof e?e.split(""):e).reduce((function(e,n){return t===n?e+1:e}),0)}
/**
* @description 计算字符串长度 isStrict为true的时候 返回一个字符串的长度,汉字算2个字符长度
* @param { String } str 要计算的字符串
* @param { Boolean } isStrict true 返回一个字符串的长度,汉字算2个字符长度; false 直接返回长度
* @return { Number } 返回字符串长度
* @example
* const str = 'd-utils库'
* console(calcStrLength(str))
* console(calcStrLength(str, true))
*/,e.calcStrLength=function(e,t){return"string"!=typeof e?0:t?Array.from(e).reduce((function(e,t){return e+(t.charCodeAt(0)>255?2:1)}),0):e.length},e.checkType=n,e.compose=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(){for(var t=this,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];return e.reduceRight((function(e,n){return n.call.apply(n,u([t],e))}),n)}}
/**
* @description 获取元素的css属性内容
* @param { HTMLElement } el dom元素
* @param { String } cssProp css的属性名称
* @return { String } css对应的属性的值
* @example
* computedStyle(document.body, 'width')
*/,e.computedStyle=function(e,t){if(e&&t)return document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(e,"")[t]:e.currentStyle[t]}
/**
* @description 复制网页文字到剪切板,之后可以粘贴在任何可粘贴的地方
* @param { String } str 拷贝的内容
* @example
* copyText('hello world')
*/,e.copyText=function(e){var t=document.createElement("textarea");t.style.cssText="position: absolute; top: -1000px; right: -1000px; z-index: -1000;",document.body.appendChild(t),t.value=e,t.select(),document.execCommand("copy"),document.body.removeChild(t)}
/**
* @description js设置元素的filter样式
* @param { HTMLElement } el dom元素
* @param { (String | Object) } type filter类型 blur、opacity、grayscale、sepia、saturate、hue-rotate、invert、brightness、contrast、drop-shadow, 当type为Object的时候就是显示一系列键值对,设置多个filter属性 `blur、opacity、grayscale、sepia、saturate、hue-rotate、invert、brightness、contrast、drop-shadow
* @param { (String | Number) } option 参数 10px 10% 等等,根据不同type的类型设定不同的参数配置
* @example
* // 单个filter属性传参数
* cssFilter(document.body, 'grayscale', 1)
* // 多个filter属性传参数
* cssFilter(document.body, {
* grayscale: 0.5,
* opacity: 0.7,
* 'hue-rotate': '90deg'
* })
*/,e.cssFilter=function(e,t,n){if("object"==typeof t&&!n){var o="";for(var r in t)t.hasOwnProperty(r)&&(o+=r+"("+t[r]+")");return e.style.filter=o,void(e.style.webkitFilter=o)}e.style.filter=t+"("+n+")",e.style.webkitFilter=t+"("+n+")"}
/**
* @description 函数柯里化工具
* @param { Function } fn 方法
* @param { Any } agrs 参数,可选
* @example
* const addCur = function (a, b, c) {
* console.log('a + b + c', a + b + c)
* }
* const reduceCur = function (a, b, c) {
* console.log('a - b - c', a - b - c)
* }
* const add = curry(addCur, 2)
* s(1)(2) // a + b + c 6
* s(1, 3) // a + b + c 6
*
* const reduce = curry(reduceCur)
* const reduce1 = curry(reduceCur)
* reduce(1)(2)(3) // a - b - c -1
* reduce1(1, 2, 3) // a - b - c -3
*/,e.curry=function e(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];var r=this,i=Array.from(arguments).slice(1),a=t.length;return function(){var n=Array.from(arguments);return i.push.apply(i,u(n)),i.length<a?e.call.apply(e,u([r,t],i)):t.apply(r,i)}}
/**
* @description 函数防抖
* @param { Function } fn 需要防抖的函数
* @param { Number } t 防抖时间,多久以后才能再执行 单位ms
* @param { Boolean } immediate true: 立刻执行方法且最后一次时间不执行, false: 等t时间之后再执行方法,如果t时间内执行,则在最后一次的t时间之后执行方法,类似动态搜索效果
* @example
* // 在鼠标resize的过程中,1秒以后可以被执行,如果在1秒内触发resize,则从新计算下一个一秒再允许执行
* window.onresize = debounce(function () {
* // es5 获取参数
* let arg = Array.prototype.slice.call(arguments)
* // es6 获取参数
* let arg1 = Array.from(arguments)
* console.log('resize-debounce', arg)
* console.log('resize-debounce', arg1)
* }, 1000)
*/,e.debounce=function(e,t,n){var o;
// 立刻执行第一次该方法
if(void 0===n&&(n=!0),"function"==typeof e)return n?function(){clearTimeout(o),o||e.apply(this,arguments),o=setTimeout((function(){setTimeout(o),o=null}),t)}:function(){clearTimeout(o),o=setTimeout((function(){setTimeout(o),e.apply(this,arguments),o=null}),t)};console.error("第一个参数必须是方法","[d-utils] GenericUtils debounce error => ")},e.deepClone=f,e.deleteUrlParam=function(e,t){void 0===t&&(t=location.href);var n=t.split("?")[1];if(!n)return t;var o=t.split("?")[0],r=new URLSearchParams(n);return e.forEach((function(e){r.delete(e)})),r.toString()?o+"?"+r.toString():o},e.diffset=function(e,t){var n=new Set(t);return e.filter((function(e){return!n.has(e)}))},e.extend=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return f(Object.assign.apply(Object,u([{}],e)))}
/**
* @description 文件转成blob流
* @param { File } dataUrl 单个file
* @return { Blob } 返回新的文件流 可以append到formdata中
*/,e.fileToBlob=function(e){for(var t=e.split(","),n=t[0].match(/:(.*?);/)[1],o=atob(t[1]),r=o.length,i=new Uint8Array(r);r--;)i[r]=o.charCodeAt(r);return new Blob([i],{type:n})}
/**
* @description 日期格式化 可转换成自己想要的格式
* @param { Date } date 日期内容 如 当前日期 new Date()
* @param { String } fmt 格式模板 'yyyy-MM-dd hh:mm:ss'
* @return { String } '2018-08-15 01:46:22'
* @example
* formatDate(new Date(), `yyyy-MM-dd hh:mm:ss`)
* @example
* formatDate(new Date(), `yyyy-MM-dd`)
*/,e.formatDate=function(e,t){void 0===e&&(e=new Date),void 0===t&&(t="yyyy-MM-dd hh:mm:ss");var n=new Date(e),o={"M+":n.getMonth()+1,"d+":n.getDate(),"h+":n.getHours(),"m+":n.getMinutes(),"s+":n.getSeconds(),"q+":~~((n.getMonth()+3)/3),S:n.getMilliseconds()};for(var r in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(n.getFullYear()+"").substr(4-RegExp.$1.length))),o)new RegExp("("+r+")").test(t)&&(t=t.replace(RegExp.$1,1===RegExp.$1.length?o[r]:("00"+o[r]).substr((""+o[r]).length)));return t},e.getCookie=m,e.hasClass=t,e.intersection=function(e,t){var n=new Set(t);return e.filter((function(e){return n.has(e)}))},e.isAndroid=v,e.isChinese=function(e){return y.test(e)},e.isEmail=function(e){return w.test(e)}
/**
* @description 判断对象是否是空对象
* @param { Object } 传入的对象
* @return Boolean 是否是空对象
* @example
* let obj = {
* a: 1,
* b: 2
* }
* let obj1 = {}
* isEmptyObject(obj) // false
* isEmptyObject(obj1) // true
*/,e.isEmptyObject=function(e){return!!s(e)&&0===Object.keys(e).length}
/**
* 判断是否是空字符串 多个空格也视为空字符
* @param str 需要校验的字符串
* @return Boolean 是否是空字符串
*/,e.isEmptyStr=function(e){return 0===e.replace(/(^\s*)|(\s*$)/g,"").length},e.isIOS=T,e.isJson=function(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}},e.isMobile=function(){var e=window.navigator.userAgent;return S.test(e)},e.isObject=s,e.isPhoneNum=function(e){return"string"==typeof e&&x.test(e)}
/**
* @description 判断当前是否是微信浏览器
* @return Boolean
* @example
* isWeiXin() // true
*/,e.isWeixin=function(){var e=window.navigator.userAgent.toLowerCase();return"micromessenger"===String(e.match(/MicroMessenger/i))}
/**
* 动态加载css样式
* @param url link的地址
* @param config link属性配置
* @returns Promise<void>
*/,e.loadCss=function(e,t){return new Promise((function(n,o){try{var r=document.createElement("link");for(var i in r.href=e,t)r[i]=t[i];document.getElementsByTagName("head")[0].appendChild(r),n()}catch(e){o(e)}}))}
/**
* @description 动态加载script标签
* @param url script 的地址
* @param config script配置
* @returns Promise<Event> onload的 e
*/,e.loadScript=function(e,t){return new Promise((function(n,o){try{var r=document.body||document.getElementsByTagName("body")[0],i=document.createElement("script");for(var a in i.src=e,i.onload=n,i.onerror=o,t)i[a]=t[a];r.appendChild(i)}catch(e){o(e)}}))}
/**
* @description 缓存函数
* @param { Function } fn 需要被缓存的函数
* @example
* const memoFn = memo((a) => {
* console.log('fn 被执行')
* return a * 1000
* })
*
* memoFn(10)
* 结果: console.log('fn 被执行')
* memoFn(10)
* 结果: 无console的打印,返回对象中存储的结果
*/,e.memo=function(e){var t={};return function(n){var o=n.toString();return t[o]||(t[o]=e(n))}}
/**
* @description 格式化替换字符串
* @param { string } str 需要操作的字符串
* @param { number } start 开始位置
* @param { number } end 结束位置 3 的话就是倒数第三个 倒数第三个不被替换
* @param { string } replaceStr 替换的值 默认 '*'
* @example
* console.log(omitStr('185098535', 2, 3, '*'))
* // 18****535
*/,e.omitStr=function(e,t,n,o){void 0===o&&(o="*");var r=t||0,i=n||0,a=e.length-r-i;return e.substr(0,r)+o.repeat(a)+e.substr(a+r,n)},e.parseUrl=C,e.promiseWrap=function(e){return e.then((function(e){return[null,e]})).catch((function(e){return[e,null]}))}
/**
* @description 返回rgba随机色
* @param { Number } opacity 透明度 0~1之间
* @return { String } rgba色值
* @example
* const color = randomColor(1)
* console(color)
*/,e.randomColor=function(e){return void 0===e&&(e=1),"rgba("+~~(256*Math.random())+","+~~(256*Math.random())+","+~~(256*Math.random())+","+e+")"}
/**
* @description 元素删除class
* @param { HTMLElement } el dom元素
* @param { (String | Array) } className class名称,可以是多个
* @example
* removeClass(document.body, 'd-utils')
*/,e.removeClass=function(e,n){Array.isArray(n)?n.forEach((function(n){t(e,n)&&e.classList.remove(n)})):t(e,n)&&e.classList.remove(n)}
/**
* @description 删除Cookie
* @param { String } name cookie名称 如果不传参数则设置所有cookie过期
* @returns { Array } 是一个伪数组
* @example
* removeCookie('test')
*/,e.removeCookie=function(e){var t=new Date;if(t.setTime(t.getTime()-1),e){var n=m(e);null!==n&&(document.cookie=e+"="+n+";expires="+t.toUTCString())}else{var o=m();for(var r in o)document.cookie=o[r].name+"="+o[r].value+";expires="+t.toUTCString()}}
/**
* @description 设置Cookie
* @param { String } name cookie名称
* @param { String } value cooke的值
* @param { Number } exp 过期时间 默认2小时 单位毫秒
* @example
* // 设置name为test的值为12345,设置过期时间为1小时
* setCookie('test', '12345', 60 * 60 * 1000)
*/,e.setCookie=function(e,t,n){void 0===n&&(n=72e5);var o=new Date;o.setTime(o.getTime()+n),document.cookie=e+"="+escape(t)+";expires="+o.toUTCString()}
/**
* @description 睡眠, 阻塞代码 timer毫秒
* @param { number } timer 睡眠时长 执行后续的操作
* @return promise
*/,e.sleep=function(e){return new Promise((function(t){setTimeout((function(){t()}),e)}))},e.strTrim=
/**
* @description 字符串的去除空格
* @param { String } str 操作的字符串
* @param { Number } type 类型 0: 去除首位空格;1: 去除所有空格; 2: 去除左边空格; 3: 去除右边空格; 默认为去除首位空格
* @return { String } 返回操作之后的字符串
* @example
* const str = ' d -js- ut ils '
* // 0: 去除首尾空格 默认为0
* strTrim(str)
* strTrim(str, 0)
* @example
* // 1: 去除所有空格
* strTrim(str, 1)
* @example
* // 2: 去除左边空格
* strTrim(str, 2)
* @example
* // 3: 去除右边空格
* strTrim(str, 3)
*/
function(e,t){if(void 0===t&&(t=E.StrTrimType.LEFT_RIGHT),"string"==typeof e)switch(t){case 0:return e.replace(/(^\s*)|(\s*$)/g,"");case 1:return e.replace(/\s/g,"");case 2:return e.replace(/(^\s*)/g,"");case 3:return e.replace(/(\s*$)/g,"");default:return e.replace(/(^\s*)|(\s*$)/g,"")}else console.error("str must be string but found "+typeof e,"[d-utils] GenericUtils strTrim error => ")},e.stringifyUrl=g,e.throttle=function(e,t){if(void 0===t&&(t=1e3),"function"==typeof e){var n=e,o=null,r=!0;return function(){var e=arguments,i=this;if(r)return n.apply(i,e),void(r=!1);o||(o=setTimeout((function(){setTimeout(o),o=null,n.apply(i,e)}),t))}}console.error("第一个参数必须是方法","[d-utils] GenericUtils throttle error => ")}
/**
* @description 返回数组之间的并集
* @param { Array } args 可以是多个数组,数量不限制
* @return { Array } 返回数组
*/,e.union=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Array.from(new Set([].concat.apply([],u(e))))}
/**
* @description 数组去重
* @param { Arrary } arr 要去重的arr
* @return { Array } 返回一个新的数组,不改变原来的数组
* @example
* // [1, 2, 3, undefined, "4"]
* uniqueArray([1,2,3,3,,3,3,'4',"4",'4',])
*/,e.uniqueArray=function(e){return u(new Set(e))}
/**
* @description 等待加载
* @param { funciton } callback 一个停止轮训的while事件 返回值为boolean 返回true的时候则停止阻塞 开始执行后续的代码
* @param { number } loopTime 单次轮训的时长 默认100毫秒
* @param { number } timeout 超时的时间 默认10000毫秒 10秒
* @return Promise
*/,e.wait=function(e,t,n){return void 0===t&&(t=100),void 0===n&&(n=1e4),new Promise((function(o,r){if("function"==typeof e&&"boolean"==typeof e())var i=setInterval((function(){e()&&(clearTimeout(i),clearTimeout(a),o())}),t),a=setTimeout((function(){clearTimeout(i),clearTimeout(a),r()}),n)}))},Object.defineProperty(e,"__esModule",{value:!0})}));