@lntvow/utils 1.5.3 → 1.5.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 +31 -4
- package/dist/index.mjs +68 -32
- package/package.json +3 -2
- package/README.md +0 -1
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 l(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}function s(t){return t>10?s(10)+s(t-10):Math.random().toString(36).padEnd(12,"0").slice(2,t+2)}const h=Object.prototype.toString,g=t=>h.call(t),u=t=>g(t)==="[object Date]",b=t=>g(t)==="[object RegExp]",f=t=>t!==null&&typeof t=="object",p=t=>t==null,d=Array.isArray,j=(t,n)=>Object.prototype.hasOwnProperty.call(t,n);function c(t){const n=new WeakMap;function r(e){if(u(e))return new Date(e);if(b(e))return new RegExp(e);if(f(e)){if(n.has(e))return n.get(e);let i={};if(d(e)){i=[],n.set(e,i);for(let o=0;o<e.length;o++)i[o]=r(e[o]);return i}n.set(e,i);for(const o in e)j(e,o)&&(i[o]=r(e[o]));return i}else return e}return r(t)}function a(t,n){return d(t)?O(t,n):y(t,n)}function y(t,n){const r={},e=Object.keys(t),i=Object.keys(n);return e.forEach(o=>{p(n[o])?r[o]=c(t[o]):r[o]=f(t[o])&&f(n[o])?a(t[o],n[o]):c(n[o])}),i.forEach(o=>{p(r[o])&&(r[o]=c(n[o]))}),r}function O(t,n){return d(n)?[...c(t),...c(n)]:c(n)}function S(t,n=1e3){let r=null;return function(...e){r&&clearTimeout(r),r=setTimeout(()=>{t.apply(this,...e)},n)}}function w(t,n=1e3){let r=0;return function(...e){if(r)return r=Date.now(),t.apply(this,...e);{const i=Date.now();if(i-r>=n)return r=i,t.apply(this,...e)}}}exports.debounce=S;exports.deepClone=c;exports.deepMerge=a;exports.getRandomColor=l;exports.getRandomString=s;exports.throttle=w;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
declare type anyObj = Record<string, any>;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description 防抖函数
|
|
5
|
+
* @param target 目标函数
|
|
6
|
+
* @param wait 等待时间 默认 1000ms
|
|
7
|
+
* @example debounce(() => console.log('debounce'),500)
|
|
8
|
+
*/
|
|
9
|
+
export declare function debounce(target: Function, wait?: number): (...args: any[]) => void;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @description 深拷贝
|
|
13
|
+
* @param target 拷贝对象
|
|
14
|
+
* @example deepClone({ name: 1, obj: { name: 1 }, arr: [1, 2, 3] }) => { name: 1, obj: { name: 1 }, arr: [1, 2, 3] }
|
|
15
|
+
*/
|
|
16
|
+
export declare function deepClone<T = any>(target: T): T;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @description 深度合并两对象
|
|
20
|
+
* @param template 模板对象 就是默认值
|
|
21
|
+
* @param source 源对象 就是用户传入的值
|
|
22
|
+
* @example deepMerge({ name: 1, obj: { name: '默认' }, arr: [1, 2, 3] }, { name: 1, obj: { name: '修改', age: '新增' }, test: 'test' }) => { name: 1, obj: { name: '修改', age: '新增' }, arr: [1, 2, 3], test: 'test' }
|
|
23
|
+
*/
|
|
24
|
+
export declare function deepMerge(template: anyObj, source: anyObj): any[] | anyObj;
|
|
2
25
|
|
|
3
26
|
/**
|
|
4
27
|
* @description 获取随机颜色
|
|
@@ -17,8 +40,12 @@ export declare function getRandomColor(): string;
|
|
|
17
40
|
* */
|
|
18
41
|
export declare function getRandomString(number: number): string;
|
|
19
42
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
43
|
+
/**
|
|
44
|
+
* @description 节流函数
|
|
45
|
+
* @param target 目标函数
|
|
46
|
+
* @param wait 等待时间 默认 1000ms
|
|
47
|
+
* @example throttle(() => console.log('throttle'),500)
|
|
48
|
+
*/
|
|
49
|
+
export declare function throttle(target: Function, wait?: number): (...args: any[]) => any;
|
|
23
50
|
|
|
24
51
|
export { }
|
package/dist/index.mjs
CHANGED
|
@@ -1,39 +1,75 @@
|
|
|
1
|
-
function
|
|
1
|
+
function O() {
|
|
2
2
|
return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
return t > 10 ?
|
|
6
|
-
}
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
if (
|
|
12
|
-
return new Date(
|
|
13
|
-
if (
|
|
14
|
-
return new RegExp(
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return r;
|
|
4
|
+
function p(t) {
|
|
5
|
+
return t > 10 ? p(10) + p(t - 10) : Math.random().toString(36).padEnd(12, "0").slice(2, t + 2);
|
|
6
|
+
}
|
|
7
|
+
const h = Object.prototype.toString, g = (t) => h.call(t), a = (t) => g(t) === "[object Date]", j = (t) => g(t) === "[object RegExp]", s = (t) => t !== null && typeof t == "object", d = (t) => t == null, f = Array.isArray, b = (t, n) => Object.prototype.hasOwnProperty.call(t, n);
|
|
8
|
+
function c(t) {
|
|
9
|
+
const n = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
function e(o) {
|
|
11
|
+
if (a(o))
|
|
12
|
+
return new Date(o);
|
|
13
|
+
if (j(o))
|
|
14
|
+
return new RegExp(o);
|
|
15
|
+
if (s(o)) {
|
|
16
|
+
if (n.has(o))
|
|
17
|
+
return n.get(o);
|
|
18
|
+
let i = {};
|
|
19
|
+
if (f(o)) {
|
|
20
|
+
i = [], n.set(o, i);
|
|
21
|
+
for (let r = 0; r < o.length; r++)
|
|
22
|
+
i[r] = e(o[r]);
|
|
23
|
+
return i;
|
|
24
|
+
}
|
|
25
|
+
n.set(o, i);
|
|
26
|
+
for (const r in o)
|
|
27
|
+
b(o, r) && (i[r] = e(o[r]));
|
|
28
|
+
return i;
|
|
30
29
|
} else
|
|
31
|
-
return
|
|
30
|
+
return o;
|
|
32
31
|
}
|
|
33
|
-
return
|
|
32
|
+
return e(t);
|
|
33
|
+
}
|
|
34
|
+
function u(t, n) {
|
|
35
|
+
return f(t) ? w(t, n) : l(t, n);
|
|
36
|
+
}
|
|
37
|
+
function l(t, n) {
|
|
38
|
+
const e = {}, o = Object.keys(t), i = Object.keys(n);
|
|
39
|
+
return o.forEach((r) => {
|
|
40
|
+
d(n[r]) ? e[r] = c(t[r]) : e[r] = s(t[r]) && s(n[r]) ? u(t[r], n[r]) : c(n[r]);
|
|
41
|
+
}), i.forEach((r) => {
|
|
42
|
+
d(e[r]) && (e[r] = c(n[r]));
|
|
43
|
+
}), e;
|
|
44
|
+
}
|
|
45
|
+
function w(t, n) {
|
|
46
|
+
return f(n) ? [...c(t), ...c(n)] : c(n);
|
|
47
|
+
}
|
|
48
|
+
function y(t, n = 1e3) {
|
|
49
|
+
let e = null;
|
|
50
|
+
return function(...o) {
|
|
51
|
+
e && clearTimeout(e), e = setTimeout(() => {
|
|
52
|
+
t.apply(this, ...o);
|
|
53
|
+
}, n);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function E(t, n = 1e3) {
|
|
57
|
+
let e = 0;
|
|
58
|
+
return function(...o) {
|
|
59
|
+
if (e)
|
|
60
|
+
return e = Date.now(), t.apply(this, ...o);
|
|
61
|
+
{
|
|
62
|
+
const i = Date.now();
|
|
63
|
+
if (i - e >= n)
|
|
64
|
+
return e = i, t.apply(this, ...o);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
34
67
|
}
|
|
35
68
|
export {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
69
|
+
y as debounce,
|
|
70
|
+
c as deepClone,
|
|
71
|
+
u as deepMerge,
|
|
72
|
+
O as getRandomColor,
|
|
73
|
+
p as getRandomString,
|
|
74
|
+
E as throttle
|
|
39
75
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lntvow/utils",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "工具库",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
"module": "dist/index.mjs",
|
|
13
13
|
"types": "dist/index.d.ts",
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@lntvow/eslint-config": "^7.1.
|
|
15
|
+
"@lntvow/eslint-config": "^7.1.12",
|
|
16
16
|
"bumpp": "^9.1.1",
|
|
17
17
|
"commitizen": "^4.3.0",
|
|
18
18
|
"cz-conventional-changelog": "^3.3.0",
|
|
19
|
+
"deepmerge": "^4.3.1",
|
|
19
20
|
"typescript": "^5.1.6",
|
|
20
21
|
"vite": "^4.4.4",
|
|
21
22
|
"vite-plugin-dts": "3.3.1",
|
package/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# 工具库
|