@lntvow/utils 1.5.9 → 1.6.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 -108
- package/dist/index.d.ts +53 -1
- package/dist/index.mjs +89 -91
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,108 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
function getRandomColor() {
|
|
4
|
-
return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
|
|
5
|
-
}
|
|
6
|
-
function getRandomString(number) {
|
|
7
|
-
return number > 10 ? getRandomString(10) + getRandomString(number - 10) : Math.random().toString(36).padEnd(12, "0").slice(2, number + 2);
|
|
8
|
-
}
|
|
9
|
-
const objectToString = Object.prototype.toString;
|
|
10
|
-
const toTypeString = (value) => objectToString.call(value);
|
|
11
|
-
const isDate = (val) => toTypeString(val) === "[object Date]";
|
|
12
|
-
const isRegExp = (val) => toTypeString(val) === "[object RegExp]";
|
|
13
|
-
const isObject = (val) => val !== null && typeof val === "object";
|
|
14
|
-
const isUndef = (val) => val === void 0 || val === null;
|
|
15
|
-
const isNull = (val) => val === null;
|
|
16
|
-
const isArray = Array.isArray;
|
|
17
|
-
const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
18
|
-
function deepClone(target) {
|
|
19
|
-
const map = /* @__PURE__ */ new WeakMap();
|
|
20
|
-
function _deepClone(value) {
|
|
21
|
-
if (isDate(value))
|
|
22
|
-
return new Date(value);
|
|
23
|
-
if (isRegExp(value))
|
|
24
|
-
return new RegExp(value);
|
|
25
|
-
if (isObject(value)) {
|
|
26
|
-
if (map.has(value))
|
|
27
|
-
return map.get(value);
|
|
28
|
-
let clone = {};
|
|
29
|
-
if (isArray(value)) {
|
|
30
|
-
clone = [];
|
|
31
|
-
map.set(value, clone);
|
|
32
|
-
for (let i = 0; i < value.length; i++) {
|
|
33
|
-
clone[i] = _deepClone(value[i]);
|
|
34
|
-
}
|
|
35
|
-
return clone;
|
|
36
|
-
}
|
|
37
|
-
map.set(value, clone);
|
|
38
|
-
for (const key in value) {
|
|
39
|
-
if (hasOwn(value, key)) {
|
|
40
|
-
clone[key] = _deepClone(value[key]);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return clone;
|
|
44
|
-
} else {
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return _deepClone(target);
|
|
49
|
-
}
|
|
50
|
-
function deepMerge(template, source, options) {
|
|
51
|
-
return isArray(template) ? arrayMerge(template, source, options) : mergeObject(template, source, options);
|
|
52
|
-
}
|
|
53
|
-
function mergeObject(template, source, options) {
|
|
54
|
-
const destination = {};
|
|
55
|
-
const templateKeys = Object.keys(template);
|
|
56
|
-
const sourceKeys = Object.keys(source);
|
|
57
|
-
templateKeys.forEach((key) => {
|
|
58
|
-
if (isUndef(source[key])) {
|
|
59
|
-
destination[key] = process(template[key], options);
|
|
60
|
-
} else {
|
|
61
|
-
destination[key] = isObject(template[key]) && isObject(source[key]) ? deepMerge(template[key], source[key], options) : process(source[key], options);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
sourceKeys.forEach((key) => {
|
|
65
|
-
if (isUndef(destination[key])) {
|
|
66
|
-
destination[key] = process(source[key], options);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
return destination;
|
|
70
|
-
}
|
|
71
|
-
function arrayMerge(template, source, options) {
|
|
72
|
-
return isArray(source) ? [...process(template, options), ...process(source, options)] : process(source, options);
|
|
73
|
-
}
|
|
74
|
-
function process(source, options) {
|
|
75
|
-
const { isDeepClone = false } = options || {};
|
|
76
|
-
return isDeepClone ? deepClone(source) : source;
|
|
77
|
-
}
|
|
78
|
-
function debounce(target, wait = 1e3) {
|
|
79
|
-
let timer = null;
|
|
80
|
-
return function(...args) {
|
|
81
|
-
if (timer)
|
|
82
|
-
clearTimeout(timer);
|
|
83
|
-
timer = setTimeout(() => {
|
|
84
|
-
target.apply(this, ...args);
|
|
85
|
-
}, wait);
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function throttle(target, wait = 1e3) {
|
|
89
|
-
let timer = null;
|
|
90
|
-
return function(...args) {
|
|
91
|
-
if (isNull(timer)) {
|
|
92
|
-
timer = Date.now();
|
|
93
|
-
return target.apply(this, ...args);
|
|
94
|
-
} else {
|
|
95
|
-
const now = Date.now();
|
|
96
|
-
if (now - timer >= wait) {
|
|
97
|
-
timer = now;
|
|
98
|
-
return target.apply(this, ...args);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
exports.debounce = debounce;
|
|
104
|
-
exports.deepClone = deepClone;
|
|
105
|
-
exports.deepMerge = deepMerge;
|
|
106
|
-
exports.getRandomColor = getRandomColor;
|
|
107
|
-
exports.getRandomString = getRandomString;
|
|
108
|
-
exports.throttle = throttle;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function m(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}function g(t){return t>10?g(10)+g(t-10):Math.random().toString(36).padEnd(12,"0").slice(2,t+2)}const w=Object.assign,d=Object.prototype.toString,f=t=>d.call(t),x=(...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)),O=t=>console.warn(t),M=t=>console.error(t),D=t=>f(t)==="[object Map]",C=t=>f(t)==="[object Set]",a=t=>f(t)==="[object Date]",u=t=>f(t)==="[object RegExp]",p=t=>typeof t=="function",R=t=>typeof t=="string",E=t=>typeof t=="symbol",c=t=>t!==null&&typeof t=="object",T=t=>c(t)&&p(t.then)&&p(t.catch),b=t=>t==null,h=t=>t===null;function A(t){return t!=null}const l=Array.isArray,y=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),P=(t,n)=>t!==n;function S(t){const n=new WeakMap;function e(o){if(a(o))return new Date(o);if(u(o))return new RegExp(o);if(c(o)){if(n.has(o))return n.get(o);let i={};if(l(o)){i=[],n.set(o,i);for(let r=0;r<o.length;r++)i[r]=e(o[r]);return i}n.set(o,i);for(const r in o)y(o,r)&&(i[r]=e(o[r]));return i}else return o}return e(t)}function j(t,n,e){return l(t)?K(t,n,e):F(t,n,e)}function F(t,n,e){const o=s(n,e);return Object.keys(t).forEach(r=>{b(n[r])?o[r]=s(t[r],e):o[r]=c(t[r])&&c(n[r])?j(t[r],n[r],e):s(n[r],e)}),o}function K(t,n,e){return l(n)?s(t,e).concat(s(n,e)):s(n,e)}function s(t,n){const{isDeepClone:e=!0}=n||{};return e?S(t):t}function N(t,n=1e3){let e=null;return function(...o){e&&clearTimeout(e),e=setTimeout(()=>{t.apply(this,...o)},n)}}function U(t,n=1e3){let e=null;return function(...o){if(h(e))return e=Date.now(),t.apply(this,...o);{const i=Date.now();if(i-e>=n)return e=i,t.apply(this,...o)}}}exports.debounce=N;exports.deepClone=S;exports.deepMerge=j;exports.error=M;exports.extend=w;exports.getRandomColor=m;exports.getRandomString=g;exports.hasChanged=P;exports.hasOwn=y;exports.isArray=l;exports.isDate=a;exports.isDef=A;exports.isFunction=p;exports.isMap=D;exports.isNull=h;exports.isObject=c;exports.isPromise=T;exports.isRegExp=u;exports.isSet=C;exports.isString=R;exports.isSymbol=E;exports.isUndef=b;exports.log=x;exports.objectToString=d;exports.throttle=U;exports.toTypeString=f;exports.warn=O;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare type anyObj = Record<string, any>;
|
|
1
|
+
export declare type anyObj = Record<string, any>;
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @description 防抖函数
|
|
@@ -19,10 +19,20 @@ export declare function deepClone<T = any>(target: T): T;
|
|
|
19
19
|
* @description 深度合并两对象
|
|
20
20
|
* @param template 模板对象 就是默认值
|
|
21
21
|
* @param source 源对象 就是用户传入的值
|
|
22
|
+
* @param options 配置对象
|
|
22
23
|
* @example deepMerge({ name: 1, obj: { name: '默认' , text: '旧值' }, arr: [1, 2, 3] }, { name: 1, obj: { name: '修改', age: '新增' }, test: 'test' }) => { name: 1, obj: { name: '修改', text: '旧值', age: '新增' }, arr: [1, 2, 3], test: 'test' }
|
|
23
24
|
*/
|
|
24
25
|
export declare function deepMerge(template: anyObj, source: anyObj, options?: Options): any;
|
|
25
26
|
|
|
27
|
+
export declare const error: (msg: string) => void;
|
|
28
|
+
|
|
29
|
+
export declare const extend: {
|
|
30
|
+
<T extends {}, U>(target: T, source: U): T & U;
|
|
31
|
+
<T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
|
|
32
|
+
<T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
|
|
33
|
+
(target: object, ...sources: any[]): any;
|
|
34
|
+
};
|
|
35
|
+
|
|
26
36
|
/**
|
|
27
37
|
* @description 获取随机颜色
|
|
28
38
|
* @return {String} 随机颜色
|
|
@@ -40,7 +50,45 @@ export declare function getRandomColor(): string;
|
|
|
40
50
|
* */
|
|
41
51
|
export declare function getRandomString(number: number): string;
|
|
42
52
|
|
|
53
|
+
export declare const hasChanged: (oldValue: unknown, newValue: unknown) => boolean;
|
|
54
|
+
|
|
55
|
+
export declare const hasOwn: <T extends object, U extends keyof T>(target: T, key: U) => boolean;
|
|
56
|
+
|
|
57
|
+
export declare const isArray: (arg: any) => arg is any[];
|
|
58
|
+
|
|
59
|
+
export declare const isDate: (val: unknown) => val is Date;
|
|
60
|
+
|
|
61
|
+
export declare function isDef<T>(v: T): v is NonNullable<T>;
|
|
62
|
+
|
|
63
|
+
export declare const isFunction: (val: unknown) => val is Function;
|
|
64
|
+
|
|
65
|
+
export declare const isMap: (val: unknown) => val is Map<any, any>;
|
|
66
|
+
|
|
67
|
+
export declare const isNull: (val: unknown) => val is null;
|
|
68
|
+
|
|
69
|
+
export declare const isObject: (val: unknown) => val is Record<any, any>;
|
|
70
|
+
|
|
71
|
+
export declare const isPromise: <T = any>(val: unknown) => val is Promise<T>;
|
|
72
|
+
|
|
73
|
+
export declare const isRegExp: (val: unknown) => val is RegExp;
|
|
74
|
+
|
|
75
|
+
export declare const isSet: (val: unknown) => val is Set<any>;
|
|
76
|
+
|
|
77
|
+
export declare const isString: (val: unknown) => val is string;
|
|
78
|
+
|
|
79
|
+
export declare const isSymbol: (val: unknown) => val is symbol;
|
|
80
|
+
|
|
81
|
+
export declare const isUndef: (val: unknown) => val is null | undefined;
|
|
82
|
+
|
|
83
|
+
export declare const log: (...arg: unknown[]) => void;
|
|
84
|
+
|
|
85
|
+
export declare const objectToString: () => string;
|
|
86
|
+
|
|
43
87
|
declare interface Options {
|
|
88
|
+
/**
|
|
89
|
+
* @description 是否开启深拷贝 默认开启
|
|
90
|
+
* @default true
|
|
91
|
+
*/
|
|
44
92
|
isDeepClone: boolean;
|
|
45
93
|
}
|
|
46
94
|
|
|
@@ -52,4 +100,8 @@ declare interface Options {
|
|
|
52
100
|
*/
|
|
53
101
|
export declare function throttle(target: Function, wait?: number): (...args: any[]) => any;
|
|
54
102
|
|
|
103
|
+
export declare const toTypeString: (value: unknown) => string;
|
|
104
|
+
|
|
105
|
+
export declare const warn: (msg: string) => void;
|
|
106
|
+
|
|
55
107
|
export { }
|
package/dist/index.mjs
CHANGED
|
@@ -1,108 +1,106 @@
|
|
|
1
|
-
function
|
|
1
|
+
function m() {
|
|
2
2
|
return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
return
|
|
4
|
+
function l(t) {
|
|
5
|
+
return t > 10 ? l(10) + l(t - 10) : Math.random().toString(36).padEnd(12, "0").slice(2, t + 2);
|
|
6
6
|
}
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
function
|
|
17
|
-
const
|
|
18
|
-
function
|
|
19
|
-
if (
|
|
20
|
-
return new Date(
|
|
21
|
-
if (
|
|
22
|
-
return new RegExp(
|
|
23
|
-
if (
|
|
24
|
-
if (
|
|
25
|
-
return
|
|
26
|
-
let
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
return clone;
|
|
34
|
-
}
|
|
35
|
-
map.set(value, clone);
|
|
36
|
-
for (const key in value) {
|
|
37
|
-
if (hasOwn(value, key)) {
|
|
38
|
-
clone[key] = _deepClone(value[key]);
|
|
39
|
-
}
|
|
7
|
+
const O = Object.assign, g = Object.prototype.toString, f = (t) => g.call(t), D = (...t) => console.log(
|
|
8
|
+
`%c ${t[0]}: `,
|
|
9
|
+
"padding: 2px 1px; border-radius: 3px 3px 3px 3px; color: #fff; background: #000; font-weight: bold;",
|
|
10
|
+
t.slice(1)
|
|
11
|
+
), M = (t) => console.warn(t), E = (t) => console.error(t), C = (t) => f(t) === "[object Map]", R = (t) => f(t) === "[object Set]", u = (t) => f(t) === "[object Date]", a = (t) => f(t) === "[object RegExp]", d = (t) => typeof t == "function", T = (t) => typeof t == "string", A = (t) => typeof t == "symbol", s = (t) => t !== null && typeof t == "object", K = (t) => s(t) && d(t.then) && d(t.catch), b = (t) => t == null, h = (t) => t === null;
|
|
12
|
+
function P(t) {
|
|
13
|
+
return t != null;
|
|
14
|
+
}
|
|
15
|
+
const p = Array.isArray, y = (t, n) => Object.prototype.hasOwnProperty.call(t, n), $ = (t, n) => t !== n;
|
|
16
|
+
function j(t) {
|
|
17
|
+
const n = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
function o(e) {
|
|
19
|
+
if (u(e))
|
|
20
|
+
return new Date(e);
|
|
21
|
+
if (a(e))
|
|
22
|
+
return new RegExp(e);
|
|
23
|
+
if (s(e)) {
|
|
24
|
+
if (n.has(e))
|
|
25
|
+
return n.get(e);
|
|
26
|
+
let c = {};
|
|
27
|
+
if (p(e)) {
|
|
28
|
+
c = [], n.set(e, c);
|
|
29
|
+
for (let r = 0; r < e.length; r++)
|
|
30
|
+
c[r] = o(e[r]);
|
|
31
|
+
return c;
|
|
40
32
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
n.set(e, c);
|
|
34
|
+
for (const r in e)
|
|
35
|
+
y(e, r) && (c[r] = o(e[r]));
|
|
36
|
+
return c;
|
|
37
|
+
} else
|
|
38
|
+
return e;
|
|
45
39
|
}
|
|
46
|
-
return
|
|
40
|
+
return o(t);
|
|
47
41
|
}
|
|
48
|
-
function
|
|
49
|
-
return
|
|
42
|
+
function w(t, n, o) {
|
|
43
|
+
return p(t) ? S(t, n, o) : x(t, n, o);
|
|
50
44
|
}
|
|
51
|
-
function
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (isUndef(source[key])) {
|
|
57
|
-
destination[key] = process(template[key], options);
|
|
58
|
-
} else {
|
|
59
|
-
destination[key] = isObject(template[key]) && isObject(source[key]) ? deepMerge(template[key], source[key], options) : process(source[key], options);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
sourceKeys.forEach((key) => {
|
|
63
|
-
if (isUndef(destination[key])) {
|
|
64
|
-
destination[key] = process(source[key], options);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
return destination;
|
|
45
|
+
function x(t, n, o) {
|
|
46
|
+
const e = i(n, o);
|
|
47
|
+
return Object.keys(t).forEach((r) => {
|
|
48
|
+
b(n[r]) ? e[r] = i(t[r], o) : e[r] = s(t[r]) && s(n[r]) ? w(t[r], n[r], o) : i(n[r], o);
|
|
49
|
+
}), e;
|
|
68
50
|
}
|
|
69
|
-
function
|
|
70
|
-
return
|
|
51
|
+
function S(t, n, o) {
|
|
52
|
+
return p(n) ? i(t, o).concat(i(n, o)) : i(n, o);
|
|
71
53
|
}
|
|
72
|
-
function
|
|
73
|
-
const { isDeepClone =
|
|
74
|
-
return
|
|
54
|
+
function i(t, n) {
|
|
55
|
+
const { isDeepClone: o = !0 } = n || {};
|
|
56
|
+
return o ? j(t) : t;
|
|
75
57
|
}
|
|
76
|
-
function
|
|
77
|
-
let
|
|
78
|
-
return function(...
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
target.apply(this, ...args);
|
|
83
|
-
}, wait);
|
|
58
|
+
function F(t, n = 1e3) {
|
|
59
|
+
let o = null;
|
|
60
|
+
return function(...e) {
|
|
61
|
+
o && clearTimeout(o), o = setTimeout(() => {
|
|
62
|
+
t.apply(this, ...e);
|
|
63
|
+
}, n);
|
|
84
64
|
};
|
|
85
65
|
}
|
|
86
|
-
function
|
|
87
|
-
let
|
|
88
|
-
return function(...
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
timer = now;
|
|
96
|
-
return target.apply(this, ...args);
|
|
97
|
-
}
|
|
66
|
+
function N(t, n = 1e3) {
|
|
67
|
+
let o = null;
|
|
68
|
+
return function(...e) {
|
|
69
|
+
if (h(o))
|
|
70
|
+
return o = Date.now(), t.apply(this, ...e);
|
|
71
|
+
{
|
|
72
|
+
const c = Date.now();
|
|
73
|
+
if (c - o >= n)
|
|
74
|
+
return o = c, t.apply(this, ...e);
|
|
98
75
|
}
|
|
99
76
|
};
|
|
100
77
|
}
|
|
101
78
|
export {
|
|
102
|
-
debounce,
|
|
103
|
-
deepClone,
|
|
104
|
-
deepMerge,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
79
|
+
F as debounce,
|
|
80
|
+
j as deepClone,
|
|
81
|
+
w as deepMerge,
|
|
82
|
+
E as error,
|
|
83
|
+
O as extend,
|
|
84
|
+
m as getRandomColor,
|
|
85
|
+
l as getRandomString,
|
|
86
|
+
$ as hasChanged,
|
|
87
|
+
y as hasOwn,
|
|
88
|
+
p as isArray,
|
|
89
|
+
u as isDate,
|
|
90
|
+
P as isDef,
|
|
91
|
+
d as isFunction,
|
|
92
|
+
C as isMap,
|
|
93
|
+
h as isNull,
|
|
94
|
+
s as isObject,
|
|
95
|
+
K as isPromise,
|
|
96
|
+
a as isRegExp,
|
|
97
|
+
R as isSet,
|
|
98
|
+
T as isString,
|
|
99
|
+
A as isSymbol,
|
|
100
|
+
b as isUndef,
|
|
101
|
+
D as log,
|
|
102
|
+
g as objectToString,
|
|
103
|
+
N as throttle,
|
|
104
|
+
f as toTypeString,
|
|
105
|
+
M as warn
|
|
108
106
|
};
|