mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Remove toString coercion method use.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import toString from './toString.js'
|
||||
import upperFirst from './upperFirst.js'
|
||||
|
||||
/**
|
||||
@@ -15,7 +14,7 @@ import upperFirst from './upperFirst.js'
|
||||
* // => 'Fred'
|
||||
*/
|
||||
function capitalize(string) {
|
||||
return upperFirst(toString(string).toLowerCase())
|
||||
return upperFirst(string.toLowerCase())
|
||||
}
|
||||
|
||||
export default capitalize
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import deburrLetter from './.internal/deburrLetter.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
/** Used to match Latin Unicode letters (excluding mathematical operators). */
|
||||
const reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g
|
||||
@@ -36,7 +35,6 @@ const reComboMark = RegExp(rsCombo, 'g')
|
||||
* // => 'deja vu'
|
||||
*/
|
||||
function deburr(string) {
|
||||
string = toString(string)
|
||||
return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import toString from './toString.js'
|
||||
|
||||
/** Used to map characters to HTML entities. */
|
||||
const htmlEscapes = {
|
||||
'&': '&',
|
||||
@@ -41,7 +39,6 @@ const reHasUnescapedHtml = RegExp(reUnescapedHtml.source)
|
||||
* // => 'fred, barney, & pebbles'
|
||||
*/
|
||||
function escape(string) {
|
||||
string = toString(string)
|
||||
return (string && reHasUnescapedHtml.test(string))
|
||||
? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr])
|
||||
: string
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import toString from './toString.js'
|
||||
|
||||
/**
|
||||
* Used to match `RegExp`
|
||||
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
||||
@@ -22,7 +20,6 @@ const reHasRegExpChar = RegExp(reRegExpChar.source)
|
||||
* // => '\[lodash\]\(https://lodash\.com/\)'
|
||||
*/
|
||||
function escapeRegExp(string) {
|
||||
string = toString(string)
|
||||
return (string && reHasRegExpChar.test(string))
|
||||
? string.replace(reRegExpChar, '\\$&')
|
||||
: string
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import root from './.internal/root.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
/** Used to match leading and trailing whitespace. */
|
||||
const reTrimStart = /^\s+/
|
||||
@@ -34,7 +33,7 @@ function parseInt(string, radix) {
|
||||
} else if (radix) {
|
||||
radix = +radix
|
||||
}
|
||||
return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0)
|
||||
return nativeParseInt(`${ string }`.replace(reTrimStart, ''), radix || 0)
|
||||
}
|
||||
|
||||
export default parseInt
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import toString from './toString.js'
|
||||
|
||||
/**
|
||||
* Replaces matches for `pattern` in `string` with `replacement`.
|
||||
*
|
||||
@@ -19,8 +17,7 @@ import toString from './toString.js'
|
||||
* // => 'Hi Barney'
|
||||
*/
|
||||
function replace(...args) {
|
||||
const string = toString(args[0])
|
||||
|
||||
const string = `${ args[0] }`
|
||||
return args.length < 3 ? string : string.replace(args[1], args[2])
|
||||
}
|
||||
|
||||
|
||||
4
split.js
4
split.js
@@ -1,9 +1,7 @@
|
||||
import baseToString from './.internal/baseToString.js'
|
||||
import castSlice from './.internal/castSlice.js'
|
||||
import hasUnicode from './.internal/hasUnicode.js'
|
||||
import isRegExp from './isRegExp.js'
|
||||
import stringToArray from './.internal/stringToArray.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
/** Used as references for the maximum length and index of an array. */
|
||||
const MAX_ARRAY_LENGTH = 4294967295
|
||||
@@ -30,12 +28,10 @@ function split(string, separator, limit) {
|
||||
if (!limit) {
|
||||
return []
|
||||
}
|
||||
string = toString(string)
|
||||
if (string && (
|
||||
typeof separator == 'string' ||
|
||||
(separator != null && !isRegExp(separator))
|
||||
)) {
|
||||
separator = baseToString(separator)
|
||||
if (!separator && hasUnicode(string)) {
|
||||
return castSlice(stringToArray(string), 0, limit)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import isError from './isError.js'
|
||||
import keys from './keys.js'
|
||||
import reInterpolate from './.internal/reInterpolate.js'
|
||||
import templateSettings from './templateSettings.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
/** Used to match empty string literals in compiled template source. */
|
||||
const reEmptyStringLeading = /\b__p \+= '';/g
|
||||
@@ -142,7 +141,6 @@ function template(string, options) {
|
||||
// and Laura Doktorova's doT.js (https://github.com/olado/doT).
|
||||
const settings = templateSettings.imports.templateSettings || templateSettings
|
||||
|
||||
string = toString(string)
|
||||
options = assignInWith({}, options, settings, customDefaultsAssignIn)
|
||||
|
||||
const imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn)
|
||||
|
||||
@@ -3,7 +3,6 @@ import copyArray from './.internal/copyArray.js'
|
||||
import isSymbol from './isSymbol.js'
|
||||
import stringToPath from './.internal/stringToPath.js'
|
||||
import toKey from './.internal/toKey.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
/**
|
||||
* Converts `value` to a property path array.
|
||||
@@ -24,7 +23,7 @@ function toPath(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return arrayMap(value, toKey)
|
||||
}
|
||||
return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)))
|
||||
return isSymbol(value) ? [value] : copyArray(stringToPath(value))
|
||||
}
|
||||
|
||||
export default toPath
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import toString from './toString.js'
|
||||
|
||||
|
||||
/**
|
||||
* Converts `string`, as a whole, to upper case just like
|
||||
|
||||
5
trim.js
5
trim.js
@@ -1,9 +1,7 @@
|
||||
import baseToString from './.internal/baseToString.js'
|
||||
import castSlice from './.internal/castSlice.js'
|
||||
import charsEndIndex from './.internal/charsEndIndex.js'
|
||||
import charsStartIndex from './.internal/charsStartIndex.js'
|
||||
import stringToArray from './.internal/stringToArray.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
/**
|
||||
* Removes leading and trailing whitespace or specified characters from `string`.
|
||||
@@ -26,11 +24,10 @@ import toString from './toString.js'
|
||||
* // => ['foo', 'bar']
|
||||
*/
|
||||
function trim(string, chars) {
|
||||
string = toString(string)
|
||||
if (string && chars === undefined) {
|
||||
return string.trim()
|
||||
}
|
||||
if (!string || !(chars = baseToString(chars))) {
|
||||
if (!string || !chars) {
|
||||
return string
|
||||
}
|
||||
const strSymbols = stringToArray(string)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import baseToString from './.internal/baseToString.js'
|
||||
import castSlice from './.internal/castSlice.js'
|
||||
import charsEndIndex from './.internal/charsEndIndex.js'
|
||||
import stringToArray from './.internal/stringToArray.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
const methodName = ''.trimRight ? 'trimRight': 'trimEnd'
|
||||
|
||||
@@ -24,11 +22,10 @@ const methodName = ''.trimRight ? 'trimRight': 'trimEnd'
|
||||
* // => '-_-abc'
|
||||
*/
|
||||
function trimEnd(string, chars) {
|
||||
string = toString(string)
|
||||
if (string && chars === undefined) {
|
||||
return string[methodName]()
|
||||
}
|
||||
if (!string || !(chars = baseToString(chars))) {
|
||||
if (!string || !chars) {
|
||||
return string
|
||||
}
|
||||
const strSymbols = stringToArray(string)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import baseToString from './.internal/baseToString.js'
|
||||
import castSlice from './.internal/castSlice.js'
|
||||
import charsStartIndex from './.internal/charsStartIndex.js'
|
||||
import stringToArray from './.internal/stringToArray.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
const methodName = ''.trimLeft ? 'trimLeft' : 'trimStart'
|
||||
|
||||
@@ -24,11 +22,10 @@ const methodName = ''.trimLeft ? 'trimLeft' : 'trimStart'
|
||||
* // => 'abc-_-'
|
||||
*/
|
||||
function trimStart(string, chars) {
|
||||
string = toString(string)
|
||||
if (string && chars === undefined) {
|
||||
return string[methodName]()
|
||||
}
|
||||
if (!string || !(chars = baseToString(chars))) {
|
||||
if (!string || !chars) {
|
||||
return string
|
||||
}
|
||||
const strSymbols = stringToArray(string)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import toString from './toString.js'
|
||||
|
||||
/** Used to map HTML entities to characters. */
|
||||
const htmlUnescapes = {
|
||||
'&': '&',
|
||||
@@ -32,7 +30,6 @@ const reHasEscapedHtml = RegExp(reEscapedHtml.source)
|
||||
* // => 'fred, barney, & pebbles'
|
||||
*/
|
||||
function unescape(string) {
|
||||
string = toString(string)
|
||||
return (string && reHasEscapedHtml.test(string))
|
||||
? string.replace(reEscapedHtml, (entity) => htmlUnescapes[entity])
|
||||
: string
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import toString from './toString.js'
|
||||
|
||||
/** Used to generate unique IDs. */
|
||||
let idCounter = 0
|
||||
|
||||
@@ -21,7 +19,7 @@ let idCounter = 0
|
||||
*/
|
||||
function uniqueId(prefix) {
|
||||
const id = ++idCounter
|
||||
return toString(prefix) + id
|
||||
return `${ prefix + id }`
|
||||
}
|
||||
|
||||
export default uniqueId
|
||||
|
||||
2
words.js
2
words.js
@@ -1,6 +1,5 @@
|
||||
import asciiWords from './.internal/asciiWords.js'
|
||||
import hasUnicodeWord from './.internal/hasUnicodeWord.js'
|
||||
import toString from './toString.js'
|
||||
import unicodeWords from './.internal/unicodeWords.js'
|
||||
|
||||
/**
|
||||
@@ -20,7 +19,6 @@ import unicodeWords from './.internal/unicodeWords.js'
|
||||
* // => ['fred', 'barney', '&', 'pebbles']
|
||||
*/
|
||||
function words(string, pattern) {
|
||||
string = toString(string)
|
||||
if (pattern === undefined) {
|
||||
return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user