Files
lodash/lowerCase.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
752 B
JavaScript

import words from './words.js'
import toString from './toString.js'
const reQuotes = /['\u2019]/g
/**
* Converts `string`, as space separated words, to lower case.
*
* @since 4.0.0
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the lower cased string.
* @see camelCase, kebabCase, snakeCase, startCase, upperCase, upperFirst
* @example
*
* lowerCase('--Foo-Bar--')
* // => 'foo bar'
*
* lowerCase('fooBar')
* // => 'foo bar'
*
* lowerCase('__FOO_BAR__')
* // => 'foo bar'
*/
const lowerCase = (string) => (
words(toString(string).replace(reQuotes, '')).reduce((result, word, index) => (
result + (index ? ' ' : '') + word.toLowerCase()
), '')
)
export default lowerCase