@qy_better_lib/core 0.0.6 → 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/utils/object.js +51 -43
- package/package.json +1 -1
|
@@ -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/utils/object.js
CHANGED
|
@@ -1,65 +1,73 @@
|
|
|
1
|
-
import { isObject as
|
|
2
|
-
function
|
|
3
|
-
const
|
|
1
|
+
import { isObject as c } from "./is.js";
|
|
2
|
+
function f(e) {
|
|
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
|
|
27
|
-
|
|
28
|
-
for (let
|
|
29
|
-
let
|
|
30
|
-
if (
|
|
31
|
-
for (let
|
|
32
|
-
|
|
25
|
+
function s(...e) {
|
|
26
|
+
let t = e.length, n = e[0];
|
|
27
|
+
c(n) || (n = {});
|
|
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
|
|
37
|
-
if (e ===
|
|
38
|
-
if (e &&
|
|
39
|
-
if (e.constructor !==
|
|
40
|
-
|
|
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;
|
|
41
42
|
if (Array.isArray(e)) {
|
|
42
|
-
if (n = e.length, n !=
|
|
43
|
-
|
|
44
|
-
|
|
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;
|
|
45
48
|
return !0;
|
|
46
49
|
}
|
|
47
|
-
if (e.constructor === RegExp) return e.source ===
|
|
48
|
-
if (e.valueOf !== Object.prototype.valueOf)
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (!
|
|
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;
|
|
56
64
|
}
|
|
57
65
|
return !0;
|
|
58
66
|
}
|
|
59
|
-
return e !== e &&
|
|
67
|
+
return e !== e && t !== t || console.log("对象比较-a", e, "对象比较-b", t), e !== e && t !== t;
|
|
60
68
|
}
|
|
61
69
|
export {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
s as deepAssign,
|
|
71
|
+
f as deepClone,
|
|
72
|
+
i as deepEqual
|
|
65
73
|
};
|