@lntvow/utils 2.2.0 → 2.2.1
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 +5 -0
- package/dist/index.mjs +24 -24
- 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 P(t,e=500){let n=null;return function(...r){n&&clearTimeout(n),n=setTimeout(()=>{t.apply(this,r)},e)}}const m=Object.prototype.toString,d=t=>m.call(t);let h=null;function
|
|
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 P(t,e=500){let n=null;return function(...r){n&&clearTimeout(n),n=setTimeout(()=>{t.apply(this,r)},e)}}const m=Object.prototype.toString,d=t=>m.call(t);let h=null;function F(t){p(t)&&(h=t)}const M=(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),h&&h(t,n)},R=(...t)=>console.warn(...t),A=(...t)=>console.error(...t),Z=t=>d(t)==="[object Map]",j=t=>d(t)==="[object Set]",b=t=>d(t)==="[object Date]",O=t=>d(t)==="[object RegExp]",p=t=>typeof t=="function",U=t=>typeof t=="number",$=t=>typeof t=="string",x=t=>typeof t=="symbol",u=t=>t!==null&&typeof t=="object",D=t=>u(t)&&p(t.then)&&p(t.catch),s=t=>t==null,L=t=>t===void 0,T=t=>t===null,W=t=>t!=null,q=t=>typeof t=="boolean",l=Array.isArray,v=(t,e)=>Object.hasOwn(t,e),z=(t,e)=>t!==e;function w(t){const e=new WeakMap;function n(r){if(b(r))return new Date(r);if(O(r))return new RegExp(r);if(u(r)){if(e.has(r))return e.get(r);let i={};if(l(r)){i=[],e.set(r,i);for(let o=0;o<r.length;o++)i[o]=n(r[o]);return i}e.set(r,i);for(const o in r)v(r,o)&&(i[o]=n(r[o]));return i}else return r}return n(t)}function f(t,e,n){return l(t)?_(t,e,n):B(t,e,n)}function B(t,e,n){const r=c(e,n);return Object.keys(t).forEach(o=>{s(e[o])?r[o]=c(t[o],n):r[o]=u(t[o])&&u(e[o])?f(t[o],e[o],n):c(e[o],n)}),r}function _(t,e,n){if(l(e)){const r=c(e,n);return r.push(...c(t,n)),r}else return c(t,n)}function c(t,e){const{isDeepClone:n=!0}=e||{};return n?w(t):t}class y extends Error{constructor(e){super(e),this.name="LntvowError"}}function C(t,e){throw new y(`[${t}] ${e}`)}function K(t,e){if(process.env.NODE_ENV!=="production"){const n=$(t)?new y(`[${t}] ${e}`):t;console.warn(n)}}function Q(t,e){const{decode:n}=f({decode:!0},e||{}),r={};t.startsWith("?")&&(t=t.slice(1)),t.includes("?")&&(t=t.slice(t.indexOf("?")+1));const i=t.split("&").filter(Boolean);for(const o of i){const[g,a]=o.split("=");r[g]=n?decodeURIComponent(a):a}return r}function E(t,e){const{encode:n}=f({encode:!0},e||{}),r=[];for(const i in t){const o=t[i];r.push(`${i}=${n?encodeURIComponent(o):o}`)}return r.join("&")}function V(t,e,n){const r=f({encode:!0},n||{}),i=E(e,r);return t.includes("?")?t.endsWith("?")||t.endsWith("&")?`${t}${i}`:`${t}&${i}`:`${t}?${i}`}const G={parse:Q,stringify:E,appendQueryString:V};function H(t,e=500){let n=null;return function(...r){if(s(n))return n=Date.now(),t.apply(this,r);{const i=Date.now();if(i-n>=e)return n=i,t.apply(this,r)}}}function J(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 X(t){return/^([\w-])+@([\w-])+(\.[\w-])+/.test(t)}function Y(t){return/^[A-Z]+$/.test(t)}function k(t){return!s(t)&&/^[a-z]+$/.test(t)}function tt(t){return/^\d+$/.test(t)}function et(t){return/^-?\d{1,3}\.\d{6}$/.test(t)}function nt(t){return t===""}function rt(t){return!s(t)&&/^[\dA-Za-z\u4E00-\u9FA5]+$/.test(t)}function ot(t){return!s(t)&&/^[A-Za-z\u4E00-\u9FA5]+$/.test(t)}function it(t){return!s(t)&&/^[\d!"#$%&'()*+,./:;<=>?@A-Z[\\\]^_`{|}~]+$/.test(t)}function st(t){return/^[\dA-Z_]+$/.test(t)}function ct(t){return/^[1-9]\d*$/.test(t)}function at(t){return/^\d+$/.test(t)}function ut(t){return/^(0*[1-9]+\d*\.?\d*|0+\.\d*[1-9]+\d*)$/.test(t)}function dt(t){return l(t)?t:[t]}function lt(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}function ft(t=0,e=1e6){return Math.random()*(e-t)+t}function gt(t=0,e=1e6){return Math.floor(Math.random()*(e-t+1))+Math.floor(t)}function pt(t,e={}){const{lowerCase:n=!0,upperCase:r=!0,number:i=!0}=e;n||r||i||C("getRandomString","lowerCase upperCase number 至少需要一个参数为true");let o="";n&&(o+="abcdefghijklmnopqrstuvwxyz"),r&&(o+="ABCDEFGHIJKLMNOPQRSTUVWXYZ"),i&&(o+="0123456789");let g="";for(let a=0;a<t;a++){const S=Math.floor(Math.random()*o.length);g+=o.charAt(S)}return g}function ht(t){return/^-?(0|[1-9]\d*)$/.test(t)}function mt(t){return/^[1-9]\d*$/.test(t)}function bt(t){return/^(0|[1-9]\d*)$/.test(t)}function Ot(t){return/^-([1-9]\d*)$/.test(t)}function $t(t){return/^(0|-(0|[1-9]\d*))$/.test(t)}function vt(t,e){return/^-?\d+(\.\d+)?$/.test(t)}function wt(t){return/^(0\.\d+|[1-9]\d*(\.\d+)?)$/.test(t)}function yt(t){return/^-\d+(\.\d+)?$/.test(t)}function Ct(t){return/^\d+(\.\d+)?$/.test(t)}function Et(t){return/^(-\d+(\.\d+)?$)|(0(\.0+)?)$/.test(t)}exports.castArray=dt;exports.compose=N;exports.composeRight=I;exports.debounce=P;exports.debugWarn=K;exports.deepClone=w;exports.deepMerge=f;exports.error=A;exports.getRandomColor=lt;exports.getRandomFloat=ft;exports.getRandomInteger=gt;exports.getRandomString=pt;exports.hasChanged=z;exports.hasOwn=v;exports.initLog=F;exports.isArray=l;exports.isBoolean=q;exports.isDate=b;exports.isDef=W;exports.isEmptyString=nt;exports.isFloat=vt;exports.isFunction=p;exports.isInteger=ht;exports.isMap=Z;exports.isNegativeFloat=yt;exports.isNegativeFloatOrZero=Et;exports.isNegativeInteger=Ot;exports.isNegativeIntegerOrZero=$t;exports.isNull=T;exports.isNumber=U;exports.isObject=u;exports.isPositiveFloat=wt;exports.isPositiveFloatOrZero=Ct;exports.isPositiveInteger=mt;exports.isPositiveIntegerOrZero=bt;exports.isPromise=D;exports.isRegExp=O;exports.isSet=j;exports.isString=$;exports.isSymbol=x;exports.isUndef=s;exports.isUndefined=L;exports.log=M;exports.objectToString=m;exports.qs=G;exports.throttle=H;exports.throwError=C;exports.toTypeString=d;exports.validatorChineseOrEnglish=ot;exports.validatorChineseOrEnglishOrNumber=rt;exports.validatorEmail=X;exports.validatorLatitudeOrLongitude=et;exports.validatorLowerCase=k;exports.validatorMobilePhone=J;exports.validatorNumber=tt;exports.validatorPositiveFloat=ut;exports.validatorPositiveInt=ct;exports.validatorPositiveIntAndZero=at;exports.validatorUpperCase=Y;exports.validatorUppercaseOrNumbersOrSpecial=it;exports.validatorUppercaseOrNumbersOrUnderline=st;exports.warn=R;
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ declare function appendQueryString(url: string, obj: AnyObj, options?: Stringify
|
|
|
13
13
|
|
|
14
14
|
export declare type Arrayable<T> = T | T[];
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @description 将非数组转换为数组 如果是目标本就是数组则直接返回
|
|
18
|
+
* @param target 目标
|
|
19
|
+
* @return 转换后的数组
|
|
20
|
+
*/
|
|
16
21
|
export declare function castArray<T>(target: T | T[]): T[];
|
|
17
22
|
|
|
18
23
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -17,9 +17,9 @@ function F(t, n = 500) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
const w = Object.prototype.toString, a = (t) => w.call(t);
|
|
20
|
-
let
|
|
20
|
+
let g = null;
|
|
21
21
|
function Z(t) {
|
|
22
|
-
|
|
22
|
+
h(t) && (g = t);
|
|
23
23
|
}
|
|
24
24
|
const P = (t, ...n) => {
|
|
25
25
|
const e = n.length === 0 ? "" : n.length === 1 ? n[0] : n;
|
|
@@ -27,20 +27,20 @@ const P = (t, ...n) => {
|
|
|
27
27
|
`%c ${t} `,
|
|
28
28
|
"padding: 2px; border-radius: 3px; color: #fff; background: #000; font-weight: bold;",
|
|
29
29
|
e
|
|
30
|
-
),
|
|
31
|
-
}, v = (...t) => console.warn(...t), D = (...t) => console.error(...t), U = (t) => a(t) === "[object Map]", L = (t) => a(t) === "[object Set]",
|
|
30
|
+
), g && g(t, e);
|
|
31
|
+
}, v = (...t) => console.warn(...t), D = (...t) => console.error(...t), U = (t) => a(t) === "[object Map]", L = (t) => a(t) === "[object Set]", O = (t) => a(t) === "[object Date]", y = (t) => a(t) === "[object RegExp]", h = (t) => typeof t == "function", W = (t) => typeof t == "number", E = (t) => typeof t == "string", T = (t) => typeof t == "symbol", f = (t) => t !== null && typeof t == "object", z = (t) => f(t) && h(t.then) && h(t.catch), c = (t) => t == null, _ = (t) => t === void 0, q = (t) => t === null, B = (t) => t != null, K = (t) => typeof t == "boolean", l = Array.isArray, C = (t, n) => Object.hasOwn(t, n), Q = (t, n) => t !== n;
|
|
32
32
|
function A(t) {
|
|
33
33
|
const n = /* @__PURE__ */ new WeakMap();
|
|
34
34
|
function e(r) {
|
|
35
|
-
if (y(r))
|
|
36
|
-
return new Date(r);
|
|
37
35
|
if (O(r))
|
|
36
|
+
return new Date(r);
|
|
37
|
+
if (y(r))
|
|
38
38
|
return new RegExp(r);
|
|
39
39
|
if (f(r)) {
|
|
40
40
|
if (n.has(r))
|
|
41
41
|
return n.get(r);
|
|
42
42
|
let i = {};
|
|
43
|
-
if (
|
|
43
|
+
if (l(r)) {
|
|
44
44
|
i = [], n.set(r, i);
|
|
45
45
|
for (let o = 0; o < r.length; o++)
|
|
46
46
|
i[o] = e(r[o]);
|
|
@@ -55,17 +55,17 @@ function A(t) {
|
|
|
55
55
|
}
|
|
56
56
|
return e(t);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
return
|
|
58
|
+
function p(t, n, e) {
|
|
59
|
+
return l(t) ? S(t, n, e) : M(t, n, e);
|
|
60
60
|
}
|
|
61
61
|
function M(t, n, e) {
|
|
62
62
|
const r = s(n, e);
|
|
63
63
|
return Object.keys(t).forEach((o) => {
|
|
64
|
-
c(n[o]) ? r[o] = s(t[o], e) : r[o] = f(t[o]) && f(n[o]) ?
|
|
64
|
+
c(n[o]) ? r[o] = s(t[o], e) : r[o] = f(t[o]) && f(n[o]) ? p(t[o], n[o], e) : s(n[o], e);
|
|
65
65
|
}), r;
|
|
66
66
|
}
|
|
67
67
|
function S(t, n, e) {
|
|
68
|
-
if (
|
|
68
|
+
if (l(n)) {
|
|
69
69
|
const r = s(n, e);
|
|
70
70
|
return r.push(...s(t, e)), r;
|
|
71
71
|
} else
|
|
@@ -90,7 +90,7 @@ function V(t, n) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
function j(t, n) {
|
|
93
|
-
const { decode: e } =
|
|
93
|
+
const { decode: e } = p({ decode: !0 }, n || {}), r = {};
|
|
94
94
|
t.startsWith("?") && (t = t.slice(1)), t.includes("?") && (t = t.slice(t.indexOf("?") + 1));
|
|
95
95
|
const i = t.split("&").filter(Boolean);
|
|
96
96
|
for (const o of i) {
|
|
@@ -100,7 +100,7 @@ function j(t, n) {
|
|
|
100
100
|
return r;
|
|
101
101
|
}
|
|
102
102
|
function b(t, n) {
|
|
103
|
-
const { encode: e } =
|
|
103
|
+
const { encode: e } = p({ encode: !0 }, n || {}), r = [];
|
|
104
104
|
for (const i in t) {
|
|
105
105
|
const o = t[i];
|
|
106
106
|
r.push(`${i}=${e ? encodeURIComponent(o) : o}`);
|
|
@@ -108,7 +108,7 @@ function b(t, n) {
|
|
|
108
108
|
return r.join("&");
|
|
109
109
|
}
|
|
110
110
|
function I(t, n, e) {
|
|
111
|
-
const r =
|
|
111
|
+
const r = p({ encode: !0 }, e || {}), i = b(n, r);
|
|
112
112
|
return t.includes("?") ? t.endsWith("?") || t.endsWith("&") ? `${t}${i}` : `${t}&${i}` : `${t}?${i}`;
|
|
113
113
|
}
|
|
114
114
|
const G = {
|
|
@@ -173,7 +173,7 @@ function dt(t) {
|
|
|
173
173
|
return /^(0*[1-9]+\d*\.?\d*|0+\.\d*[1-9]+\d*)$/.test(t);
|
|
174
174
|
}
|
|
175
175
|
function ft(t) {
|
|
176
|
-
return
|
|
176
|
+
return l(t) ? t : [t];
|
|
177
177
|
}
|
|
178
178
|
function at() {
|
|
179
179
|
return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
|
|
@@ -211,10 +211,10 @@ function mt(t) {
|
|
|
211
211
|
function wt(t) {
|
|
212
212
|
return /^(0|-(0|[1-9]\d*))$/.test(t);
|
|
213
213
|
}
|
|
214
|
-
function
|
|
214
|
+
function Ot(t, n) {
|
|
215
215
|
return /^-?\d+(\.\d+)?$/.test(t);
|
|
216
216
|
}
|
|
217
|
-
function
|
|
217
|
+
function yt(t) {
|
|
218
218
|
return /^(0\.\d+|[1-9]\d*(\.\d+)?)$/.test(t);
|
|
219
219
|
}
|
|
220
220
|
function Et(t) {
|
|
@@ -233,7 +233,7 @@ export {
|
|
|
233
233
|
F as debounce,
|
|
234
234
|
V as debugWarn,
|
|
235
235
|
A as deepClone,
|
|
236
|
-
|
|
236
|
+
p as deepMerge,
|
|
237
237
|
D as error,
|
|
238
238
|
at as getRandomColor,
|
|
239
239
|
lt as getRandomFloat,
|
|
@@ -242,13 +242,13 @@ export {
|
|
|
242
242
|
Q as hasChanged,
|
|
243
243
|
C as hasOwn,
|
|
244
244
|
Z as initLog,
|
|
245
|
-
|
|
245
|
+
l as isArray,
|
|
246
246
|
K as isBoolean,
|
|
247
|
-
|
|
247
|
+
O as isDate,
|
|
248
248
|
B as isDef,
|
|
249
249
|
et as isEmptyString,
|
|
250
|
-
|
|
251
|
-
|
|
250
|
+
Ot as isFloat,
|
|
251
|
+
h as isFunction,
|
|
252
252
|
ht as isInteger,
|
|
253
253
|
U as isMap,
|
|
254
254
|
Et as isNegativeFloat,
|
|
@@ -258,12 +258,12 @@ export {
|
|
|
258
258
|
q as isNull,
|
|
259
259
|
W as isNumber,
|
|
260
260
|
f as isObject,
|
|
261
|
-
|
|
261
|
+
yt as isPositiveFloat,
|
|
262
262
|
Ct as isPositiveFloatOrZero,
|
|
263
263
|
$t as isPositiveInteger,
|
|
264
264
|
bt as isPositiveIntegerOrZero,
|
|
265
265
|
z as isPromise,
|
|
266
|
-
|
|
266
|
+
y as isRegExp,
|
|
267
267
|
L as isSet,
|
|
268
268
|
E as isString,
|
|
269
269
|
T as isSymbol,
|