@qy_better_lib/core 0.0.5 → 0.0.6

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.
@@ -1 +1 @@
1
- (function(o,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(o=typeof globalThis<"u"?globalThis:o||self,f(o["@qy_better_lib/core"]={}))})(this,function(o){"use strict";function f(){return Math.floor(Math.random()*1e4)}function E(e){return Math.floor(Math.random()*Math.floor(e))}function $(){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 v(e){return e===void 0}function h(e){return Object.prototype.toString.call(e)==="[object Array]"}function d(e){return typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"}function w(e){return Object.prototype.toString.call(e)==="[object Date]"}function M(e){return!e&&e!==0||h(e)&&e.length===0||d(e)&&!Object.keys(e).length}function N(e){return typeof Element>"u"?!1:e instanceof Element}const b=typeof window<"u",S=e=>typeof e=="number",k=e=>typeof e=="string",A=e=>k(e)?!Number.isNaN(Number(e)):!1;function L(e){return/^1[3-9]\d{9}$/.test(e)}function B(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 R(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 _(e,t="key",n="children"){const r={},i=(a,s)=>{for(let u=0;u<a.length;u++){const l=a[u],g=l[t];if(!r[g]){r[g]=l,s&&(r[g].parent=r[s]);const m=l[n];m&&m.length>0&&i(m,l[t])}}};return i(e),r}function P(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 S(e)?Number(t?Number(e).toFixed(t):e):Number.NaN}function J(e,t){return S(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 j(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 q(){localStorage.removeItem("token")}function V(e,t,n="local"){const r=n=="local"?localStorage:sessionStorage;t!=null&&r.setItem(e,JSON.stringify(t))}function Y(e,t="local"){let r=(t=="local"?localStorage:sessionStorage).getItem(e);return r&&JSON.parse(r||"")}function z(e,t="local"){(t=="local"?localStorage:sessionStorage).removeItem(e)}function G(e="local"){(e=="local"?localStorage:sessionStorage).clear()}function I(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 r=[];return e.global&&r.push("g"),e.multiline&&r.push("m"),e.ignoreCase&&r.push("i"),new RegExp(e.source,r.join(""))}if(t.call(e)==="[object FormData]"){const r=new FormData;for(const[i,a]of e.entries())r.append(i,a);return r}const n=Array.isArray(e)?[]:e.constructor?new e.constructor:{};for(const r in e)n[r]=I(e[r]);return n}function O(...e){let t=e.length,n=e[0];d(n)||(n={});for(let r=1;r<t;r++){let i=e[r];if(d(i))for(let a in i)a==="__proto__"||n===i[a]||(d(i[a])?n[a]=O(n[a],i[a]):n[a]=i[a])}return n}function T(e,t){return!e||e.tagName==="BODY"?null:e.classList.contains(t)?e:T(e.parentNode,t)}function D({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 K(e){e.forEach(t=>{D({path:t.url,name:t.name})})}async function Q(e){if(!e)return;const t=new FileReader;return t.readAsDataURL(e),new Promise((n,r)=>{t.onload=i=>{var a;return n((a=i.target)==null?void 0:a.result)},t.onerror=i=>r(void 0)})}const c=new Map;let F;b&&(document.addEventListener("mousedown",e=>F=e),document.addEventListener("mouseup",e=>{for(const t of c.values())for(const{documentHandler:n}of t)n(e,F)}));function C(e,t){let n=[];return Array.isArray(t.arg)?n=t.arg:N(t.arg)&&n.push(t.arg),function(r,i){const a=t.instance.popperRef,s=r.target,u=i==null?void 0:i.target,l=!t||!t.instance,g=!s||!u,m=e.contains(s)||e.contains(u),X=e===s,Z=n.length&&n.some(y=>y==null?void 0:y.contains(s))||n.length&&n.includes(u),x=a&&(a.contains(s)||a.contains(u));l||g||m||X||Z||x||t.value(r,i)}}const W={beforeMount(e,t){var n;c.has(e)||c.set(e,[]),(n=c.get(e))==null||n.push({documentHandler:C(e,t),bindingFn:t.value})},updated(e,t){c.has(e)||c.set(e,[]);const n=c.get(e),r=n==null?void 0:n.findIndex(a=>a.bindingFn===t.oldValue),i={documentHandler:C(e,t),bindingFn:t.value};r&&r>=0?n==null||n.splice(r,1,i):n==null||n.push(i)},unmounted(e){c.delete(e)}};o.ClickOutside=W,o.clearStorage=G,o.deepAssign=O,o.deepClone=I,o.downLoadFile=D,o.downLoadFiles=K,o.generateId=f,o.generateString=p,o.getParentByClass=T,o.getRandomInt=E,o.getStorage=Y,o.getToken=U,o.guiID=$,o.isArray=h,o.isClient=b,o.isDate=w,o.isElement=N,o.isEmpty=M,o.isIp=B,o.isMobile=L,o.isNumber=S,o.isObject=d,o.isPort=R,o.isString=k,o.isStringNumber=A,o.isUndefined=v,o.removeStorage=z,o.removeToken=q,o.setStorage=V,o.setToken=j,o.thousandSeparator=P,o.toBase64=Q,o.toFixed=J,o.toNumber=H,o.treeFlat=_,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(o,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(o=typeof globalThis<"u"?globalThis:o||self,f(o["@qy_better_lib/core"]={}))})(this,function(o){"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=h;return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function h(){return Math.floor((1+Math.random())*65536).toString(16).substring(1)}function $(e){return e===void 0}function N(e){return Object.prototype.toString.call(e)==="[object Array]"}function g(e){return typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"}function A(e){return Object.prototype.toString.call(e)==="[object Date]"}function M(e){return!e&&e!==0||N(e)&&e.length===0||g(e)&&!Object.keys(e).length}function O(e){return typeof Element>"u"?!1:e instanceof Element}const k=typeof window<"u",y=e=>typeof e=="number",v=e=>typeof e=="string",j=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 r={},i=(c,a)=>{for(let s=0;s<c.length;s++){const l=c[s],d=l[t];if(!r[d]){r[d]=l,a&&(r[d].parent=r[a]);const m=l[n];m&&m.length>0&&i(m,l[t])}}};return i(e),r}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 y(e)?Number(t?Number(e).toFixed(t):e):Number.NaN}function J(e,t){return y(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 r=n=="local"?localStorage:sessionStorage;t!=null&&r.setItem(e,JSON.stringify(t))}function z(e,t="local"){let r=(t=="local"?localStorage:sessionStorage).getItem(e);return r&&JSON.parse(r||"")}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 r=[];return e.global&&r.push("g"),e.multiline&&r.push("m"),e.ignoreCase&&r.push("i"),new RegExp(e.source,r.join(""))}if(t.call(e)==="[object FormData]"){const r=new FormData;for(const[i,c]of e.entries())r.append(i,c);return r}const n=Array.isArray(e)?[]:e.constructor?new e.constructor:{};for(const r in e)n[r]=E(e[r]);return n}function I(...e){let t=e.length,n=e[0];g(n)||(n={});for(let r=1;r<t;r++){let i=e[r];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!1;let n,r,i;if(Array.isArray(e)){if(n=e.length,n!=t.length)return!1;for(r=n;r--!==0;)if(!S(e[r],t[r]))return!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();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!Object.prototype.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const c=i[r];if(!S(e[c],t[c]))return!1}return!0}return e!==e&&t!==t}function T(e,t){return!e||e.tagName==="BODY"?null:e.classList.contains(t)?e:T(e.parentNode,t)}function D({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=>{D({path:t.url,name:t.name})})}async function W(e){if(!e)return;const t=new FileReader;return t.readAsDataURL(e),new Promise((n,r)=>{t.onload=i=>{var c;return n((c=i.target)==null?void 0:c.result)},t.onerror=i=>r(void 0)})}const u=new Map;let F;k&&(document.addEventListener("mousedown",e=>F=e),document.addEventListener("mouseup",e=>{for(const t of u.values())for(const{documentHandler:n}of t)n(e,F)}));function b(e,t){let n=[];return Array.isArray(t.arg)?n=t.arg:O(t.arg)&&n.push(t.arg),function(r,i){const c=t.instance.popperRef,a=r.target,s=i==null?void 0:i.target,l=!t||!t.instance,d=!a||!s,m=e.contains(a)||e.contains(s),Z=e===a,x=n.length&&n.some(p=>p==null?void 0:p.contains(a))||n.length&&n.includes(s),ee=c&&(c.contains(a)||c.contains(s));l||d||m||Z||x||ee||t.value(r,i)}}const X={beforeMount(e,t){var n;u.has(e)||u.set(e,[]),(n=u.get(e))==null||n.push({documentHandler:b(e,t),bindingFn:t.value})},updated(e,t){u.has(e)||u.set(e,[]);const n=u.get(e),r=n==null?void 0:n.findIndex(c=>c.bindingFn===t.oldValue),i={documentHandler:b(e,t),bindingFn:t.value};r&&r>=0?n==null||n.splice(r,1,i):n==null||n.push(i)},unmounted(e){u.delete(e)}};o.ClickOutside=X,o.clearStorage=K,o.deepAssign=I,o.deepClone=E,o.deepEqual=S,o.downLoadFile=D,o.downLoadFiles=Q,o.generateId=f,o.generateString=h,o.getParentByClass=T,o.getRandomInt=w,o.getStorage=z,o.getToken=U,o.guiID=C,o.isArray=N,o.isClient=k,o.isDate=A,o.isElement=O,o.isEmpty=M,o.isIp=R,o.isMobile=L,o.isNumber=y,o.isObject=g,o.isPort=B,o.isString=v,o.isStringNumber=j,o.isUndefined=$,o.removeStorage=G,o.removeToken=V,o.setStorage=Y,o.setToken=q,o.thousandSeparator=_,o.toBase64=W,o.toFixed=J,o.toNumber=H,o.treeFlat=P,Object.defineProperty(o,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 g, isElement as d, isEmpty as p, isIp as f, isMobile as l, isNumber as x, isObject as S, isPort as u, isString as b, isStringNumber as k, isUndefined as C } from "./utils/is.js";
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 N, toNumber as T } from "./utils/number.js";
5
- import { clearStorage as w, getStorage as A, getToken as B, removeStorage as D, removeToken as E, setStorage as L, setToken as O } from "./utils/storage.js";
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 q, downLoadFiles as z, toBase64 as G } from "./utils/file.js";
9
- import { default as J } from "./directives/click-outside.js";
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
- J as ClickOutside,
12
- w as clearStorage,
11
+ K as ClickOutside,
12
+ v as clearStorage,
13
13
  h as deepAssign,
14
14
  j as deepClone,
15
- q as downLoadFile,
16
- z as downLoadFiles,
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
- A as getStorage,
22
- B as getToken,
22
+ w as getStorage,
23
+ A as getToken,
23
24
  s as guiID,
24
25
  n as isArray,
25
26
  m as isClient,
26
- g as isDate,
27
- d as isElement,
27
+ d as isDate,
28
+ g as isElement,
28
29
  p as isEmpty,
29
- f as isIp,
30
- l as isMobile,
30
+ l as isIp,
31
+ f as isMobile,
31
32
  x as isNumber,
32
- S as isObject,
33
- u as isPort,
33
+ u as isObject,
34
+ S as isPort,
34
35
  b as isString,
35
36
  k as isStringNumber,
36
37
  C as isUndefined,
37
- D as removeStorage,
38
- E as removeToken,
38
+ B as removeStorage,
39
+ D as removeToken,
39
40
  L as setStorage,
40
41
  O as setToken,
41
42
  y as thousandSeparator,
42
- G as toBase64,
43
- N as toFixed,
44
- T as toNumber,
43
+ H as toBase64,
44
+ E as toFixed,
45
+ N as toNumber,
45
46
  I as treeFlat
46
47
  };
@@ -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;
@@ -1,39 +1,65 @@
1
- import { isObject as c } from "./is.js";
2
- function f(e) {
3
- const o = Object.prototype.toString;
1
+ import { isObject as i } from "./is.js";
2
+ function c(e) {
3
+ const r = 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 (o.call(e) === "[object Date]")
8
+ if (r.call(e) === "[object Date]")
9
9
  return new Date(e.getTime());
10
- if (o.call(e) === "[object RegExp]") {
10
+ if (r.call(e) === "[object RegExp]") {
11
11
  const t = [];
12
12
  return e.global && t.push("g"), e.multiline && t.push("m"), e.ignoreCase && t.push("i"), new RegExp(e.source, t.join(""));
13
13
  }
14
- if (o.call(e) === "[object FormData]") {
14
+ if (r.call(e) === "[object FormData]") {
15
15
  const t = new FormData();
16
- for (const [i, r] of e.entries())
17
- t.append(i, r);
16
+ for (const [o, f] of e.entries())
17
+ t.append(o, f);
18
18
  return t;
19
19
  }
20
20
  const n = Array.isArray(e) ? [] : e.constructor ? new e.constructor() : {};
21
21
  for (const t in e)
22
- n[t] = f(e[t]);
22
+ n[t] = c(e[t]);
23
23
  return n;
24
24
  }
25
25
  function l(...e) {
26
- let o = e.length, n = e[0];
27
- c(n) || (n = {});
28
- for (let t = 1; t < o; t++) {
29
- let i = e[t];
30
- if (c(i))
31
- for (let r in i)
32
- r === "__proto__" || n === i[r] || (c(i[r]) ? n[r] = l(n[r], i[r]) : n[r] = i[r]);
26
+ let r = e.length, n = e[0];
27
+ i(n) || (n = {});
28
+ for (let t = 1; t < r; t++) {
29
+ let o = e[t];
30
+ if (i(o))
31
+ for (let f in o)
32
+ f === "__proto__" || n === o[f] || (i(o[f]) ? n[f] = l(n[f], o[f]) : n[f] = o[f]);
33
33
  }
34
34
  return n;
35
35
  }
36
+ function u(e, r) {
37
+ if (e === r) return !0;
38
+ if (e && r && typeof e == "object" && typeof r == "object") {
39
+ if (e.constructor !== r.constructor) return !1;
40
+ let n, t, o;
41
+ if (Array.isArray(e)) {
42
+ if (n = e.length, n != r.length) return !1;
43
+ for (t = n; t-- !== 0; )
44
+ if (!u(e[t], r[t])) return !1;
45
+ return !0;
46
+ }
47
+ if (e.constructor === RegExp) return e.source === r.source && e.flags === r.flags;
48
+ if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === r.valueOf();
49
+ if (e.toString !== Object.prototype.toString) return e.toString() === r.toString();
50
+ if (o = Object.keys(e), n = o.length, n !== Object.keys(r).length) return !1;
51
+ for (t = n; t-- !== 0; )
52
+ if (!Object.prototype.hasOwnProperty.call(r, o[t])) return !1;
53
+ for (t = n; t-- !== 0; ) {
54
+ const f = o[t];
55
+ if (!u(e[f], r[f])) return !1;
56
+ }
57
+ return !0;
58
+ }
59
+ return e !== e && r !== r;
60
+ }
36
61
  export {
37
62
  l as deepAssign,
38
- f as deepClone
63
+ c as deepClone,
64
+ u as deepEqual
39
65
  };
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.5",
4
+ "version": "0.0.6",
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
+ }