@formo/analytics 1.13.3-alpha.4 → 1.13.3-alpha.5
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/cjs/src/lib/utils.d.ts.map +1 -1
- package/dist/cjs/src/lib/utils.js +7 -5
- package/dist/cjs/src/lib/utils.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/lib/utils.d.ts.map +1 -1
- package/dist/esm/src/lib/utils.js +7 -5
- package/dist/esm/src/lib/utils.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/utils.ts +7 -5
package/package.json
CHANGED
package/src/lib/utils.ts
CHANGED
|
@@ -7,13 +7,15 @@ const toSnake = (str: string) =>
|
|
|
7
7
|
// Converts object keys to snake_case, omitting keys in the omitKeys array
|
|
8
8
|
export function toSnakeCase(obj: any, omitKeys: string[] = []) {
|
|
9
9
|
const convert = (data: any): any => {
|
|
10
|
-
if (Array.isArray(
|
|
11
|
-
return
|
|
12
|
-
} else if (
|
|
13
|
-
return Object.keys(
|
|
10
|
+
if (Array.isArray(data)) {
|
|
11
|
+
return data.map(convert); // Recursively handle array elements
|
|
12
|
+
} else if (data !== null && typeof data === "object") {
|
|
13
|
+
return Object.keys(data).reduce((acc: any, key) => {
|
|
14
14
|
// If the key is in omitKeys, keep it as it is
|
|
15
15
|
const resultKey = omitKeys.includes(key) ? key : toSnake(key);
|
|
16
|
-
acc[resultKey] = omitKeys.includes(key)
|
|
16
|
+
acc[resultKey] = omitKeys.includes(key)
|
|
17
|
+
? data[key]
|
|
18
|
+
: convert(data[key]);
|
|
17
19
|
return acc;
|
|
18
20
|
}, {});
|
|
19
21
|
}
|