@emqx/shared-ui-utils 0.0.7 → 0.0.8

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 +1,2 @@
1
1
  export * from './objectUtils';
2
+ export * from './jsonUtils';
package/dist/index.js CHANGED
@@ -1,27 +1,52 @@
1
- const o = (e, c = [], t = {}) => {
2
- if (typeof e == "object" && !Array.isArray(e) && e !== null)
3
- for (const r of Object.keys(e))
4
- o(e[r], c.concat(r), t);
1
+ const l = (r, e = [], t = {}) => {
2
+ if (typeof r == "object" && !Array.isArray(r) && r !== null)
3
+ for (const n of Object.keys(r))
4
+ l(r[n], e.concat(n), t);
5
5
  else
6
- t[c.join(".")] = e;
6
+ t[e.join(".")] = r;
7
7
  return t;
8
- }, a = (e) => {
9
- if (Object(e) !== e && !Array.isArray(e))
10
- return e;
11
- const c = /\.?([^.[\]]+)|\[(\d+)\]/g, t = {};
8
+ }, i = (r) => {
9
+ if (Object(r) !== r && !Array.isArray(r))
10
+ return r;
11
+ const e = /\.?([^.[\]]+)|\[(\d+)\]/g, t = {};
12
12
  try {
13
- for (const r in e) {
14
- let n = t, l = "", s;
15
- for (; s = c.exec(r); )
16
- n = n[l] || (n[l] = s[2] ? [] : {}), l = s[2] || s[1];
17
- n[l] = e[r];
13
+ for (const n in r) {
14
+ let c = t, s = "", o;
15
+ for (; o = e.exec(n); )
16
+ c = c[s] || (c[s] = o[2] ? [] : {}), s = o[2] || o[1];
17
+ c[s] = r[n];
18
18
  }
19
- } catch (r) {
20
- console.error(r);
19
+ } catch (n) {
20
+ console.error(n);
21
21
  }
22
22
  return t[""] || t;
23
+ }, y = (r) => Object.keys(r).length === 0, a = (r) => {
24
+ try {
25
+ return JSON.parse(r);
26
+ } catch {
27
+ console.error("An error occurred while parsing the JSON string");
28
+ }
29
+ }, f = (r, e) => {
30
+ try {
31
+ return typeof r == "string" ? r : JSON.stringify(r, null, e);
32
+ } catch (t) {
33
+ return console.error(t), "stringify error";
34
+ }
35
+ }, u = (r) => {
36
+ if (typeof r != "string")
37
+ return !1;
38
+ try {
39
+ const e = JSON.parse(r);
40
+ return typeof e == "object" && e !== null;
41
+ } catch {
42
+ return !1;
43
+ }
23
44
  };
24
45
  export {
25
- o as flattenObject,
26
- a as unflattenObject
46
+ l as flattenObject,
47
+ y as isEmptyObj,
48
+ u as isJSONString,
49
+ a as parseJSONSafely,
50
+ f as stringifyObjSafely,
51
+ i as unflattenObject
27
52
  };
@@ -1 +1 @@
1
- (function(t,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(t=typeof globalThis<"u"?globalThis:t||self,c(t["@emqx/shared-ui-utils"]={}))})(this,function(t){"use strict";const c=(e,i=[],n={})=>{if(typeof e=="object"&&!Array.isArray(e)&&e!==null)for(const r of Object.keys(e))c(e[r],i.concat(r),n);else n[i.join(".")]=e;return n},l=e=>{if(Object(e)!==e&&!Array.isArray(e))return e;const i=/\.?([^.[\]]+)|\[(\d+)\]/g,n={};try{for(const r in e){let f=n,o="",s;for(;s=i.exec(r);)f=f[o]||(f[o]=s[2]?[]:{}),o=s[2]||s[1];f[o]=e[r]}}catch(r){console.error(r)}return n[""]||n};t.flattenObject=c,t.unflattenObject=l,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ (function(t,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(t=typeof globalThis<"u"?globalThis:t||self,s(t["@emqx/shared-ui-utils"]={}))})(this,function(t){"use strict";const s=(e,r=[],n={})=>{if(typeof e=="object"&&!Array.isArray(e)&&e!==null)for(const i of Object.keys(e))s(e[i],r.concat(i),n);else n[r.join(".")]=e;return n},l=e=>{if(Object(e)!==e&&!Array.isArray(e))return e;const r=/\.?([^.[\]]+)|\[(\d+)\]/g,n={};try{for(const i in e){let c=n,f="",o;for(;o=r.exec(i);)c=c[f]||(c[f]=o[2]?[]:{}),f=o[2]||o[1];c[f]=e[i]}}catch(i){console.error(i)}return n[""]||n},y=e=>Object.keys(e).length===0,u=e=>{try{return JSON.parse(e)}catch{console.error("An error occurred while parsing the JSON string")}},a=(e,r)=>{try{return typeof e=="string"?e:JSON.stringify(e,null,r)}catch(n){return console.error(n),"stringify error"}},O=e=>{if(typeof e!="string")return!1;try{const r=JSON.parse(e);return typeof r=="object"&&r!==null}catch{return!1}};t.flattenObject=s,t.isEmptyObj=y,t.isJSONString=O,t.parseJSONSafely=u,t.stringifyObjSafely=a,t.unflattenObject=l,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
@@ -11,3 +11,9 @@ export declare const parseJSONSafely: (str: any) => Record<string, any> | void;
11
11
  * @returns The JSON string representation of the object, or 'stringify error' if an error occurs.
12
12
  */
13
13
  export declare const stringifyObjSafely: (obj: Record<string, any>, tabSpaces?: number) => string;
14
+ /**
15
+ * Checks if a given string is a valid JSON string.
16
+ * @param str - The string to be checked.
17
+ * @returns A boolean indicating whether the string is a valid JSON string or not.
18
+ */
19
+ export declare const isJSONString: (str: string) => boolean;
@@ -22,3 +22,9 @@ export declare const flattenObject: (obj: {
22
22
  export declare const unflattenObject: (obj: {
23
23
  [key: string]: any;
24
24
  }) => any;
25
+ /**
26
+ * Checks if an object is empty.
27
+ * @param obj - The object to check.
28
+ * @returns True if the object is empty, false otherwise.
29
+ */
30
+ export declare const isEmptyObj: (obj: Record<any, any>) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emqx/shared-ui-utils",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "homepage": "https://emqx.io",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {