Skip to content

Instantly share code, notes, and snippets.

@dtomasi
Created April 18, 2017 09:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtomasi/9327f704398be8d8ff5d0ab560b95641 to your computer and use it in GitHub Desktop.
Save dtomasi/9327f704398be8d8ff5d0ab560b95641 to your computer and use it in GitHub Desktop.
CamelCase to kebab-case and backwards
/**
* Convert Strings from camelCase to kebab-case
* @returns {string}
* @param input
*/
static camelToKebab(input: string) {
return input.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
/**
* Convert Strings from kebab-case to camelCase
* @returns {string}
* @param input
*/
static kebabToCamel(input: string) {
return input.replace(/-([a-z])/g, function (g) {
return g[1].toUpperCase();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment