Skip to content

Instantly share code, notes, and snippets.

@alex-cory
Created November 20, 2018 18:42
Show Gist options
  • Save alex-cory/2f503aeb3b3a22f3a69cdf8750f9a878 to your computer and use it in GitHub Desktop.
Save alex-cory/2f503aeb3b3a22f3a69cdf8750f9a878 to your computer and use it in GitHub Desktop.
converts strings to a different case
/**
* this_is_snake_case
* thisIsCamelCase
* this-is-cabob-case
*/
const camelToSnakeCase = w => w.replace(/([A-Z])/g, l => '_' + l.toLowerCase())
const toCamel = s => s.replace(/(\-[a-z])/g, l => l.toUpperCase().replace('-',''))
const cabobToCamelCase = s => s.replace(/([A-Z])/g, l => "-"+l.toLowerCase())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment