zed/styles/utils/decamelizeTree.ts
Nathan Sobo 6734a0e69d Write theme JSON files from buildThemes script
Co-Authored-By: Nate Butler <1714999+iamnbutler@users.noreply.github.com>
2022-04-01 09:45:11 -06:00

21 lines
532 B
TypeScript

import { snakeCase } from "case-anything";
export default function decamelizeTree(object: { [key: string]: any }) {
const snakeObject: { [key: string]: any } = {};
for (const key in object) {
snakeObject[snakeCase(key)] = decamelizeValue(object[key]);
}
return snakeObject;
}
function decamelizeValue(value: any): any {
if (typeof value === "object") {
if (Array.isArray(value)) {
return value.map(decamelizeValue);
} else {
return decamelizeTree(value);
}
} else {
return value;
}
}