Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame
502 Bytes
import type { FieldValues } from '../types';
import { isObjectType } from './isObject';
export const flatten = (obj: FieldValues) => {
const output: FieldValues = {};
for (const key of Object.keys(obj)) {
if (isObjectType(obj[key]) && obj[key] !== null) {
const nested = flatten(obj[key]);
for (const nestedKey of Object.keys(nested)) {
output[`${key}.${nestedKey}`] = nested[nestedKey];
}
} else {
output[key] = obj[key];
}
}
return output;
};