UNPKG

cross-env-plugins

Version:

A common-plugins npm package

194 lines (193 loc) 5.69 kB
function g(e) { const t = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], n = new Date(e).getDay(); return t[n]; } function h(e, t = /* @__PURE__ */ 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 p(e, t = 2) { return parseFloat(e).toFixed(t).replace(/\d(?=(\d{3})+\.)/g, "$&,"); } function d(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 y(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 w(e, t) { let n = 0; return (...r) => { const o = (/* @__PURE__ */ 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 M(e, t, n = !0) { for (let r in t) t.hasOwnProperty(r) && (n || !(r in e)) && (e[r] = t[r]); return e; } function D(e) { return [...new Set(e)]; } function x(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 T = (e, t) => Math.floor(Math.random() * (t - e + 1)) + e, $ = (e = /* @__PURE__ */ 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; }, b = (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]) : ""; } }, E = (e = 16) => { let t = Array(26).fill(0).map((s, i) => String.fromCharCode(97 + i)), n = (/* @__PURE__ */ 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() - 0.5).join(""); }, P = { random: T, // 随机数 formatTime: $, // 格式化时间 getDayOfWeek: g, // 获取日期对应的星期几 getTimeUntilEnd: h, // 计算当前时间距离结束时间的时间戳 formatCurrency: p, // 金额格式化 convertToChinese: d, // 金额转换为中文大写 generateRandomCode: y, // 生成随机验证码 debounce: m, // 防抖 throttle: w, // 节流 getUrlParam: b, // 解析url 获取指定参数值 deepClone: c, // 深拷贝 mergeObjects: M, // 对象合并 uniqueArray: D, // 数组去重 checkPwd: x, // 检测密码强度等级 randomStr: E // 随机字符串 }; function S(e) { return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e); } function A(e) { return /^1\d{10}$/.test(e); } function R(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 f(t) ? u(e) : !1; } function u(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 f(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 k = { isEmail: S, isMobile: A, validateIDCard: R, checkCode: u, isValidDate: f }; (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: P, valids: k }; }); export { P as utils, k as valids };