@lntvow/utils 2.2.2 → 2.2.4
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/index.cjs +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +36 -35
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function N(...t){return t.reduce((e,n)=>function(...r){return n(e(...r))})}function I(...t){return t.reduce((e,n)=>function(...r){return e(n(...r))})}function F(t,e=500){let n=null;return function(...r){n&&clearTimeout(n),n=setTimeout(()=>{t.apply(this,r)},e)}}const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function N(...t){return t.reduce((e,n)=>function(...r){return n(e(...r))})}function I(...t){return t.reduce((e,n)=>function(...r){return e(n(...r))})}function F(t,e=500){let n=null;return function(...r){n&&clearTimeout(n),n=setTimeout(()=>{t.apply(this,r)},e)}}const O=Object.prototype.toString,l=t=>O.call(t);let m=null;function M(t){p(t)&&(m=t)}const R=(t,...e)=>{const n=e.length===0?"":e.length===1?e[0]:e;console.log(`%c ${t} `,"padding: 2px; border-radius: 3px; color: #fff; background: #000; font-weight: bold;",n),m&&m(t,n)},A=(...t)=>console.warn(...t),Z=(...t)=>console.error(...t),x=t=>l(t)==="[object Map]",U=t=>l(t)==="[object Set]",v=t=>l(t)==="[object Date]",w=t=>l(t)==="[object RegExp]",p=t=>typeof t=="function",j=t=>typeof t=="number",y=t=>typeof t=="string",L=t=>typeof t=="symbol",d=t=>t!==null&&typeof t=="object",D=t=>d(t)&&p(t.then)&&p(t.catch),s=t=>t==null,T=t=>t===void 0,W=t=>t===null,q=t=>t!=null,z=t=>typeof t=="boolean",f=Array.isArray,h=(t,e)=>Object.hasOwn(t,e),B=(t,e)=>t!==e;function b(t){const e=new WeakMap;function n(r){if(v(r))return new Date(r);if(w(r))return new RegExp(r);if(d(r)){if(e.has(r))return e.get(r);let o={};if(f(r)){o=[],e.set(r,o);for(let i=0;i<r.length;i++)o[i]=n(r[i]);return o}e.set(r,o);for(const i in r)h(r,i)&&(o[i]=n(r[i]));return o}else return r}return n(t)}function u(t,e,n){return f(t)?K(t,e,n):_(t,e,n)}function _(t,e,n){const r=c(e,n);return Object.keys(t).forEach(i=>{s(e[i])?r[i]=c(t[i],n):r[i]=d(t[i])&&d(e[i])?u(t[i],e[i],n):c(e[i],n)}),r}function K(t,e,n){if(f(e)){const r=c(e,n);return r.push(...c(t,n)),r}else return c(t,n)}function c(t,e){const{clone:n=!0}=e||{};return n?b(t):t}class E extends Error{constructor(e){super(e),this.name="LntvowError"}}function P(t,e){throw new E(`[${t}] ${e}`)}function Q(t,e){if(process.env.NODE_ENV!=="production"){const n=y(t)?new E(`[${t}] ${e}`):t;console.warn(n)}}function V(t,e){const{decode:n}=u({decode:!0},e||{}),r={};t.startsWith("?")&&(t=t.slice(1)),t.includes("?")&&(t=t.slice(t.indexOf("?")+1));const o=t.split("&").filter(Boolean);for(const i of o){const[g,a]=i.split("=");r[g]=n?decodeURIComponent(a):a}return r}function S(t,e){const{encode:n}=u({encode:!0},e||{}),r=[];for(const o in t){const i=t[o];r.push(`${o}=${n?encodeURIComponent(i):i}`)}return r.join("&")}function G(t,e,n){const r=u({encode:!0},n||{}),o=S(e,r);return t.includes("?")?t.endsWith("?")||t.endsWith("&")?`${t}${o}`:`${t}&${o}`:`${t}?${o}`}const H={parse:V,stringify:S,appendQueryString:G};function J(t,e=500){let n=null;return function(...r){if(s(n))return n=Date.now(),t.apply(this,r);{const o=Date.now();if(o-n>=e)return n=o,t.apply(this,r)}}}function X(t){return/^(?:(?:\+|00)86)?1(?:(?:3\d)|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8\d)|(?:9[1589]))\d{8}$/.test(t)}function Y(t){return/^([\w-])+@([\w-])+(\.[\w-])+/.test(t)}function k(t){return/^[A-Z]+$/.test(t)}function tt(t){return!s(t)&&/^[a-z]+$/.test(t)}function et(t){return/^\d+$/.test(t)}function nt(t){return/^-?\d{1,3}\.\d{6}$/.test(t)}function rt(t){return t===""}function ot(t){return!s(t)&&/^[\dA-Za-z\u4E00-\u9FA5]+$/.test(t)}function it(t){return!s(t)&&/^[A-Za-z\u4E00-\u9FA5]+$/.test(t)}function st(t){return!s(t)&&/^[\d!"#$%&'()*+,./:;<=>?@A-Z[\\\]^_`{|}~]+$/.test(t)}function ct(t){return/^[\dA-Z_]+$/.test(t)}function ut(t){return/^[1-9]\d*$/.test(t)}function at(t){return/^\d+$/.test(t)}function dt(t){return/^(0*[1-9]+\d*\.?\d*|0+\.\d*[1-9]+\d*)$/.test(t)}function $(t){return f(t)?t:[t]}function lt(t,e){const n=b(t);return $(e).forEach(o=>{h(n,o)&&delete n[o]}),n}function ft(t,e){const n={};return $(e).forEach(o=>{h(t,o)&&(n[o]=t[o])}),n}function gt(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}function pt(t=0,e=1e6){return Math.random()*(e-t)+t}function ht(t=0,e=1e6){return Math.floor(Math.random()*(e-t+1))+Math.floor(t)}function mt(t,e={}){const{lowerCase:n=!0,upperCase:r=!0,number:o=!0}=e;n||r||o||P("getRandomString","lowerCase upperCase number 至少需要一个参数为true");let i="";n&&(i+="abcdefghijklmnopqrstuvwxyz"),r&&(i+="ABCDEFGHIJKLMNOPQRSTUVWXYZ"),o&&(i+="0123456789");let g="";for(let a=0;a<t;a++){const C=Math.floor(Math.random()*i.length);g+=i.charAt(C)}return g}function bt(t){return/^-?(0|[1-9]\d*)$/.test(t)}function $t(t){return/^[1-9]\d*$/.test(t)}function Ot(t){return/^(0|[1-9]\d*)$/.test(t)}function vt(t){return/^-([1-9]\d*)$/.test(t)}function wt(t){return/^(0|-(0|[1-9]\d*))$/.test(t)}function yt(t,e={}){const{integer:n}=u({integer:!0},e);return n?/^-?(0|[1-9]\d*)(\.\d+)?$/.test(t):/^-?(0|[1-9]\d*)\.\d+$/.test(t)}function Et(t){return/^[1-9]\d*\.?\d*|0\.\d*[1-9]\d*$/.test(t)}function Pt(t){return/^-\d+(\.\d+)?$/.test(t)}function St(t){return/^\d+(\.\d+)?$/.test(t)}function Ct(t){return/^(-\d+(\.\d+)?$)|(0(\.0+)?)$/.test(t)}exports.castArray=$;exports.compose=N;exports.composeRight=I;exports.debounce=F;exports.debugWarn=Q;exports.deepClone=b;exports.deepMerge=u;exports.error=Z;exports.excludeProperties=lt;exports.extractProperties=ft;exports.getRandomColor=gt;exports.getRandomFloat=pt;exports.getRandomInteger=ht;exports.getRandomString=mt;exports.hasChanged=B;exports.hasOwn=h;exports.initLog=M;exports.isArray=f;exports.isBoolean=z;exports.isDate=v;exports.isDef=q;exports.isEmptyString=rt;exports.isFloat=yt;exports.isFunction=p;exports.isInteger=bt;exports.isMap=x;exports.isNegativeFloat=Pt;exports.isNegativeFloatOrZero=Ct;exports.isNegativeInteger=vt;exports.isNegativeIntegerOrZero=wt;exports.isNull=W;exports.isNumber=j;exports.isObject=d;exports.isPositiveFloat=Et;exports.isPositiveFloatOrZero=St;exports.isPositiveInteger=$t;exports.isPositiveIntegerOrZero=Ot;exports.isPromise=D;exports.isRegExp=w;exports.isSet=U;exports.isString=y;exports.isSymbol=L;exports.isUndef=s;exports.isUndefined=T;exports.log=R;exports.objectToString=O;exports.qs=H;exports.throttle=J;exports.throwError=P;exports.toTypeString=l;exports.validatorChineseOrEnglish=it;exports.validatorChineseOrEnglishOrNumber=ot;exports.validatorEmail=Y;exports.validatorLatitudeOrLongitude=nt;exports.validatorLowerCase=tt;exports.validatorMobilePhone=X;exports.validatorNumber=et;exports.validatorPositiveFloat=dt;exports.validatorPositiveInt=ut;exports.validatorPositiveIntAndZero=at;exports.validatorUpperCase=k;exports.validatorUppercaseOrNumbersOrSpecial=st;exports.validatorUppercaseOrNumbersOrUnderline=ct;exports.warn=A;
|
package/dist/index.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare function debugWarn(scope: string, message: string): void;
|
|
|
51
51
|
* @param target 拷贝对象
|
|
52
52
|
* @example deepClone({ name: 1, obj: { name: 1 }, arr: [1, 2, 3] }) => { name: 1, obj: { name: 1 }, arr: [1, 2, 3] }
|
|
53
53
|
*/
|
|
54
|
-
export declare function deepClone<T
|
|
54
|
+
export declare function deepClone<T>(target: T): T;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* @description 深度合并两对象
|
|
@@ -85,7 +85,7 @@ export declare function extractProperties<T extends AnyObj, K extends keyof T>(o
|
|
|
85
85
|
export declare interface FloatOptions {
|
|
86
86
|
/**
|
|
87
87
|
* @description 是否包括整数
|
|
88
|
-
* @default
|
|
88
|
+
* @default true
|
|
89
89
|
*/
|
|
90
90
|
integer?: boolean;
|
|
91
91
|
}
|
|
@@ -247,7 +247,7 @@ declare interface Options {
|
|
|
247
247
|
* @description 是否开启深拷贝 默认开启
|
|
248
248
|
* @default true
|
|
249
249
|
*/
|
|
250
|
-
|
|
250
|
+
clone: boolean;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -16,19 +16,19 @@ function F(t, n = 500) {
|
|
|
16
16
|
}, n);
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
const y = Object.prototype.toString,
|
|
20
|
-
let
|
|
19
|
+
const y = Object.prototype.toString, l = (t) => y.call(t);
|
|
20
|
+
let p = null;
|
|
21
21
|
function Z(t) {
|
|
22
|
-
h(t) && (
|
|
22
|
+
h(t) && (p = t);
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const U = (t, ...n) => {
|
|
25
25
|
const e = n.length === 0 ? "" : n.length === 1 ? n[0] : n;
|
|
26
26
|
console.log(
|
|
27
27
|
`%c ${t} `,
|
|
28
28
|
"padding: 2px; border-radius: 3px; color: #fff; background: #000; font-weight: bold;",
|
|
29
29
|
e
|
|
30
|
-
),
|
|
31
|
-
},
|
|
30
|
+
), p && p(t, e);
|
|
31
|
+
}, v = (...t) => console.warn(...t), D = (...t) => console.error(...t), L = (t) => l(t) === "[object Map]", W = (t) => l(t) === "[object Set]", C = (t) => l(t) === "[object Date]", A = (t) => l(t) === "[object RegExp]", h = (t) => typeof t == "function", T = (t) => typeof t == "number", M = (t) => typeof t == "string", z = (t) => typeof t == "symbol", a = (t) => t !== null && typeof t == "object", _ = (t) => a(t) && h(t.then) && h(t.catch), c = (t) => t == null, q = (t) => t === void 0, B = (t) => t === null, K = (t) => t != null, Q = (t) => typeof t == "boolean", g = Array.isArray, $ = (t, n) => Object.hasOwn(t, n), V = (t, n) => t !== n;
|
|
32
32
|
function m(t) {
|
|
33
33
|
const n = /* @__PURE__ */ new WeakMap();
|
|
34
34
|
function e(r) {
|
|
@@ -36,11 +36,11 @@ function m(t) {
|
|
|
36
36
|
return new Date(r);
|
|
37
37
|
if (A(r))
|
|
38
38
|
return new RegExp(r);
|
|
39
|
-
if (
|
|
39
|
+
if (a(r)) {
|
|
40
40
|
if (n.has(r))
|
|
41
41
|
return n.get(r);
|
|
42
42
|
let o = {};
|
|
43
|
-
if (
|
|
43
|
+
if (g(r)) {
|
|
44
44
|
o = [], n.set(r, o);
|
|
45
45
|
for (let i = 0; i < r.length; i++)
|
|
46
46
|
o[i] = e(r[i]);
|
|
@@ -55,24 +55,24 @@ function m(t) {
|
|
|
55
55
|
}
|
|
56
56
|
return e(t);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
return
|
|
58
|
+
function d(t, n, e) {
|
|
59
|
+
return g(t) ? x(t, n, e) : S(t, n, e);
|
|
60
60
|
}
|
|
61
61
|
function S(t, n, e) {
|
|
62
62
|
const r = s(n, e);
|
|
63
63
|
return Object.keys(t).forEach((i) => {
|
|
64
|
-
c(n[i]) ? r[i] = s(t[i], e) : r[i] =
|
|
64
|
+
c(n[i]) ? r[i] = s(t[i], e) : r[i] = a(t[i]) && a(n[i]) ? d(t[i], n[i], e) : s(n[i], e);
|
|
65
65
|
}), r;
|
|
66
66
|
}
|
|
67
67
|
function x(t, n, e) {
|
|
68
|
-
if (
|
|
68
|
+
if (g(n)) {
|
|
69
69
|
const r = s(n, e);
|
|
70
70
|
return r.push(...s(t, e)), r;
|
|
71
71
|
} else
|
|
72
72
|
return s(t, e);
|
|
73
73
|
}
|
|
74
74
|
function s(t, n) {
|
|
75
|
-
const {
|
|
75
|
+
const { clone: e = !0 } = n || {};
|
|
76
76
|
return e ? m(t) : t;
|
|
77
77
|
}
|
|
78
78
|
class b extends Error {
|
|
@@ -90,7 +90,7 @@ function G(t, n) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
function I(t, n) {
|
|
93
|
-
const { decode: e } =
|
|
93
|
+
const { decode: e } = d({ decode: !0 }, n || {}), r = {};
|
|
94
94
|
t.startsWith("?") && (t = t.slice(1)), t.includes("?") && (t = t.slice(t.indexOf("?") + 1));
|
|
95
95
|
const o = t.split("&").filter(Boolean);
|
|
96
96
|
for (const i of o) {
|
|
@@ -100,7 +100,7 @@ function I(t, n) {
|
|
|
100
100
|
return r;
|
|
101
101
|
}
|
|
102
102
|
function w(t, n) {
|
|
103
|
-
const { encode: e } =
|
|
103
|
+
const { encode: e } = d({ encode: !0 }, n || {}), r = [];
|
|
104
104
|
for (const o in t) {
|
|
105
105
|
const i = t[o];
|
|
106
106
|
r.push(`${o}=${e ? encodeURIComponent(i) : i}`);
|
|
@@ -108,7 +108,7 @@ function w(t, n) {
|
|
|
108
108
|
return r.join("&");
|
|
109
109
|
}
|
|
110
110
|
function P(t, n, e) {
|
|
111
|
-
const r =
|
|
111
|
+
const r = d({ encode: !0 }, e || {}), o = w(n, r);
|
|
112
112
|
return t.includes("?") ? t.endsWith("?") || t.endsWith("&") ? `${t}${o}` : `${t}&${o}` : `${t}?${o}`;
|
|
113
113
|
}
|
|
114
114
|
const H = {
|
|
@@ -166,14 +166,14 @@ function ct(t) {
|
|
|
166
166
|
function ut(t) {
|
|
167
167
|
return /^[1-9]\d*$/.test(t);
|
|
168
168
|
}
|
|
169
|
-
function
|
|
169
|
+
function dt(t) {
|
|
170
170
|
return /^\d+$/.test(t);
|
|
171
171
|
}
|
|
172
|
-
function
|
|
172
|
+
function ft(t) {
|
|
173
173
|
return /^(0*[1-9]+\d*\.?\d*|0+\.\d*[1-9]+\d*)$/.test(t);
|
|
174
174
|
}
|
|
175
175
|
function O(t) {
|
|
176
|
-
return
|
|
176
|
+
return g(t) ? t : [t];
|
|
177
177
|
}
|
|
178
178
|
function at(t, n) {
|
|
179
179
|
const e = m(t);
|
|
@@ -187,10 +187,10 @@ function lt(t, n) {
|
|
|
187
187
|
$(t, o) && (e[o] = t[o]);
|
|
188
188
|
}), e;
|
|
189
189
|
}
|
|
190
|
-
function
|
|
190
|
+
function gt() {
|
|
191
191
|
return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function pt(t = 0, n = 1e6) {
|
|
194
194
|
return Math.random() * (n - t) + t;
|
|
195
195
|
}
|
|
196
196
|
function ht(t = 0, n = 1e6) {
|
|
@@ -223,11 +223,12 @@ function Ot(t) {
|
|
|
223
223
|
function Et(t) {
|
|
224
224
|
return /^(0|-(0|[1-9]\d*))$/.test(t);
|
|
225
225
|
}
|
|
226
|
-
function yt(t, n) {
|
|
227
|
-
|
|
226
|
+
function yt(t, n = {}) {
|
|
227
|
+
const { integer: e } = d({ integer: !0 }, n);
|
|
228
|
+
return e ? /^-?(0|[1-9]\d*)(\.\d+)?$/.test(t) : /^-?(0|[1-9]\d*)\.\d+$/.test(t);
|
|
228
229
|
}
|
|
229
230
|
function Ct(t) {
|
|
230
|
-
return /^
|
|
231
|
+
return /^[1-9]\d*\.?\d*|0\.\d*[1-9]\d*$/.test(t);
|
|
231
232
|
}
|
|
232
233
|
function At(t) {
|
|
233
234
|
return /^-\d+(\.\d+)?$/.test(t);
|
|
@@ -245,18 +246,18 @@ export {
|
|
|
245
246
|
F as debounce,
|
|
246
247
|
G as debugWarn,
|
|
247
248
|
m as deepClone,
|
|
248
|
-
|
|
249
|
-
|
|
249
|
+
d as deepMerge,
|
|
250
|
+
D as error,
|
|
250
251
|
at as excludeProperties,
|
|
251
252
|
lt as extractProperties,
|
|
252
|
-
|
|
253
|
-
|
|
253
|
+
gt as getRandomColor,
|
|
254
|
+
pt as getRandomFloat,
|
|
254
255
|
ht as getRandomInteger,
|
|
255
256
|
$t as getRandomString,
|
|
256
257
|
V as hasChanged,
|
|
257
258
|
$ as hasOwn,
|
|
258
259
|
Z as initLog,
|
|
259
|
-
|
|
260
|
+
g as isArray,
|
|
260
261
|
Q as isBoolean,
|
|
261
262
|
C as isDate,
|
|
262
263
|
K as isDef,
|
|
@@ -271,7 +272,7 @@ export {
|
|
|
271
272
|
Et as isNegativeIntegerOrZero,
|
|
272
273
|
B as isNull,
|
|
273
274
|
T as isNumber,
|
|
274
|
-
|
|
275
|
+
a as isObject,
|
|
275
276
|
Ct as isPositiveFloat,
|
|
276
277
|
Mt as isPositiveFloatOrZero,
|
|
277
278
|
bt as isPositiveInteger,
|
|
@@ -283,12 +284,12 @@ export {
|
|
|
283
284
|
z as isSymbol,
|
|
284
285
|
c as isUndef,
|
|
285
286
|
q as isUndefined,
|
|
286
|
-
|
|
287
|
+
U as log,
|
|
287
288
|
y as objectToString,
|
|
288
289
|
H as qs,
|
|
289
290
|
J as throttle,
|
|
290
291
|
N as throwError,
|
|
291
|
-
|
|
292
|
+
l as toTypeString,
|
|
292
293
|
it as validatorChineseOrEnglish,
|
|
293
294
|
ot as validatorChineseOrEnglishOrNumber,
|
|
294
295
|
Y as validatorEmail,
|
|
@@ -296,11 +297,11 @@ export {
|
|
|
296
297
|
tt as validatorLowerCase,
|
|
297
298
|
X as validatorMobilePhone,
|
|
298
299
|
nt as validatorNumber,
|
|
299
|
-
|
|
300
|
+
ft as validatorPositiveFloat,
|
|
300
301
|
ut as validatorPositiveInt,
|
|
301
|
-
|
|
302
|
+
dt as validatorPositiveIntAndZero,
|
|
302
303
|
k as validatorUpperCase,
|
|
303
304
|
st as validatorUppercaseOrNumbersOrSpecial,
|
|
304
305
|
ct as validatorUppercaseOrNumbersOrUnderline,
|
|
305
|
-
|
|
306
|
+
v as warn
|
|
306
307
|
};
|