hyphenate.js.flow 690 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  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. * @providesModule hyphenate
  8. * @typechecks
  9. */
  10. const _uppercasePattern = /([A-Z])/g;
  11. /**
  12. * Hyphenates a camelcased string, for example:
  13. *
  14. * > hyphenate('backgroundColor')
  15. * < "background-color"
  16. *
  17. * For CSS style names, use `hyphenateStyleName` instead which works properly
  18. * with all vendor prefixes, including `ms`.
  19. *
  20. * @param {string} string
  21. * @return {string}
  22. */
  23. function hyphenate(string) {
  24. return string.replace(_uppercasePattern, '-$1').toLowerCase();
  25. }
  26. module.exports = hyphenate;