[6a3a178] | 1 | # camelcase [![Build Status](https://travis-ci.org/sindresorhus/camelcase.svg?branch=master)](https://travis-ci.org/sindresorhus/camelcase)
|
---|
| 2 |
|
---|
| 3 | > Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`
|
---|
| 4 |
|
---|
| 5 | ---
|
---|
| 6 |
|
---|
| 7 | <div align="center">
|
---|
| 8 | <b>
|
---|
| 9 | <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>
|
---|
| 10 | </b>
|
---|
| 11 | <br>
|
---|
| 12 | <sub>
|
---|
| 13 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
---|
| 14 | </sub>
|
---|
| 15 | </div>
|
---|
| 16 |
|
---|
| 17 | ---
|
---|
| 18 |
|
---|
| 19 | ## Install
|
---|
| 20 |
|
---|
| 21 | ```
|
---|
| 22 | $ npm install camelcase
|
---|
| 23 | ```
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | ## Usage
|
---|
| 27 |
|
---|
| 28 | ```js
|
---|
| 29 | const camelCase = require('camelcase');
|
---|
| 30 |
|
---|
| 31 | camelCase('foo-bar');
|
---|
| 32 | //=> 'fooBar'
|
---|
| 33 |
|
---|
| 34 | camelCase('foo_bar');
|
---|
| 35 | //=> 'fooBar'
|
---|
| 36 |
|
---|
| 37 | camelCase('Foo-Bar');
|
---|
| 38 | //=> 'fooBar'
|
---|
| 39 |
|
---|
| 40 | camelCase('Foo-Bar', {pascalCase: true});
|
---|
| 41 | //=> 'FooBar'
|
---|
| 42 |
|
---|
| 43 | camelCase('--foo.bar', {pascalCase: false});
|
---|
| 44 | //=> 'fooBar'
|
---|
| 45 |
|
---|
| 46 | camelCase('foo bar');
|
---|
| 47 | //=> 'fooBar'
|
---|
| 48 |
|
---|
| 49 | console.log(process.argv[3]);
|
---|
| 50 | //=> '--foo-bar'
|
---|
| 51 | camelCase(process.argv[3]);
|
---|
| 52 | //=> 'fooBar'
|
---|
| 53 |
|
---|
| 54 | camelCase(['foo', 'bar']);
|
---|
| 55 | //=> 'fooBar'
|
---|
| 56 |
|
---|
| 57 | camelCase(['__foo__', '--bar'], {pascalCase: true});
|
---|
| 58 | //=> 'FooBar'
|
---|
| 59 | ```
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | ## API
|
---|
| 63 |
|
---|
| 64 | ### camelCase(input, [options])
|
---|
| 65 |
|
---|
| 66 | #### input
|
---|
| 67 |
|
---|
| 68 | Type: `string` `string[]`
|
---|
| 69 |
|
---|
| 70 | String to convert to camel case.
|
---|
| 71 |
|
---|
| 72 | #### options
|
---|
| 73 |
|
---|
| 74 | Type: `Object`
|
---|
| 75 |
|
---|
| 76 | ##### pascalCase
|
---|
| 77 |
|
---|
| 78 | Type: `boolean`<br>
|
---|
| 79 | Default: `false`
|
---|
| 80 |
|
---|
| 81 | Uppercase the first character: `foo-bar` → `FooBar`
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | ## Security
|
---|
| 85 |
|
---|
| 86 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | ## Related
|
---|
| 90 |
|
---|
| 91 | - [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module
|
---|
| 92 | - [uppercamelcase](https://github.com/SamVerschueren/uppercamelcase) - Like this module, but to PascalCase instead of camelCase
|
---|
| 93 | - [titleize](https://github.com/sindresorhus/titleize) - Capitalize every word in string
|
---|
| 94 | - [humanize-string](https://github.com/sindresorhus/humanize-string) - Convert a camelized/dasherized/underscored string into a humanized one
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | ## License
|
---|
| 98 |
|
---|
| 99 | MIT © [Sindre Sorhus](https://sindresorhus.com)
|
---|