@emqx/shared-ui-utils 0.0.5 → 0.0.7
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 +1 -1
- package/dist/index.js +25 -4
- package/dist/index.umd.cjs +1 -1
- package/dist/jsonUtils.d.ts +13 -0
- package/dist/objectUtils.d.ts +24 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './objectUtils';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
5
|
+
else
|
|
6
|
+
t[c.join(".")] = e;
|
|
7
|
+
return t;
|
|
8
|
+
}, a = (e) => {
|
|
9
|
+
if (Object(e) !== e && !Array.isArray(e))
|
|
10
|
+
return e;
|
|
11
|
+
const c = /\.?([^.[\]]+)|\[(\d+)\]/g, t = {};
|
|
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];
|
|
18
|
+
}
|
|
19
|
+
} catch (r) {
|
|
20
|
+
console.error(r);
|
|
21
|
+
}
|
|
22
|
+
return t[""] || t;
|
|
23
|
+
};
|
|
4
24
|
export {
|
|
5
|
-
|
|
25
|
+
o as flattenObject,
|
|
26
|
+
a as unflattenObject
|
|
6
27
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
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"})});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a JSON string safely and returns a JavaScript object.
|
|
3
|
+
* @param str - The JSON string to parse.
|
|
4
|
+
* @returns A JavaScript object if parsing is successful, otherwise void.
|
|
5
|
+
*/
|
|
6
|
+
export declare const parseJSONSafely: (str: any) => Record<string, any> | void;
|
|
7
|
+
/**
|
|
8
|
+
* Safely stringify a JavaScript object to a JSON string, handling circular references.
|
|
9
|
+
* @param obj - The object to stringify.
|
|
10
|
+
* @param tabSpaces - The number of spaces to use for indentation.
|
|
11
|
+
* @returns The JSON string representation of the object, or 'stringify error' if an error occurs.
|
|
12
|
+
*/
|
|
13
|
+
export declare const stringifyObjSafely: (obj: Record<string, any>, tabSpaces?: number) => string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flattens a nested object into a single-level object with dot-separated keys.
|
|
3
|
+
* @param obj - The object to flatten.
|
|
4
|
+
* @param prefix - An optional array of keys to use as a prefix for the flattened keys.
|
|
5
|
+
* @param current - An optional object to use as the initial flattened object.
|
|
6
|
+
* @returns The flattened object.
|
|
7
|
+
* Example: { a: { b: c: 1 } } => { 'a.b.c': 1 }
|
|
8
|
+
*/
|
|
9
|
+
export declare const flattenObject: (obj: {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}, prefix?: any[], current?: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}) => {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Converts a flattened object to a nested object.
|
|
18
|
+
* @param obj - The flattened object to convert.
|
|
19
|
+
* @returns The nested object.
|
|
20
|
+
* Example: { 'a.b.c': 1 } => { a: { b: { c: 1 } } }
|
|
21
|
+
*/
|
|
22
|
+
export declare const unflattenObject: (obj: {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}) => any;
|