hyphenateStyleName.js 848 B

123456789101112131415161718192021222324252627282930313233343536
  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. * @typechecks
  8. */
  9. 'use strict';
  10. var hyphenate = require('./hyphenate');
  11. var msPattern = /^ms-/;
  12. /**
  13. * Hyphenates a camelcased CSS property name, for example:
  14. *
  15. * > hyphenateStyleName('backgroundColor')
  16. * < "background-color"
  17. * > hyphenateStyleName('MozTransition')
  18. * < "-moz-transition"
  19. * > hyphenateStyleName('msTransition')
  20. * < "-ms-transition"
  21. *
  22. * As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix
  23. * is converted to `-ms-`.
  24. *
  25. * @param {string} string
  26. * @return {string}
  27. */
  28. function hyphenateStyleName(string) {
  29. return hyphenate(string).replace(msPattern, '-ms-');
  30. }
  31. module.exports = hyphenateStyleName;