fix snake-case of arrays

This commit is contained in:
Dave Horton
2021-05-07 16:29:40 -04:00
parent 5cc4852bf9
commit 686cf1b094
3 changed files with 41 additions and 88 deletions

View File

@@ -3,8 +3,11 @@ const snakeCase = require('to-snake-case');
const isObject = (value) => typeof value === 'object' && value !== null;
const snakeObject = (obj, excludes) => {
const target = {};
if (Array.isArray(obj)) return obj.map((o) => {
return isObject(o) ? snakeObject(o, excludes) : o;
});
const target = {};
for (const [key, value] of Object.entries(obj)) {
if (excludes.includes(key)) {
target[key] = value;