@emqx/shared-ui-utils 0.0.10 → 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/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './objectUtils';
2
2
  export * from './jsonUtils';
3
3
  export * from './format';
4
+ export * from './download';
package/dist/index.js CHANGED
@@ -1,60 +1,64 @@
1
- const i = (r, t = [], e = {}) => {
2
- if (typeof r == "object" && !Array.isArray(r) && r !== null)
3
- for (const n of Object.keys(r))
4
- i(r[n], t.concat(n), e);
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
- e[t.join(".")] = r;
7
- return e;
8
- }, f = (r) => {
9
- if (Object(r) !== r && !Array.isArray(r))
10
- return r;
11
- const t = /\.?([^.[\]]+)|\[(\d+)\]/g, e = {};
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 n in r) {
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];
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 (n) {
20
- console.error(n);
19
+ } catch (t) {
20
+ console.error(t);
21
21
  }
22
- return e[""] || e;
23
- }, l = (r) => Object.keys(r).length === 0, y = (r) => {
22
+ return n[""] || n;
23
+ }, a = (e) => Object.keys(e).length === 0, y = (e) => {
24
24
  try {
25
- return JSON.parse(r);
25
+ return JSON.parse(e);
26
26
  } catch {
27
27
  console.error("An error occurred while parsing the JSON string");
28
28
  }
29
- }, u = (r, t) => {
29
+ }, u = (e, r) => {
30
30
  try {
31
- return typeof r == "string" ? r : JSON.stringify(r, null, t);
32
- } catch (e) {
33
- return console.error(e), "stringify 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
- }, a = (r) => {
36
- if (typeof r != "string")
35
+ }, f = (e) => {
36
+ if (typeof e != "string")
37
37
  return !1;
38
38
  try {
39
- const t = JSON.parse(r);
40
- return typeof t == "object" && t !== null;
39
+ const r = JSON.parse(e);
40
+ return typeof r == "object" && r !== null;
41
41
  } catch {
42
42
  return !1;
43
43
  }
44
- }, p = (r) => {
45
- if (typeof r != "number" || isNaN(r) || r < 0)
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 (r === 0)
47
+ if (e === 0)
48
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]}`;
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
- p as formatSizeUnit,
55
- l as isEmptyObj,
56
- a as isJSONString,
58
+ d as formatSizeUnit,
59
+ a as isEmptyObj,
60
+ f as isJSONString,
57
61
  y as parseJSONSafely,
58
62
  u as stringifyObjSafely,
59
- f as unflattenObject
63
+ l as unflattenObject
60
64
  };
@@ -1 +1 @@
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"})});
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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emqx/shared-ui-utils",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "homepage": "https://emqx.io",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {