Skip to content

Instantly share code, notes, and snippets.

@pinkhominid
Created March 3, 2021 14:21
Show Gist options
  • Save pinkhominid/3f6106ba3a1a0b2b720e86c183e0bbe5 to your computer and use it in GitHub Desktop.
Save pinkhominid/3f6106ba3a1a0b2b720e86c183e0bbe5 to your computer and use it in GitHub Desktop.
Case conversion utils
// Derived from https://stackoverflow.com/a/52551910
export function camelize(str) {
return str.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
}
export function pascalize(str) {
return (' ' + str).toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment