@lntvow/utils 1.7.8 → 1.7.10
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 +14 -0
- package/dist/index.mjs +38 -26
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("vconsole");function O(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("vconsole");function O(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}function u(t){return t>10?u(10)+u(t-10):Math.random().toString(36).padEnd(12,"0").slice(2,t+2)}const S=Object.prototype.toString,f=t=>S.call(t),D=(...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)),x=t=>console.warn(t),M=t=>console.error(t),R=t=>f(t)==="[object Map]",E=t=>f(t)==="[object Set]",h=t=>f(t)==="[object Date]",b=t=>f(t)==="[object RegExp]",g=t=>typeof t=="function",T=t=>typeof t=="string",N=t=>typeof t=="symbol",l=t=>t!==null&&typeof t=="object",A=t=>l(t)&&g(t.then)&&g(t.catch),w=t=>t==null,y=t=>t===null;function I(t){return t!=null}const a=Array.isArray,j=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),P=(t,n)=>t!==n;function C(t){const n=new WeakMap;function e(o){if(h(o))return new Date(o);if(b(o))return new RegExp(o);if(l(o)){if(n.has(o))return n.get(o);let i={};if(a(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)j(o,r)&&(i[r]=e(o[r]));return i}else return o}return e(t)}function p(t,n,e){return a(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=>{w(n[r])?o[r]=s(t[r],e):o[r]=l(t[r])&&l(n[r])?p(t[r],n[r],e):s(n[r],e)}),o}function K(t,n,e){return a(n)?s(t,e).concat(s(n,e)):s(n,e)}function s(t,n){const{isDeepClone:e=!0}=n||{};return e?C(t):t}function L(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(y(e))return e=Date.now(),t.apply(this,...o);{const i=Date.now();if(i-e>=n)return e=i,t.apply(this,...o)}}}let c={name:"LNTVOW_CONSOLE",time:3600,count:20};function V(t){c=p(c,t||{});const n=localStorage.getItem(c.name);if(!n)return;Date.now()-Number(n)>=1e3*c.time?localStorage.removeItem(c.name):new m}let d=0;function W(){d++,d>=c.count&&!localStorage.getItem(c.name)&&(localStorage.setItem(c.name,Date.now().toString()),new m)}const _={initConsole:V,showConsole:W};function $(...t){return t.reduce((n,e)=>function(...o){return e(n(...o))})}function q(...t){return t.reduce((n,e)=>function(...o){return n(e(...o))})}exports.compose=$;exports.composeRight=q;exports.debounce=L;exports.deepClone=C;exports.deepMerge=p;exports.error=M;exports.getRandomColor=O;exports.getRandomString=u;exports.hasChanged=P;exports.hasOwn=j;exports.isArray=a;exports.isDate=h;exports.isDef=I;exports.isFunction=g;exports.isMap=R;exports.isNull=y;exports.isObject=l;exports.isPromise=A;exports.isRegExp=b;exports.isSet=E;exports.isString=T;exports.isSymbol=N;exports.isUndef=w;exports.log=D;exports.nConsole=_;exports.objectToString=S;exports.throttle=U;exports.toTypeString=f;exports.warn=x;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
export declare type AnyObj = Record<string, any>;
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @description compose
|
|
5
|
+
* @param fns 任意函数
|
|
6
|
+
* @url https://lntvow.vercel.app/web/javascript/compose.html
|
|
7
|
+
*/
|
|
8
|
+
export declare function compose(...fns: ((...args: any[]) => any)[]): (...args: any[]) => any;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description compose 从右到左
|
|
12
|
+
* @param fns 任意函数
|
|
13
|
+
* @url https://lntvow.vercel.app/web/javascript/compose.html
|
|
14
|
+
*/
|
|
15
|
+
export declare function composeRight(...fns: ((...args: any[]) => any)[]): (...args: any[]) => any;
|
|
16
|
+
|
|
3
17
|
/**
|
|
4
18
|
* @description 防抖函数
|
|
5
19
|
* @param target 目标函数
|
package/dist/index.mjs
CHANGED
|
@@ -2,18 +2,18 @@ import m from "vconsole";
|
|
|
2
2
|
function R() {
|
|
3
3
|
return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
return t > 10 ?
|
|
5
|
+
function a(t) {
|
|
6
|
+
return t > 10 ? a(10) + a(t - 10) : Math.random().toString(36).padEnd(12, "0").slice(2, t + 2);
|
|
7
7
|
}
|
|
8
8
|
const h = Object.prototype.toString, l = (t) => h.call(t), T = (...t) => console.log(
|
|
9
9
|
`%c ${t[0]}: `,
|
|
10
10
|
"padding: 2px 1px; border-radius: 3px 3px 3px 3px; color: #fff; background: #000; font-weight: bold;",
|
|
11
11
|
t.slice(1)
|
|
12
|
-
), I = (t) => console.warn(t), N = (t) => console.error(t), A = (t) => l(t) === "[object Map]", K = (t) => l(t) === "[object Set]", b = (t) => l(t) === "[object Date]", w = (t) => l(t) === "[object RegExp]",
|
|
12
|
+
), I = (t) => console.warn(t), N = (t) => console.error(t), A = (t) => l(t) === "[object Map]", K = (t) => l(t) === "[object Set]", b = (t) => l(t) === "[object Date]", w = (t) => l(t) === "[object RegExp]", p = (t) => typeof t == "function", L = (t) => typeof t == "string", P = (t) => typeof t == "symbol", f = (t) => t !== null && typeof t == "object", V = (t) => f(t) && p(t.then) && p(t.catch), S = (t) => t == null, y = (t) => t === null;
|
|
13
13
|
function W(t) {
|
|
14
14
|
return t != null;
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const u = Array.isArray, j = (t, n) => Object.prototype.hasOwnProperty.call(t, n), _ = (t, n) => t !== n;
|
|
17
17
|
function O(t) {
|
|
18
18
|
const n = /* @__PURE__ */ new WeakMap();
|
|
19
19
|
function e(o) {
|
|
@@ -24,24 +24,24 @@ function O(t) {
|
|
|
24
24
|
if (f(o)) {
|
|
25
25
|
if (n.has(o))
|
|
26
26
|
return n.get(o);
|
|
27
|
-
let
|
|
28
|
-
if (
|
|
29
|
-
|
|
27
|
+
let c = {};
|
|
28
|
+
if (u(o)) {
|
|
29
|
+
c = [], n.set(o, c);
|
|
30
30
|
for (let r = 0; r < o.length; r++)
|
|
31
|
-
|
|
32
|
-
return
|
|
31
|
+
c[r] = e(o[r]);
|
|
32
|
+
return c;
|
|
33
33
|
}
|
|
34
|
-
n.set(o,
|
|
34
|
+
n.set(o, c);
|
|
35
35
|
for (const r in o)
|
|
36
|
-
j(o, r) && (
|
|
37
|
-
return
|
|
36
|
+
j(o, r) && (c[r] = e(o[r]));
|
|
37
|
+
return c;
|
|
38
38
|
} else
|
|
39
39
|
return o;
|
|
40
40
|
}
|
|
41
41
|
return e(t);
|
|
42
42
|
}
|
|
43
43
|
function d(t, n, e) {
|
|
44
|
-
return
|
|
44
|
+
return u(t) ? C(t, n, e) : x(t, n, e);
|
|
45
45
|
}
|
|
46
46
|
function x(t, n, e) {
|
|
47
47
|
const o = s(n, e);
|
|
@@ -50,7 +50,7 @@ function x(t, n, e) {
|
|
|
50
50
|
}), o;
|
|
51
51
|
}
|
|
52
52
|
function C(t, n, e) {
|
|
53
|
-
return
|
|
53
|
+
return u(n) ? s(t, e).concat(s(n, e)) : s(n, e);
|
|
54
54
|
}
|
|
55
55
|
function s(t, n) {
|
|
56
56
|
const { isDeepClone: e = !0 } = n || {};
|
|
@@ -70,45 +70,57 @@ function F(t, n = 1e3) {
|
|
|
70
70
|
if (y(e))
|
|
71
71
|
return e = Date.now(), t.apply(this, ...o);
|
|
72
72
|
{
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
return e =
|
|
73
|
+
const c = Date.now();
|
|
74
|
+
if (c - e >= n)
|
|
75
|
+
return e = c, t.apply(this, ...o);
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
let
|
|
79
|
+
let i = {
|
|
80
80
|
name: "LNTVOW_CONSOLE",
|
|
81
81
|
time: 3600,
|
|
82
82
|
count: 20
|
|
83
83
|
};
|
|
84
84
|
function D(t) {
|
|
85
|
-
|
|
86
|
-
const n = localStorage.getItem(
|
|
85
|
+
i = d(i, t || {});
|
|
86
|
+
const n = localStorage.getItem(i.name);
|
|
87
87
|
if (!n)
|
|
88
88
|
return;
|
|
89
|
-
Date.now() - Number(n) >= 1e3 *
|
|
89
|
+
Date.now() - Number(n) >= 1e3 * i.time ? localStorage.removeItem(i.name) : new m();
|
|
90
90
|
}
|
|
91
|
-
let
|
|
91
|
+
let g = 0;
|
|
92
92
|
function E() {
|
|
93
|
-
|
|
93
|
+
g++, g >= i.count && !localStorage.getItem(i.name) && (localStorage.setItem(i.name, Date.now().toString()), new m());
|
|
94
94
|
}
|
|
95
95
|
const U = {
|
|
96
96
|
initConsole: D,
|
|
97
97
|
showConsole: E
|
|
98
98
|
};
|
|
99
|
+
function q(...t) {
|
|
100
|
+
return t.reduce((n, e) => function(...o) {
|
|
101
|
+
return e(n(...o));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function z(...t) {
|
|
105
|
+
return t.reduce((n, e) => function(...o) {
|
|
106
|
+
return n(e(...o));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
99
109
|
export {
|
|
110
|
+
q as compose,
|
|
111
|
+
z as composeRight,
|
|
100
112
|
$ as debounce,
|
|
101
113
|
O as deepClone,
|
|
102
114
|
d as deepMerge,
|
|
103
115
|
N as error,
|
|
104
116
|
R as getRandomColor,
|
|
105
|
-
|
|
117
|
+
a as getRandomString,
|
|
106
118
|
_ as hasChanged,
|
|
107
119
|
j as hasOwn,
|
|
108
|
-
|
|
120
|
+
u as isArray,
|
|
109
121
|
b as isDate,
|
|
110
122
|
W as isDef,
|
|
111
|
-
|
|
123
|
+
p as isFunction,
|
|
112
124
|
A as isMap,
|
|
113
125
|
y as isNull,
|
|
114
126
|
f as isObject,
|