@emqx/shared-ui-utils 0.0.8 → 0.0.10
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/format.d.ts +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +33 -25
- 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/format.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a size unit value into a human-readable string representation.
|
|
3
|
+
* @param val - The size unit value to format.
|
|
4
|
+
* @returns A string representing the formatted size unit value.
|
|
5
|
+
* @throws {Error} If the input is not a non-negative number.
|
|
6
|
+
*/
|
|
7
|
+
export declare const formatSizeUnit: (val: number) => string;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,52 +1,60 @@
|
|
|
1
|
-
const
|
|
1
|
+
const i = (r, t = [], e = {}) => {
|
|
2
2
|
if (typeof r == "object" && !Array.isArray(r) && r !== null)
|
|
3
3
|
for (const n of Object.keys(r))
|
|
4
|
-
|
|
4
|
+
i(r[n], t.concat(n), e);
|
|
5
5
|
else
|
|
6
|
-
t
|
|
7
|
-
return
|
|
8
|
-
},
|
|
6
|
+
e[t.join(".")] = r;
|
|
7
|
+
return e;
|
|
8
|
+
}, f = (r) => {
|
|
9
9
|
if (Object(r) !== r && !Array.isArray(r))
|
|
10
10
|
return r;
|
|
11
|
-
const
|
|
11
|
+
const t = /\.?([^.[\]]+)|\[(\d+)\]/g, e = {};
|
|
12
12
|
try {
|
|
13
13
|
for (const n in r) {
|
|
14
|
-
let
|
|
15
|
-
for (;
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
let o = e, s = "", c;
|
|
15
|
+
for (; c = t.exec(n); )
|
|
16
|
+
o = o[s] || (o[s] = c[2] ? [] : {}), s = c[2] || c[1];
|
|
17
|
+
o[s] = r[n];
|
|
18
18
|
}
|
|
19
19
|
} catch (n) {
|
|
20
20
|
console.error(n);
|
|
21
21
|
}
|
|
22
|
-
return
|
|
23
|
-
},
|
|
22
|
+
return e[""] || e;
|
|
23
|
+
}, l = (r) => Object.keys(r).length === 0, y = (r) => {
|
|
24
24
|
try {
|
|
25
25
|
return JSON.parse(r);
|
|
26
26
|
} catch {
|
|
27
27
|
console.error("An error occurred while parsing the JSON string");
|
|
28
28
|
}
|
|
29
|
-
},
|
|
29
|
+
}, u = (r, t) => {
|
|
30
30
|
try {
|
|
31
|
-
return typeof r == "string" ? r : JSON.stringify(r, null,
|
|
32
|
-
} catch (
|
|
33
|
-
return console.error(
|
|
31
|
+
return typeof r == "string" ? r : JSON.stringify(r, null, t);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return console.error(e), "stringify error";
|
|
34
34
|
}
|
|
35
|
-
},
|
|
35
|
+
}, a = (r) => {
|
|
36
36
|
if (typeof r != "string")
|
|
37
37
|
return !1;
|
|
38
38
|
try {
|
|
39
|
-
const
|
|
40
|
-
return typeof
|
|
39
|
+
const t = JSON.parse(r);
|
|
40
|
+
return typeof t == "object" && t !== null;
|
|
41
41
|
} catch {
|
|
42
42
|
return !1;
|
|
43
43
|
}
|
|
44
|
+
}, p = (r) => {
|
|
45
|
+
if (typeof r != "number" || isNaN(r) || r < 0)
|
|
46
|
+
throw new Error("Invalid input: input should be a non-negative number");
|
|
47
|
+
if (r === 0)
|
|
48
|
+
return "0 Bytes";
|
|
49
|
+
const t = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], e = Math.floor(Math.log(r) / Math.log(1024));
|
|
50
|
+
return `${(r / 1024 ** e).toFixed(1)} ${t[e]}`;
|
|
44
51
|
};
|
|
45
52
|
export {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
a as
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
i as flattenObject,
|
|
54
|
+
p as formatSizeUnit,
|
|
55
|
+
l as isEmptyObj,
|
|
56
|
+
a as isJSONString,
|
|
57
|
+
y as parseJSONSafely,
|
|
58
|
+
u as stringifyObjSafely,
|
|
59
|
+
f as unflattenObject
|
|
52
60
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r["@emqx/shared-ui-utils"]={}))})(this,function(r){"use strict";const o=(e,t=[],n={})=>{if(typeof e=="object"&&!Array.isArray(e)&&e!==null)for(const i of Object.keys(e))o(e[i],t.concat(i),n);else n[t.join(".")]=e;return n},u=e=>{if(Object(e)!==e&&!Array.isArray(e))return e;const t=/\.?([^.[\]]+)|\[(\d+)\]/g,n={};try{for(const i in e){let s=n,c="",f;for(;f=t.exec(i);)s=s[c]||(s[c]=f[2]?[]:{}),c=f[2]||f[1];s[c]=e[i]}}catch(i){console.error(i)}return n[""]||n},l=e=>Object.keys(e).length===0,y=e=>{try{return JSON.parse(e)}catch{console.error("An error occurred while parsing the JSON string")}},a=(e,t)=>{try{return typeof e=="string"?e:JSON.stringify(e,null,t)}catch(n){return console.error(n),"stringify error"}},O=e=>{if(typeof e!="string")return!1;try{const t=JSON.parse(e);return typeof t=="object"&&t!==null}catch{return!1}},d=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"],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**n).toFixed(1)} ${t[n]}`};r.flattenObject=o,r.formatSizeUnit=d,r.isEmptyObj=l,r.isJSONString=O,r.parseJSONSafely=y,r.stringifyObjSafely=a,r.unflattenObject=u,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|