Files
lodash/camelCase.js
Luiz Américo e51a424513 Fix string methods to handle empty values (#4442)
* Enable strings category methods tests

* Ensure escape, pad, padEnd, padStart, trim, trimEnd, trimStart, unescape return an empty string for falsey values

* Coerce value to string using toString in truncate, capitalize and case methods

* Ensure createCaseFirst returns an empty string for falsey values
2019-08-26 06:13:55 -07:00

32 lines
811 B
JavaScript

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