@lntvow/utils 2.1.11 → 2.1.17
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 +90 -12
- package/dist/index.mjs +223 -184
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function P(...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,d=t=>O.call(t);let h=null;function M(t){p(t)&&(h=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),h&&h(t,n)},A=(...t)=>console.warn(...t),Z=(...t)=>console.error(...t),j=t=>d(t)==="[object Map]",U=t=>d(t)==="[object Set]",$=t=>d(t)==="[object Date]",v=t=>d(t)==="[object RegExp]",p=t=>typeof t=="function",x=t=>typeof t=="number",w=t=>typeof t=="string",D=t=>typeof t=="symbol",u=t=>t!==null&&typeof t=="object",L=t=>u(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",l=Array.isArray,m=(t,e)=>Object.hasOwn(t,e),B=(t,e)=>t!==e;function b(t){const e=new WeakMap;function n(r){if($(r))return new Date(r);if(v(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)m(r,o)&&(i[o]=n(r[o]));return i}else return r}return n(t)}function f(t,e,n){return l(t)?K(t,e,n):_(t,e,n)}function _(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 K(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?b(t):t}class y extends Error{constructor(e){super(e),this.name="LntvowError"}}function E(t,e){throw new y(`[${t}] ${e}`)}function Q(t,e){if(process.env.NODE_ENV!=="production"){const n=w(t)?new y(`[${t}] ${e}`):t;console.warn(n)}}function V(t,e){const n=b(t);return S(e).forEach(i=>{m(n,i)&&delete n[i]}),n}function G(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 C(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 H(t,e,n){const r=f({encode:!0},n||{}),i=C(e,r);return t.includes("?")?t.endsWith("?")||t.endsWith("&")?`${t}${i}`:`${t}&${i}`:`${t}?${i}`}const J={parse:G,stringify:C,appendQueryString:H};function X(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 Y(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 k(t){return/^([\w-])+@([\w-])+(\.[\w-])+/.test(t)}function tt(t){return/^[A-Z]+$/.test(t)}function et(t){return!s(t)&&/^[a-z]+$/.test(t)}function nt(t){return/^\d+$/.test(t)}function rt(t){return/^-?\d{1,3}\.\d{6}$/.test(t)}function ot(t){return t===""}function it(t){return!s(t)&&/^[\dA-Za-z\u4E00-\u9FA5]+$/.test(t)}function st(t){return!s(t)&&/^[A-Za-z\u4E00-\u9FA5]+$/.test(t)}function ct(t){return!s(t)&&/^[\d!"#$%&'()*+,./:;<=>?@A-Z[\\\]^_`{|}~]+$/.test(t)}function at(t){return/^[\dA-Z_]+$/.test(t)}function ut(t){return/^[1-9]\d*$/.test(t)}function dt(t){return/^\d+$/.test(t)}function lt(t){return/^(0*[1-9]+\d*\.?\d*|0+\.\d*[1-9]+\d*)$/.test(t)}function S(t){return l(t)?t:[t]}function ft(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}function gt(t=0,e=1e6){return Math.random()*(e-t)+t}function pt(t=0,e=1e6){return Math.floor(Math.random()*(e-t+1))+Math.floor(t)}function ht(t,e={}){const{lowerCase:n=!0,upperCase:r=!0,number:i=!0}=e;n||r||i||E("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 N=Math.floor(Math.random()*o.length);g+=o.charAt(N)}return g}function mt(t){return/^-?(0|[1-9]\d*)$/.test(t)}function bt(t){return/^[1-9]\d*$/.test(t)}function Ot(t){return/^(0|[1-9]\d*)$/.test(t)}function $t(t){return/^-([1-9]\d*)$/.test(t)}function vt(t){return/^(0|-(0|[1-9]\d*))$/.test(t)}function wt(t,e){return/^-?\d+(\.\d+)?$/.test(t)}function yt(t){return/^(0\.\d+|[1-9]\d*(\.\d+)?)$/.test(t)}function Et(t){return/^-\d+(\.\d+)?$/.test(t)}function Ct(t){return/^\d+(\.\d+)?$/.test(t)}function St(t){return/^(-\d+(\.\d+)?$)|(0(\.0+)?)$/.test(t)}exports.castArray=S;exports.compose=P;exports.composeRight=I;exports.debounce=F;exports.debugWarn=Q;exports.deepClone=b;exports.deepMerge=f;exports.error=Z;exports.excludeProperties=V;exports.getRandomColor=ft;exports.getRandomFloat=gt;exports.getRandomInteger=pt;exports.getRandomString=ht;exports.hasChanged=B;exports.hasOwn=m;exports.initLog=M;exports.isArray=l;exports.isBoolean=z;exports.isDate=$;exports.isDef=q;exports.isEmptyString=ot;exports.isFloat=wt;exports.isFunction=p;exports.isInteger=mt;exports.isMap=j;exports.isNegativeFloat=Et;exports.isNegativeFloatOrZero=St;exports.isNegativeInteger=$t;exports.isNegativeIntegerOrZero=vt;exports.isNull=W;exports.isNumber=x;exports.isObject=u;exports.isPositiveFloat=yt;exports.isPositiveFloatOrZero=Ct;exports.isPositiveInteger=bt;exports.isPositiveIntegerOrZero=Ot;exports.isPromise=L;exports.isRegExp=v;exports.isSet=U;exports.isString=w;exports.isSymbol=D;exports.isUndef=s;exports.isUndefined=T;exports.log=R;exports.objectToString=O;exports.qs=J;exports.throttle=X;exports.throwError=E;exports.toTypeString=d;exports.validatorChineseOrEnglish=st;exports.validatorChineseOrEnglishOrNumber=it;exports.validatorEmail=k;exports.validatorLatitudeOrLongitude=rt;exports.validatorLowerCase=et;exports.validatorMobilePhone=Y;exports.validatorNumber=nt;exports.validatorPositiveFloat=lt;exports.validatorPositiveInt=ut;exports.validatorPositiveIntAndZero=dt;exports.validatorUpperCase=tt;exports.validatorUppercaseOrNumbersOrSpecial=ct;exports.validatorUppercaseOrNumbersOrUnderline=at;exports.warn=A;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
export declare type AnyObj = Record<string, any>;
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @description url追加查询字符串
|
|
5
|
+
* @param url url
|
|
6
|
+
* @param obj 查询字符串对象
|
|
7
|
+
* @return 追加后的url
|
|
8
|
+
* @example
|
|
9
|
+
* appendQueryString('https://www.baidu.com', { a: '1', b: '2' }) => 'https://www.baidu.com?a=1&b=2'
|
|
10
|
+
* appendQueryString('/pages/index?id=10', { test:'23' }) => '/pages/index?id=10&test=23'
|
|
11
|
+
*/
|
|
12
|
+
declare function appendQueryString(url: string, obj: AnyObj, options?: StringifyOptions): string;
|
|
13
|
+
|
|
14
|
+
export declare type Arrayable<T> = T | T[];
|
|
15
|
+
|
|
3
16
|
export declare function castArray<T = unknown>(target: T): (T & any[]) | T[];
|
|
4
17
|
|
|
5
18
|
/**
|
|
@@ -46,6 +59,23 @@ export declare function deepMerge(template: AnyObj, source: AnyObj, options?: Op
|
|
|
46
59
|
|
|
47
60
|
export declare const error: (...arg: unknown[]) => void;
|
|
48
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @description 排除对象中的某些属性
|
|
64
|
+
* @param obj 目标对象
|
|
65
|
+
* @param propertiesToExclude 要排除的属性
|
|
66
|
+
* @return 排除后的对象
|
|
67
|
+
* @example excludeProperties({ a: 1, b: 2, c: 3 }, ['a', 'b']) => { c: 3 }
|
|
68
|
+
*/
|
|
69
|
+
export declare function excludeProperties(obj: AnyObj, propertiesToExclude: Arrayable<string>): AnyObj;
|
|
70
|
+
|
|
71
|
+
export declare interface FloatOptions {
|
|
72
|
+
/**
|
|
73
|
+
* @description 是否包括整数
|
|
74
|
+
* @default false
|
|
75
|
+
*/
|
|
76
|
+
integer?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
49
79
|
/**
|
|
50
80
|
* @description 获取随机颜色
|
|
51
81
|
* @return 随机颜色
|
|
@@ -55,12 +85,22 @@ export declare const error: (...arg: unknown[]) => void;
|
|
|
55
85
|
export declare function getRandomColor(): string;
|
|
56
86
|
|
|
57
87
|
/**
|
|
58
|
-
* @description
|
|
88
|
+
* @description 获取范围内的随机浮点数
|
|
89
|
+
* @param min 最小值 默认值为 0
|
|
90
|
+
* @param max 最大值 默认值为 1000000
|
|
91
|
+
* @return 随机整数
|
|
92
|
+
*
|
|
93
|
+
* @example getRandomFloat() => 390083.99373681104
|
|
94
|
+
* */
|
|
95
|
+
export declare function getRandomFloat(min?: number, max?: number): number;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @description 获取范围内的随机整数
|
|
59
99
|
* @param min 最小值 默认值为 0
|
|
60
|
-
* @param max 最大值 默认值为
|
|
100
|
+
* @param max 最大值 默认值为 1000000
|
|
61
101
|
* @return 随机整数
|
|
62
102
|
*
|
|
63
|
-
* @example getRandomInteger() =>
|
|
103
|
+
* @example getRandomInteger() => 217342
|
|
64
104
|
* */
|
|
65
105
|
export declare function getRandomInteger(min?: number, max?: number): number;
|
|
66
106
|
|
|
@@ -73,7 +113,7 @@ export declare function getRandomInteger(min?: number, max?: number): number;
|
|
|
73
113
|
* */
|
|
74
114
|
export declare function getRandomString(length: number, options?: GetRandomStringOptions): string;
|
|
75
115
|
|
|
76
|
-
declare interface GetRandomStringOptions {
|
|
116
|
+
export declare interface GetRandomStringOptions {
|
|
77
117
|
/**
|
|
78
118
|
* @description 是否包含小写字母
|
|
79
119
|
* @default true
|
|
@@ -112,15 +152,13 @@ export declare function isEmptyString(value: string): boolean;
|
|
|
112
152
|
|
|
113
153
|
/**
|
|
114
154
|
* @description 校验是否为浮点数
|
|
115
|
-
* @returns 如果是浮点数包括整数返回 true,否则返回 false
|
|
116
155
|
*/
|
|
117
|
-
export declare function isFloat(val: string): boolean;
|
|
156
|
+
export declare function isFloat(val: string, floatOptions?: FloatOptions): boolean;
|
|
118
157
|
|
|
119
158
|
export declare const isFunction: (val: unknown) => val is Function;
|
|
120
159
|
|
|
121
160
|
/**
|
|
122
161
|
* @description 校验是否为整数
|
|
123
|
-
* @returns 如果是整数返回 true,否则返回 false
|
|
124
162
|
*/
|
|
125
163
|
export declare function isInteger(val: string): boolean;
|
|
126
164
|
|
|
@@ -138,13 +176,11 @@ export declare function isNegativeFloatOrZero(val: string): boolean;
|
|
|
138
176
|
|
|
139
177
|
/**
|
|
140
178
|
* @description 校验是否为负整数
|
|
141
|
-
* @returns 如果是负整数返回 true,否则返回 false
|
|
142
179
|
*/
|
|
143
180
|
export declare function isNegativeInteger(val: string): boolean;
|
|
144
181
|
|
|
145
182
|
/**
|
|
146
183
|
* @description 校验是否为小于等于零的整数
|
|
147
|
-
* @returns 如果是小于等于零的整数返回 true,否则返回 false
|
|
148
184
|
*/
|
|
149
185
|
export declare function isNegativeIntegerOrZero(val: string): boolean;
|
|
150
186
|
|
|
@@ -156,7 +192,6 @@ export declare const isObject: (val: unknown) => val is Record<any, any>;
|
|
|
156
192
|
|
|
157
193
|
/**
|
|
158
194
|
* @description 校验是否为大于零的浮点数
|
|
159
|
-
* @returns 如果是大于零的浮点数返回 true,否则返回 false
|
|
160
195
|
*/
|
|
161
196
|
export declare function isPositiveFloat(val: string): boolean;
|
|
162
197
|
|
|
@@ -167,13 +202,11 @@ export declare function isPositiveFloatOrZero(val: string): boolean;
|
|
|
167
202
|
|
|
168
203
|
/**
|
|
169
204
|
* @description 校验否为正整数
|
|
170
|
-
* @returns 如果是正整数返回 true,否则返回 false
|
|
171
205
|
*/
|
|
172
206
|
export declare function isPositiveInteger(val: string): boolean;
|
|
173
207
|
|
|
174
208
|
/**
|
|
175
209
|
* @description 校验是否为大于等于零的整数
|
|
176
|
-
* @returns 如果是大于等于零的整数返回 true,否则返回 false
|
|
177
210
|
*/
|
|
178
211
|
export declare function isPositiveIntegerOrZero(val: string): boolean;
|
|
179
212
|
|
|
@@ -203,6 +236,51 @@ declare interface Options {
|
|
|
203
236
|
isDeepClone: boolean;
|
|
204
237
|
}
|
|
205
238
|
|
|
239
|
+
/**
|
|
240
|
+
* @description 解析查询字符串
|
|
241
|
+
* @param str 转换的字符串
|
|
242
|
+
* @return 转换后的对象
|
|
243
|
+
* @example
|
|
244
|
+
* parse('a=1&b=2') => { a: '1', b: '2' }
|
|
245
|
+
* parse('?a=1&b=2') => { a: '1', b: '2' }
|
|
246
|
+
* parse('&a=1&b=2') => { a: '1', b: '2' }
|
|
247
|
+
* parse('from=%E4%B8%AD%E5%9B%BD') => { from: '中国' }
|
|
248
|
+
* parse('from=%E4%B8%AD%E5%9B%BD', { decode: false }) => { from: '%E4%B8%AD%E5%9B%BD' }
|
|
249
|
+
*/
|
|
250
|
+
declare function parse(str: string, options?: ParseOptions): Record<string, string>;
|
|
251
|
+
|
|
252
|
+
export declare interface ParseOptions {
|
|
253
|
+
/**
|
|
254
|
+
* @description 是否解码
|
|
255
|
+
* @default true
|
|
256
|
+
*/
|
|
257
|
+
decode?: boolean;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export declare const qs: {
|
|
261
|
+
parse: typeof parse;
|
|
262
|
+
stringify: typeof stringify;
|
|
263
|
+
appendQueryString: typeof appendQueryString;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
*@description 转换对象为查询字符串
|
|
268
|
+
* @param obj 转换的对象
|
|
269
|
+
* @return 转换后的字符串
|
|
270
|
+
* @example
|
|
271
|
+
* stringify({ a: '1', b: '2' }) => 'a=1&b=2'
|
|
272
|
+
* stringify({ from: '中国' }) => 'from=%E4%B8%AD%E5%9B%BD'
|
|
273
|
+
*/
|
|
274
|
+
declare function stringify(obj: Record<string, any>, options?: StringifyOptions): string;
|
|
275
|
+
|
|
276
|
+
export declare interface StringifyOptions {
|
|
277
|
+
/**
|
|
278
|
+
* @description 是否编码
|
|
279
|
+
* @default true
|
|
280
|
+
*/
|
|
281
|
+
encode?: boolean;
|
|
282
|
+
}
|
|
283
|
+
|
|
206
284
|
/**
|
|
207
285
|
* @description 节流函数
|
|
208
286
|
* @param target 目标函数
|
package/dist/index.mjs
CHANGED
|
@@ -1,260 +1,299 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
const j = (t, ...n) => {
|
|
7
|
-
const r = n.length === 0 ? "" : n.length === 1 ? n[0] : n;
|
|
8
|
-
console.log(
|
|
9
|
-
`%c ${t} `,
|
|
10
|
-
"padding: 2px; border-radius: 3px; color: #fff; background: #000; font-weight: bold;",
|
|
11
|
-
r
|
|
12
|
-
), d && d(t, r);
|
|
13
|
-
}, Z = (...t) => console.warn(...t), x = (...t) => console.error(...t), F = (t) => f(t) === "[object Map]", I = (t) => f(t) === "[object Set]", m = (t) => f(t) === "[object Date]", w = (t) => f(t) === "[object RegExp]", a = (t) => typeof t == "function", P = (t) => typeof t == "number", O = (t) => typeof t == "string", D = (t) => typeof t == "symbol", u = (t) => t !== null && typeof t == "object", R = (t) => u(t) && a(t.then) && a(t.catch), c = (t) => t == null, v = (t) => t === void 0, L = (t) => t === null, U = (t) => t != null, T = (t) => typeof t == "boolean", l = Array.isArray, y = (t, n) => Object.hasOwn(t, n), z = (t, n) => t !== n;
|
|
14
|
-
class h extends Error {
|
|
15
|
-
constructor(n) {
|
|
16
|
-
super(n), this.name = "LntvowError";
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function _(t, n) {
|
|
20
|
-
throw new h(`[${t}] ${n}`);
|
|
21
|
-
}
|
|
22
|
-
function E(t, n) {
|
|
23
|
-
if (process.env.NODE_ENV !== "production") {
|
|
24
|
-
const r = O(t) ? new h(`[${t}] ${n}`) : t;
|
|
25
|
-
console.warn(r);
|
|
26
|
-
}
|
|
1
|
+
function R(...t) {
|
|
2
|
+
return t.reduce((n, e) => function(...r) {
|
|
3
|
+
return e(n(...r));
|
|
4
|
+
});
|
|
27
5
|
}
|
|
28
|
-
function
|
|
29
|
-
return
|
|
6
|
+
function F(...t) {
|
|
7
|
+
return t.reduce((n, e) => function(...r) {
|
|
8
|
+
return n(e(...r));
|
|
9
|
+
});
|
|
30
10
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const $ = Math.floor(Math.random() * o.length);
|
|
39
|
-
g += o.charAt($);
|
|
40
|
-
}
|
|
41
|
-
return g;
|
|
11
|
+
function P(t, n = 500) {
|
|
12
|
+
let e = null;
|
|
13
|
+
return function(...r) {
|
|
14
|
+
e && clearTimeout(e), e = setTimeout(() => {
|
|
15
|
+
t.apply(this, r);
|
|
16
|
+
}, n);
|
|
17
|
+
};
|
|
42
18
|
}
|
|
43
|
-
|
|
44
|
-
|
|
19
|
+
const y = Object.prototype.toString, a = (t) => y.call(t);
|
|
20
|
+
let g = null;
|
|
21
|
+
function Z(t) {
|
|
22
|
+
h(t) && (g = t);
|
|
45
23
|
}
|
|
46
|
-
|
|
24
|
+
const v = (t, ...n) => {
|
|
25
|
+
const e = n.length === 0 ? "" : n.length === 1 ? n[0] : n;
|
|
26
|
+
console.log(
|
|
27
|
+
`%c ${t} `,
|
|
28
|
+
"padding: 2px; border-radius: 3px; color: #fff; background: #000; font-weight: bold;",
|
|
29
|
+
e
|
|
30
|
+
), g && g(t, e);
|
|
31
|
+
}, D = (...t) => console.warn(...t), U = (...t) => console.error(...t), L = (t) => a(t) === "[object Map]", W = (t) => a(t) === "[object Set]", E = (t) => a(t) === "[object Date]", C = (t) => a(t) === "[object RegExp]", h = (t) => typeof t == "function", T = (t) => typeof t == "number", A = (t) => typeof t == "string", z = (t) => typeof t == "symbol", f = (t) => t !== null && typeof t == "object", _ = (t) => f(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", l = Array.isArray, $ = (t, n) => Object.hasOwn(t, n), V = (t, n) => t !== n;
|
|
32
|
+
function b(t) {
|
|
47
33
|
const n = /* @__PURE__ */ new WeakMap();
|
|
48
|
-
function r
|
|
49
|
-
if (
|
|
50
|
-
return new Date(
|
|
51
|
-
if (
|
|
52
|
-
return new RegExp(
|
|
53
|
-
if (
|
|
54
|
-
if (n.has(
|
|
55
|
-
return n.get(
|
|
34
|
+
function e(r) {
|
|
35
|
+
if (E(r))
|
|
36
|
+
return new Date(r);
|
|
37
|
+
if (C(r))
|
|
38
|
+
return new RegExp(r);
|
|
39
|
+
if (f(r)) {
|
|
40
|
+
if (n.has(r))
|
|
41
|
+
return n.get(r);
|
|
56
42
|
let i = {};
|
|
57
|
-
if (l(
|
|
58
|
-
i = [], n.set(
|
|
59
|
-
for (let o = 0; o <
|
|
60
|
-
i[o] = r
|
|
43
|
+
if (l(r)) {
|
|
44
|
+
i = [], n.set(r, i);
|
|
45
|
+
for (let o = 0; o < r.length; o++)
|
|
46
|
+
i[o] = e(r[o]);
|
|
61
47
|
return i;
|
|
62
48
|
}
|
|
63
|
-
n.set(
|
|
64
|
-
for (const o in
|
|
65
|
-
|
|
49
|
+
n.set(r, i);
|
|
50
|
+
for (const o in r)
|
|
51
|
+
$(r, o) && (i[o] = e(r[o]));
|
|
66
52
|
return i;
|
|
67
53
|
} else
|
|
68
|
-
return
|
|
54
|
+
return r;
|
|
69
55
|
}
|
|
70
|
-
return
|
|
56
|
+
return e(t);
|
|
71
57
|
}
|
|
72
|
-
function
|
|
73
|
-
return l(t) ?
|
|
58
|
+
function p(t, n, e) {
|
|
59
|
+
return l(t) ? S(t, n, e) : M(t, n, e);
|
|
74
60
|
}
|
|
75
|
-
function M(t, n,
|
|
76
|
-
const
|
|
61
|
+
function M(t, n, e) {
|
|
62
|
+
const r = s(n, e);
|
|
77
63
|
return Object.keys(t).forEach((o) => {
|
|
78
|
-
c(n[o]) ?
|
|
79
|
-
}),
|
|
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
|
+
}), r;
|
|
80
66
|
}
|
|
81
|
-
function
|
|
67
|
+
function S(t, n, e) {
|
|
82
68
|
if (l(n)) {
|
|
83
|
-
const
|
|
84
|
-
return
|
|
69
|
+
const r = s(n, e);
|
|
70
|
+
return r.push(...s(t, e)), r;
|
|
85
71
|
} else
|
|
86
|
-
return s(t,
|
|
72
|
+
return s(t, e);
|
|
87
73
|
}
|
|
88
74
|
function s(t, n) {
|
|
89
|
-
const { isDeepClone:
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
};
|
|
75
|
+
const { isDeepClone: e = !0 } = n || {};
|
|
76
|
+
return e ? b(t) : t;
|
|
77
|
+
}
|
|
78
|
+
class m extends Error {
|
|
79
|
+
constructor(n) {
|
|
80
|
+
super(n), this.name = "LntvowError";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function N(t, n) {
|
|
84
|
+
throw new m(`[${t}] ${n}`);
|
|
85
|
+
}
|
|
86
|
+
function G(t, n) {
|
|
87
|
+
if (process.env.NODE_ENV !== "production") {
|
|
88
|
+
const e = A(t) ? new m(`[${t}] ${n}`) : t;
|
|
89
|
+
console.warn(e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function H(t, n) {
|
|
93
|
+
const e = b(t);
|
|
94
|
+
return I(n).forEach((i) => {
|
|
95
|
+
$(e, i) && delete e[i];
|
|
96
|
+
}), e;
|
|
99
97
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
function j(t, n) {
|
|
99
|
+
const { decode: e } = p({ decode: !0 }, n || {}), r = {};
|
|
100
|
+
t.startsWith("?") && (t = t.slice(1)), t.includes("?") && (t = t.slice(t.indexOf("?") + 1));
|
|
101
|
+
const i = t.split("&").filter(Boolean);
|
|
102
|
+
for (const o of i) {
|
|
103
|
+
const [d, u] = o.split("=");
|
|
104
|
+
r[d] = e ? decodeURIComponent(u) : u;
|
|
105
|
+
}
|
|
106
|
+
return r;
|
|
107
|
+
}
|
|
108
|
+
function w(t, n) {
|
|
109
|
+
const { encode: e } = p({ encode: !0 }, n || {}), r = [];
|
|
110
|
+
for (const i in t) {
|
|
111
|
+
const o = t[i];
|
|
112
|
+
r.push(`${i}=${e ? encodeURIComponent(o) : o}`);
|
|
113
|
+
}
|
|
114
|
+
return r.join("&");
|
|
115
|
+
}
|
|
116
|
+
function x(t, n, e) {
|
|
117
|
+
const r = p({ encode: !0 }, e || {}), i = w(n, r);
|
|
118
|
+
return t.includes("?") ? t.endsWith("?") || t.endsWith("&") ? `${t}${i}` : `${t}&${i}` : `${t}?${i}`;
|
|
119
|
+
}
|
|
120
|
+
const J = {
|
|
121
|
+
parse: j,
|
|
122
|
+
stringify: w,
|
|
123
|
+
appendQueryString: x
|
|
124
|
+
};
|
|
125
|
+
function X(t, n = 500) {
|
|
126
|
+
let e = null;
|
|
127
|
+
return function(...r) {
|
|
128
|
+
if (c(e))
|
|
129
|
+
return e = Date.now(), t.apply(this, r);
|
|
105
130
|
{
|
|
106
131
|
const i = Date.now();
|
|
107
|
-
if (i -
|
|
108
|
-
return
|
|
132
|
+
if (i - e >= n)
|
|
133
|
+
return e = i, t.apply(this, r);
|
|
109
134
|
}
|
|
110
135
|
};
|
|
111
136
|
}
|
|
112
|
-
function
|
|
113
|
-
return t.reduce((n, r) => function(...e) {
|
|
114
|
-
return r(n(...e));
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function H(...t) {
|
|
118
|
-
return t.reduce((n, r) => function(...e) {
|
|
119
|
-
return n(r(...e));
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
function J(t) {
|
|
137
|
+
function Y(t) {
|
|
123
138
|
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(
|
|
124
139
|
t
|
|
125
140
|
);
|
|
126
141
|
}
|
|
127
|
-
function
|
|
142
|
+
function k(t) {
|
|
128
143
|
return /^([\w-])+@([\w-])+(\.[\w-])+/.test(t);
|
|
129
144
|
}
|
|
130
|
-
function
|
|
145
|
+
function tt(t) {
|
|
131
146
|
return /^[A-Z]+$/.test(t);
|
|
132
147
|
}
|
|
133
|
-
function
|
|
148
|
+
function nt(t) {
|
|
134
149
|
return !c(t) && /^[a-z]+$/.test(t);
|
|
135
150
|
}
|
|
136
|
-
function
|
|
151
|
+
function et(t) {
|
|
137
152
|
return /^\d+$/.test(t);
|
|
138
153
|
}
|
|
139
|
-
function
|
|
154
|
+
function rt(t) {
|
|
140
155
|
return /^-?\d{1,3}\.\d{6}$/.test(t);
|
|
141
156
|
}
|
|
142
|
-
function
|
|
157
|
+
function ot(t) {
|
|
143
158
|
return t === "";
|
|
144
159
|
}
|
|
145
|
-
function
|
|
160
|
+
function it(t) {
|
|
146
161
|
return !c(t) && /^[\dA-Za-z\u4E00-\u9FA5]+$/.test(t);
|
|
147
162
|
}
|
|
148
|
-
function
|
|
163
|
+
function st(t) {
|
|
149
164
|
return !c(t) && /^[A-Za-z\u4E00-\u9FA5]+$/.test(t);
|
|
150
165
|
}
|
|
151
|
-
function
|
|
166
|
+
function ct(t) {
|
|
152
167
|
return !c(t) && /^[\d!"#$%&'()*+,./:;<=>?@A-Z[\\\]^_`{|}~]+$/.test(t);
|
|
153
168
|
}
|
|
154
|
-
function
|
|
169
|
+
function ut(t) {
|
|
155
170
|
return /^[\dA-Z_]+$/.test(t);
|
|
156
171
|
}
|
|
157
|
-
function
|
|
172
|
+
function dt(t) {
|
|
158
173
|
return /^[1-9]\d*$/.test(t);
|
|
159
174
|
}
|
|
160
|
-
function
|
|
175
|
+
function ft(t) {
|
|
161
176
|
return /^\d+$/.test(t);
|
|
162
177
|
}
|
|
163
|
-
function
|
|
178
|
+
function at(t) {
|
|
164
179
|
return /^(0*[1-9]+\d*\.?\d*|0+\.\d*[1-9]+\d*)$/.test(t);
|
|
165
180
|
}
|
|
166
|
-
function
|
|
167
|
-
return
|
|
181
|
+
function I(t) {
|
|
182
|
+
return l(t) ? t : [t];
|
|
168
183
|
}
|
|
169
|
-
function
|
|
170
|
-
return
|
|
184
|
+
function lt() {
|
|
185
|
+
return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
|
|
171
186
|
}
|
|
172
|
-
function
|
|
173
|
-
return
|
|
187
|
+
function pt(t = 0, n = 1e6) {
|
|
188
|
+
return Math.random() * (n - t) + t;
|
|
189
|
+
}
|
|
190
|
+
function gt(t = 0, n = 1e6) {
|
|
191
|
+
return Math.floor(Math.random() * (n - t + 1)) + Math.floor(t);
|
|
192
|
+
}
|
|
193
|
+
function ht(t, n = {}) {
|
|
194
|
+
const { lowerCase: e = !0, upperCase: r = !0, number: i = !0 } = n;
|
|
195
|
+
e || r || i || N("getRandomString", "lowerCase upperCase number 至少需要一个参数为true");
|
|
196
|
+
let o = "";
|
|
197
|
+
e && (o += "abcdefghijklmnopqrstuvwxyz"), r && (o += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), i && (o += "0123456789");
|
|
198
|
+
let d = "";
|
|
199
|
+
for (let u = 0; u < t; u++) {
|
|
200
|
+
const O = Math.floor(Math.random() * o.length);
|
|
201
|
+
d += o.charAt(O);
|
|
202
|
+
}
|
|
203
|
+
return d;
|
|
174
204
|
}
|
|
175
|
-
function
|
|
176
|
-
return
|
|
205
|
+
function $t(t) {
|
|
206
|
+
return /^-?(0|[1-9]\d*)$/.test(t);
|
|
207
|
+
}
|
|
208
|
+
function bt(t) {
|
|
209
|
+
return /^[1-9]\d*$/.test(t);
|
|
177
210
|
}
|
|
178
|
-
function
|
|
211
|
+
function mt(t) {
|
|
179
212
|
return /^(0|[1-9]\d*)$/.test(t);
|
|
180
213
|
}
|
|
181
|
-
function
|
|
182
|
-
return
|
|
214
|
+
function wt(t) {
|
|
215
|
+
return /^-([1-9]\d*)$/.test(t);
|
|
183
216
|
}
|
|
184
|
-
function
|
|
217
|
+
function Ot(t) {
|
|
218
|
+
return /^(0|-(0|[1-9]\d*))$/.test(t);
|
|
219
|
+
}
|
|
220
|
+
function yt(t, n) {
|
|
185
221
|
return /^-?\d+(\.\d+)?$/.test(t);
|
|
186
222
|
}
|
|
187
|
-
function
|
|
223
|
+
function Et(t) {
|
|
188
224
|
return /^(0\.\d+|[1-9]\d*(\.\d+)?)$/.test(t);
|
|
189
225
|
}
|
|
190
|
-
function
|
|
226
|
+
function Ct(t) {
|
|
191
227
|
return /^-\d+(\.\d+)?$/.test(t);
|
|
192
228
|
}
|
|
193
|
-
function
|
|
229
|
+
function At(t) {
|
|
194
230
|
return /^\d+(\.\d+)?$/.test(t);
|
|
195
231
|
}
|
|
196
|
-
function
|
|
232
|
+
function Mt(t) {
|
|
197
233
|
return /^(-\d+(\.\d+)?$)|(0(\.0+)?)$/.test(t);
|
|
198
234
|
}
|
|
199
235
|
export {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
236
|
+
I as castArray,
|
|
237
|
+
R as compose,
|
|
238
|
+
F as composeRight,
|
|
239
|
+
P as debounce,
|
|
240
|
+
G as debugWarn,
|
|
241
|
+
b as deepClone,
|
|
242
|
+
p as deepMerge,
|
|
243
|
+
U as error,
|
|
244
|
+
H as excludeProperties,
|
|
245
|
+
lt as getRandomColor,
|
|
246
|
+
pt as getRandomFloat,
|
|
247
|
+
gt as getRandomInteger,
|
|
248
|
+
ht as getRandomString,
|
|
249
|
+
V as hasChanged,
|
|
250
|
+
$ as hasOwn,
|
|
251
|
+
Z as initLog,
|
|
214
252
|
l as isArray,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
253
|
+
Q as isBoolean,
|
|
254
|
+
E as isDate,
|
|
255
|
+
K as isDef,
|
|
256
|
+
ot as isEmptyString,
|
|
257
|
+
yt as isFloat,
|
|
258
|
+
h as isFunction,
|
|
259
|
+
$t as isInteger,
|
|
260
|
+
L as isMap,
|
|
261
|
+
Ct as isNegativeFloat,
|
|
262
|
+
Mt as isNegativeFloatOrZero,
|
|
263
|
+
wt as isNegativeInteger,
|
|
264
|
+
Ot as isNegativeIntegerOrZero,
|
|
265
|
+
B as isNull,
|
|
266
|
+
T as isNumber,
|
|
267
|
+
f as isObject,
|
|
268
|
+
Et as isPositiveFloat,
|
|
269
|
+
At as isPositiveFloatOrZero,
|
|
270
|
+
bt as isPositiveInteger,
|
|
271
|
+
mt as isPositiveIntegerOrZero,
|
|
272
|
+
_ as isPromise,
|
|
273
|
+
C as isRegExp,
|
|
274
|
+
W as isSet,
|
|
275
|
+
A as isString,
|
|
276
|
+
z as isSymbol,
|
|
239
277
|
c as isUndef,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
278
|
+
q as isUndefined,
|
|
279
|
+
v as log,
|
|
280
|
+
y as objectToString,
|
|
281
|
+
J as qs,
|
|
282
|
+
X as throttle,
|
|
283
|
+
N as throwError,
|
|
284
|
+
a as toTypeString,
|
|
285
|
+
st as validatorChineseOrEnglish,
|
|
286
|
+
it as validatorChineseOrEnglishOrNumber,
|
|
287
|
+
k as validatorEmail,
|
|
288
|
+
rt as validatorLatitudeOrLongitude,
|
|
289
|
+
nt as validatorLowerCase,
|
|
290
|
+
Y as validatorMobilePhone,
|
|
291
|
+
et as validatorNumber,
|
|
292
|
+
at as validatorPositiveFloat,
|
|
293
|
+
dt as validatorPositiveInt,
|
|
294
|
+
ft as validatorPositiveIntAndZero,
|
|
295
|
+
tt as validatorUpperCase,
|
|
296
|
+
ct as validatorUppercaseOrNumbersOrSpecial,
|
|
297
|
+
ut as validatorUppercaseOrNumbersOrUnderline,
|
|
298
|
+
D as warn
|
|
260
299
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lntvow/utils",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.17",
|
|
4
4
|
"description": "工具库",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
"@commitlint/cli": "^18.4.3",
|
|
16
16
|
"@commitlint/config-conventional": "^18.4.3",
|
|
17
17
|
"@lntvow/eslint-config": "^8.3.5",
|
|
18
|
+
"@vitest/coverage-istanbul": "^1.2.0",
|
|
19
|
+
"@vitest/ui": "^1.2.0",
|
|
18
20
|
"bumpp": "^9.2.1",
|
|
19
21
|
"commitizen": "^4.3.0",
|
|
20
22
|
"cz-conventional-changelog": "^3.3.0",
|
|
@@ -35,8 +37,9 @@
|
|
|
35
37
|
]
|
|
36
38
|
},
|
|
37
39
|
"scripts": {
|
|
38
|
-
"dev": "vite",
|
|
39
40
|
"test": "vitest",
|
|
41
|
+
"test:ui": "vitest --ui",
|
|
42
|
+
"coverage": "vitest run --coverage",
|
|
40
43
|
"build": "vite build",
|
|
41
44
|
"commit": "git add . && git-cz && git push",
|
|
42
45
|
"release": "git add . && bumpp package.json --all --commit --no-tag --push",
|