@lntvow/utils 4.0.14 → 4.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils.cjs-bundler.cjs +849 -1
- package/dist/utils.esm-browser.mjs +1165 -1
- package/dist/utils.esm-bundler.d.ts +11 -0
- package/dist/utils.esm-bundler.mjs +731 -1
- package/dist/utils.global.js +1177 -1
- package/package.json +1 -1
|
@@ -1 +1,849 @@
|
|
|
1
|
-
"use strict";var et=Object.create;var w=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var ot=Object.getPrototypeOf,it=Object.prototype.hasOwnProperty;var st=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0})},W=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of nt(e))!it.call(t,o)&&o!==r&&w(t,o,{get:()=>e[o],enumerable:!(n=rt(e,o))||n.enumerable});return t};var S=(t,e,r)=>(r=t!=null?et(ot(t)):{},W(e||!t||!t.__esModule?w(r,"default",{value:t,enumerable:!0}):r,t)),at=t=>W(w({},"__esModule",{value:!0}),t);var Oe={};st(Oe,{base64Decode:()=>xt,base64Encode:()=>lt,castArray:()=>y,compose:()=>bt,composeRight:()=>yt,debounce:()=>ht,debugWarn:()=>U,debugWarnInvalidTypeMessage:()=>Mt,decimalToBinary:()=>dt,deepClone:()=>O,deepMerge:()=>v,deprecated:()=>St,error:()=>wt,generateRandomArray:()=>Yt,generateRandomColor:()=>vt,generateRandomDate:()=>R,generateRandomEmail:()=>X,generateRandomFloat:()=>Zt,generateRandomIdCard:()=>Gt,generateRandomMobilePhone:()=>qt,generateRandomStringFromSource:()=>T,getRandomInt:()=>a,getRandomItem:()=>p,getRandomString:()=>g,getRandomUrl:()=>Bt,hasChanged:()=>gt,isArray:()=>u,isBoolean:()=>ct,isChineseString:()=>oe,isDate:()=>C,isDateString:()=>J,isDef:()=>ut,isEmail:()=>be,isEmptyString:()=>ye,isEnglishAphabet:()=>Xt,isFloat:()=>ie,isFunction:()=>A,isIdCard:()=>he,isInteger:()=>pe,isLowerCase:()=>ee,isLowerCaseAndNumber:()=>re,isLowerCaseAndNumberAndChinese:()=>ne,isMap:()=>N,isMobilePhone:()=>le,isNegativeFloat:()=>me,isNegativeInteger:()=>ge,isNonNegativeFloat:()=>ae,isNonNegativeInteger:()=>ue,isNonPositiveFloat:()=>ce,isNonPositiveInteger:()=>de,isNull:()=>pt,isNumber:()=>f,isNumberOrNumberString:()=>Vt,isObject:()=>mt,isObjectLike:()=>$,isPlainObject:()=>x,isPositiveFloat:()=>se,isPositiveInteger:()=>fe,isPromise:()=>Y,isRegExp:()=>F,isSet:()=>k,isString:()=>P,isSymbol:()=>I,isUndef:()=>h,isUndefined:()=>ft,isUpperCase:()=>Qt,isUpperCaseAndNumber:()=>Jt,isUpperCaseAndNumberAndChinese:()=>te,isUrl:()=>xe,objectToString:()=>H,omit:()=>Ft,pick:()=>_,qs:()=>Et,throttle:()=>Dt,throwError:()=>s,throwErrorInvalidTypeMessage:()=>jt,toTypeString:()=>b,toTypeValue:()=>j,validatorChineseOrEnglish:()=>It,validatorChineseOrEnglishOrNumber:()=>Pt,validatorUppercaseOrNumbersOrSpecial:()=>Nt,validatorUppercaseOrNumbersOrUnderline:()=>kt,warn:()=>At});module.exports=at(Oe);function mt(t){let e=typeof t;return t!==null&&(e==="object"||e==="function")}function $(t){return t!==null&&typeof t=="object"}var H=Object.prototype.toString,b=t=>H.call(t),j=t=>b(t).slice(8,-1),P=t=>typeof t=="string",f=t=>typeof t=="number"&&Number.isFinite(t),ct=t=>typeof t=="boolean",pt=t=>t===null,ft=t=>t===void 0,I=t=>typeof t=="symbol",u=Array.isArray,A=t=>typeof t=="function",N=t=>b(t)==="[object Map]",k=t=>b(t)==="[object Set]",C=t=>b(t)==="[object Date]",F=t=>b(t)==="[object RegExp]",Y=t=>$(t)&&A(t?.then)&&A(t?.catch),h=t=>t==null,ut=t=>t!=null,gt=(t,e)=>t!==e;function x(t){return b(t)==="[object Object]"}function y(t){return u(t)?t:[t]}function dt(t){let e=[],r,n="";for(;t>0;)r=Math.floor(t%2),e.push(r),t=Math.floor(t/2);for(;e.length>0;)n+=e.pop().toString();return n}var Z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function lt(t){let e="",r="";for(let o=0;o<t.length;o++)r+=t[o].charCodeAt(0).toString(2).padStart(8,"0");for(let o=0;o<r.length;o+=6)e+=Z[parseInt(r.slice(o,o+6).padEnd(6,"0"),2)];let n=e.length%4;return n!==0&&(e+="=".repeat(4-n)),e}function xt(t){let e="",r="";for(let n=0;n<t.length&&t[n]!=="=";n++)r+=Z.indexOf(t[n]).toString(2).padStart(6,"0");for(let n=0;n<r.length;n+=8){let o=parseInt(r.slice(n,n+8),2);o&&(e+=String.fromCharCode(o))}return e}function bt(...t){return t.reduce((e,r)=>function(...n){return r(e(...n))})}function yt(...t){return t.reduce((e,r)=>function(...n){return e(r(...n))})}function ht(t,e=500){let r=null;return function(...n){r&&clearTimeout(r),r=setTimeout(()=>{t.apply(this,n)},e)}}function O(t){let e=new WeakMap;function r(n){if(!$(n))return n;if(C(n))return new Date(n);if(F(n))return new RegExp(n);if(Y(n))return n;if(e.has(n))return e.get(n);if(N(n)){let i=new Map;return e.set(n,i),n.forEach((c,d)=>i.set(r(d),r(c))),i}if(k(n)){let i=new Set;return e.set(n,i),n.forEach(c=>i.add(r(c))),i}let o=u(n)?Object.setPrototypeOf([],Object.getPrototypeOf(n)):Object.create(Object.getPrototypeOf(n));e.set(n,o);let m=Object.getOwnPropertyDescriptors(n);for(let i of Reflect.ownKeys(m)){let c=m[i];c.get||c.set?Object.defineProperty(o,i,c):Object.defineProperty(o,i,{...c,value:r(c.value)})}return o}return r(t)}function v(t,e,r={}){return q(G(t,r),G(e,r),r)}function q(t,e,r){return u(t)?$t(t,e,r):Ot(t,e,r)}function Ot(t,e,r){if(!x(e))return e;let n=Object.getOwnPropertyDescriptors(e);return Reflect.ownKeys(e).forEach(o=>{(x(t[o])||u(t[o]))&&(x(e[o])||u(e[o]))?t[o]=q(t[o],e[o],r):Object.defineProperty(t,o,n[o])}),t}function $t(t,e,r){let{mergeStrategy:n="replace"}=r;if(u(e))switch(n){case"merge":return t.concat(e);case"replace":return e;default:return e}return e}function G(t,e){let{deepClone:r=!0}=e;return r?O(t):t}var M=class extends Error{constructor(e,r="Utils"){super(e),this.name=r}};function s(t,e){throw new M(`[${t}] ${e}`)}function U(t,e){let r=P(t)?new M(`[${t}] ${e}`,"UtilsWarn"):t;console.warn(r)}function At(...t){console.warn(...t)}function wt(...t){console.error(...t)}var St=({from:t,replacement:e,version:r,type:n="API"})=>{U(`${n}`,`${t} is about to be deprecated in version ${r}, please use ${e} instead.`)};function jt(t,e,r,n){let o=`Invalid params: type check failed for params "${e}". Expected ${r}, got ${j(n)} with value ${n}.`;s(t,o)}function Mt(t,e,r,n){let o=`Invalid params: type check failed for params "${e}". Expected ${r}, got ${j(n)} with value ${n}.`;U(t,o)}function Rt(t,e){let{decode:r=!0}=e||{},n={};t.startsWith("?")&&(t=t.slice(1)),t.includes("?")&&(t=t.slice(t.indexOf("?")+1));let o=t.split("&").filter(Boolean);for(let m of o){let[i,c]=m.split("=");n[i]=r?decodeURIComponent(c):c}return n}function B(t,e){let{encode:r=!0}=e||{},n=[];for(let o in t){let m=t[o];n.push(`${o}=${r?encodeURIComponent(m):m}`)}return n.join("&")}function Tt(t,e,r){let n=v({encode:!0},{...r}),o=B(e,n);return t.includes("?")?t.endsWith("?")||t.endsWith("&")?`${t}${o}`:`${t}&${o}`:`${t}?${o}`}var Et={parse:Rt,stringify:B,appendQueryString:Tt};function Dt(t,e=500){let r=null;return function(...n){if(h(r))return r=Date.now(),t.apply(this,n);let o=Date.now();if(o-r>=e)return r=o,t.apply(this,n)}}function Pt(t){return!h(t)&&/^[\dA-Z\u4E00-\u9FA5]+$/i.test(t)}function It(t){return!h(t)&&/^[A-Z\u4E00-\u9FA5]+$/i.test(t)}function Nt(t){return!h(t)&&/^[\d!"#$%&'()*+,./:;<=>?@A-Z[\\\]^_`{|}~]+$/.test(t)}function kt(t){return/^[\dA-Z_]+$/.test(t)}function _(t,e,r={}){let{includeProto:n=!1,includeSymbols:o=!0,includeNonEnum:m=!1}=r,i={};return x(t)&&y(e).forEach(d=>{I(d)&&!o||!(n?d in t:Object.hasOwn(t,d))||!m&&(n?Ct(t,d):Object.getOwnPropertyDescriptor(t,d))?.enumerable===!1||(i[d]=O(t[d]))}),i}function Ct(t,e){let r=t;for(;r!==null;){let n=Object.getOwnPropertyDescriptor(r,e);if(n)return n;r=Object.getPrototypeOf(r)}}function Ft(t,e){if(!x(t))return{};let r=O(t),n=y(e),o=Object.keys(r).filter(m=>!n.includes(m));return _(r,o)}function Yt(t,e){return(!f(t)||t<=0)&&s("generateRandomArray","num \u5FC5\u987B\u5927\u4E8E0"),A(e)||s("generateRandomArray","cb \u5FC5\u987B\u662F\u51FD\u6570"),Array.from({length:t}).fill(0).map((r,n)=>e(r,n))}function vt(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}var l=S(require("dayjs"),1),V=S(require("dayjs/plugin/customParseFormat"),1);function p(t){return t[Math.floor(Math.random()*t.length)]}function a(t={}){f(t)&&(t={max:t});let{min:e=1,max:r=p(_t())}=t;Ut(e,r);let n=Math.ceil(e),o=Math.floor(r);return Math.floor(Math.random()*(o-n+1)+n)}function Ut(t,e){let r=Math.ceil(t),n=Math.floor(e);Number.isSafeInteger(r)||s("getRandomInt",`The minimum value Math.ceil(${t}) should be a safe integer`),Number.isSafeInteger(n)||s("getRandomInt",`The maximum value Math.floor(${e}) should be a safe integer`),n<r&&(e>=t&&s("getRandomInt",`No integer value found between ${t} and ${e}`),s("getRandomInt",`The maximum value ${e} should be greater than the minimum value ${t}`))}function _t(){return Array.from({length:Number.MAX_SAFE_INTEGER.toString().length}).map((t,e)=>{let r=Number.MAX_SAFE_INTEGER.toString().slice(0,e+1);return Number(r)})}(0,l.extend)(V.default);function R(t={}){let{start:e="1800-01-01 00:00:00",end:r=(0,l.default)().format("YYYY-MM-DD HH:mm:ss"),format:n="YYYY-MM-DD HH:mm:ss"}=t;(!(0,l.default)(e).isValid()||!(0,l.default)(r).isValid())&&s("generateRandomDate","start end \u53C2\u6570\u5FC5\u987B\u662F\u5408\u6CD5\u7684\u65F6\u95F4\u683C\u5F0F");let o=(0,l.default)(e).year(),m=(0,l.default)(r).year(),i=a({min:o,max:m}),c=a({min:1,max:12}),d=a({min:1,max:31}),L=a(23),z=a(59),tt=a(59),D=(0,l.default)(`${i}-${c}-${d} ${L}:${z}:${tt}`);return D.isBefore((0,l.default)(e))||D.isAfter((0,l.default)(r))?R(t):D.format(n)}function g(t={}){let e=Lt(t),r=zt(e);Wt(r);let{length:n}=e;Ht(n.min,n.max);let o=a(n),m=e.prefix||"";for(let i=0;i<o;i++)m+=r.charAt(Math.floor(Math.random()*r.length));return m+(e.suffix||"")}var Kt=16,K=1;function Lt(t){let e=f(t);return{lowerCase:!0,upperCase:!0,number:!0,...e?{}:t,length:e?{max:t,min:t}:f(t.length)?{max:t.length,min:t.length}:{max:Kt,min:K,...t.length},extra:e?[]:[...new Set(y(t.extra||[]))]}}function zt(t){let e="";return t.lowerCase&&(e+="abcdefghijklmnopqrstuvwxyz"),t.upperCase&&(e+="ABCDEFGHIJKLMNOPQRSTUVWXYZ"),t.number&&(e+="0123456789"),e+=y(t.extra).join(""),e}function Wt(t){t.length===0&&s("getRandomString","At least one character set (lowercase, uppercase, number) must be enabled or extra characters provided")}function Ht(t,e){Number.isInteger(t)||s("getRandomString","min must be an integer"),Number.isInteger(e)||s("getRandomString","max must be an integer"),t<K&&s("getRandomString",`Minimum length cannot be less than ${K}`),e<t&&s("getRandomString","Maximum length cannot be less than minimum length")}function X(){let t=["gmail.com","outlook.com.cn","example.com","qq.com","163.com","test.com.cn"],e=`${g(1)}${g({length:a({max:30,min:1})})}${g(1)}@${p(t)}`;return/\.{2,}/.test(e)?X():e}function Zt(t={}){f(t)&&(t={max:t});let{min:e=0,max:r=1,fractionDigits:n=2}=t;if(e===r)return e;if(e>r)throw new Error(`\u6700\u5927\u503C ${r} \u5E94\u5927\u4E8E\u6700\u5C0F\u503C ${e}`);return Math.random()*(r-e)+e}function T(t,e){(!f(t)||t<=0)&&s("generateRandomStringFromSource","num \u5FC5\u987B\u5927\u4E8E0"),(!u(e)||e.length===0)&&s("generateRandomStringFromSource","source \u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");let r="";for(let n=0;n<t;n++)r+=p(e);return r}function Gt(){let t=a({min:1e5,max:999999}),e=[0,1,2,3,4,5,6,7,8,9];return[t,R({format:"YYYYMMDD"}),T(3,e),T(1,[...e,"X","x"])].join("")}function qt(){return p(["13","14","15","16","17","18","19"])+a(999999999).toString().padEnd(9,"0")}function Bt(){let t=["http://","https://"],e=[".com",".net",".org",".cn",".top"],r=[`?name=${g({length:{min:4,max:8}})}`,`?id=${a()}`,`?page=${g({length:{min:2,max:4}})}`,`?query=${g({length:{min:5,max:6}})}`,`?search=${g({length:{min:1,max:4}})}`,`?token=${g({length:{min:16,max:16}})}`];return`${p(t)}${g({length:{min:5,max:25}})}${p(e)}${p(r)}`}function Vt(t){return/^\d+$/.test(t)}function Xt(t){return/^[A-Z]+$/i.test(t)}function Qt(t){return/^[A-Z]+$/.test(t)}function Jt(t){return/^[\dA-Z]+$/.test(t)}function te(t){return/^[\dA-Z\u4E00-\u9FA5]+$/.test(t)}function ee(t){return/^[a-z]+$/.test(t)}function re(t){return/^[\da-z]+$/.test(t)}function ne(t){return/^[\da-z\u4E00-\u9FA5]+$/.test(t)}function oe(t){return/^[\u4E00-\u9FA5]+$/.test(t)}function ie(t){return/^-?(?:0|[1-9]\d*)\.\d+$/.test(t)}function se(t){return/^(?:0\.0*[1-9]\d*|[1-9]\d*\.\d+)$/.test(t)}function ae(t){return/^(?:0|[1-9]\d*)\.\d+$/.test(t)}function me(t){return/^-(?:0\.0*[1-9]\d*|[1-9]\d*\.\d+)$/.test(t)}function ce(t){return/^-(?:0|[1-9]\d*)\.\d+$/.test(t)}function pe(t){return/^-?(?:0|[1-9]\d*)$/.test(t)}function fe(t){return/^[1-9]\d*$/.test(t)}function ue(t){return/^(?:0|[1-9]\d*)$/.test(t)&&!Object.is(t,-0)}function ge(t){return/^-[1-9]\d*$/.test(t)}function de(t){return/^-(?:0|[1-9]\d*)$/.test(t)||Object.is(t,-0)}var E=S(require("dayjs"),1),Q=S(require("dayjs/plugin/customParseFormat"),1);function le(t){return/^1[3-9]\d{9}$/.test(t)}function xe(t){return/^https?:\/\/\S+$/i.test(t)}function be(t){return/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(t)}function ye(t){return t===""}function J(t,e="YYYY-MM-DD HH:mm:ss"){return(0,E.extend)(Q.default),(0,E.default)(t,e,!0).isValid()}function he(t){return/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dX]$/i.test(t)&&J(t.slice(6,14),"YYYYMMDD")}0&&(module.exports={base64Decode,base64Encode,castArray,compose,composeRight,debounce,debugWarn,debugWarnInvalidTypeMessage,decimalToBinary,deepClone,deepMerge,deprecated,error,generateRandomArray,generateRandomColor,generateRandomDate,generateRandomEmail,generateRandomFloat,generateRandomIdCard,generateRandomMobilePhone,generateRandomStringFromSource,getRandomInt,getRandomItem,getRandomString,getRandomUrl,hasChanged,isArray,isBoolean,isChineseString,isDate,isDateString,isDef,isEmail,isEmptyString,isEnglishAphabet,isFloat,isFunction,isIdCard,isInteger,isLowerCase,isLowerCaseAndNumber,isLowerCaseAndNumberAndChinese,isMap,isMobilePhone,isNegativeFloat,isNegativeInteger,isNonNegativeFloat,isNonNegativeInteger,isNonPositiveFloat,isNonPositiveInteger,isNull,isNumber,isNumberOrNumberString,isObject,isObjectLike,isPlainObject,isPositiveFloat,isPositiveInteger,isPromise,isRegExp,isSet,isString,isSymbol,isUndef,isUndefined,isUpperCase,isUpperCaseAndNumber,isUpperCaseAndNumberAndChinese,isUrl,objectToString,omit,pick,qs,throttle,throwError,throwErrorInvalidTypeMessage,toTypeString,toTypeValue,validatorChineseOrEnglish,validatorChineseOrEnglishOrNumber,validatorUppercaseOrNumbersOrSpecial,validatorUppercaseOrNumbersOrUnderline,warn});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
base64Decode: () => base64Decode,
|
|
34
|
+
base64Encode: () => base64Encode,
|
|
35
|
+
castArray: () => castArray,
|
|
36
|
+
compose: () => compose,
|
|
37
|
+
composeRight: () => composeRight,
|
|
38
|
+
debounce: () => debounce,
|
|
39
|
+
debugWarn: () => debugWarn,
|
|
40
|
+
debugWarnInvalidTypeMessage: () => debugWarnInvalidTypeMessage,
|
|
41
|
+
decimalToBinary: () => decimalToBinary,
|
|
42
|
+
deepClone: () => deepClone,
|
|
43
|
+
deepMerge: () => deepMerge,
|
|
44
|
+
deprecated: () => deprecated,
|
|
45
|
+
error: () => error,
|
|
46
|
+
generateRandomArray: () => generateRandomArray,
|
|
47
|
+
generateRandomColor: () => generateRandomColor,
|
|
48
|
+
generateRandomDate: () => generateRandomDate,
|
|
49
|
+
generateRandomEmail: () => generateRandomEmail,
|
|
50
|
+
generateRandomFloat: () => generateRandomFloat,
|
|
51
|
+
generateRandomIdCard: () => generateRandomIdCard,
|
|
52
|
+
generateRandomMobilePhone: () => generateRandomMobilePhone,
|
|
53
|
+
generateRandomStringFromSource: () => generateRandomStringFromSource,
|
|
54
|
+
getRandomInt: () => getRandomInt,
|
|
55
|
+
getRandomItem: () => getRandomItem,
|
|
56
|
+
getRandomString: () => getRandomString,
|
|
57
|
+
getRandomUrl: () => getRandomUrl,
|
|
58
|
+
hasChanged: () => hasChanged,
|
|
59
|
+
isArray: () => isArray,
|
|
60
|
+
isBoolean: () => isBoolean,
|
|
61
|
+
isChineseString: () => isChineseString,
|
|
62
|
+
isDate: () => isDate,
|
|
63
|
+
isDateString: () => isDateString,
|
|
64
|
+
isDef: () => isDef,
|
|
65
|
+
isEmail: () => isEmail,
|
|
66
|
+
isEmptyString: () => isEmptyString,
|
|
67
|
+
isEnglishAphabet: () => isEnglishAphabet,
|
|
68
|
+
isFloat: () => isFloat,
|
|
69
|
+
isFunction: () => isFunction,
|
|
70
|
+
isIdCard: () => isIdCard,
|
|
71
|
+
isInteger: () => isInteger,
|
|
72
|
+
isLowerCase: () => isLowerCase,
|
|
73
|
+
isLowerCaseAndNumber: () => isLowerCaseAndNumber,
|
|
74
|
+
isLowerCaseAndNumberAndChinese: () => isLowerCaseAndNumberAndChinese,
|
|
75
|
+
isMap: () => isMap,
|
|
76
|
+
isMobilePhone: () => isMobilePhone,
|
|
77
|
+
isNegativeFloat: () => isNegativeFloat,
|
|
78
|
+
isNegativeInteger: () => isNegativeInteger,
|
|
79
|
+
isNonNegativeFloat: () => isNonNegativeFloat,
|
|
80
|
+
isNonNegativeInteger: () => isNonNegativeInteger,
|
|
81
|
+
isNonPositiveFloat: () => isNonPositiveFloat,
|
|
82
|
+
isNonPositiveInteger: () => isNonPositiveInteger,
|
|
83
|
+
isNull: () => isNull,
|
|
84
|
+
isNumber: () => isNumber,
|
|
85
|
+
isNumberOrNumberString: () => isNumberOrNumberString,
|
|
86
|
+
isObject: () => isObject,
|
|
87
|
+
isObjectLike: () => isObjectLike,
|
|
88
|
+
isPlainObject: () => isPlainObject,
|
|
89
|
+
isPositiveFloat: () => isPositiveFloat,
|
|
90
|
+
isPositiveInteger: () => isPositiveInteger,
|
|
91
|
+
isPromise: () => isPromise,
|
|
92
|
+
isRegExp: () => isRegExp,
|
|
93
|
+
isSet: () => isSet,
|
|
94
|
+
isString: () => isString,
|
|
95
|
+
isSymbol: () => isSymbol,
|
|
96
|
+
isUndef: () => isUndef,
|
|
97
|
+
isUndefined: () => isUndefined,
|
|
98
|
+
isUpperCase: () => isUpperCase,
|
|
99
|
+
isUpperCaseAndNumber: () => isUpperCaseAndNumber,
|
|
100
|
+
isUpperCaseAndNumberAndChinese: () => isUpperCaseAndNumberAndChinese,
|
|
101
|
+
isUrl: () => isUrl,
|
|
102
|
+
objectToString: () => objectToString,
|
|
103
|
+
omit: () => omit,
|
|
104
|
+
pick: () => pick,
|
|
105
|
+
qs: () => qs,
|
|
106
|
+
throttle: () => throttle,
|
|
107
|
+
throwError: () => throwError,
|
|
108
|
+
throwErrorInvalidTypeMessage: () => throwErrorInvalidTypeMessage,
|
|
109
|
+
toTypeString: () => toTypeString,
|
|
110
|
+
toTypeValue: () => toTypeValue,
|
|
111
|
+
validatorChineseOrEnglish: () => validatorChineseOrEnglish,
|
|
112
|
+
validatorChineseOrEnglishOrNumber: () => validatorChineseOrEnglishOrNumber,
|
|
113
|
+
validatorUppercaseOrNumbersOrSpecial: () => validatorUppercaseOrNumbersOrSpecial,
|
|
114
|
+
validatorUppercaseOrNumbersOrUnderline: () => validatorUppercaseOrNumbersOrUnderline,
|
|
115
|
+
warn: () => warn
|
|
116
|
+
});
|
|
117
|
+
module.exports = __toCommonJS(src_exports);
|
|
118
|
+
|
|
119
|
+
// src/lang/isObject.ts
|
|
120
|
+
function isObject(value) {
|
|
121
|
+
const type = typeof value;
|
|
122
|
+
return value !== null && (type === "object" || type === "function");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/lang/isObjectLike.ts
|
|
126
|
+
function isObjectLike(value) {
|
|
127
|
+
return value !== null && typeof value === "object";
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/lang/type.ts
|
|
131
|
+
var objectToString = Object.prototype.toString;
|
|
132
|
+
var toTypeString = (value) => objectToString.call(value);
|
|
133
|
+
var toTypeValue = (value) => toTypeString(value).slice(8, -1);
|
|
134
|
+
var isString = (val) => typeof val === "string";
|
|
135
|
+
var isNumber = (val) => typeof val === "number" && Number.isFinite(val);
|
|
136
|
+
var isBoolean = (val) => typeof val === "boolean";
|
|
137
|
+
var isNull = (val) => val === null;
|
|
138
|
+
var isUndefined = (val) => val === void 0;
|
|
139
|
+
var isSymbol = (val) => typeof val === "symbol";
|
|
140
|
+
var isArray = Array.isArray;
|
|
141
|
+
var isFunction = (val) => typeof val === "function";
|
|
142
|
+
var isMap = (val) => toTypeString(val) === "[object Map]";
|
|
143
|
+
var isSet = (val) => toTypeString(val) === "[object Set]";
|
|
144
|
+
var isDate = (val) => toTypeString(val) === "[object Date]";
|
|
145
|
+
var isRegExp = (val) => toTypeString(val) === "[object RegExp]";
|
|
146
|
+
var isPromise = (val) => isObjectLike(val) && isFunction(val?.then) && isFunction(val?.catch);
|
|
147
|
+
var isUndef = (val) => val === void 0 || val === null;
|
|
148
|
+
var isDef = (val) => val !== void 0 && val !== null;
|
|
149
|
+
var hasChanged = (oldValue, newValue) => oldValue !== newValue;
|
|
150
|
+
|
|
151
|
+
// src/lang/isPlainObject.ts
|
|
152
|
+
function isPlainObject(value) {
|
|
153
|
+
return toTypeString(value) === "[object Object]";
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/array/castArray.ts
|
|
157
|
+
function castArray(target) {
|
|
158
|
+
return isArray(target) ? target : [target];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/utils/code.ts
|
|
162
|
+
function decimalToBinary(decNumber) {
|
|
163
|
+
const stack = [];
|
|
164
|
+
let remainder;
|
|
165
|
+
let binaryString = "";
|
|
166
|
+
while (decNumber > 0) {
|
|
167
|
+
remainder = Math.floor(decNumber % 2);
|
|
168
|
+
stack.push(remainder);
|
|
169
|
+
decNumber = Math.floor(decNumber / 2);
|
|
170
|
+
}
|
|
171
|
+
while (stack.length > 0) {
|
|
172
|
+
binaryString += stack.pop().toString();
|
|
173
|
+
}
|
|
174
|
+
return binaryString;
|
|
175
|
+
}
|
|
176
|
+
var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
177
|
+
function base64Encode(str) {
|
|
178
|
+
let result = "";
|
|
179
|
+
let bin = "";
|
|
180
|
+
for (let i = 0; i < str.length; i++) {
|
|
181
|
+
bin += str[i].charCodeAt(0).toString(2).padStart(8, "0");
|
|
182
|
+
}
|
|
183
|
+
for (let i = 0; i < bin.length; i += 6) {
|
|
184
|
+
result += BASE64_CHARS[parseInt(bin.slice(i, i + 6).padEnd(6, "0"), 2)];
|
|
185
|
+
}
|
|
186
|
+
const padding = result.length % 4;
|
|
187
|
+
if (padding !== 0) result += "=".repeat(4 - padding);
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
function base64Decode(str) {
|
|
191
|
+
let result = "";
|
|
192
|
+
let bin = "";
|
|
193
|
+
for (let i = 0; i < str.length; i++) {
|
|
194
|
+
if (str[i] === "=") break;
|
|
195
|
+
bin += BASE64_CHARS.indexOf(str[i]).toString(2).padStart(6, "0");
|
|
196
|
+
}
|
|
197
|
+
for (let i = 0; i < bin.length; i += 8) {
|
|
198
|
+
const binary = parseInt(bin.slice(i, i + 8), 2);
|
|
199
|
+
if (binary) {
|
|
200
|
+
result += String.fromCharCode(binary);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/utils/compose.ts
|
|
207
|
+
function compose(...fns) {
|
|
208
|
+
return fns.reduce(
|
|
209
|
+
(previous, current) => function(...args) {
|
|
210
|
+
return current(previous(...args));
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
function composeRight(...fns) {
|
|
215
|
+
return fns.reduce(
|
|
216
|
+
(previous, current) => function(...args) {
|
|
217
|
+
return previous(current(...args));
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/utils/debounce.ts
|
|
223
|
+
function debounce(target, wait = 500) {
|
|
224
|
+
let timer = null;
|
|
225
|
+
return function(...args) {
|
|
226
|
+
if (timer) clearTimeout(timer);
|
|
227
|
+
timer = setTimeout(() => {
|
|
228
|
+
target.apply(this, args);
|
|
229
|
+
}, wait);
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/utils/deepClone.ts
|
|
234
|
+
function deepClone(target) {
|
|
235
|
+
const map = /* @__PURE__ */ new WeakMap();
|
|
236
|
+
function _deepClone(value) {
|
|
237
|
+
if (!isObjectLike(value)) return value;
|
|
238
|
+
if (isDate(value)) return new Date(value);
|
|
239
|
+
if (isRegExp(value)) return new RegExp(value);
|
|
240
|
+
if (isPromise(value)) return value;
|
|
241
|
+
if (map.has(value)) return map.get(value);
|
|
242
|
+
if (isMap(value)) {
|
|
243
|
+
const cloned2 = /* @__PURE__ */ new Map();
|
|
244
|
+
map.set(value, cloned2);
|
|
245
|
+
value.forEach((val, key) => cloned2.set(_deepClone(key), _deepClone(val)));
|
|
246
|
+
return cloned2;
|
|
247
|
+
}
|
|
248
|
+
if (isSet(value)) {
|
|
249
|
+
const cloned2 = /* @__PURE__ */ new Set();
|
|
250
|
+
map.set(value, cloned2);
|
|
251
|
+
value.forEach((val) => cloned2.add(_deepClone(val)));
|
|
252
|
+
return cloned2;
|
|
253
|
+
}
|
|
254
|
+
const cloned = isArray(value) ? Object.setPrototypeOf([], Object.getPrototypeOf(value)) : Object.create(Object.getPrototypeOf(value));
|
|
255
|
+
map.set(value, cloned);
|
|
256
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
257
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
258
|
+
const descriptor = descriptors[key];
|
|
259
|
+
if (descriptor.get || descriptor.set) {
|
|
260
|
+
Object.defineProperty(cloned, key, descriptor);
|
|
261
|
+
} else {
|
|
262
|
+
Object.defineProperty(cloned, key, { ...descriptor, value: _deepClone(descriptor.value) });
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return cloned;
|
|
266
|
+
}
|
|
267
|
+
return _deepClone(target);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/utils/deepMerge.ts
|
|
271
|
+
function deepMerge(template, source, options = {}) {
|
|
272
|
+
return _deepMerge(clone(template, options), clone(source, options), options);
|
|
273
|
+
}
|
|
274
|
+
function _deepMerge(template, source, options) {
|
|
275
|
+
return isArray(template) ? arrayMerge(template, source, options) : mergeObject(template, source, options);
|
|
276
|
+
}
|
|
277
|
+
function mergeObject(template, source, options) {
|
|
278
|
+
if (!isPlainObject(source)) return source;
|
|
279
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
280
|
+
Reflect.ownKeys(source).forEach((key) => {
|
|
281
|
+
if ((isPlainObject(template[key]) || isArray(template[key])) && (isPlainObject(source[key]) || isArray(source[key]))) {
|
|
282
|
+
template[key] = _deepMerge(template[key], source[key], options);
|
|
283
|
+
} else {
|
|
284
|
+
Object.defineProperty(template, key, descriptors[key]);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
return template;
|
|
288
|
+
}
|
|
289
|
+
function arrayMerge(template, source, options) {
|
|
290
|
+
const { mergeStrategy = "replace" } = options;
|
|
291
|
+
if (isArray(source)) {
|
|
292
|
+
switch (mergeStrategy) {
|
|
293
|
+
case "merge":
|
|
294
|
+
return template.concat(source);
|
|
295
|
+
case "replace":
|
|
296
|
+
return source;
|
|
297
|
+
default:
|
|
298
|
+
return source;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return source;
|
|
302
|
+
}
|
|
303
|
+
function clone(source, options) {
|
|
304
|
+
const { deepClone: _deepClone = true } = options;
|
|
305
|
+
return _deepClone ? deepClone(source) : source;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/utils/error.ts
|
|
309
|
+
var UtilsError = class extends Error {
|
|
310
|
+
constructor(m, name = "Utils") {
|
|
311
|
+
super(m);
|
|
312
|
+
this.name = name;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
function throwError(scope, message) {
|
|
316
|
+
throw new UtilsError(`[${scope}] ${message}`);
|
|
317
|
+
}
|
|
318
|
+
function debugWarn(scope, message) {
|
|
319
|
+
const error2 = isString(scope) ? new UtilsError(`[${scope}] ${message}`, "UtilsWarn") : scope;
|
|
320
|
+
console.warn(error2);
|
|
321
|
+
}
|
|
322
|
+
function warn(...args) {
|
|
323
|
+
console.warn(...args);
|
|
324
|
+
}
|
|
325
|
+
function error(...args) {
|
|
326
|
+
console.error(...args);
|
|
327
|
+
}
|
|
328
|
+
var deprecated = ({
|
|
329
|
+
from,
|
|
330
|
+
replacement,
|
|
331
|
+
version,
|
|
332
|
+
type = "API"
|
|
333
|
+
}) => {
|
|
334
|
+
debugWarn(`${type}`, `${from} is about to be deprecated in version ${version}, please use ${replacement} instead.`);
|
|
335
|
+
};
|
|
336
|
+
function throwErrorInvalidTypeMessage(scope, key, type, value) {
|
|
337
|
+
const message = `Invalid params: type check failed for params "${key}". Expected ${type}, got ${toTypeValue(value)} with value ${value}.`;
|
|
338
|
+
throwError(scope, message);
|
|
339
|
+
}
|
|
340
|
+
function debugWarnInvalidTypeMessage(scope, key, type, value) {
|
|
341
|
+
const message = `Invalid params: type check failed for params "${key}". Expected ${type}, got ${toTypeValue(value)} with value ${value}.`;
|
|
342
|
+
debugWarn(scope, message);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/utils/log.ts
|
|
346
|
+
var baseConsole = (type, name, ...arg) => {
|
|
347
|
+
if (!name) return;
|
|
348
|
+
const context = arg.length === 0 ? "" : arg.length === 1 ? arg[0] : arg;
|
|
349
|
+
console[type](`[Log] ${name}:`, context);
|
|
350
|
+
};
|
|
351
|
+
var log = (name, ...arg) => {
|
|
352
|
+
baseConsole("info", name, ...arg);
|
|
353
|
+
};
|
|
354
|
+
log.info = (name, ...arg) => {
|
|
355
|
+
baseConsole("info", name, ...arg);
|
|
356
|
+
};
|
|
357
|
+
log.error = (name, ...arg) => {
|
|
358
|
+
baseConsole("error", name, ...arg);
|
|
359
|
+
};
|
|
360
|
+
log.warn = (name, ...arg) => {
|
|
361
|
+
baseConsole("warn", name, ...arg);
|
|
362
|
+
};
|
|
363
|
+
if (typeof globalThis !== "undefined") {
|
|
364
|
+
globalThis.log = log;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/utils/qs.ts
|
|
368
|
+
function parse(str, options) {
|
|
369
|
+
const { decode = true } = options || {};
|
|
370
|
+
const result = {};
|
|
371
|
+
str.startsWith("?") && (str = str.slice(1));
|
|
372
|
+
str.includes("?") && (str = str.slice(str.indexOf("?") + 1));
|
|
373
|
+
const pairs = str.split("&").filter(Boolean);
|
|
374
|
+
for (const pair of pairs) {
|
|
375
|
+
const [key, value] = pair.split("=");
|
|
376
|
+
result[key] = decode ? decodeURIComponent(value) : value;
|
|
377
|
+
}
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
function stringify(obj, options) {
|
|
381
|
+
const { encode = true } = options || {};
|
|
382
|
+
const pairs = [];
|
|
383
|
+
for (const key in obj) {
|
|
384
|
+
const value = obj[key];
|
|
385
|
+
pairs.push(`${key}=${encode ? encodeURIComponent(value) : value}`);
|
|
386
|
+
}
|
|
387
|
+
return pairs.join("&");
|
|
388
|
+
}
|
|
389
|
+
function appendQueryString(url, obj, options) {
|
|
390
|
+
const stringifyOptions = deepMerge({ encode: true }, { ...options });
|
|
391
|
+
const query = stringify(obj, stringifyOptions);
|
|
392
|
+
if (url.includes("?")) {
|
|
393
|
+
return url.endsWith("?") || url.endsWith("&") ? `${url}${query}` : `${url}&${query}`;
|
|
394
|
+
}
|
|
395
|
+
return `${url}?${query}`;
|
|
396
|
+
}
|
|
397
|
+
var qs = {
|
|
398
|
+
parse,
|
|
399
|
+
stringify,
|
|
400
|
+
appendQueryString
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// src/utils/throttle.ts
|
|
404
|
+
function throttle(target, wait = 500) {
|
|
405
|
+
let timer = null;
|
|
406
|
+
return function(...args) {
|
|
407
|
+
if (isUndef(timer)) {
|
|
408
|
+
timer = Date.now();
|
|
409
|
+
return target.apply(this, args);
|
|
410
|
+
}
|
|
411
|
+
const now = Date.now();
|
|
412
|
+
if (now - timer >= wait) {
|
|
413
|
+
timer = now;
|
|
414
|
+
return target.apply(this, args);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/utils/validator.ts
|
|
420
|
+
function validatorChineseOrEnglishOrNumber(value) {
|
|
421
|
+
return !isUndef(value) && /^[\dA-Z\u4E00-\u9FA5]+$/i.test(value);
|
|
422
|
+
}
|
|
423
|
+
function validatorChineseOrEnglish(value) {
|
|
424
|
+
return !isUndef(value) && /^[A-Z\u4E00-\u9FA5]+$/i.test(value);
|
|
425
|
+
}
|
|
426
|
+
function validatorUppercaseOrNumbersOrSpecial(value) {
|
|
427
|
+
return !isUndef(value) && /^[\d!"#$%&'()*+,./:;<=>?@A-Z[\\\]^_`{|}~]+$/.test(value);
|
|
428
|
+
}
|
|
429
|
+
function validatorUppercaseOrNumbersOrUnderline(value) {
|
|
430
|
+
return /^[\dA-Z_]+$/.test(value);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/object/pick.ts
|
|
434
|
+
function pick(target, properties, options = {}) {
|
|
435
|
+
const { includeProto = false, includeSymbols = true, includeNonEnum = false } = options;
|
|
436
|
+
const cloned = {};
|
|
437
|
+
if (!isPlainObject(target)) return cloned;
|
|
438
|
+
const propsToPick = castArray(properties);
|
|
439
|
+
propsToPick.forEach((key) => {
|
|
440
|
+
if (isSymbol(key) && !includeSymbols) return;
|
|
441
|
+
const exists = includeProto ? key in target : Object.hasOwn(target, key);
|
|
442
|
+
if (!exists) return;
|
|
443
|
+
if (!includeNonEnum) {
|
|
444
|
+
const descriptor = includeProto ? findPropertyDescriptor(target, key) : Object.getOwnPropertyDescriptor(target, key);
|
|
445
|
+
if (descriptor?.enumerable === false) return;
|
|
446
|
+
}
|
|
447
|
+
cloned[key] = deepClone(target[key]);
|
|
448
|
+
});
|
|
449
|
+
return cloned;
|
|
450
|
+
}
|
|
451
|
+
function findPropertyDescriptor(obj, key) {
|
|
452
|
+
let current = obj;
|
|
453
|
+
while (current !== null) {
|
|
454
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
455
|
+
if (descriptor) return descriptor;
|
|
456
|
+
current = Object.getPrototypeOf(current);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// src/object/omit.ts
|
|
461
|
+
function omit(target, properties) {
|
|
462
|
+
if (!isPlainObject(target)) return {};
|
|
463
|
+
const cloned = deepClone(target);
|
|
464
|
+
const propsToOmit = castArray(properties);
|
|
465
|
+
const keysToPick = Object.keys(cloned).filter(
|
|
466
|
+
(key) => !propsToOmit.includes(key)
|
|
467
|
+
);
|
|
468
|
+
return pick(cloned, keysToPick);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// src/random/generateRandomArray.ts
|
|
472
|
+
function generateRandomArray(num, cb) {
|
|
473
|
+
if (!isNumber(num) || num <= 0) {
|
|
474
|
+
throwError("generateRandomArray", "num \u5FC5\u987B\u5927\u4E8E0");
|
|
475
|
+
}
|
|
476
|
+
if (!isFunction(cb)) {
|
|
477
|
+
throwError("generateRandomArray", "cb \u5FC5\u987B\u662F\u51FD\u6570");
|
|
478
|
+
}
|
|
479
|
+
return Array.from({ length: num }).fill(0).map((e, i) => cb(e, i));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/random/generateRandomColor.ts
|
|
483
|
+
function generateRandomColor() {
|
|
484
|
+
return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/random/generateRandomDate.ts
|
|
488
|
+
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
489
|
+
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"), 1);
|
|
490
|
+
|
|
491
|
+
// src/random/getRandomItem.ts
|
|
492
|
+
function getRandomItem(list) {
|
|
493
|
+
return list[Math.floor(Math.random() * list.length)];
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// src/random/getRandomInt.ts
|
|
497
|
+
function getRandomInt(options = {}) {
|
|
498
|
+
if (isNumber(options)) options = { max: options };
|
|
499
|
+
const { min = 1, max = getRandomItem(getMaxSafeIntegerList()) } = options;
|
|
500
|
+
validateOptions(min, max);
|
|
501
|
+
const effectiveMin = Math.ceil(min);
|
|
502
|
+
const effectiveMax = Math.floor(max);
|
|
503
|
+
return Math.floor(Math.random() * (effectiveMax - effectiveMin + 1) + effectiveMin);
|
|
504
|
+
}
|
|
505
|
+
function validateOptions(min, max) {
|
|
506
|
+
const effectiveMin = Math.ceil(min);
|
|
507
|
+
const effectiveMax = Math.floor(max);
|
|
508
|
+
if (!Number.isSafeInteger(effectiveMin)) {
|
|
509
|
+
throwError("getRandomInt", `The minimum value Math.ceil(${min}) should be a safe integer`);
|
|
510
|
+
}
|
|
511
|
+
if (!Number.isSafeInteger(effectiveMax)) {
|
|
512
|
+
throwError("getRandomInt", `The maximum value Math.floor(${max}) should be a safe integer`);
|
|
513
|
+
}
|
|
514
|
+
if (effectiveMax < effectiveMin) {
|
|
515
|
+
if (max >= min) {
|
|
516
|
+
throwError("getRandomInt", `No integer value found between ${min} and ${max}`);
|
|
517
|
+
}
|
|
518
|
+
throwError("getRandomInt", `The maximum value ${max} should be greater than the minimum value ${min}`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function getMaxSafeIntegerList() {
|
|
522
|
+
return Array.from({ length: Number.MAX_SAFE_INTEGER.toString().length }).map((_, i) => {
|
|
523
|
+
const max = Number.MAX_SAFE_INTEGER.toString().slice(0, i + 1);
|
|
524
|
+
return Number(max);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// src/random/generateRandomDate.ts
|
|
529
|
+
(0, import_dayjs.extend)(import_customParseFormat.default);
|
|
530
|
+
function generateRandomDate(options = {}) {
|
|
531
|
+
const {
|
|
532
|
+
start = "1800-01-01 00:00:00",
|
|
533
|
+
end = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss"),
|
|
534
|
+
format = "YYYY-MM-DD HH:mm:ss"
|
|
535
|
+
} = options;
|
|
536
|
+
if (!(0, import_dayjs.default)(start).isValid() || !(0, import_dayjs.default)(end).isValid()) {
|
|
537
|
+
throwError("generateRandomDate", "start end \u53C2\u6570\u5FC5\u987B\u662F\u5408\u6CD5\u7684\u65F6\u95F4\u683C\u5F0F");
|
|
538
|
+
}
|
|
539
|
+
const startYear = (0, import_dayjs.default)(start).year();
|
|
540
|
+
const endYear = (0, import_dayjs.default)(end).year();
|
|
541
|
+
const randomYear = getRandomInt({ min: startYear, max: endYear });
|
|
542
|
+
const randomMonth = getRandomInt({ min: 1, max: 12 });
|
|
543
|
+
const randomDay = getRandomInt({ min: 1, max: 31 });
|
|
544
|
+
const randomHour = getRandomInt(23);
|
|
545
|
+
const randomMinute = getRandomInt(59);
|
|
546
|
+
const randomSecond = getRandomInt(59);
|
|
547
|
+
const result = (0, import_dayjs.default)(`${randomYear}-${randomMonth}-${randomDay} ${randomHour}:${randomMinute}:${randomSecond}`);
|
|
548
|
+
if (result.isBefore((0, import_dayjs.default)(start)) || result.isAfter((0, import_dayjs.default)(end))) {
|
|
549
|
+
return generateRandomDate(options);
|
|
550
|
+
}
|
|
551
|
+
return result.format(format);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// src/random/getRandomString.ts
|
|
555
|
+
function getRandomString(options = {}) {
|
|
556
|
+
const normalizedOptions = normalizeOptions(options);
|
|
557
|
+
const characters = buildCharacterSet(normalizedOptions);
|
|
558
|
+
validateLengthCharacters(characters);
|
|
559
|
+
const { length } = normalizedOptions;
|
|
560
|
+
validateLength(length.min, length.max);
|
|
561
|
+
const len = getRandomInt(length);
|
|
562
|
+
let result = normalizedOptions.prefix || "";
|
|
563
|
+
for (let i = 0; i < len; i++) {
|
|
564
|
+
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
565
|
+
}
|
|
566
|
+
return result + (normalizedOptions.suffix || "");
|
|
567
|
+
}
|
|
568
|
+
var DEFAULT_MAX = 16;
|
|
569
|
+
var DEFAULT_MIN = 1;
|
|
570
|
+
function normalizeOptions(options) {
|
|
571
|
+
const simple = isNumber(options);
|
|
572
|
+
return {
|
|
573
|
+
lowerCase: true,
|
|
574
|
+
upperCase: true,
|
|
575
|
+
number: true,
|
|
576
|
+
...simple ? {} : options,
|
|
577
|
+
length: simple ? { max: options, min: options } : isNumber(options.length) ? { max: options.length, min: options.length } : { max: DEFAULT_MAX, min: DEFAULT_MIN, ...options.length },
|
|
578
|
+
extra: simple ? [] : [...new Set(castArray(options.extra || []))]
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function buildCharacterSet(options) {
|
|
582
|
+
let characters = "";
|
|
583
|
+
if (options.lowerCase) characters += "abcdefghijklmnopqrstuvwxyz";
|
|
584
|
+
if (options.upperCase) characters += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
585
|
+
if (options.number) characters += "0123456789";
|
|
586
|
+
characters += castArray(options.extra).join("");
|
|
587
|
+
return characters;
|
|
588
|
+
}
|
|
589
|
+
function validateLengthCharacters(characters) {
|
|
590
|
+
if (characters.length === 0) {
|
|
591
|
+
throwError(
|
|
592
|
+
"getRandomString",
|
|
593
|
+
"At least one character set (lowercase, uppercase, number) must be enabled or extra characters provided"
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function validateLength(min, max) {
|
|
598
|
+
if (!Number.isInteger(min)) throwError("getRandomString", "min must be an integer");
|
|
599
|
+
if (!Number.isInteger(max)) throwError("getRandomString", "max must be an integer");
|
|
600
|
+
if (min < DEFAULT_MIN) throwError("getRandomString", `Minimum length cannot be less than ${DEFAULT_MIN}`);
|
|
601
|
+
if (max < min) throwError("getRandomString", `Maximum length cannot be less than minimum length`);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// src/random/generateRandomEmail.ts
|
|
605
|
+
function generateRandomEmail() {
|
|
606
|
+
const emailProviders = ["gmail.com", "outlook.com.cn", "example.com", "qq.com", "163.com", "test.com.cn"];
|
|
607
|
+
const result = `${getRandomString(1)}${getRandomString({
|
|
608
|
+
length: getRandomInt({ max: 30, min: 1 })
|
|
609
|
+
})}${getRandomString(1)}@${getRandomItem(emailProviders)}`;
|
|
610
|
+
if (/\.{2,}/.test(result)) {
|
|
611
|
+
return generateRandomEmail();
|
|
612
|
+
}
|
|
613
|
+
return result;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// src/random/generateRandomFloat.ts
|
|
617
|
+
function generateRandomFloat(options = {}) {
|
|
618
|
+
if (isNumber(options)) {
|
|
619
|
+
options = { max: options };
|
|
620
|
+
}
|
|
621
|
+
const { min = 0, max = 1, fractionDigits = 2 } = options;
|
|
622
|
+
if (min === max) {
|
|
623
|
+
return min;
|
|
624
|
+
}
|
|
625
|
+
if (min > max) {
|
|
626
|
+
throw new Error(`\u6700\u5927\u503C ${max} \u5E94\u5927\u4E8E\u6700\u5C0F\u503C ${min}`);
|
|
627
|
+
}
|
|
628
|
+
return Math.random() * (max - min) + min;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// src/random/generateRandomStringFromSource.ts
|
|
632
|
+
function generateRandomStringFromSource(num, source) {
|
|
633
|
+
if (!isNumber(num) || num <= 0) {
|
|
634
|
+
throwError("generateRandomStringFromSource", "num \u5FC5\u987B\u5927\u4E8E0");
|
|
635
|
+
}
|
|
636
|
+
if (!isArray(source) || source.length === 0) {
|
|
637
|
+
throwError("generateRandomStringFromSource", "source \u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");
|
|
638
|
+
}
|
|
639
|
+
let result = "";
|
|
640
|
+
for (let i = 0; i < num; i++) {
|
|
641
|
+
result += getRandomItem(source);
|
|
642
|
+
}
|
|
643
|
+
return result;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// src/random/generateRandomIdCard.ts
|
|
647
|
+
function generateRandomIdCard() {
|
|
648
|
+
const prefix = getRandomInt({ min: 1e5, max: 999999 });
|
|
649
|
+
const zeroToNine = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
650
|
+
return [
|
|
651
|
+
prefix,
|
|
652
|
+
generateRandomDate({ format: "YYYYMMDD" }),
|
|
653
|
+
generateRandomStringFromSource(3, zeroToNine),
|
|
654
|
+
generateRandomStringFromSource(1, [...zeroToNine, "X", "x"])
|
|
655
|
+
].join("");
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// src/random/generateRandomMobilePhone.ts
|
|
659
|
+
function generateRandomMobilePhone() {
|
|
660
|
+
return getRandomItem(["13", "14", "15", "16", "17", "18", "19"]) + getRandomInt(999999999).toString().padEnd(9, "0");
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// src/random/getRandomUrl.ts
|
|
664
|
+
function getRandomUrl() {
|
|
665
|
+
const urlPrefix = ["http://", "https://"];
|
|
666
|
+
const domainSuffix = [".com", ".net", ".org", ".cn", ".top"];
|
|
667
|
+
const parameters = [
|
|
668
|
+
`?name=${getRandomString({ length: { min: 4, max: 8 } })}`,
|
|
669
|
+
`?id=${getRandomInt()}`,
|
|
670
|
+
`?page=${getRandomString({ length: { min: 2, max: 4 } })}`,
|
|
671
|
+
`?query=${getRandomString({ length: { min: 5, max: 6 } })}`,
|
|
672
|
+
`?search=${getRandomString({ length: { min: 1, max: 4 } })}`,
|
|
673
|
+
`?token=${getRandomString({ length: { min: 16, max: 16 } })}`
|
|
674
|
+
];
|
|
675
|
+
return `${getRandomItem(urlPrefix)}${getRandomString({ length: { min: 5, max: 25 } })}${getRandomItem(domainSuffix)}${getRandomItem(parameters)}`;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// src/validator/aphabet.ts
|
|
679
|
+
function isNumberOrNumberString(val) {
|
|
680
|
+
return /^\d+$/.test(val);
|
|
681
|
+
}
|
|
682
|
+
function isEnglishAphabet(val) {
|
|
683
|
+
return /^[A-Z]+$/i.test(val);
|
|
684
|
+
}
|
|
685
|
+
function isUpperCase(val) {
|
|
686
|
+
return /^[A-Z]+$/.test(val);
|
|
687
|
+
}
|
|
688
|
+
function isUpperCaseAndNumber(val) {
|
|
689
|
+
return /^[\dA-Z]+$/.test(val);
|
|
690
|
+
}
|
|
691
|
+
function isUpperCaseAndNumberAndChinese(val) {
|
|
692
|
+
return /^[\dA-Z\u4E00-\u9FA5]+$/.test(val);
|
|
693
|
+
}
|
|
694
|
+
function isLowerCase(val) {
|
|
695
|
+
return /^[a-z]+$/.test(val);
|
|
696
|
+
}
|
|
697
|
+
function isLowerCaseAndNumber(val) {
|
|
698
|
+
return /^[\da-z]+$/.test(val);
|
|
699
|
+
}
|
|
700
|
+
function isLowerCaseAndNumberAndChinese(val) {
|
|
701
|
+
return /^[\da-z\u4E00-\u9FA5]+$/.test(val);
|
|
702
|
+
}
|
|
703
|
+
function isChineseString(val) {
|
|
704
|
+
return /^[\u4E00-\u9FA5]+$/.test(val);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/validator/float.ts
|
|
708
|
+
function isFloat(val) {
|
|
709
|
+
return /^-?(?:0|[1-9]\d*)\.\d+$/.test(val);
|
|
710
|
+
}
|
|
711
|
+
function isPositiveFloat(val) {
|
|
712
|
+
return /^(?:0\.0*[1-9]\d*|[1-9]\d*\.\d+)$/.test(val);
|
|
713
|
+
}
|
|
714
|
+
function isNonNegativeFloat(val) {
|
|
715
|
+
return /^(?:0|[1-9]\d*)\.\d+$/.test(val);
|
|
716
|
+
}
|
|
717
|
+
function isNegativeFloat(val) {
|
|
718
|
+
return /^-(?:0\.0*[1-9]\d*|[1-9]\d*\.\d+)$/.test(val);
|
|
719
|
+
}
|
|
720
|
+
function isNonPositiveFloat(val) {
|
|
721
|
+
return /^-(?:0|[1-9]\d*)\.\d+$/.test(val);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// src/validator/integer.ts
|
|
725
|
+
function isInteger(val) {
|
|
726
|
+
return /^-?(?:0|[1-9]\d*)$/.test(val);
|
|
727
|
+
}
|
|
728
|
+
function isPositiveInteger(val) {
|
|
729
|
+
return /^[1-9]\d*$/.test(val);
|
|
730
|
+
}
|
|
731
|
+
function isNonNegativeInteger(val) {
|
|
732
|
+
return /^(?:0|[1-9]\d*)$/.test(val) && !Object.is(val, -0);
|
|
733
|
+
}
|
|
734
|
+
function isNegativeInteger(val) {
|
|
735
|
+
return /^-[1-9]\d*$/.test(val);
|
|
736
|
+
}
|
|
737
|
+
function isNonPositiveInteger(val) {
|
|
738
|
+
return /^-(?:0|[1-9]\d*)$/.test(val) || Object.is(val, -0);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// src/validator/utils.ts
|
|
742
|
+
var import_dayjs2 = __toESM(require("dayjs"), 1);
|
|
743
|
+
var import_customParseFormat2 = __toESM(require("dayjs/plugin/customParseFormat"), 1);
|
|
744
|
+
function isMobilePhone(val) {
|
|
745
|
+
return /^1[3-9]\d{9}$/.test(val);
|
|
746
|
+
}
|
|
747
|
+
function isUrl(val) {
|
|
748
|
+
return /^https?:\/\/\S+$/i.test(val);
|
|
749
|
+
}
|
|
750
|
+
function isEmail(val) {
|
|
751
|
+
return /^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(val);
|
|
752
|
+
}
|
|
753
|
+
function isEmptyString(val) {
|
|
754
|
+
return val === "";
|
|
755
|
+
}
|
|
756
|
+
function isDateString(val, format = "YYYY-MM-DD HH:mm:ss") {
|
|
757
|
+
(0, import_dayjs2.extend)(import_customParseFormat2.default);
|
|
758
|
+
return (0, import_dayjs2.default)(val, format, true).isValid();
|
|
759
|
+
}
|
|
760
|
+
function isIdCard(val) {
|
|
761
|
+
const flag = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dX]$/i.test(val) && isDateString(val.slice(6, 14), "YYYYMMDD");
|
|
762
|
+
return flag;
|
|
763
|
+
}
|
|
764
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
765
|
+
0 && (module.exports = {
|
|
766
|
+
base64Decode,
|
|
767
|
+
base64Encode,
|
|
768
|
+
castArray,
|
|
769
|
+
compose,
|
|
770
|
+
composeRight,
|
|
771
|
+
debounce,
|
|
772
|
+
debugWarn,
|
|
773
|
+
debugWarnInvalidTypeMessage,
|
|
774
|
+
decimalToBinary,
|
|
775
|
+
deepClone,
|
|
776
|
+
deepMerge,
|
|
777
|
+
deprecated,
|
|
778
|
+
error,
|
|
779
|
+
generateRandomArray,
|
|
780
|
+
generateRandomColor,
|
|
781
|
+
generateRandomDate,
|
|
782
|
+
generateRandomEmail,
|
|
783
|
+
generateRandomFloat,
|
|
784
|
+
generateRandomIdCard,
|
|
785
|
+
generateRandomMobilePhone,
|
|
786
|
+
generateRandomStringFromSource,
|
|
787
|
+
getRandomInt,
|
|
788
|
+
getRandomItem,
|
|
789
|
+
getRandomString,
|
|
790
|
+
getRandomUrl,
|
|
791
|
+
hasChanged,
|
|
792
|
+
isArray,
|
|
793
|
+
isBoolean,
|
|
794
|
+
isChineseString,
|
|
795
|
+
isDate,
|
|
796
|
+
isDateString,
|
|
797
|
+
isDef,
|
|
798
|
+
isEmail,
|
|
799
|
+
isEmptyString,
|
|
800
|
+
isEnglishAphabet,
|
|
801
|
+
isFloat,
|
|
802
|
+
isFunction,
|
|
803
|
+
isIdCard,
|
|
804
|
+
isInteger,
|
|
805
|
+
isLowerCase,
|
|
806
|
+
isLowerCaseAndNumber,
|
|
807
|
+
isLowerCaseAndNumberAndChinese,
|
|
808
|
+
isMap,
|
|
809
|
+
isMobilePhone,
|
|
810
|
+
isNegativeFloat,
|
|
811
|
+
isNegativeInteger,
|
|
812
|
+
isNonNegativeFloat,
|
|
813
|
+
isNonNegativeInteger,
|
|
814
|
+
isNonPositiveFloat,
|
|
815
|
+
isNonPositiveInteger,
|
|
816
|
+
isNull,
|
|
817
|
+
isNumber,
|
|
818
|
+
isNumberOrNumberString,
|
|
819
|
+
isObject,
|
|
820
|
+
isObjectLike,
|
|
821
|
+
isPlainObject,
|
|
822
|
+
isPositiveFloat,
|
|
823
|
+
isPositiveInteger,
|
|
824
|
+
isPromise,
|
|
825
|
+
isRegExp,
|
|
826
|
+
isSet,
|
|
827
|
+
isString,
|
|
828
|
+
isSymbol,
|
|
829
|
+
isUndef,
|
|
830
|
+
isUndefined,
|
|
831
|
+
isUpperCase,
|
|
832
|
+
isUpperCaseAndNumber,
|
|
833
|
+
isUpperCaseAndNumberAndChinese,
|
|
834
|
+
isUrl,
|
|
835
|
+
objectToString,
|
|
836
|
+
omit,
|
|
837
|
+
pick,
|
|
838
|
+
qs,
|
|
839
|
+
throttle,
|
|
840
|
+
throwError,
|
|
841
|
+
throwErrorInvalidTypeMessage,
|
|
842
|
+
toTypeString,
|
|
843
|
+
toTypeValue,
|
|
844
|
+
validatorChineseOrEnglish,
|
|
845
|
+
validatorChineseOrEnglishOrNumber,
|
|
846
|
+
validatorUppercaseOrNumbersOrSpecial,
|
|
847
|
+
validatorUppercaseOrNumbersOrUnderline,
|
|
848
|
+
warn
|
|
849
|
+
});
|