Convert PascalCase to kebab-case!

String
Result

Convert PascalCase to kebab-case!

Is the variable naming in the code you copied from somewhere else different from your code? Don't worry! It converts variables to your desired naming convention!

Converts PascalCase to kebab-case: SearchResultList → search-result-list. Component names are PascalCase in code, but HTML-facing names are hyphenated: Vue components used in DOM templates, custom element tags, CSS class names in BEM, and file names in many style guides.

Paste component usages, class names or a list of exports to get the tag, file or class names on the markup side.

How to use

  1. Set the source to PascalCase and the target to kebab-case.
  2. Paste template markup, component names or exports into String.
  3. Copy the result from Result.

Example

Input (PascalCase)
<DatePicker />
<UserCard :user="user" />
<SearchResultList />
Output (kebab-case)
<date-picker />
<user-card :user="user" />
<search-result-list />

The component tags become hyphenated, which is the form Vue requires when templates are written directly in an HTML file. The :user="user" binding is lowercase and is not changed.

Supported features

  • Inserts a hyphen before each capital after the first and lowercases the name: UserCard → user-card.
  • Leaves surrounding markup such as <, /> and attributes alone.
  • Digits stay attached: Step2Form → step2-form.

Use cases

Vue components in in-DOM templates

HTML is case-insensitive, so <DatePicker> written inside an .html page must be <date-picker>. Converting the markup does that for every multi-word component at once.

File and CSS class names from components

Style guides that name files date-picker.tsx or use a .search-result-list block class can derive both from the component name.

Notes and limitations

  • Acronyms stay in one piece: XMLParser → xml-parser, UIButtonGroup → ui-button-group.
  • One-word components (Modal, Button) are not recognized and stay capitalized, so adjust them by hand.

FAQ

Is this how Angular selectors are named?

Angular selectors are kebab-case with a prefix, such as app-user-card for UserCardComponent. Convert the name and add the prefix yourself.

Why is <Modal /> unchanged?

Only names with at least two capitals are treated as PascalCase, so single-word components are skipped.