camelize.js.flow 597 B

12345678910111213141516171819202122232425262728
  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 camelize
  8. * @typechecks
  9. */
  10. const _hyphenPattern = /-(.)/g;
  11. /**
  12. * Camelcases a hyphenated string, for example:
  13. *
  14. * > camelize('background-color')
  15. * < "backgroundColor"
  16. *
  17. * @param {string} string
  18. * @return {string}
  19. */
  20. function camelize(string) {
  21. return string.replace(_hyphenPattern, function (_, character) {
  22. return character.toUpperCase();
  23. });
  24. }
  25. module.exports = camelize;