panzerdp/voca

Reverse camelcase?

jsodeman opened this issue · 1 comments

I like Voca better than the alternatives, but I can't see how you would convert camelcase into words. In other libs it's called .humanize

For example:

"camelCase" -> "camel case"

Looking for the same. Found a solution on https://zellwk.com/blog/case-conversion/, first convert the string to kebabCase via voca, then applying the presented solution.

import { kebabCase } from 'voca'

const humanize = (string: string) => {
  const interim = kebabCase(string).replace(/-/g, ' ')

  return interim.slice(0, 1).toUpperCase() + interim.slice(1)
}