@qy_better_lib/core 0.0.5 → 0.0.7
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/@qy_better_lib/core.min.js +1 -1
- package/lib/index.js +24 -23
- package/lib/utils/object.d.ts +6 -0
- package/lib/utils/object.js +55 -21
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(r=typeof globalThis<"u"?globalThis:r||self,f(r["@qy_better_lib/core"]={}))})(this,function(r){"use strict";function f(){return Math.floor(Math.random()*1e4)}function w(e){return Math.floor(Math.random()*Math.floor(e))}function C(){const e=p;return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function p(){return Math.floor((1+Math.random())*65536).toString(16).substring(1)}function $(e){return e===void 0}function O(e){return Object.prototype.toString.call(e)==="[object Array]"}function g(e){return typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"}function j(e){return Object.prototype.toString.call(e)==="[object Date]"}function A(e){return!e&&e!==0||O(e)&&e.length===0||g(e)&&!Object.keys(e).length}function k(e){return typeof Element>"u"?!1:e instanceof Element}const N=typeof window<"u",m=e=>typeof e=="number",v=e=>typeof e=="string",M=e=>v(e)?!Number.isNaN(Number(e)):!1;function L(e){return/^1[3-9]\d{9}$/.test(e)}function R(e){return/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(e)}function B(e){return/^(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]\d{4}|[1-9]\d{0,3}|0)$/.test(e)}function P(e,t="key",n="children"){const o={},i=(c,l)=>{for(let u=0;u<c.length;u++){const a=c[u],d=a[t];if(!o[d]){o[d]=a,l&&(o[d].parent=o[l]);const y=a[n];y&&y.length>0&&i(y,a[t])}}};return i(e),o}function _(e){return e?Object.prototype.toString.call(1)!=="[object Number]"?`${e}`:`${e}`.replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g,"$1,"):"0"}function H(e,t){return m(e)?Number(t?Number(e).toFixed(t):e):Number.NaN}function J(e,t){return m(e)?Number(e.toFixed(t)):Number.NaN}function U(){const e=localStorage.getItem("token");if(!e)return;const t=JSON.parse(e);if(t!==null)if(t.expirse!=null&&t.expirse<new Date().getTime())localStorage.removeItem("token");else return t.value;return null}function q(e,t){!t&&(t=7*24*60*60*1e3)||(t=t*1e3);const n={value:e,expirse:new Date().getTime()+t};localStorage.setItem("token",JSON.stringify(n))}function V(){localStorage.removeItem("token")}function Y(e,t,n="local"){const o=n=="local"?localStorage:sessionStorage;t!=null&&o.setItem(e,JSON.stringify(t))}function z(e,t="local"){let o=(t=="local"?localStorage:sessionStorage).getItem(e);return o&&JSON.parse(o||"")}function G(e,t="local"){(t=="local"?localStorage:sessionStorage).removeItem(e)}function K(e="local"){(e=="local"?localStorage:sessionStorage).clear()}function E(e){const t=Object.prototype.toString;if(!e||typeof e!="object")return e;if(e.nodeType&&"cloneNode"in e)return e.cloneNode(!0);if(t.call(e)==="[object Date]")return new Date(e.getTime());if(t.call(e)==="[object RegExp]"){const o=[];return e.global&&o.push("g"),e.multiline&&o.push("m"),e.ignoreCase&&o.push("i"),new RegExp(e.source,o.join(""))}if(t.call(e)==="[object FormData]"){const o=new FormData;for(const[i,c]of e.entries())o.append(i,c);return o}const n=Array.isArray(e)?[]:e.constructor?new e.constructor:{};for(const o in e)n[o]=E(e[o]);return n}function I(...e){let t=e.length,n=e[0];g(n)||(n={});for(let o=1;o<t;o++){let i=e[o];if(g(i))for(let c in i)c==="__proto__"||n===i[c]||(g(i[c])?n[c]=I(n[c],i[c]):n[c]=i[c])}return n}function S(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){if(e.constructor!==t.constructor)return console.log("对象比较-a.constructor",e.constructor,"对象比较-b.constructor",t.constructor),!1;let n,o,i;if(Array.isArray(e)){if(n=e.length,n!=t.length)return console.log("对象比较-a.length",e.length,"对象比较-b.length",t.length),!1;for(o=n;o--!==0;)if(!S(e[o],t[o]))return console.log("对象比较-a[i]",e[o],"对象比较-b[i]",t[o]),!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()!==t.valueOf()&&console.log("对象比较-a.valueOf()",e.valueOf(),"对象比较-b.valueOf()",e.valueOf()),e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString()&&console.log("对象比较-a.toString()",e.toString(),"对象比较-b.toString()",t.toString()),e.toString()===t.toString();if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return console.log("对象比较-Object.keys(a).length",Object.keys(e).length,"对象比较-Object.keys(b).length",Object.keys(t).length),!1;for(o=n;o--!==0;)if(!Object.prototype.hasOwnProperty.call(t,i[o]))return console.log("对象比较-keys[i]",i[o],"对象比较-b",t),!1;for(o=n;o--!==0;){const c=i[o];if(!S(e[c],t[c]))return console.log("对象比较-a[key]",e[c],"对象比较-b[key]",t[c]),!1}return!0}return e!==e&&t!==t||console.log("对象比较-a",e,"对象比较-b",t),e!==e&&t!==t}function T(e,t){return!e||e.tagName==="BODY"?null:e.classList.contains(t)?e:T(e.parentNode,t)}function b({path:e,name:t}){const n=document.createElement("a");n.href=e,n.target="_blank",t&&n.setAttribute("download",t),document.body.appendChild(n),n.click(),document.body.removeChild(n)}function Q(e){e.forEach(t=>{b({path:t.url,name:t.name})})}async function W(e){if(!e)return;const t=new FileReader;return t.readAsDataURL(e),new Promise((n,o)=>{t.onload=i=>{var c;return n((c=i.target)==null?void 0:c.result)},t.onerror=i=>o(void 0)})}const s=new Map;let D;N&&(document.addEventListener("mousedown",e=>D=e),document.addEventListener("mouseup",e=>{for(const t of s.values())for(const{documentHandler:n}of t)n(e,D)}));function F(e,t){let n=[];return Array.isArray(t.arg)?n=t.arg:k(t.arg)&&n.push(t.arg),function(o,i){const c=t.instance.popperRef,l=o.target,u=i==null?void 0:i.target,a=!t||!t.instance,d=!l||!u,y=e.contains(l)||e.contains(u),Z=e===l,x=n.length&&n.some(h=>h==null?void 0:h.contains(l))||n.length&&n.includes(u),ee=c&&(c.contains(l)||c.contains(u));a||d||y||Z||x||ee||t.value(o,i)}}const X={beforeMount(e,t){var n;s.has(e)||s.set(e,[]),(n=s.get(e))==null||n.push({documentHandler:F(e,t),bindingFn:t.value})},updated(e,t){s.has(e)||s.set(e,[]);const n=s.get(e),o=n==null?void 0:n.findIndex(c=>c.bindingFn===t.oldValue),i={documentHandler:F(e,t),bindingFn:t.value};o&&o>=0?n==null||n.splice(o,1,i):n==null||n.push(i)},unmounted(e){s.delete(e)}};r.ClickOutside=X,r.clearStorage=K,r.deepAssign=I,r.deepClone=E,r.deepEqual=S,r.downLoadFile=b,r.downLoadFiles=Q,r.generateId=f,r.generateString=p,r.getParentByClass=T,r.getRandomInt=w,r.getStorage=z,r.getToken=U,r.guiID=C,r.isArray=O,r.isClient=N,r.isDate=j,r.isElement=k,r.isEmpty=A,r.isIp=R,r.isMobile=L,r.isNumber=m,r.isObject=g,r.isPort=B,r.isString=v,r.isStringNumber=M,r.isUndefined=$,r.removeStorage=G,r.removeToken=V,r.setStorage=Y,r.setToken=q,r.thousandSeparator=_,r.toBase64=W,r.toFixed=J,r.toNumber=H,r.treeFlat=P,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/lib/index.js
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
1
|
import { generateId as o, generateString as r, getRandomInt as i, guiID as s } from "./utils/random.js";
|
|
2
|
-
import { isArray as n, isClient as m, isDate as
|
|
2
|
+
import { isArray as n, isClient as m, isDate as d, isElement as g, isEmpty as p, isIp as l, isMobile as f, isNumber as x, isObject as u, isPort as S, isString as b, isStringNumber as k, isUndefined as C } from "./utils/is.js";
|
|
3
3
|
import { treeFlat as I } from "./utils/tree.js";
|
|
4
|
-
import { thousandSeparator as y, toFixed as
|
|
5
|
-
import { clearStorage as
|
|
6
|
-
import { deepAssign as h, deepClone as j } from "./utils/object.js";
|
|
4
|
+
import { thousandSeparator as y, toFixed as E, toNumber as N } from "./utils/number.js";
|
|
5
|
+
import { clearStorage as v, getStorage as w, getToken as A, removeStorage as B, removeToken as D, setStorage as L, setToken as O } from "./utils/storage.js";
|
|
6
|
+
import { deepAssign as h, deepClone as j, deepEqual as q } from "./utils/object.js";
|
|
7
7
|
import { getParentByClass as R } from "./utils/dom.js";
|
|
8
|
-
import { downLoadFile as
|
|
9
|
-
import { default as
|
|
8
|
+
import { downLoadFile as z, downLoadFiles as G, toBase64 as H } from "./utils/file.js";
|
|
9
|
+
import { default as K } from "./directives/click-outside.js";
|
|
10
10
|
export {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
K as ClickOutside,
|
|
12
|
+
v as clearStorage,
|
|
13
13
|
h as deepAssign,
|
|
14
14
|
j as deepClone,
|
|
15
|
-
q as
|
|
16
|
-
z as
|
|
15
|
+
q as deepEqual,
|
|
16
|
+
z as downLoadFile,
|
|
17
|
+
G as downLoadFiles,
|
|
17
18
|
o as generateId,
|
|
18
19
|
r as generateString,
|
|
19
20
|
R as getParentByClass,
|
|
20
21
|
i as getRandomInt,
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
w as getStorage,
|
|
23
|
+
A as getToken,
|
|
23
24
|
s as guiID,
|
|
24
25
|
n as isArray,
|
|
25
26
|
m as isClient,
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
d as isDate,
|
|
28
|
+
g as isElement,
|
|
28
29
|
p as isEmpty,
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
l as isIp,
|
|
31
|
+
f as isMobile,
|
|
31
32
|
x as isNumber,
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
u as isObject,
|
|
34
|
+
S as isPort,
|
|
34
35
|
b as isString,
|
|
35
36
|
k as isStringNumber,
|
|
36
37
|
C as isUndefined,
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
B as removeStorage,
|
|
39
|
+
D as removeToken,
|
|
39
40
|
L as setStorage,
|
|
40
41
|
O as setToken,
|
|
41
42
|
y as thousandSeparator,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
H as toBase64,
|
|
44
|
+
E as toFixed,
|
|
45
|
+
N as toNumber,
|
|
45
46
|
I as treeFlat
|
|
46
47
|
};
|
package/lib/utils/object.d.ts
CHANGED
|
@@ -3,3 +3,9 @@ export declare function deepClone(obj: any): any;
|
|
|
3
3
|
*深度合并多个对象的方法
|
|
4
4
|
*/
|
|
5
5
|
export declare function deepAssign(...arg: any[]): Record<string, any>;
|
|
6
|
+
/**
|
|
7
|
+
* 深度比较两个对象值是否一致
|
|
8
|
+
* 不考虑值,不考虑引用地址
|
|
9
|
+
* @returns boolean
|
|
10
|
+
*/
|
|
11
|
+
export declare function deepEqual(a: any, b: any): boolean;
|
package/lib/utils/object.js
CHANGED
|
@@ -1,39 +1,73 @@
|
|
|
1
1
|
import { isObject as c } from "./is.js";
|
|
2
2
|
function f(e) {
|
|
3
|
-
const
|
|
3
|
+
const t = Object.prototype.toString;
|
|
4
4
|
if (!e || typeof e != "object")
|
|
5
5
|
return e;
|
|
6
6
|
if (e.nodeType && "cloneNode" in e)
|
|
7
7
|
return e.cloneNode(!0);
|
|
8
|
-
if (
|
|
8
|
+
if (t.call(e) === "[object Date]")
|
|
9
9
|
return new Date(e.getTime());
|
|
10
|
-
if (
|
|
11
|
-
const
|
|
12
|
-
return e.global &&
|
|
10
|
+
if (t.call(e) === "[object RegExp]") {
|
|
11
|
+
const r = [];
|
|
12
|
+
return e.global && r.push("g"), e.multiline && r.push("m"), e.ignoreCase && r.push("i"), new RegExp(e.source, r.join(""));
|
|
13
13
|
}
|
|
14
|
-
if (
|
|
15
|
-
const
|
|
16
|
-
for (const [
|
|
17
|
-
|
|
18
|
-
return
|
|
14
|
+
if (t.call(e) === "[object FormData]") {
|
|
15
|
+
const r = new FormData();
|
|
16
|
+
for (const [l, o] of e.entries())
|
|
17
|
+
r.append(l, o);
|
|
18
|
+
return r;
|
|
19
19
|
}
|
|
20
20
|
const n = Array.isArray(e) ? [] : e.constructor ? new e.constructor() : {};
|
|
21
|
-
for (const
|
|
22
|
-
n[
|
|
21
|
+
for (const r in e)
|
|
22
|
+
n[r] = f(e[r]);
|
|
23
23
|
return n;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
let
|
|
25
|
+
function s(...e) {
|
|
26
|
+
let t = e.length, n = e[0];
|
|
27
27
|
c(n) || (n = {});
|
|
28
|
-
for (let
|
|
29
|
-
let
|
|
30
|
-
if (c(
|
|
31
|
-
for (let
|
|
32
|
-
|
|
28
|
+
for (let r = 1; r < t; r++) {
|
|
29
|
+
let l = e[r];
|
|
30
|
+
if (c(l))
|
|
31
|
+
for (let o in l)
|
|
32
|
+
o === "__proto__" || n === l[o] || (c(l[o]) ? n[o] = s(n[o], l[o]) : n[o] = l[o]);
|
|
33
33
|
}
|
|
34
34
|
return n;
|
|
35
35
|
}
|
|
36
|
+
function i(e, t) {
|
|
37
|
+
if (e === t) return !0;
|
|
38
|
+
if (e && t && typeof e == "object" && typeof t == "object") {
|
|
39
|
+
if (e.constructor !== t.constructor)
|
|
40
|
+
return console.log("对象比较-a.constructor", e.constructor, "对象比较-b.constructor", t.constructor), !1;
|
|
41
|
+
let n, r, l;
|
|
42
|
+
if (Array.isArray(e)) {
|
|
43
|
+
if (n = e.length, n != t.length)
|
|
44
|
+
return console.log("对象比较-a.length", e.length, "对象比较-b.length", t.length), !1;
|
|
45
|
+
for (r = n; r-- !== 0; )
|
|
46
|
+
if (!i(e[r], t[r]))
|
|
47
|
+
return console.log("对象比较-a[i]", e[r], "对象比较-b[i]", t[r]), !1;
|
|
48
|
+
return !0;
|
|
49
|
+
}
|
|
50
|
+
if (e.constructor === RegExp) return e.source === t.source && e.flags === t.flags;
|
|
51
|
+
if (e.valueOf !== Object.prototype.valueOf)
|
|
52
|
+
return e.valueOf() !== t.valueOf() && console.log("对象比较-a.valueOf()", e.valueOf(), "对象比较-b.valueOf()", e.valueOf()), e.valueOf() === t.valueOf();
|
|
53
|
+
if (e.toString !== Object.prototype.toString)
|
|
54
|
+
return e.toString() === t.toString() && console.log("对象比较-a.toString()", e.toString(), "对象比较-b.toString()", t.toString()), e.toString() === t.toString();
|
|
55
|
+
if (l = Object.keys(e), n = l.length, n !== Object.keys(t).length)
|
|
56
|
+
return console.log("对象比较-Object.keys(a).length", Object.keys(e).length, "对象比较-Object.keys(b).length", Object.keys(t).length), !1;
|
|
57
|
+
for (r = n; r-- !== 0; )
|
|
58
|
+
if (!Object.prototype.hasOwnProperty.call(t, l[r]))
|
|
59
|
+
return console.log("对象比较-keys[i]", l[r], "对象比较-b", t), !1;
|
|
60
|
+
for (r = n; r-- !== 0; ) {
|
|
61
|
+
const o = l[r];
|
|
62
|
+
if (!i(e[o], t[o]))
|
|
63
|
+
return console.log("对象比较-a[key]", e[o], "对象比较-b[key]", t[o]), !1;
|
|
64
|
+
}
|
|
65
|
+
return !0;
|
|
66
|
+
}
|
|
67
|
+
return e !== e && t !== t || console.log("对象比较-a", e, "对象比较-b", t), e !== e && t !== t;
|
|
68
|
+
}
|
|
36
69
|
export {
|
|
37
|
-
|
|
38
|
-
f as deepClone
|
|
70
|
+
s as deepAssign,
|
|
71
|
+
f as deepClone,
|
|
72
|
+
i as deepEqual
|
|
39
73
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qy_better_lib/core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"description": "qy better lib core",
|
|
6
6
|
"author": "luhuiming",
|
|
7
7
|
"license": "ISC",
|
|
@@ -47,4 +47,4 @@
|
|
|
47
47
|
"vite-plugin-dts": "^3.9.1",
|
|
48
48
|
"vue": "^3.4.31"
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|