@lntvow/utils 1.8.0 → 1.8.2

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 CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function j(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}function p(t){return t>10?p(10)+p(t-10):Math.random().toString(36).padEnd(12,"0").slice(2,t+2)}const l=Object.prototype.toString,f=t=>l.call(t),w=(...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),O=t=>f(t)==="[object Map]",R=t=>f(t)==="[object Set]",d=t=>f(t)==="[object Date]",a=t=>f(t)==="[object RegExp]",g=t=>typeof t=="function",D=t=>typeof t=="string",C=t=>typeof t=="symbol",s=t=>t!==null&&typeof t=="object",E=t=>s(t)&&g(t.then)&&g(t.catch),h=t=>t==null,b=t=>t===null;function T(t){return t!=null}const u=Array.isArray,y=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),A=(t,n)=>t!==n;function S(t){const n=new WeakMap;function e(o){if(d(o))return new Date(o);if(a(o))return new RegExp(o);if(s(o)){if(n.has(o))return n.get(o);let i={};if(u(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 m(t,n,e){return u(t)?F(t,n,e):P(t,n,e)}function P(t,n,e){const o=c(n,e);return Object.keys(t).forEach(r=>{h(n[r])?o[r]=c(t[r],e):o[r]=s(t[r])&&s(n[r])?m(t[r],n[r],e):c(n[r],e)}),o}function F(t,n,e){return u(n)?c(t,e).concat(c(n,e)):c(n,e)}function c(t,n){const{isDeepClone:e=!0}=n||{};return e?S(t):t}function K(t,n=1e3){let e=null;return function(...o){e&&clearTimeout(e),e=setTimeout(()=>{t.apply(this,...o)},n)}}function N(t,n=1e3){let e=null;return function(...o){if(b(e))return e=Date.now(),t.apply(this,...o);{const i=Date.now();if(i-e>=n)return e=i,t.apply(this,...o)}}}function U(...t){return t.reduce((n,e)=>function(...o){return e(n(...o))})}function $(...t){return t.reduce((n,e)=>function(...o){return n(e(...o))})}exports.compose=U;exports.composeRight=$;exports.debounce=K;exports.deepClone=S;exports.deepMerge=m;exports.error=M;exports.getRandomColor=j;exports.getRandomString=p;exports.hasChanged=A;exports.hasOwn=y;exports.isArray=u;exports.isDate=d;exports.isDef=T;exports.isFunction=g;exports.isMap=O;exports.isNull=b;exports.isObject=s;exports.isPromise=E;exports.isRegExp=a;exports.isSet=R;exports.isString=D;exports.isSymbol=C;exports.isUndef=h;exports.log=w;exports.objectToString=l;exports.throttle=N;exports.toTypeString=f;exports.warn=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function j(){return`#${Math.random().toString(16).slice(2,8).padEnd(6,"0")}`}function l(n){return n>10?l(10)+l(n-10):Math.random().toString(36).padEnd(12,"0").slice(2,n+2)}const p=Object.prototype.toString,f=n=>p.call(n),w=(...n)=>console.log(`%c ${n[0]}: `,"padding: 2px 1px; border-radius: 3px 3px 3px 3px; color: #fff; background: #000; font-weight: bold;",n.slice(1)),x=(...n)=>console.warn(...n),M=(...n)=>console.error(...n),O=n=>f(n)==="[object Map]",R=n=>f(n)==="[object Set]",d=n=>f(n)==="[object Date]",a=n=>f(n)==="[object RegExp]",g=n=>typeof n=="function",D=n=>typeof n=="string",C=n=>typeof n=="symbol",c=n=>n!==null&&typeof n=="object",E=n=>c(n)&&g(n.then)&&g(n.catch),h=n=>n==null,b=n=>n===null;function T(n){return n!=null}function A(n){return typeof n=="boolean"}const u=Array.isArray,S=(n,e)=>Object.hasOwn(n,e),P=(n,e)=>n!==e;function y(n){const e=new WeakMap;function o(t){if(d(t))return new Date(t);if(a(t))return new RegExp(t);if(c(t)){if(e.has(t))return e.get(t);let i={};if(u(t)){i=[],e.set(t,i);for(let r=0;r<t.length;r++)i[r]=o(t[r]);return i}e.set(t,i);for(const r in t)S(t,r)&&(i[r]=o(t[r]));return i}else return t}return o(n)}function m(n,e,o){return u(n)?F(n,e,o):B(n,e,o)}function B(n,e,o){const t=s(e,o);return Object.keys(n).forEach(r=>{h(e[r])?t[r]=s(n[r],o):t[r]=c(n[r])&&c(e[r])?m(n[r],e[r],o):s(e[r],o)}),t}function F(n,e,o){if(u(e)){const t=s(e,o);return t.push(...s(n,o)),t}else return s(n,o)}function s(n,e){const{isDeepClone:o=!0}=e||{};return o?y(n):n}function K(n,e=1e3){let o=null;return function(...t){o&&clearTimeout(o),o=setTimeout(()=>{n.apply(this,...t)},e)}}function N(n,e=1e3){let o=null;return function(...t){if(b(o))return o=Date.now(),n.apply(this,...t);{const i=Date.now();if(i-o>=e)return o=i,n.apply(this,...t)}}}function U(...n){return n.reduce((e,o)=>function(...t){return o(e(...t))})}function $(...n){return n.reduce((e,o)=>function(...t){return e(o(...t))})}exports.compose=U;exports.composeRight=$;exports.debounce=K;exports.deepClone=y;exports.deepMerge=m;exports.error=M;exports.getRandomColor=j;exports.getRandomString=l;exports.hasChanged=P;exports.hasOwn=S;exports.isArray=u;exports.isBoolean=A;exports.isDate=d;exports.isDef=T;exports.isFunction=g;exports.isMap=O;exports.isNull=b;exports.isObject=c;exports.isPromise=E;exports.isRegExp=a;exports.isSet=R;exports.isString=D;exports.isSymbol=C;exports.isUndef=h;exports.log=w;exports.objectToString=p;exports.throttle=N;exports.toTypeString=f;exports.warn=x;
package/dist/index.d.ts CHANGED
@@ -63,6 +63,8 @@ export declare const hasOwn: <T extends object, U extends keyof T>(target: T, ke
63
63
 
64
64
  export declare const isArray: (arg: any) => arg is any[];
65
65
 
66
+ export declare function isBoolean(val: unknown): val is boolean;
67
+
66
68
  export declare const isDate: (val: unknown) => val is Date;
67
69
 
68
70
  export declare function isDef<T>(v: T): v is NonNullable<T>;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- function S() {
1
+ function m() {
2
2
  return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
3
3
  }
4
4
  function p(n) {
@@ -8,95 +8,103 @@ const d = Object.prototype.toString, f = (n) => d.call(n), D = (...n) => console
8
8
  `%c ${n[0]}: `,
9
9
  "padding: 2px 1px; border-radius: 3px 3px 3px 3px; color: #fff; background: #000; font-weight: bold;",
10
10
  n.slice(1)
11
- ), M = (...n) => console.warn(...n), O = (...n) => console.error(...n), E = (n) => f(n) === "[object Map]", R = (n) => f(n) === "[object Set]", g = (n) => f(n) === "[object Date]", a = (n) => f(n) === "[object RegExp]", l = (n) => typeof n == "function", C = (n) => typeof n == "string", T = (n) => typeof n == "symbol", s = (n) => n !== null && typeof n == "object", A = (n) => s(n) && l(n.then) && l(n.catch), h = (n) => n == null, b = (n) => n === null;
11
+ ), M = (...n) => console.warn(...n), O = (...n) => console.error(...n), E = (n) => f(n) === "[object Map]", R = (n) => f(n) === "[object Set]", g = (n) => f(n) === "[object Date]", h = (n) => f(n) === "[object RegExp]", l = (n) => typeof n == "function", C = (n) => typeof n == "string", T = (n) => typeof n == "symbol", s = (n) => n !== null && typeof n == "object", A = (n) => s(n) && l(n.then) && l(n.catch), a = (n) => n == null, b = (n) => n === null;
12
12
  function K(n) {
13
13
  return n != null;
14
14
  }
15
- const u = Array.isArray, y = (n, t) => Object.prototype.hasOwnProperty.call(n, t), P = (n, t) => n !== t;
15
+ function $(n) {
16
+ return typeof n == "boolean";
17
+ }
18
+ const u = Array.isArray, y = (n, e) => Object.hasOwn(n, e), B = (n, e) => n !== e;
16
19
  function j(n) {
17
- const t = /* @__PURE__ */ new WeakMap();
18
- function o(e) {
19
- if (g(e))
20
- return new Date(e);
21
- if (a(e))
22
- return new RegExp(e);
23
- if (s(e)) {
24
- if (t.has(e))
25
- return t.get(e);
20
+ const e = /* @__PURE__ */ new WeakMap();
21
+ function o(t) {
22
+ if (g(t))
23
+ return new Date(t);
24
+ if (h(t))
25
+ return new RegExp(t);
26
+ if (s(t)) {
27
+ if (e.has(t))
28
+ return e.get(t);
26
29
  let c = {};
27
- if (u(e)) {
28
- c = [], t.set(e, c);
29
- for (let r = 0; r < e.length; r++)
30
- c[r] = o(e[r]);
30
+ if (u(t)) {
31
+ c = [], e.set(t, c);
32
+ for (let r = 0; r < t.length; r++)
33
+ c[r] = o(t[r]);
31
34
  return c;
32
35
  }
33
- t.set(e, c);
34
- for (const r in e)
35
- y(e, r) && (c[r] = o(e[r]));
36
+ e.set(t, c);
37
+ for (const r in t)
38
+ y(t, r) && (c[r] = o(t[r]));
36
39
  return c;
37
40
  } else
38
- return e;
41
+ return t;
39
42
  }
40
43
  return o(n);
41
44
  }
42
- function w(n, t, o) {
43
- return u(n) ? x(n, t, o) : m(n, t, o);
45
+ function w(n, e, o) {
46
+ return u(n) ? S(n, e, o) : x(n, e, o);
44
47
  }
45
- function m(n, t, o) {
46
- const e = i(t, o);
48
+ function x(n, e, o) {
49
+ const t = i(e, o);
47
50
  return Object.keys(n).forEach((r) => {
48
- h(t[r]) ? e[r] = i(n[r], o) : e[r] = s(n[r]) && s(t[r]) ? w(n[r], t[r], o) : i(t[r], o);
49
- }), e;
51
+ a(e[r]) ? t[r] = i(n[r], o) : t[r] = s(n[r]) && s(e[r]) ? w(n[r], e[r], o) : i(e[r], o);
52
+ }), t;
50
53
  }
51
- function x(n, t, o) {
52
- return u(t) ? i(n, o).concat(i(t, o)) : i(t, o);
54
+ function S(n, e, o) {
55
+ if (u(e)) {
56
+ const t = i(e, o);
57
+ return t.push(...i(n, o)), t;
58
+ } else
59
+ return i(n, o);
53
60
  }
54
- function i(n, t) {
55
- const { isDeepClone: o = !0 } = t || {};
61
+ function i(n, e) {
62
+ const { isDeepClone: o = !0 } = e || {};
56
63
  return o ? j(n) : n;
57
64
  }
58
- function $(n, t = 1e3) {
65
+ function F(n, e = 1e3) {
59
66
  let o = null;
60
- return function(...e) {
67
+ return function(...t) {
61
68
  o && clearTimeout(o), o = setTimeout(() => {
62
- n.apply(this, ...e);
63
- }, t);
69
+ n.apply(this, ...t);
70
+ }, e);
64
71
  };
65
72
  }
66
- function F(n, t = 1e3) {
73
+ function N(n, e = 1e3) {
67
74
  let o = null;
68
- return function(...e) {
75
+ return function(...t) {
69
76
  if (b(o))
70
- return o = Date.now(), n.apply(this, ...e);
77
+ return o = Date.now(), n.apply(this, ...t);
71
78
  {
72
79
  const c = Date.now();
73
- if (c - o >= t)
74
- return o = c, n.apply(this, ...e);
80
+ if (c - o >= e)
81
+ return o = c, n.apply(this, ...t);
75
82
  }
76
83
  };
77
84
  }
78
- function N(...n) {
79
- return n.reduce((t, o) => function(...e) {
80
- return o(t(...e));
85
+ function P(...n) {
86
+ return n.reduce((e, o) => function(...t) {
87
+ return o(e(...t));
81
88
  });
82
89
  }
83
90
  function U(...n) {
84
- return n.reduce((t, o) => function(...e) {
85
- return t(o(...e));
91
+ return n.reduce((e, o) => function(...t) {
92
+ return e(o(...t));
86
93
  });
87
94
  }
88
95
  export {
89
- N as compose,
96
+ P as compose,
90
97
  U as composeRight,
91
- $ as debounce,
98
+ F as debounce,
92
99
  j as deepClone,
93
100
  w as deepMerge,
94
101
  O as error,
95
- S as getRandomColor,
102
+ m as getRandomColor,
96
103
  p as getRandomString,
97
- P as hasChanged,
104
+ B as hasChanged,
98
105
  y as hasOwn,
99
106
  u as isArray,
107
+ $ as isBoolean,
100
108
  g as isDate,
101
109
  K as isDef,
102
110
  l as isFunction,
@@ -104,14 +112,14 @@ export {
104
112
  b as isNull,
105
113
  s as isObject,
106
114
  A as isPromise,
107
- a as isRegExp,
115
+ h as isRegExp,
108
116
  R as isSet,
109
117
  C as isString,
110
118
  T as isSymbol,
111
- h as isUndef,
119
+ a as isUndef,
112
120
  D as log,
113
121
  d as objectToString,
114
- F as throttle,
122
+ N as throttle,
115
123
  f as toTypeString,
116
124
  M as warn
117
125
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lntvow/utils",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "工具库",
5
5
  "type": "module",
6
6
  "license": "MIT",