UNPKG

cross-env-plugins

Version:

A common-plugins npm package

2 lines (1 loc) 4.31 kB
(function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a.crossEnvPlugins={}))})(this,function(a){"use strict";function l(e){const t=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],n=new Date(e).getDay();return t[n]}function m(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 w(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 c="";for(let u=0;u<r[1].length&&e>0;u++)c=n[e%10]+r[1][u]+c,e=Math.floor(e/10);s=c.replace(/(零.)*零$/,"").replace(/^$/,"零")+r[0][i]+s}return o+s.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/^整$/,"零元整")}function M(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 D(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>{e(...r)},t)}}function T(e,t){let n=0;return(...r)=>{const o=new Date().getTime();o-n>=t&&(e(...r),n=o)}}function f(e){if(typeof e!="object"||e===null)return e;const t=Array.isArray(e)?[]:{};for(const n in e)e.hasOwnProperty(n)&&(t[n]=f(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 b(e){return[...new Set(e)]}function P(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 g={random:(e,t)=>Math.floor(Math.random()*(t-e+1))+e,formatTime:(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},getDayOfWeek:l,getTimeUntilEnd:m,formatCurrency:y,convertToChinese:w,generateRandomCode:M,debounce:D,throttle:T,getUrlParam: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]):""}},deepClone:f,mergeObjects:x,uniqueArray:b,checkPwd:P,randomStr:(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("")}};function S(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function E(e){return/^1\d{10}$/.test(e)}function $(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 h(t)?d(e):!1}function d(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 h(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 p={isEmail:S,isMobile:E,validateIDCard:$,checkCode:d,isValidDate:h};(function(e,t){typeof define=="function"&&define.amd?define([],t):typeof a=="object"&&typeof module<"u"?module.exports=t():e.crossEnvPlugins=t()})(typeof self<"u"?self:void 0,function(){return{utils:g,valids:p}}),a.utils=g,a.valids=p,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});