You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
525 B

4 years ago
  1. /**
  2. * Convert a string from camel case to dash-case
  3. * @param {string} string - probably a component tag name
  4. * @returns {string} component name normalized
  5. */
  6. export function camelToDashCase(string) {
  7. return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
  8. }
  9. /**
  10. * Convert a string containing dashes to camel case
  11. * @param {string} string - input string
  12. * @returns {string} my-string -> myString
  13. */
  14. export function dashToCamelCase(string) {
  15. return string.replace(/-(\w)/g, (_, c) => c.toUpperCase())
  16. }