You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.2 KiB

4 years ago
  1. # camelcase [![Build Status](https://travis-ci.org/sindresorhus/camelcase.svg?branch=master)](https://travis-ci.org/sindresorhus/camelcase)
  2. > Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`
  3. ---
  4. <div align="center">
  5. <b>
  6. <a href="https://tidelift.com/subscription/pkg/npm-camelcase?utm_source=npm-camelcase&utm_medium=referral&utm_campaign=readme">Get professional support for 'camelcase' with a Tidelift subscription</a>
  7. </b>
  8. <br>
  9. <sub>
  10. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  11. </sub>
  12. </div>
  13. ---
  14. ## Install
  15. ```
  16. $ npm install camelcase
  17. ```
  18. ## Usage
  19. ```js
  20. const camelCase = require('camelcase');
  21. camelCase('foo-bar');
  22. //=> 'fooBar'
  23. camelCase('foo_bar');
  24. //=> 'fooBar'
  25. camelCase('Foo-Bar');
  26. //=> 'fooBar'
  27. camelCase('Foo-Bar', {pascalCase: true});
  28. //=> 'FooBar'
  29. camelCase('--foo.bar', {pascalCase: false});
  30. //=> 'fooBar'
  31. camelCase('foo bar');
  32. //=> 'fooBar'
  33. console.log(process.argv[3]);
  34. //=> '--foo-bar'
  35. camelCase(process.argv[3]);
  36. //=> 'fooBar'
  37. camelCase(['foo', 'bar']);
  38. //=> 'fooBar'
  39. camelCase(['__foo__', '--bar'], {pascalCase: true});
  40. //=> 'FooBar'
  41. ```
  42. ## API
  43. ### camelCase(input, [options])
  44. #### input
  45. Type: `string` `string[]`
  46. String to convert to camel case.
  47. #### options
  48. Type: `Object`
  49. ##### pascalCase
  50. Type: `boolean`<br>
  51. Default: `false`
  52. Uppercase the first character: `foo-bar``FooBar`
  53. ## Security
  54. To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
  55. ## Related
  56. - [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module
  57. - [uppercamelcase](https://github.com/SamVerschueren/uppercamelcase) - Like this module, but to PascalCase instead of camelCase
  58. - [titleize](https://github.com/sindresorhus/titleize) - Capitalize every word in string
  59. - [humanize-string](https://github.com/sindresorhus/humanize-string) - Convert a camelized/dasherized/underscored string into a humanized one
  60. ## License
  61. MIT © [Sindre Sorhus](https://sindresorhus.com)