Skip to the code
cf.
+10 XP

#603 CSS Property to Style Key

easy

Your design system stores CSS property names like background-color, but the component library expects JavaScript style keys like backgroundColor.

Write toStyleKey(property) that converts a property name. Remove every - and make the letter right after it uppercase. A leading - (as in vendor prefixes) works the same way, so -webkit-line-clamp becomes WebkitLineClamp.

CSS custom properties start with -- and must stay exactly as they are, so --brand-color is returned unchanged. An empty string returns an empty string.

Example 1

Input: property = "background-color"
Output: "backgroundColor"

The c after the dash becomes C and the dash is dropped.

Example 2

Input: property = "-webkit-line-clamp"
Output: "WebkitLineClamp"

The leading dash makes the w uppercase too.

Constraints

  • 0 <= property.length <= 100
  • property contains lowercase letters, digits, and -.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).