Snake case to camel case

PHOTO EMBED

Tue Aug 09 2022 19:30:37 GMT+0000 (Coordinated Universal Time)

Saved by @johnnye562 #javascript

const snakeToCamelCase = (text) => {
  if (!(typeof text === "string" || text instanceof String)) {
    console.error(`string expected, ${typeof text} provided`)
    return text
  }
  text
    .toLowerCase()
    .replace(/([-_][a-z])/g, group =>
      group
        .toUpperCase()
        .replace("-", "")
        .replace("_", "")
    )
}

snakeToCamelCase("snake_case_to_camel_case") // snakeCaseToCamelCase
content_copyCOPY

https://justacoding.blog/9-useful-javascript-utility-functions/