@lntvow/utils 4.0.4 → 4.0.5
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.esm-bundler.mjs → esm-bundler.mjs} +1 -1
- package/package.json +7 -7
- /package/dist/{utils.esm-browser.mjs → esm-browser.mjs} +0 -0
- /package/dist/{utils.esm-bundler.cjs → esm-bundler.cjs} +0 -0
- /package/dist/{utils.esm-bundler.d.ts → esm-bundler.d.ts} +0 -0
- /package/dist/{utils.global.js → global.js} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* @ts-self-types="./
|
|
1
|
+
/* @ts-self-types="./esm-bundler.d.ts" */
|
|
2
2
|
function dt(t){let e=typeof t;return t!==null&&(e==="object"||e==="function")}function w(t){return t!==null&&typeof t=="object"}var B=Object.prototype.toString,b=t=>B.call(t),M=t=>b(t).slice(8,-1),I=t=>typeof t=="string",u=t=>typeof t=="number"&&Number.isFinite(t),ht=t=>typeof t=="boolean",Ot=t=>t===null,wt=t=>t===void 0,N=t=>typeof t=="symbol",g=Array.isArray,$=t=>typeof t=="function",C=t=>b(t)==="[object Map]",F=t=>b(t)==="[object Set]",v=t=>b(t)==="[object Date]",Y=t=>b(t)==="[object RegExp]",U=t=>w(t)&&$(t?.then)&&$(t?.catch),h=t=>t==null,$t=t=>t!=null,At=(t,e)=>t!==e;function d(t){return b(t)==="[object Object]"}function y(t){return g(t)?t:[t]}function Ft(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 _="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function vt(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+=_[parseInt(r.slice(o,o+6).padEnd(6,"0"),2)];let n=e.length%4;return n!==0&&(e+="=".repeat(4-n)),e}function Yt(t){let e="",r="";for(let n=0;n<t.length&&t[n]!=="=";n++)r+=_.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 _t(...t){return t.reduce((e,r)=>function(...n){return r(e(...n))})}function Kt(...t){return t.reduce((e,r)=>function(...n){return e(r(...n))})}function zt(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(!w(n))return n;if(v(n))return new Date(n);if(Y(n))return new RegExp(n);if(U(n))return n;if(e.has(n))return e.get(n);if(C(n)){let i=new Map;return e.set(n,i),n.forEach((c,f)=>i.set(r(f),r(c))),i}if(F(n)){let i=new Set;return e.set(n,i),n.forEach(c=>i.add(r(c))),i}let o=g(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 L(t,e,r={}){return z(K(t,r),K(e,r),r)}function z(t,e,r){return g(t)?X(t,e,r):V(t,e,r)}function V(t,e,r){if(!d(e))return e;let n=Object.getOwnPropertyDescriptors(e);return Reflect.ownKeys(e).forEach(o=>{(d(t[o])||g(t[o]))&&(d(e[o])||g(e[o]))?t[o]=z(t[o],e[o],r):Object.defineProperty(t,o,n[o])}),t}function X(t,e,r){let{mergeStrategy:n="replace"}=r;if(g(e))switch(n){case"merge":return t.concat(e);case"replace":return e;default:return e}return e}function K(t,e){let{deepClone:r=!0}=e;return r?O(t):t}var A=class extends Error{constructor(e,r="Utils"){super(e),this.name=r}};function s(t,e){throw new A(`[${t}] ${e}`)}function W(t,e){let r=I(t)?new A(`[${t}] ${e}`,"UtilsWarn"):t;console.warn(r)}function Xt(...t){console.warn(...t)}function Qt(...t){console.error(...t)}var H=({from:t,replacement:e,version:r,type:n="API"})=>{W(`${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 ${M(n)} with value ${n}.`;s(t,o)}function te(t,e,r,n){let o=`Invalid params: type check failed for params "${e}". Expected ${r}, got ${M(n)} with value ${n}.`;W(t,o)}var S=(t,e,...r)=>{if(!e)return;let n=r.length===0?"":r.length===1?r[0]:r;console[t](`[Log] ${e}:`,n)},j=(t,...e)=>{S("info",t,...e)};j.info=(t,...e)=>{S("info",t,...e)};j.error=(t,...e)=>{S("error",t,...e)};j.warn=(t,...e)=>{S("warn",t,...e)};function Q(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 Z(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 J(t,e,r){let n=L({encode:!0},{...r}),o=Z(e,n);return t.includes("?")?t.endsWith("?")||t.endsWith("&")?`${t}${o}`:`${t}&${o}`:`${t}?${o}`}var oe={parse:Q,stringify:Z,appendQueryString:J};function ae(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 fe(t){return!h(t)&&/^[\dA-Z\u4E00-\u9FA5]+$/i.test(t)}function ue(t){return!h(t)&&/^[A-Z\u4E00-\u9FA5]+$/i.test(t)}function ge(t){return!h(t)&&/^[\d!"#$%&'()*+,./:;<=>?@A-Z[\\\]^_`{|}~]+$/.test(t)}function le(t){return/^[\dA-Z_]+$/.test(t)}function de(t){return H({from:"validatorEmail",replacement:"isEmail",version:"2.4.0"}),/^([\w-])+@([\w-])+(\.[\w-])+/.test(t)}function G(t,e,r={}){let{includeProto:n=!1,includeSymbols:o=!0,includeNonEnum:m=!1}=r,i={};return d(t)&&y(e).forEach(f=>{N(f)&&!o||!(n?f in t:Object.hasOwn(t,f))||!m&&(n?tt(t,f):Object.getOwnPropertyDescriptor(t,f))?.enumerable===!1||(i[f]=O(t[f]))}),i}function tt(t,e){let r=t;for(;r!==null;){let n=Object.getOwnPropertyDescriptor(r,e);if(n)return n;r=Object.getPrototypeOf(r)}}function Fe(t,e){if(!d(t))return{};let r=O(t),n=y(e),o=Object.keys(r).filter(m=>!n.includes(m));return G(r,o)}function ze(t,e){return(!u(t)||t<=0)&&s("generateRandomArray","num \u5FC5\u987B\u5927\u4E8E0"),$(e)||s("generateRandomArray","cb \u5FC5\u987B\u662F\u51FD\u6570"),Array.from({length:t}).fill(0).map((r,n)=>e(r,n))}function He(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}import x,{extend as nt}from"dayjs";import ot from"dayjs/plugin/customParseFormat";function p(t){return t[Math.floor(Math.random()*t.length)]}function a(t={}){u(t)&&(t={max:t});let{min:e=1,max:r=p(rt())}=t;et(e,r);let n=Math.ceil(e),o=Math.floor(r);return Math.floor(Math.random()*(o-n+1)+n)}function et(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 rt(){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)})}nt(ot);function T(t={}){let{start:e="1800-01-01 00:00:00",end:r=x().format("YYYY-MM-DD HH:mm:ss"),format:n="YYYY-MM-DD HH:mm:ss"}=t;(!x(e).isValid()||!x(r).isValid())&&s("generateRandomDate","start end \u53C2\u6570\u5FC5\u987B\u662F\u5408\u6CD5\u7684\u65F6\u95F4\u683C\u5F0F");let o=x(e).year(),m=x(r).year(),i=a({min:o,max:m}),c=a({min:1,max:12}),f=a({min:1,max:31}),P=a(23),D=a(59),q=a(59),R=x(`${i}-${c}-${f} ${P}:${D}:${q}`);return R.isBefore(x(e))||R.isAfter(x(r))?T(t):R.format(n)}function l(t={}){let e=st(t),r=at(e);mt(r);let{length:n}=e;ct(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 it=16,E=1;function st(t){let e=u(t);return{lowerCase:!0,upperCase:!0,number:!0,...e?{}:t,length:e?{max:t,min:t}:u(t.length)?{max:t.length,min:t.length}:{max:it,min:E,...t.length},extra:e?[]:[...new Set(y(t.extra||[]))]}}function at(t){let e="";return t.lowerCase&&(e+="abcdefghijklmnopqrstuvwxyz"),t.upperCase&&(e+="ABCDEFGHIJKLMNOPQRSTUVWXYZ"),t.number&&(e+="0123456789"),e+=y(t.extra).join(""),e}function mt(t){t.length===0&&s("getRandomString","At least one character set (lowercase, uppercase, number) must be enabled or extra characters provided")}function ct(t,e){Number.isInteger(t)||s("getRandomString","min must be an integer"),Number.isInteger(e)||s("getRandomString","max must be an integer"),t<E&&s("getRandomString",`Minimum length cannot be less than ${E}`),e<t&&s("getRandomString","Maximum length cannot be less than minimum length")}function pt(){let t=["gmail.com","outlook.com.cn","example.com","qq.com","163.com","test.com.cn"],e=`${l(1)}${l({length:a({max:30,min:1})})}${l(1)}@${p(t)}`;return/\.{2,}/.test(e)?pt():e}function gr(t={}){u(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 k(t,e){(!u(t)||t<=0)&&s("generateRandomStringFromSource","num \u5FC5\u987B\u5927\u4E8E0"),(!g(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 $r(){let t=a({min:1e5,max:999999}),e=[0,1,2,3,4,5,6,7,8,9];return[t,T({format:"YYYYMMDD"}),k(3,e),k(1,[...e,"X","x"])].join("")}function Mr(){return p(["13","14","15","16","17","18","19"])+a(999999999).toString().padEnd(9,"0")}function Pr(){let t=["http://","https://"],e=[".com",".net",".org",".cn",".top"],r=[`?name=${l({length:{min:4,max:8}})}`,`?id=${a()}`,`?page=${l({length:{min:2,max:4}})}`,`?query=${l({length:{min:5,max:6}})}`,`?search=${l({length:{min:1,max:4}})}`,`?token=${l({length:{min:16,max:16}})}`];return`${p(t)}${l({length:{min:5,max:25}})}${p(e)}${p(r)}`}function Gr(t){return/^\d+$/.test(t)}function qr(t){return/^[A-Z]+$/i.test(t)}function Br(t){return/^[A-Z]+$/.test(t)}function Vr(t){return/^[\dA-Z]+$/.test(t)}function Xr(t){return/^[\dA-Z\u4E00-\u9FA5]+$/.test(t)}function Qr(t){return/^[a-z]+$/.test(t)}function Jr(t){return/^[\da-z]+$/.test(t)}function tn(t){return/^[\da-z\u4E00-\u9FA5]+$/.test(t)}function en(t){return/^[\u4E00-\u9FA5]+$/.test(t)}function nn(t){return/^-?(?:0|[1-9]\d*)\.\d+$/.test(t)}function on(t){return/^(?:0\.0*[1-9]\d*|[1-9]\d*\.\d+)$/.test(t)}function sn(t){return/^(?:0|[1-9]\d*)\.\d+$/.test(t)}function an(t){return/^-(?:0\.0*[1-9]\d*|[1-9]\d*\.\d+)$/.test(t)}function mn(t){return/^-(?:0|[1-9]\d*)\.\d+$/.test(t)}function pn(t){return/^-?(?:0|[1-9]\d*)$/.test(t)}function fn(t){return/^[1-9]\d*$/.test(t)}function un(t){return/^(?:0|[1-9]\d*)$/.test(t)&&!Object.is(t,-0)}function gn(t){return/^-[1-9]\d*$/.test(t)}function ln(t){return/^-(?:0|[1-9]\d*)$/.test(t)||Object.is(t,-0)}import ft,{extend as ut}from"dayjs";import gt from"dayjs/plugin/customParseFormat";function yn(t){return/^1[3-9]\d{9}$/.test(t)}function hn(t){return/^https?:\/\/\S+$/i.test(t)}function On(t){return/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(t)}function wn(t){return t===""}function lt(t,e="YYYY-MM-DD HH:mm:ss"){return ut(gt),ft(t,e,!0).isValid()}function $n(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)&<(t.slice(6,14),"YYYYMMDD")}export{Yt as base64Decode,vt as base64Encode,y as castArray,_t as compose,Kt as composeRight,zt as debounce,W as debugWarn,te as debugWarnInvalidTypeMessage,Ft as decimalToBinary,O as deepClone,L as deepMerge,H as deprecated,Qt as error,ze as generateRandomArray,He as generateRandomColor,T as generateRandomDate,pt as generateRandomEmail,gr as generateRandomFloat,$r as generateRandomIdCard,Mr as generateRandomMobilePhone,k as generateRandomStringFromSource,a as getRandomInt,p as getRandomItem,l as getRandomString,Pr as getRandomUrl,At as hasChanged,g as isArray,ht as isBoolean,en as isChineseString,v as isDate,lt as isDateString,$t as isDef,On as isEmail,wn as isEmptyString,qr as isEnglishAphabet,nn as isFloat,$ as isFunction,$n as isIdCard,pn as isInteger,Qr as isLowerCase,Jr as isLowerCaseAndNumber,tn as isLowerCaseAndNumberAndChinese,C as isMap,yn as isMobilePhone,an as isNegativeFloat,gn as isNegativeInteger,sn as isNonNegativeFloat,un as isNonNegativeInteger,mn as isNonPositiveFloat,ln as isNonPositiveInteger,Ot as isNull,u as isNumber,Gr as isNumberOrNumberString,dt as isObject,w as isObjectLike,d as isPlainObject,on as isPositiveFloat,fn as isPositiveInteger,U as isPromise,Y as isRegExp,F as isSet,I as isString,N as isSymbol,h as isUndef,wt as isUndefined,Br as isUpperCase,Vr as isUpperCaseAndNumber,Xr as isUpperCaseAndNumberAndChinese,hn as isUrl,j as log,B as objectToString,Fe as omit,G as pick,oe as qs,ae as throttle,s as throwError,Jt as throwErrorInvalidTypeMessage,b as toTypeString,M as toTypeValue,ue as validatorChineseOrEnglish,fe as validatorChineseOrEnglishOrNumber,de as validatorEmail,ge as validatorUppercaseOrNumbersOrSpecial,le as validatorUppercaseOrNumbersOrUnderline,Xt as warn};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lntvow/utils",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "工具库",
|
|
6
6
|
"keywords": [
|
|
@@ -14,19 +14,19 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
|
-
"main": "dist/
|
|
18
|
-
"module": "dist/
|
|
19
|
-
"types": "dist/
|
|
17
|
+
"main": "dist/esm-bundler.cjs",
|
|
18
|
+
"module": "dist/esm-bundler.mjs",
|
|
19
|
+
"types": "dist/esm-bundler.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"dayjs": "^1.11.13"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@lntvow/dev": "^4.4.2",
|
|
25
|
-
"@vitest/coverage-v8": "^3.2.
|
|
26
|
-
"@vitest/ui": "^3.2.
|
|
25
|
+
"@vitest/coverage-v8": "^3.2.3",
|
|
26
|
+
"@vitest/ui": "^3.2.3",
|
|
27
27
|
"tsup": "^8.5.0",
|
|
28
28
|
"typescript": "^5.8.3",
|
|
29
|
-
"vitest": "^3.2.
|
|
29
|
+
"vitest": "^3.2.3"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"postinstall": "simple-git-hooks",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|