| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | const uppercasePattern = /([A-Z])/g; |
| 11 | const msPattern = /^ms-/; |
| 12 | |
| 13 | /** |
| 14 | * Hyphenates a camelcased CSS property name, for example: |
| 15 | * |
| 16 | * > hyphenateStyleName('backgroundColor') |
| 17 | * < "background-color" |
| 18 | * > hyphenateStyleName('MozTransition') |
| 19 | * < "-moz-transition" |
| 20 | * > hyphenateStyleName('msTransition') |
| 21 | * < "-ms-transition" |
| 22 | * |
| 23 | * As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix |
| 24 | * is converted to `-ms-`. |
| 25 | */ |
| 26 | export default function hyphenateStyleName(name: string): string { |
| 27 | return name |
| 28 | .replace(uppercasePattern, '-$1') |
| 29 | .toLowerCase() |
| 30 | .replace(msPattern, '-ms-'); |
| 31 | } |