mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
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:
committed by
John-David Dalton
parent
abb54cc49a
commit
e51a424513
@@ -5,6 +5,7 @@ import isObject from './isObject.js'
|
||||
import isRegExp from './isRegExp.js'
|
||||
import stringSize from './.internal/stringSize.js'
|
||||
import stringToArray from './.internal/stringToArray.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
/** Used as default options for `truncate`. */
|
||||
const DEFAULT_TRUNC_LENGTH = 30
|
||||
@@ -59,6 +60,9 @@ function truncate(string, options) {
|
||||
length = 'length' in options ? options.length : length
|
||||
omission = 'omission' in options ? baseToString(options.omission) : omission
|
||||
}
|
||||
|
||||
string = toString(string)
|
||||
|
||||
let strSymbols
|
||||
let strLength = string.length
|
||||
if (hasUnicode(string)) {
|
||||
|
||||
Reference in New Issue
Block a user