forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camelCase.js
31 lines (29 loc) · 811 Bytes
/
camelCase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import upperFirst from './upperFirst.js'
import words from './words.js'
import toString from './toString.js'
/**
* Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
*
* @since 3.0.0
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the camel cased string.
* @see lowerCase, kebabCase, snakeCase, startCase, upperCase, upperFirst
* @example
*
* camelCase('Foo Bar')
* // => 'fooBar'
*
* camelCase('--foo-bar--')
* // => 'fooBar'
*
* camelCase('__FOO_BAR__')
* // => 'fooBar'
*/
const camelCase = (string) => (
words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => {
word = word.toLowerCase()
return result + (index ? upperFirst(word) : word)
}, '')
)
export default camelCase