@lntvow/utils 1.8.2 → 1.8.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 +62 -2
- package/dist/index.mjs +143 -93
- 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
|
@@ -18,7 +18,7 @@ export declare function composeRight(...fns: ((...args: any[]) => any)[]): (...a
|
|
|
18
18
|
* @description 防抖函数
|
|
19
19
|
* @param target 目标函数
|
|
20
20
|
* @param wait 等待时间 默认 1000ms
|
|
21
|
-
* @example debounce(() => console.log('debounce'),500)
|
|
21
|
+
* @example debounce(() => console.log('debounce'), 500)
|
|
22
22
|
*/
|
|
23
23
|
export declare function debounce(target: Function, wait?: number): (...args: any[]) => void;
|
|
24
24
|
|
|
@@ -61,22 +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
|
|
|
66
71
|
export declare function isBoolean(val: unknown): val is boolean;
|
|
67
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
|
+
|
|
68
83
|
export declare const isDate: (val: unknown) => val is Date;
|
|
69
84
|
|
|
70
85
|
export declare function isDef<T>(v: T): v is NonNullable<T>;
|
|
71
86
|
|
|
87
|
+
/**
|
|
88
|
+
* @description 校验邮箱
|
|
89
|
+
*/
|
|
90
|
+
export declare function isEmail(value: string): boolean;
|
|
91
|
+
|
|
72
92
|
export declare const isFunction: (val: unknown) => val is Function;
|
|
73
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
|
+
|
|
74
104
|
export declare const isMap: (val: unknown) => val is Map<any, any>;
|
|
75
105
|
|
|
106
|
+
/**
|
|
107
|
+
* @description 校验手机号
|
|
108
|
+
*/
|
|
109
|
+
export declare function isMobilePhone(value: string): boolean;
|
|
110
|
+
|
|
76
111
|
export declare const isNull: (val: unknown) => val is null;
|
|
77
112
|
|
|
113
|
+
/**
|
|
114
|
+
* @description 校验校验数字
|
|
115
|
+
*/
|
|
116
|
+
export declare function isNumber(value: string): boolean;
|
|
117
|
+
|
|
78
118
|
export declare const isObject: (val: unknown) => val is Record<any, any>;
|
|
79
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
|
+
|
|
80
130
|
export declare const isPromise: <T = any>(val: unknown) => val is Promise<T>;
|
|
81
131
|
|
|
82
132
|
export declare const isRegExp: (val: unknown) => val is RegExp;
|
|
@@ -89,6 +139,16 @@ export declare const isSymbol: (val: unknown) => val is symbol;
|
|
|
89
139
|
|
|
90
140
|
export declare const isUndef: (val: unknown) => val is null | undefined;
|
|
91
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
|
+
|
|
92
152
|
export declare const log: (...arg: unknown[]) => void;
|
|
93
153
|
|
|
94
154
|
export declare const objectToString: () => string;
|
|
@@ -105,7 +165,7 @@ declare interface Options {
|
|
|
105
165
|
* @description 节流函数
|
|
106
166
|
* @param target 目标函数
|
|
107
167
|
* @param wait 等待时间 默认 1000ms
|
|
108
|
-
* @example throttle(() =>
|
|
168
|
+
* @example throttle(() => console.log('hello world'), 500)
|
|
109
169
|
*/
|
|
110
170
|
export declare function throttle(target: Function, wait?: number): (...args: any[]) => any;
|
|
111
171
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,125 +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
|
-
function
|
|
16
|
-
return typeof
|
|
15
|
+
function T(t) {
|
|
16
|
+
return typeof t == "boolean";
|
|
17
17
|
}
|
|
18
|
-
const
|
|
19
|
-
function
|
|
18
|
+
const f = Array.isArray, w = (t, e) => Object.hasOwn(t, e), Z = (t, e) => t !== e;
|
|
19
|
+
function m(t) {
|
|
20
20
|
const e = /* @__PURE__ */ new WeakMap();
|
|
21
|
-
function
|
|
22
|
-
if (
|
|
23
|
-
return new Date(
|
|
24
|
-
if (
|
|
25
|
-
return new RegExp(
|
|
26
|
-
if (
|
|
27
|
-
if (e.has(
|
|
28
|
-
return e.get(
|
|
29
|
-
let
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
for (let
|
|
33
|
-
|
|
34
|
-
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;
|
|
35
35
|
}
|
|
36
|
-
e.set(
|
|
37
|
-
for (const
|
|
38
|
-
|
|
39
|
-
return
|
|
36
|
+
e.set(n, i);
|
|
37
|
+
for (const o in n)
|
|
38
|
+
w(n, o) && (i[o] = r(n[o]));
|
|
39
|
+
return i;
|
|
40
40
|
} else
|
|
41
|
-
return
|
|
41
|
+
return n;
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return r(t);
|
|
44
44
|
}
|
|
45
|
-
function
|
|
46
|
-
return
|
|
45
|
+
function $(t, e, r) {
|
|
46
|
+
return f(t) ? y(t, e, r) : O(t, e, r);
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
return Object.keys(
|
|
51
|
-
|
|
52
|
-
}),
|
|
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;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
if (
|
|
56
|
-
const
|
|
57
|
-
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;
|
|
58
58
|
} else
|
|
59
|
-
return
|
|
59
|
+
return s(t, r);
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
const { isDeepClone:
|
|
63
|
-
return
|
|
61
|
+
function s(t, e) {
|
|
62
|
+
const { isDeepClone: r = !0 } = e || {};
|
|
63
|
+
return r ? m(t) : t;
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
let
|
|
67
|
-
return function(...
|
|
68
|
-
|
|
69
|
-
|
|
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);
|
|
70
70
|
}, e);
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
function N(
|
|
74
|
-
let
|
|
75
|
-
return function(...
|
|
76
|
-
if (b(
|
|
77
|
-
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);
|
|
78
78
|
{
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
return
|
|
79
|
+
const i = Date.now();
|
|
80
|
+
if (i - r >= e)
|
|
81
|
+
return r = i, t.apply(this, ...n);
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
function P(...
|
|
86
|
-
return
|
|
87
|
-
return
|
|
85
|
+
function P(...t) {
|
|
86
|
+
return t.reduce((e, r) => function(...n) {
|
|
87
|
+
return r(e(...n));
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
return
|
|
92
|
-
return e(
|
|
90
|
+
function L(...t) {
|
|
91
|
+
return t.reduce((e, r) => function(...n) {
|
|
92
|
+
return e(r(...n));
|
|
93
93
|
});
|
|
94
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
|
+
}
|
|
95
133
|
export {
|
|
96
134
|
P as compose,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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,
|
|
112
157
|
b as isNull,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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,
|
|
122
172
|
N as throttle,
|
|
123
|
-
|
|
124
|
-
|
|
173
|
+
u as toTypeString,
|
|
174
|
+
j as warn
|
|
125
175
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lntvow/utils",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.4",
|
|
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",
|