hyphenate.js 674 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. /**
  3. * Copyright (c) 2013-present, Facebook, Inc.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. *
  8. * @typechecks
  9. */
  10. var _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;