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
This commit is contained in:
Luiz Américo
2019-08-26 10:13:56 -03:00
committed by John-David Dalton
parent abb54cc49a
commit e51a424513
18 changed files with 111 additions and 57 deletions

View File

@@ -1,5 +1,6 @@
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).
@@ -21,7 +22,7 @@ import words from './words.js'
* // => 'fooBar'
*/
const camelCase = (string) => (
words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => {
words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => {
word = word.toLowerCase()
return result + (index ? upperFirst(word) : word)
}, '')