Last active
May 28, 2022 10:50
-
-
Save antonybudianto/f222f9b4a6a7a48d28522b0be16440f7 to your computer and use it in GitHub Desktop.
snake to camel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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