cross-env-plugins
Version:
A common-plugins npm package
2 lines (1 loc) • 4.13 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(e){const t=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],n=new Date(e).getDay();return t[n]}function d(e,t=new Date){t=new Date(t);const n=Date.now(),r=new Date(Date.parse(e)).getTime(),o=new Date(Date.parse(t)).getTime();if(isNaN(o)||isNaN(r))throw new Error("Invalid start or end time format");return n<o?Math.max(r-o,0):Math.max(r-n,0)}function y(e,t=2){return parseFloat(e).toFixed(t).replace(/\d(?=(\d{3})+\.)/g,"$&,")}function m(e){const t=["角","分"],n=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],r=[["元","万","亿"],["","拾","佰","仟"]];let o=e<0?"负":"";e=Math.abs(e);let s="";for(let i=0;i<t.length;i++)s+=(n[Math.floor(e*10*Math.pow(10,i))%10]+t[i]).replace(/零./,"");s=s||"整",e=Math.floor(e);for(let i=0;i<r[0].length&&e>0;i++){let a="";for(let l=0;l<r[1].length&&e>0;l++)a=n[e%10]+r[1][l]+a,e=Math.floor(e/10);s=a.replace(/(零.)*零$/,"").replace(/^$/,"零")+r[0][i]+s}return o+s.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/^整$/,"零元整")}function w(e=6){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let r=0;r<e;r++)n+=t.charAt(Math.floor(Math.random()*t.length));return n}function M(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>{e(...r)},t)}}function D(e,t){let n=0;return(...r)=>{const o=new Date().getTime();o-n>=t&&(e(...r),n=o)}}function c(e){if(typeof e!="object"||e===null)return e;const t=Array.isArray(e)?[]:{};for(const n in e)e.hasOwnProperty(n)&&(t[n]=c(e[n]));return t}function x(e,t,n=!0){for(let r in t)t.hasOwnProperty(r)&&(n||!(r in e))&&(e[r]=t[r]);return e}function T(e){return[...new Set(e)]}function b(e){let t=0;const n=["[A-Z]","[a-z]","[0-9]","[!@#$%^&*()_+\\-={};':\",.<>?`~\\[\\]\\\\/]|\\\\"];for(let r=0;r<n.length;r++)new RegExp(n[r]).test(e)&&t++;return t}const S=(e,t)=>Math.floor(Math.random()*(t-e+1))+e,$=(e=new Date,t="yyyy-MM-dd hh:mm:ss")=>{e=new Date(e);const n={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(const r in n)new RegExp("("+r+")").test(t)&&(t=t.replace(RegExp.$1,RegExp.$1.length===1?n[r]:("00"+n[r]).substr((""+n[r]).length)));return t},E=e=>{if(typeof wx<"u"){const t=getCurrentPages(),n=t[t.length-1];return e?n.options[e]:n.options}else{const t=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),n=window.location.search.substr(1).match(t);return n!=null?decodeURIComponent(n[2]):""}},P=(e=16)=>{let t=Array(26).fill(0).map((s,i)=>String.fromCharCode(97+i)),n=new Date().getTime(),r=String(n).substring(5).split("");e>26&&(r=String(n).split(""));let o=r.length;for(let s=o;s<e;s++)r.push(t[Math.floor(Math.random()*t.length)]);return r.sort(()=>Math.random()-.5).join("")},u={random:S,formatTime:$,getDayOfWeek:p,getTimeUntilEnd:d,formatCurrency:y,convertToChinese:m,generateRandomCode:w,debounce:M,throttle:D,getUrlParam:E,deepClone:c,mergeObjects:x,uniqueArray:T,checkPwd:b,randomStr:P};function A(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function R(e){return/^1\d{10}$/.test(e)}function v(e){if(!/^\d{15}$|^\d{17}(\d|X|x)$/.test(e))return!1;e.length===15&&(e=convertTo18Digits(e));const t=e.substring(6,14);return g(t)?f(e):!1}function f(e){const t=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],n=e.slice(0,17).split("").reduce((o,s,i)=>o+s*t[i],0),r="10X98765432".charAt(n%11);return e.charAt(17).toUpperCase()===r}function g(e){const t=parseInt(e.substring(0,4),10),n=parseInt(e.substring(4,6),10),r=parseInt(e.substring(6,8),10),o=new Date(t,n-1,r);return o.getFullYear()===t&&o.getMonth()===n-1&&o.getDate()===r}const h={isEmail:A,isMobile:R,validateIDCard:v,checkCode:f,isValidDate:g};(function(e,t){typeof define=="function"&&define.amd?define([],t):typeof exports=="object"&&typeof module<"u"?module.exports=t():e.crossEnvPlugins=t()})(typeof self<"u"?self:void 0,function(){return{utils:u,valids:h}});exports.utils=u;exports.valids=h;