@emqx/shared-ui-utils 0.0.9 → 0.0.11
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/download.d.ts +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +41 -37
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a download link for a given Blob data with the specified filename.
|
|
3
|
+
* The link is automatically clicked to initiate the download, and then removed from the document body.
|
|
4
|
+
*
|
|
5
|
+
* @param blobData - The Blob data to be downloaded.
|
|
6
|
+
* @param filename - The name of the file to be downloaded.
|
|
7
|
+
*/
|
|
8
|
+
export declare const createDownloadBlobLink: (blobData: Blob, filename: string) => void;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,60 +1,64 @@
|
|
|
1
|
-
const i = (
|
|
2
|
-
if (typeof
|
|
3
|
-
for (const
|
|
4
|
-
i(
|
|
1
|
+
const i = (e, r = [], n = {}) => {
|
|
2
|
+
if (typeof e == "object" && !Array.isArray(e) && e !== null)
|
|
3
|
+
for (const t of Object.keys(e))
|
|
4
|
+
i(e[t], r.concat(t), n);
|
|
5
5
|
else
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
},
|
|
9
|
-
if (Object(
|
|
10
|
-
return
|
|
11
|
-
const
|
|
6
|
+
n[r.join(".")] = e;
|
|
7
|
+
return n;
|
|
8
|
+
}, l = (e) => {
|
|
9
|
+
if (Object(e) !== e && !Array.isArray(e))
|
|
10
|
+
return e;
|
|
11
|
+
const r = /\.?([^.[\]]+)|\[(\d+)\]/g, n = {};
|
|
12
12
|
try {
|
|
13
|
-
for (const
|
|
14
|
-
let o =
|
|
15
|
-
for (;
|
|
16
|
-
o = o[
|
|
17
|
-
o[
|
|
13
|
+
for (const t in e) {
|
|
14
|
+
let o = n, c = "", s;
|
|
15
|
+
for (; s = r.exec(t); )
|
|
16
|
+
o = o[c] || (o[c] = s[2] ? [] : {}), c = s[2] || s[1];
|
|
17
|
+
o[c] = e[t];
|
|
18
18
|
}
|
|
19
|
-
} catch (
|
|
20
|
-
console.error(
|
|
19
|
+
} catch (t) {
|
|
20
|
+
console.error(t);
|
|
21
21
|
}
|
|
22
|
-
return
|
|
23
|
-
},
|
|
22
|
+
return n[""] || n;
|
|
23
|
+
}, a = (e) => Object.keys(e).length === 0, y = (e) => {
|
|
24
24
|
try {
|
|
25
|
-
return JSON.parse(
|
|
25
|
+
return JSON.parse(e);
|
|
26
26
|
} catch {
|
|
27
27
|
console.error("An error occurred while parsing the JSON string");
|
|
28
28
|
}
|
|
29
|
-
}, u = (
|
|
29
|
+
}, u = (e, r) => {
|
|
30
30
|
try {
|
|
31
|
-
return typeof
|
|
32
|
-
} catch (
|
|
33
|
-
return console.error(
|
|
31
|
+
return typeof e == "string" ? e : JSON.stringify(e, null, r);
|
|
32
|
+
} catch (n) {
|
|
33
|
+
return console.error(n), "stringify error";
|
|
34
34
|
}
|
|
35
|
-
},
|
|
36
|
-
if (typeof
|
|
35
|
+
}, f = (e) => {
|
|
36
|
+
if (typeof e != "string")
|
|
37
37
|
return !1;
|
|
38
38
|
try {
|
|
39
|
-
const
|
|
40
|
-
return typeof
|
|
39
|
+
const r = JSON.parse(e);
|
|
40
|
+
return typeof r == "object" && r !== null;
|
|
41
41
|
} catch {
|
|
42
42
|
return !1;
|
|
43
43
|
}
|
|
44
|
-
},
|
|
45
|
-
if (typeof
|
|
44
|
+
}, d = (e) => {
|
|
45
|
+
if (typeof e != "number" || isNaN(e) || e < 0)
|
|
46
46
|
throw new Error("Invalid input: input should be a non-negative number");
|
|
47
|
-
if (
|
|
47
|
+
if (e === 0)
|
|
48
48
|
return "0 Bytes";
|
|
49
|
-
const
|
|
50
|
-
return `${(
|
|
49
|
+
const r = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], n = Math.floor(Math.log(e) / Math.log(1024));
|
|
50
|
+
return `${(e / 1024 ** n).toFixed(1)} ${r[n]}`;
|
|
51
|
+
}, p = (e, r) => {
|
|
52
|
+
const n = window.URL.createObjectURL(new Blob([e])), t = document.createElement("a");
|
|
53
|
+
t.style.display = "none", t.href = n, t.download = r, document.body.appendChild(t), t.click(), document.body.removeChild(t);
|
|
51
54
|
};
|
|
52
55
|
export {
|
|
56
|
+
p as createDownloadBlobLink,
|
|
53
57
|
i as flattenObject,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
d as formatSizeUnit,
|
|
59
|
+
a as isEmptyObj,
|
|
60
|
+
f as isJSONString,
|
|
57
61
|
y as parseJSONSafely,
|
|
58
62
|
u as stringifyObjSafely,
|
|
59
|
-
|
|
63
|
+
l as unflattenObject
|
|
60
64
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o["@emqx/shared-ui-utils"]={}))})(this,function(o){"use strict";const i=(e,t=[],r={})=>{if(typeof e=="object"&&!Array.isArray(e)&&e!==null)for(const n of Object.keys(e))i(e[n],t.concat(n),r);else r[t.join(".")]=e;return r},f=e=>{if(Object(e)!==e&&!Array.isArray(e))return e;const t=/\.?([^.[\]]+)|\[(\d+)\]/g,r={};try{for(const n in e){let c=r,s="",l;for(;l=t.exec(n);)c=c[s]||(c[s]=l[2]?[]:{}),s=l[2]||l[1];c[s]=e[n]}}catch(n){console.error(n)}return r[""]||r},a=e=>Object.keys(e).length===0,u=e=>{try{return JSON.parse(e)}catch{console.error("An error occurred while parsing the JSON string")}},y=(e,t)=>{try{return typeof e=="string"?e:JSON.stringify(e,null,t)}catch(r){return console.error(r),"stringify error"}},d=e=>{if(typeof e!="string")return!1;try{const t=JSON.parse(e);return typeof t=="object"&&t!==null}catch{return!1}},h=e=>{if(typeof e!="number"||isNaN(e)||e<0)throw new Error("Invalid input: input should be a non-negative number");if(e===0)return"0 Bytes";const t=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],r=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**r).toFixed(1)} ${t[r]}`},O=(e,t)=>{const r=window.URL.createObjectURL(new Blob([e])),n=document.createElement("a");n.style.display="none",n.href=r,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n)};o.createDownloadBlobLink=O,o.flattenObject=i,o.formatSizeUnit=h,o.isEmptyObj=a,o.isJSONString=d,o.parseJSONSafely=u,o.stringifyObjSafely=y,o.unflattenObject=f,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|