Skip to content

Instantly share code, notes, and snippets.

@antonybudianto
Last active May 28, 2022 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonybudianto/f222f9b4a6a7a48d28522b0be16440f7 to your computer and use it in GitHub Desktop.
Save antonybudianto/f222f9b4a6a7a48d28522b0be16440f7 to your computer and use it in GitHub Desktop.
snake to camel
const A = (O) => {
const keys = Object.keys(O);
const newO = {};
keys.forEach((k) => {
const newK = k
.split("_")
.map((s, i) => {
if (i > 0) {
return s[0].toUpperCase() + s.substring(1);
}
return s;
})
.join("");
let v = O[k];
if (typeof v === "object" && v !== null) {
v = A(v);
}
newO[newK] = v;
});
return newO;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment