@lntvow/utils 1.8.1 → 1.8.3
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 +62 -0
- package/dist/index.mjs +144 -90
- package/package.json +1 -6
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function w(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}function l(t){return t>10?l(10)+l(t-10):Math.random().toString(36).padEnd(12,"0").slice(2,t+2)}const a=Object.prototype.toString,u=t=>a.call(t),y=(...t)=>console.log(`%c ${t[0]}: `,"padding: 2px 1px; border-radius: 3px 3px 3px 3px; color: #fff; background: #000; font-weight: bold;",t.slice(1)),C=(...t)=>console.warn(...t),E=(...t)=>console.error(...t),j=t=>u(t)==="[object Map]",A=t=>u(t)==="[object Set]",p=t=>u(t)==="[object Date]",g=t=>u(t)==="[object RegExp]",d=t=>typeof t=="function",$=t=>typeof t=="string",x=t=>typeof t=="symbol",c=t=>t!==null&&typeof t=="object",M=t=>c(t)&&d(t.then)&&d(t.catch),h=t=>t==null,b=t=>t===null;function R(t){return t!=null}function D(t){return typeof t=="boolean"}const f=Array.isArray,m=(t,e)=>Object.hasOwn(t,e),P=(t,e)=>t!==e;function O(t){const e=new WeakMap;function r(n){if(p(n))return new Date(n);if(g(n))return new RegExp(n);if(c(n)){if(e.has(n))return e.get(n);let o={};if(f(n)){o=[],e.set(n,o);for(let i=0;i<n.length;i++)o[i]=r(n[i]);return o}e.set(n,o);for(const i in n)m(n,i)&&(o[i]=r(n[i]));return o}else return n}return r(t)}function S(t,e,r){return f(t)?N(t,e,r):T(t,e,r)}function T(t,e,r){const n=s(e,r);return Object.keys(t).forEach(i=>{h(e[i])?n[i]=s(t[i],r):n[i]=c(t[i])&&c(e[i])?S(t[i],e[i],r):s(e[i],r)}),n}function N(t,e,r){if(f(e)){const n=s(e,r);return n.push(...s(t,r)),n}else return s(t,r)}function s(t,e){const{isDeepClone:r=!0}=e||{};return r?O(t):t}function F(t,e=1e3){let r=null;return function(...n){r&&clearTimeout(r),r=setTimeout(()=>{t.apply(this,...n)},e)}}function L(t,e=1e3){let r=null;return function(...n){if(b(r))return r=Date.now(),t.apply(this,...n);{const o=Date.now();if(o-r>=e)return r=o,t.apply(this,...n)}}}function U(...t){return t.reduce((e,r)=>function(...n){return r(e(...n))})}function Z(...t){return t.reduce((e,r)=>function(...n){return e(r(...n))})}function z(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 B(t){return/^([\w-])+@([\w-])+(.[\w-])+/.test(t)}function I(t){return/^[A-Z]+$/.test(t)}function K(t){return/^[a-z]+$/.test(t)}function W(t){return/^\d+$/.test(t)}function _(t){return/^-?\d{1,3}\.\d{6}$/.test(t)}function q(t){return/^[\dA-Za-z\u4E00-\u9FA5]+$/.test(t)}function G(t){return/^[A-Za-z\u4E00-\u9FA5]+$/.test(t)}function H(t){return/^[\dA-Za-z\u4E00-\u9FA5]+$/.test(t)}function J(t){return/^[\d!#$%&*@A-Z^]+$/.test(t)}function Q(t){return/^[1-9]\d*$/.test(t)}function V(t){return/^(0*[1-9]+\d*\.?\d*|0+\.\d*[1-9]+\d*)$/.test(t)}exports.compose=U;exports.composeRight=Z;exports.debounce=F;exports.deepClone=O;exports.deepMerge=S;exports.error=E;exports.getRandomColor=w;exports.getRandomString=l;exports.hasChanged=P;exports.hasOwn=m;exports.isAlphanumericText=q;exports.isArray=f;exports.isBoolean=D;exports.isChineseOrEnglish=G;exports.isChineseOrEnglishOrNumber=H;exports.isDate=p;exports.isDef=R;exports.isEmail=B;exports.isFunction=d;exports.isLatitudeOrLongitude=_;exports.isLowerCase=K;exports.isMap=j;exports.isMobilePhone=z;exports.isNull=b;exports.isNumber=W;exports.isObject=c;exports.isPositiveFloat=V;exports.isPositiveInt=Q;exports.isPromise=M;exports.isRegExp=g;exports.isSet=A;exports.isString=$;exports.isSymbol=x;exports.isUndef=h;exports.isUpperCase=I;exports.isUppercaseOrNumbersOrSpecial=J;exports.log=y;exports.objectToString=a;exports.throttle=L;exports.toTypeString=u;exports.warn=C;
|
package/dist/index.d.ts
CHANGED
|
@@ -61,20 +61,72 @@ export declare const hasChanged: (oldValue: unknown, newValue: unknown) => boole
|
|
|
61
61
|
|
|
62
62
|
export declare const hasOwn: <T extends object, U extends keyof T>(target: T, key: U) => boolean;
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* @description 校验中英文、数字
|
|
66
|
+
*/
|
|
67
|
+
export declare function isAlphanumericText(value: string): boolean;
|
|
68
|
+
|
|
64
69
|
export declare const isArray: (arg: any) => arg is any[];
|
|
65
70
|
|
|
71
|
+
export declare function isBoolean(val: unknown): val is boolean;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @description 校验中英文
|
|
75
|
+
*/
|
|
76
|
+
export declare function isChineseOrEnglish(value: string): boolean;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @description 校验中文、字母、数字
|
|
80
|
+
*/
|
|
81
|
+
export declare function isChineseOrEnglishOrNumber(value: string): boolean;
|
|
82
|
+
|
|
66
83
|
export declare const isDate: (val: unknown) => val is Date;
|
|
67
84
|
|
|
68
85
|
export declare function isDef<T>(v: T): v is NonNullable<T>;
|
|
69
86
|
|
|
87
|
+
/**
|
|
88
|
+
* @description 校验邮箱
|
|
89
|
+
*/
|
|
90
|
+
export declare function isEmail(value: string): boolean;
|
|
91
|
+
|
|
70
92
|
export declare const isFunction: (val: unknown) => val is Function;
|
|
71
93
|
|
|
94
|
+
/**
|
|
95
|
+
* @description 校验经纬度
|
|
96
|
+
*/
|
|
97
|
+
export declare function isLatitudeOrLongitude(value: string): boolean;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @description 校验小写字母
|
|
101
|
+
*/
|
|
102
|
+
export declare function isLowerCase(value: string): boolean;
|
|
103
|
+
|
|
72
104
|
export declare const isMap: (val: unknown) => val is Map<any, any>;
|
|
73
105
|
|
|
106
|
+
/**
|
|
107
|
+
* @description 校验手机号
|
|
108
|
+
*/
|
|
109
|
+
export declare function isMobilePhone(value: string): boolean;
|
|
110
|
+
|
|
74
111
|
export declare const isNull: (val: unknown) => val is null;
|
|
75
112
|
|
|
113
|
+
/**
|
|
114
|
+
* @description 校验校验数字
|
|
115
|
+
*/
|
|
116
|
+
export declare function isNumber(value: string): boolean;
|
|
117
|
+
|
|
76
118
|
export declare const isObject: (val: unknown) => val is Record<any, any>;
|
|
77
119
|
|
|
120
|
+
/**
|
|
121
|
+
* @description 校验正浮点数
|
|
122
|
+
*/
|
|
123
|
+
export declare function isPositiveFloat(value: string): boolean;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @description 校验正整数
|
|
127
|
+
*/
|
|
128
|
+
export declare function isPositiveInt(value: string): boolean;
|
|
129
|
+
|
|
78
130
|
export declare const isPromise: <T = any>(val: unknown) => val is Promise<T>;
|
|
79
131
|
|
|
80
132
|
export declare const isRegExp: (val: unknown) => val is RegExp;
|
|
@@ -87,6 +139,16 @@ export declare const isSymbol: (val: unknown) => val is symbol;
|
|
|
87
139
|
|
|
88
140
|
export declare const isUndef: (val: unknown) => val is null | undefined;
|
|
89
141
|
|
|
142
|
+
/**
|
|
143
|
+
* @description 校验大写字母
|
|
144
|
+
*/
|
|
145
|
+
export declare function isUpperCase(value: string): boolean;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @description 校验大写字母、数字、特殊字符
|
|
149
|
+
*/
|
|
150
|
+
export declare function isUppercaseOrNumbersOrSpecial(value: string): boolean;
|
|
151
|
+
|
|
90
152
|
export declare const log: (...arg: unknown[]) => void;
|
|
91
153
|
|
|
92
154
|
export declare const objectToString: () => string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,121 +1,175 @@
|
|
|
1
|
-
function
|
|
1
|
+
function A() {
|
|
2
2
|
return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
return
|
|
4
|
+
function d(t) {
|
|
5
|
+
return t > 10 ? d(10) + d(t - 10) : Math.random().toString(36).padEnd(12, "0").slice(2, t + 2);
|
|
6
6
|
}
|
|
7
|
-
const
|
|
8
|
-
`%c ${
|
|
7
|
+
const l = Object.prototype.toString, u = (t) => l.call(t), E = (...t) => console.log(
|
|
8
|
+
`%c ${t[0]}: `,
|
|
9
9
|
"padding: 2px 1px; border-radius: 3px 3px 3px 3px; color: #fff; background: #000; font-weight: bold;",
|
|
10
|
-
|
|
11
|
-
),
|
|
12
|
-
function
|
|
13
|
-
return
|
|
10
|
+
t.slice(1)
|
|
11
|
+
), j = (...t) => console.warn(...t), x = (...t) => console.error(...t), S = (t) => u(t) === "[object Map]", C = (t) => u(t) === "[object Set]", a = (t) => u(t) === "[object Date]", g = (t) => u(t) === "[object RegExp]", p = (t) => typeof t == "function", M = (t) => typeof t == "string", D = (t) => typeof t == "symbol", c = (t) => t !== null && typeof t == "object", R = (t) => c(t) && p(t.then) && p(t.catch), h = (t) => t == null, b = (t) => t === null;
|
|
12
|
+
function F(t) {
|
|
13
|
+
return t != null;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
function T(t) {
|
|
16
|
+
return typeof t == "boolean";
|
|
17
|
+
}
|
|
18
|
+
const f = Array.isArray, w = (t, e) => Object.hasOwn(t, e), Z = (t, e) => t !== e;
|
|
19
|
+
function m(t) {
|
|
17
20
|
const e = /* @__PURE__ */ new WeakMap();
|
|
18
|
-
function
|
|
19
|
-
if (
|
|
20
|
-
return new Date(
|
|
21
|
-
if (
|
|
22
|
-
return new RegExp(
|
|
23
|
-
if (
|
|
24
|
-
if (e.has(
|
|
25
|
-
return e.get(
|
|
26
|
-
let
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
for (let
|
|
30
|
-
|
|
31
|
-
return
|
|
21
|
+
function r(n) {
|
|
22
|
+
if (a(n))
|
|
23
|
+
return new Date(n);
|
|
24
|
+
if (g(n))
|
|
25
|
+
return new RegExp(n);
|
|
26
|
+
if (c(n)) {
|
|
27
|
+
if (e.has(n))
|
|
28
|
+
return e.get(n);
|
|
29
|
+
let i = {};
|
|
30
|
+
if (f(n)) {
|
|
31
|
+
i = [], e.set(n, i);
|
|
32
|
+
for (let o = 0; o < n.length; o++)
|
|
33
|
+
i[o] = r(n[o]);
|
|
34
|
+
return i;
|
|
32
35
|
}
|
|
33
|
-
e.set(
|
|
34
|
-
for (const
|
|
35
|
-
|
|
36
|
-
return
|
|
36
|
+
e.set(n, i);
|
|
37
|
+
for (const o in n)
|
|
38
|
+
w(n, o) && (i[o] = r(n[o]));
|
|
39
|
+
return i;
|
|
37
40
|
} else
|
|
38
|
-
return
|
|
41
|
+
return n;
|
|
39
42
|
}
|
|
40
|
-
return
|
|
43
|
+
return r(t);
|
|
41
44
|
}
|
|
42
|
-
function
|
|
43
|
-
return
|
|
45
|
+
function $(t, e, r) {
|
|
46
|
+
return f(t) ? y(t, e, r) : O(t, e, r);
|
|
44
47
|
}
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
return Object.keys(
|
|
48
|
-
|
|
49
|
-
}),
|
|
48
|
+
function O(t, e, r) {
|
|
49
|
+
const n = s(e, r);
|
|
50
|
+
return Object.keys(t).forEach((o) => {
|
|
51
|
+
h(e[o]) ? n[o] = s(t[o], r) : n[o] = c(t[o]) && c(e[o]) ? $(t[o], e[o], r) : s(e[o], r);
|
|
52
|
+
}), n;
|
|
50
53
|
}
|
|
51
|
-
function
|
|
52
|
-
if (
|
|
53
|
-
const
|
|
54
|
-
return
|
|
54
|
+
function y(t, e, r) {
|
|
55
|
+
if (f(e)) {
|
|
56
|
+
const n = s(e, r);
|
|
57
|
+
return n.push(...s(t, r)), n;
|
|
55
58
|
} else
|
|
56
|
-
return
|
|
59
|
+
return s(t, r);
|
|
57
60
|
}
|
|
58
|
-
function
|
|
59
|
-
const { isDeepClone:
|
|
60
|
-
return
|
|
61
|
+
function s(t, e) {
|
|
62
|
+
const { isDeepClone: r = !0 } = e || {};
|
|
63
|
+
return r ? m(t) : t;
|
|
61
64
|
}
|
|
62
|
-
function
|
|
63
|
-
let
|
|
64
|
-
return function(...
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
function z(t, e = 1e3) {
|
|
66
|
+
let r = null;
|
|
67
|
+
return function(...n) {
|
|
68
|
+
r && clearTimeout(r), r = setTimeout(() => {
|
|
69
|
+
t.apply(this, ...n);
|
|
67
70
|
}, e);
|
|
68
71
|
};
|
|
69
72
|
}
|
|
70
|
-
function N(
|
|
71
|
-
let
|
|
72
|
-
return function(...
|
|
73
|
-
if (b(
|
|
74
|
-
return
|
|
73
|
+
function N(t, e = 1e3) {
|
|
74
|
+
let r = null;
|
|
75
|
+
return function(...n) {
|
|
76
|
+
if (b(r))
|
|
77
|
+
return r = Date.now(), t.apply(this, ...n);
|
|
75
78
|
{
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
return
|
|
79
|
+
const i = Date.now();
|
|
80
|
+
if (i - r >= e)
|
|
81
|
+
return r = i, t.apply(this, ...n);
|
|
79
82
|
}
|
|
80
83
|
};
|
|
81
84
|
}
|
|
82
|
-
function P(...
|
|
83
|
-
return
|
|
84
|
-
return
|
|
85
|
+
function P(...t) {
|
|
86
|
+
return t.reduce((e, r) => function(...n) {
|
|
87
|
+
return r(e(...n));
|
|
85
88
|
});
|
|
86
89
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
89
|
-
return e(
|
|
90
|
+
function L(...t) {
|
|
91
|
+
return t.reduce((e, r) => function(...n) {
|
|
92
|
+
return e(r(...n));
|
|
90
93
|
});
|
|
91
94
|
}
|
|
95
|
+
function U(t) {
|
|
96
|
+
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(
|
|
97
|
+
t
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
function K(t) {
|
|
101
|
+
return /^([\w-])+@([\w-])+(.[\w-])+/.test(t);
|
|
102
|
+
}
|
|
103
|
+
function B(t) {
|
|
104
|
+
return /^[A-Z]+$/.test(t);
|
|
105
|
+
}
|
|
106
|
+
function I(t) {
|
|
107
|
+
return /^[a-z]+$/.test(t);
|
|
108
|
+
}
|
|
109
|
+
function W(t) {
|
|
110
|
+
return /^\d+$/.test(t);
|
|
111
|
+
}
|
|
112
|
+
function _(t) {
|
|
113
|
+
return /^-?\d{1,3}\.\d{6}$/.test(t);
|
|
114
|
+
}
|
|
115
|
+
function q(t) {
|
|
116
|
+
return /^[\dA-Za-z\u4E00-\u9FA5]+$/.test(t);
|
|
117
|
+
}
|
|
118
|
+
function G(t) {
|
|
119
|
+
return /^[A-Za-z\u4E00-\u9FA5]+$/.test(t);
|
|
120
|
+
}
|
|
121
|
+
function H(t) {
|
|
122
|
+
return /^[\dA-Za-z\u4E00-\u9FA5]+$/.test(t);
|
|
123
|
+
}
|
|
124
|
+
function J(t) {
|
|
125
|
+
return /^[\d!#$%&*@A-Z^]+$/.test(t);
|
|
126
|
+
}
|
|
127
|
+
function Q(t) {
|
|
128
|
+
return /^[1-9]\d*$/.test(t);
|
|
129
|
+
}
|
|
130
|
+
function V(t) {
|
|
131
|
+
return /^(0*[1-9]+\d*\.?\d*|0+\.\d*[1-9]+\d*)$/.test(t);
|
|
132
|
+
}
|
|
92
133
|
export {
|
|
93
134
|
P as compose,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
135
|
+
L as composeRight,
|
|
136
|
+
z as debounce,
|
|
137
|
+
m as deepClone,
|
|
138
|
+
$ as deepMerge,
|
|
139
|
+
x as error,
|
|
140
|
+
A as getRandomColor,
|
|
141
|
+
d as getRandomString,
|
|
142
|
+
Z as hasChanged,
|
|
143
|
+
w as hasOwn,
|
|
144
|
+
q as isAlphanumericText,
|
|
145
|
+
f as isArray,
|
|
146
|
+
T as isBoolean,
|
|
147
|
+
G as isChineseOrEnglish,
|
|
148
|
+
H as isChineseOrEnglishOrNumber,
|
|
149
|
+
a as isDate,
|
|
150
|
+
F as isDef,
|
|
151
|
+
K as isEmail,
|
|
152
|
+
p as isFunction,
|
|
153
|
+
_ as isLatitudeOrLongitude,
|
|
154
|
+
I as isLowerCase,
|
|
155
|
+
S as isMap,
|
|
156
|
+
U as isMobilePhone,
|
|
108
157
|
b as isNull,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
158
|
+
W as isNumber,
|
|
159
|
+
c as isObject,
|
|
160
|
+
V as isPositiveFloat,
|
|
161
|
+
Q as isPositiveInt,
|
|
162
|
+
R as isPromise,
|
|
163
|
+
g as isRegExp,
|
|
164
|
+
C as isSet,
|
|
165
|
+
M as isString,
|
|
166
|
+
D as isSymbol,
|
|
167
|
+
h as isUndef,
|
|
168
|
+
B as isUpperCase,
|
|
169
|
+
J as isUppercaseOrNumbersOrSpecial,
|
|
170
|
+
E as log,
|
|
171
|
+
l as objectToString,
|
|
118
172
|
N as throttle,
|
|
119
|
-
|
|
120
|
-
|
|
173
|
+
u as toTypeString,
|
|
174
|
+
j as warn
|
|
121
175
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lntvow/utils",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.3",
|
|
4
4
|
"description": "工具库",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,11 +24,6 @@
|
|
|
24
24
|
"vitest": "^0.33.0",
|
|
25
25
|
"vconsole": "^3.15.1"
|
|
26
26
|
},
|
|
27
|
-
"config": {
|
|
28
|
-
"commitizen": {
|
|
29
|
-
"path": "node_modules/cz-conventional-changelog"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
27
|
"scripts": {
|
|
33
28
|
"dev": "vite",
|
|
34
29
|
"test": "vitest",
|