camelize.js 582 B

1234567891011121314151617181920212223242526272829
  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 _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;