@lntvow/utils 1.7.2 → 1.7.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 CHANGED
@@ -1,141 +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 extend = Object.assign;
10
- const objectToString = Object.prototype.toString;
11
- const toTypeString = (value) => objectToString.call(value);
12
- const log = (...arg) => console.log(
13
- `%c ${arg[0]}: `,
14
- "padding: 2px 1px; border-radius: 3px 3px 3px 3px; color: #fff; background: #000; font-weight: bold;",
15
- arg.slice(1)
16
- );
17
- const warn = (msg) => console.warn(msg);
18
- const error = (msg) => console.error(msg);
19
- const isMap = (val) => toTypeString(val) === "[object Map]";
20
- const isSet = (val) => toTypeString(val) === "[object Set]";
21
- const isDate = (val) => toTypeString(val) === "[object Date]";
22
- const isRegExp = (val) => toTypeString(val) === "[object RegExp]";
23
- const isFunction = (val) => typeof val === "function";
24
- const isString = (val) => typeof val === "string";
25
- const isSymbol = (val) => typeof val === "symbol";
26
- const isObject = (val) => val !== null && typeof val === "object";
27
- const isPromise = (val) => isObject(val) && isFunction(val.then) && isFunction(val.catch);
28
- const isUndef = (val) => val === void 0 || val === null;
29
- const isNull = (val) => val === null;
30
- function isDef(v) {
31
- return v !== void 0 && v !== null;
32
- }
33
- const isArray = Array.isArray;
34
- const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
35
- const hasChanged = (oldValue, newValue) => oldValue !== newValue;
36
- function deepClone(target) {
37
- const map = /* @__PURE__ */ new WeakMap();
38
- function _deepClone(value) {
39
- if (isDate(value))
40
- return new Date(value);
41
- if (isRegExp(value))
42
- return new RegExp(value);
43
- if (isObject(value)) {
44
- if (map.has(value))
45
- return map.get(value);
46
- let clone = {};
47
- if (isArray(value)) {
48
- clone = [];
49
- map.set(value, clone);
50
- for (let i = 0; i < value.length; i++) {
51
- clone[i] = _deepClone(value[i]);
52
- }
53
- return clone;
54
- }
55
- map.set(value, clone);
56
- for (const key in value) {
57
- if (hasOwn(value, key)) {
58
- clone[key] = _deepClone(value[key]);
59
- }
60
- }
61
- return clone;
62
- } else {
63
- return value;
64
- }
65
- }
66
- return _deepClone(target);
67
- }
68
- function deepMerge(template, source, options) {
69
- return isArray(template) ? arrayMerge(template, source, options) : mergeObject(template, source, options);
70
- }
71
- function mergeObject(template, source, options) {
72
- const target = process(source, options);
73
- const templateKeys = Object.keys(template);
74
- templateKeys.forEach((key) => {
75
- if (isUndef(source[key])) {
76
- target[key] = process(template[key], options);
77
- } else {
78
- target[key] = isObject(template[key]) && isObject(source[key]) ? deepMerge(template[key], source[key], options) : process(source[key], options);
79
- }
80
- });
81
- return target;
82
- }
83
- function arrayMerge(template, source, options) {
84
- return isArray(source) ? process(template, options).concat(process(source, options)) : process(source, options);
85
- }
86
- function process(source, options) {
87
- const { isDeepClone = true } = options || {};
88
- return isDeepClone ? deepClone(source) : source;
89
- }
90
- function debounce(target, wait = 1e3) {
91
- let timer = null;
92
- return function(...args) {
93
- if (timer)
94
- clearTimeout(timer);
95
- timer = setTimeout(() => {
96
- target.apply(this, ...args);
97
- }, wait);
98
- };
99
- }
100
- function throttle(target, wait = 1e3) {
101
- let timer = null;
102
- return function(...args) {
103
- if (isNull(timer)) {
104
- timer = Date.now();
105
- return target.apply(this, ...args);
106
- } else {
107
- const now = Date.now();
108
- if (now - timer >= wait) {
109
- timer = now;
110
- return target.apply(this, ...args);
111
- }
112
- }
113
- };
114
- }
115
- exports.debounce = debounce;
116
- exports.deepClone = deepClone;
117
- exports.deepMerge = deepMerge;
118
- exports.error = error;
119
- exports.extend = extend;
120
- exports.getRandomColor = getRandomColor;
121
- exports.getRandomString = getRandomString;
122
- exports.hasChanged = hasChanged;
123
- exports.hasOwn = hasOwn;
124
- exports.isArray = isArray;
125
- exports.isDate = isDate;
126
- exports.isDef = isDef;
127
- exports.isFunction = isFunction;
128
- exports.isMap = isMap;
129
- exports.isNull = isNull;
130
- exports.isObject = isObject;
131
- exports.isPromise = isPromise;
132
- exports.isRegExp = isRegExp;
133
- exports.isSet = isSet;
134
- exports.isString = isString;
135
- exports.isSymbol = isSymbol;
136
- exports.isUndef = isUndef;
137
- exports.log = log;
138
- exports.objectToString = objectToString;
139
- exports.throttle = throttle;
140
- exports.toTypeString = toTypeString;
141
- exports.warn = warn;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("vconsole");function C(){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 m=Object.prototype.toString,a=t=>m.call(t),O=(...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)),D=t=>console.warn(t),x=t=>console.error(t),M=t=>a(t)==="[object Map]",E=t=>a(t)==="[object Set]",S=t=>a(t)==="[object Date]",b=t=>a(t)==="[object RegExp]",p=t=>typeof t=="function",R=t=>typeof t=="string",T=t=>typeof t=="symbol",l=t=>t!==null&&typeof t=="object",N=t=>l(t)&&p(t.then)&&p(t.catch),h=t=>t==null,w=t=>t===null;function A(t){return t!=null}const f=Array.isArray,y=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),I=(t,n)=>t!==n;function j(t){const n=new WeakMap;function e(o){if(S(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(f(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 u(t,n,e){return f(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]=l(t[r])&&l(n[r])?u(t[r],n[r],e):c(n[r],e)}),o}function F(t,n,e){return f(n)?c(t,e).concat(c(n,e)):c(n,e)}function c(t,n){const{isDeepClone:e=!0}=n||{};return e?j(t):t}function K(t,n=1e3){let e=null;return function(...o){e&&clearTimeout(e),e=setTimeout(()=>{t.apply(this,...o)},n)}}function L(t,n=1e3){let e=null;return function(...o){if(w(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 s={name:"LNTVOW_CONSOLE",time:3600,count:20};function U(t){s=u(s,t);const n=localStorage.getItem(s.name);if(!n)return;Date.now()-Number(n)>=1e3*s.time?localStorage.removeItem(s.name):new d}function V(){s.count++,s.count>=20&&!localStorage.getItem(s.name)&&(localStorage.setItem(s.name,Date.now().toString()),new d)}const W={initConsole:U,showConsole:V};exports.debounce=K;exports.deepClone=j;exports.deepMerge=u;exports.error=x;exports.getRandomColor=C;exports.getRandomString=g;exports.hasChanged=I;exports.hasOwn=y;exports.isArray=f;exports.isDate=S;exports.isDef=A;exports.isFunction=p;exports.isMap=M;exports.isNull=w;exports.isObject=l;exports.isPromise=N;exports.isRegExp=b;exports.isSet=E;exports.isString=R;exports.isSymbol=T;exports.isUndef=h;exports.log=O;exports.nConsole=W;exports.objectToString=m;exports.throttle=L;exports.toTypeString=a;exports.warn=D;
package/dist/index.d.ts CHANGED
@@ -26,13 +26,6 @@ export declare function deepMerge(template: AnyObj, source: AnyObj, options?: Op
26
26
 
27
27
  export declare const error: (msg: string) => void;
28
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
-
36
29
  /**
37
30
  * @description 获取随机颜色
38
31
  * @return {String} 随机颜色
@@ -54,6 +47,30 @@ export declare const hasChanged: (oldValue: unknown, newValue: unknown) => boole
54
47
 
55
48
  export declare const hasOwn: <T extends object, U extends keyof T>(target: T, key: U) => boolean;
56
49
 
50
+ /**
51
+ * @description 初始化
52
+ * @param options 初始化配置
53
+ */
54
+ declare function initConsole(options: InitConsoleOptions): void;
55
+
56
+ declare interface InitConsoleOptions {
57
+ /**
58
+ * @description 缓存的key
59
+ * @default LNTVOW_CONSOLE
60
+ */
61
+ name: string;
62
+ /**
63
+ * @description 显示console的时间 单位s
64
+ * @default 3600 一个小时
65
+ */
66
+ time: number;
67
+ /**
68
+ * @description 显示console的事件触发次数
69
+ * @default 20
70
+ */
71
+ count: number;
72
+ }
73
+
57
74
  export declare const isArray: (arg: any) => arg is any[];
58
75
 
59
76
  export declare const isDate: (val: unknown) => val is Date;
@@ -82,6 +99,11 @@ export declare const isUndef: (val: unknown) => val is null | undefined;
82
99
 
83
100
  export declare const log: (...arg: unknown[]) => void;
84
101
 
102
+ export declare const nConsole: {
103
+ initConsole: typeof initConsole;
104
+ showConsole: typeof showConsole;
105
+ };
106
+
85
107
  export declare const objectToString: () => string;
86
108
 
87
109
  declare interface Options {
@@ -92,6 +114,11 @@ declare interface Options {
92
114
  isDeepClone: boolean;
93
115
  }
94
116
 
117
+ /**
118
+ * @description 触发显示事件
119
+ */
120
+ declare function showConsole(): void;
121
+
95
122
  /**
96
123
  * @description 节流函数
97
124
  * @param target 目标函数
package/dist/index.mjs CHANGED
@@ -1,141 +1,126 @@
1
- function getRandomColor() {
1
+ import u from "vconsole";
2
+ function M() {
2
3
  return `#${Math.random().toString(16).slice(2, 8).padEnd(6, "0")}`;
3
4
  }
4
- function getRandomString(number) {
5
- return number > 10 ? getRandomString(10) + getRandomString(number - 10) : Math.random().toString(36).padEnd(12, "0").slice(2, number + 2);
5
+ function p(t) {
6
+ return t > 10 ? p(10) + p(t - 10) : Math.random().toString(36).padEnd(12, "0").slice(2, t + 2);
6
7
  }
7
- const extend = Object.assign;
8
- const objectToString = Object.prototype.toString;
9
- const toTypeString = (value) => objectToString.call(value);
10
- const log = (...arg) => console.log(
11
- `%c ${arg[0]}: `,
8
+ const d = Object.prototype.toString, l = (t) => d.call(t), R = (...t) => console.log(
9
+ `%c ${t[0]}: `,
12
10
  "padding: 2px 1px; border-radius: 3px 3px 3px 3px; color: #fff; background: #000; font-weight: bold;",
13
- arg.slice(1)
14
- );
15
- const warn = (msg) => console.warn(msg);
16
- const error = (msg) => console.error(msg);
17
- const isMap = (val) => toTypeString(val) === "[object Map]";
18
- const isSet = (val) => toTypeString(val) === "[object Set]";
19
- const isDate = (val) => toTypeString(val) === "[object Date]";
20
- const isRegExp = (val) => toTypeString(val) === "[object RegExp]";
21
- const isFunction = (val) => typeof val === "function";
22
- const isString = (val) => typeof val === "string";
23
- const isSymbol = (val) => typeof val === "symbol";
24
- const isObject = (val) => val !== null && typeof val === "object";
25
- const isPromise = (val) => isObject(val) && isFunction(val.then) && isFunction(val.catch);
26
- const isUndef = (val) => val === void 0 || val === null;
27
- const isNull = (val) => val === null;
28
- function isDef(v) {
29
- return v !== void 0 && v !== null;
11
+ t.slice(1)
12
+ ), T = (t) => console.warn(t), I = (t) => console.error(t), N = (t) => l(t) === "[object Map]", A = (t) => l(t) === "[object Set]", h = (t) => l(t) === "[object Date]", b = (t) => l(t) === "[object RegExp]", g = (t) => typeof t == "function", K = (t) => typeof t == "string", L = (t) => typeof t == "symbol", f = (t) => t !== null && typeof t == "object", P = (t) => f(t) && g(t.then) && g(t.catch), w = (t) => t == null, S = (t) => t === null;
13
+ function V(t) {
14
+ return t != null;
30
15
  }
31
- const isArray = Array.isArray;
32
- const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
33
- const hasChanged = (oldValue, newValue) => oldValue !== newValue;
34
- function deepClone(target) {
35
- const map = /* @__PURE__ */ new WeakMap();
36
- function _deepClone(value) {
37
- if (isDate(value))
38
- return new Date(value);
39
- if (isRegExp(value))
40
- return new RegExp(value);
41
- if (isObject(value)) {
42
- if (map.has(value))
43
- return map.get(value);
44
- let clone = {};
45
- if (isArray(value)) {
46
- clone = [];
47
- map.set(value, clone);
48
- for (let i = 0; i < value.length; i++) {
49
- clone[i] = _deepClone(value[i]);
50
- }
51
- return clone;
16
+ const a = Array.isArray, y = (t, n) => Object.prototype.hasOwnProperty.call(t, n), W = (t, n) => t !== n;
17
+ function j(t) {
18
+ const n = /* @__PURE__ */ new WeakMap();
19
+ function e(o) {
20
+ if (h(o))
21
+ return new Date(o);
22
+ if (b(o))
23
+ return new RegExp(o);
24
+ if (f(o)) {
25
+ if (n.has(o))
26
+ return n.get(o);
27
+ let i = {};
28
+ if (a(o)) {
29
+ i = [], n.set(o, i);
30
+ for (let r = 0; r < o.length; r++)
31
+ i[r] = e(o[r]);
32
+ return i;
52
33
  }
53
- map.set(value, clone);
54
- for (const key in value) {
55
- if (hasOwn(value, key)) {
56
- clone[key] = _deepClone(value[key]);
57
- }
58
- }
59
- return clone;
60
- } else {
61
- return value;
62
- }
34
+ n.set(o, i);
35
+ for (const r in o)
36
+ y(o, r) && (i[r] = e(o[r]));
37
+ return i;
38
+ } else
39
+ return o;
63
40
  }
64
- return _deepClone(target);
41
+ return e(t);
65
42
  }
66
- function deepMerge(template, source, options) {
67
- return isArray(template) ? arrayMerge(template, source, options) : mergeObject(template, source, options);
43
+ function m(t, n, e) {
44
+ return a(t) ? x(t, n, e) : O(t, n, e);
68
45
  }
69
- function mergeObject(template, source, options) {
70
- const target = process(source, options);
71
- const templateKeys = Object.keys(template);
72
- templateKeys.forEach((key) => {
73
- if (isUndef(source[key])) {
74
- target[key] = process(template[key], options);
75
- } else {
76
- target[key] = isObject(template[key]) && isObject(source[key]) ? deepMerge(template[key], source[key], options) : process(source[key], options);
77
- }
78
- });
79
- return target;
46
+ function O(t, n, e) {
47
+ const o = s(n, e);
48
+ return Object.keys(t).forEach((r) => {
49
+ w(n[r]) ? o[r] = s(t[r], e) : o[r] = f(t[r]) && f(n[r]) ? m(t[r], n[r], e) : s(n[r], e);
50
+ }), o;
80
51
  }
81
- function arrayMerge(template, source, options) {
82
- return isArray(source) ? process(template, options).concat(process(source, options)) : process(source, options);
52
+ function x(t, n, e) {
53
+ return a(n) ? s(t, e).concat(s(n, e)) : s(n, e);
83
54
  }
84
- function process(source, options) {
85
- const { isDeepClone = true } = options || {};
86
- return isDeepClone ? deepClone(source) : source;
55
+ function s(t, n) {
56
+ const { isDeepClone: e = !0 } = n || {};
57
+ return e ? j(t) : t;
87
58
  }
88
- function debounce(target, wait = 1e3) {
89
- let timer = null;
90
- return function(...args) {
91
- if (timer)
92
- clearTimeout(timer);
93
- timer = setTimeout(() => {
94
- target.apply(this, ...args);
95
- }, wait);
59
+ function _(t, n = 1e3) {
60
+ let e = null;
61
+ return function(...o) {
62
+ e && clearTimeout(e), e = setTimeout(() => {
63
+ t.apply(this, ...o);
64
+ }, n);
96
65
  };
97
66
  }
98
- function throttle(target, wait = 1e3) {
99
- let timer = null;
100
- return function(...args) {
101
- if (isNull(timer)) {
102
- timer = Date.now();
103
- return target.apply(this, ...args);
104
- } else {
105
- const now = Date.now();
106
- if (now - timer >= wait) {
107
- timer = now;
108
- return target.apply(this, ...args);
109
- }
67
+ function $(t, n = 1e3) {
68
+ let e = null;
69
+ return function(...o) {
70
+ if (S(e))
71
+ return e = Date.now(), t.apply(this, ...o);
72
+ {
73
+ const i = Date.now();
74
+ if (i - e >= n)
75
+ return e = i, t.apply(this, ...o);
110
76
  }
111
77
  };
112
78
  }
79
+ let c = {
80
+ name: "LNTVOW_CONSOLE",
81
+ time: 3600,
82
+ count: 20
83
+ };
84
+ function C(t) {
85
+ c = m(c, t);
86
+ const n = localStorage.getItem(c.name);
87
+ if (!n)
88
+ return;
89
+ Date.now() - Number(n) >= 1e3 * c.time ? localStorage.removeItem(c.name) : new u();
90
+ }
91
+ function D() {
92
+ c.count++, c.count >= 20 && !localStorage.getItem(c.name) && (localStorage.setItem(c.name, Date.now().toString()), new u());
93
+ }
94
+ const F = {
95
+ initConsole: C,
96
+ showConsole: D
97
+ };
113
98
  export {
114
- debounce,
115
- deepClone,
116
- deepMerge,
117
- error,
118
- extend,
119
- getRandomColor,
120
- getRandomString,
121
- hasChanged,
122
- hasOwn,
123
- isArray,
124
- isDate,
125
- isDef,
126
- isFunction,
127
- isMap,
128
- isNull,
129
- isObject,
130
- isPromise,
131
- isRegExp,
132
- isSet,
133
- isString,
134
- isSymbol,
135
- isUndef,
136
- log,
137
- objectToString,
138
- throttle,
139
- toTypeString,
140
- warn
99
+ _ as debounce,
100
+ j as deepClone,
101
+ m as deepMerge,
102
+ I as error,
103
+ M as getRandomColor,
104
+ p as getRandomString,
105
+ W as hasChanged,
106
+ y as hasOwn,
107
+ a as isArray,
108
+ h as isDate,
109
+ V as isDef,
110
+ g as isFunction,
111
+ N as isMap,
112
+ S as isNull,
113
+ f as isObject,
114
+ P as isPromise,
115
+ b as isRegExp,
116
+ A as isSet,
117
+ K as isString,
118
+ L as isSymbol,
119
+ w as isUndef,
120
+ R as log,
121
+ F as nConsole,
122
+ d as objectToString,
123
+ $ as throttle,
124
+ l as toTypeString,
125
+ T as warn
141
126
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lntvow/utils",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "工具库",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -12,7 +12,8 @@
12
12
  "module": "dist/index.mjs",
13
13
  "types": "dist/index.d.ts",
14
14
  "devDependencies": {
15
- "@lntvow/eslint-config": "^7.1.12",
15
+ "@lntvow/eslint-config": "^8.2.3",
16
+ "@rollup/plugin-node-resolve": "^15.2.1",
16
17
  "bumpp": "^9.1.1",
17
18
  "commitizen": "^4.3.0",
18
19
  "cz-conventional-changelog": "^3.3.0",
@@ -27,12 +28,15 @@
27
28
  "path": "node_modules/cz-conventional-changelog"
28
29
  }
29
30
  },
31
+ "dependencies": {
32
+ "vconsole": "^3.15.1"
33
+ },
30
34
  "scripts": {
31
35
  "dev": "vite",
32
36
  "test": "vitest",
33
37
  "build": "vite build",
34
38
  "commit": "git add . && git-cz && git push",
35
- "release": "bumpp package.json --all --commit --no-tag --push",
39
+ "release": "git add . && bumpp package.json --all --commit --no-tag --push",
36
40
  "rimraf": "rimraf ./node_modules/"
37
41
  }
38
42
  }