Remove toString coercion method use.

This commit is contained in:
John-David Dalton
2017-03-14 23:27:37 -07:00
parent 351e44a127
commit b8a3a42278
16 changed files with 9 additions and 45 deletions

View File

@@ -1,4 +1,3 @@
import toString from './toString.js'
import upperFirst from './upperFirst.js' import upperFirst from './upperFirst.js'
/** /**
@@ -15,7 +14,7 @@ import upperFirst from './upperFirst.js'
* // => 'Fred' * // => 'Fred'
*/ */
function capitalize(string) { function capitalize(string) {
return upperFirst(toString(string).toLowerCase()) return upperFirst(string.toLowerCase())
} }
export default capitalize export default capitalize

View File

@@ -1,5 +1,4 @@
import deburrLetter from './.internal/deburrLetter.js' import deburrLetter from './.internal/deburrLetter.js'
import toString from './toString.js'
/** Used to match Latin Unicode letters (excluding mathematical operators). */ /** Used to match Latin Unicode letters (excluding mathematical operators). */
const reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g const reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g
@@ -36,7 +35,6 @@ const reComboMark = RegExp(rsCombo, 'g')
* // => 'deja vu' * // => 'deja vu'
*/ */
function deburr(string) { function deburr(string) {
string = toString(string)
return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '') return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '')
} }

View File

@@ -1,5 +1,3 @@
import toString from './toString.js'
/** Used to map characters to HTML entities. */ /** Used to map characters to HTML entities. */
const htmlEscapes = { const htmlEscapes = {
'&': '&amp', '&': '&amp',
@@ -41,7 +39,6 @@ const reHasUnescapedHtml = RegExp(reUnescapedHtml.source)
* // => 'fred, barney, &amp pebbles' * // => 'fred, barney, &amp pebbles'
*/ */
function escape(string) { function escape(string) {
string = toString(string)
return (string && reHasUnescapedHtml.test(string)) return (string && reHasUnescapedHtml.test(string))
? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr]) ? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr])
: string : string

View File

@@ -1,5 +1,3 @@
import toString from './toString.js'
/** /**
* Used to match `RegExp` * Used to match `RegExp`
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). * [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/\)' * // => '\[lodash\]\(https://lodash\.com/\)'
*/ */
function escapeRegExp(string) { function escapeRegExp(string) {
string = toString(string)
return (string && reHasRegExpChar.test(string)) return (string && reHasRegExpChar.test(string))
? string.replace(reRegExpChar, '\\$&') ? string.replace(reRegExpChar, '\\$&')
: string : string

View File

@@ -1,5 +1,4 @@
import root from './.internal/root.js' import root from './.internal/root.js'
import toString from './toString.js'
/** Used to match leading and trailing whitespace. */ /** Used to match leading and trailing whitespace. */
const reTrimStart = /^\s+/ const reTrimStart = /^\s+/
@@ -34,7 +33,7 @@ function parseInt(string, radix) {
} else if (radix) { } else if (radix) {
radix = +radix radix = +radix
} }
return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0) return nativeParseInt(`${ string }`.replace(reTrimStart, ''), radix || 0)
} }
export default parseInt export default parseInt

View File

@@ -1,5 +1,3 @@
import toString from './toString.js'
/** /**
* Replaces matches for `pattern` in `string` with `replacement`. * Replaces matches for `pattern` in `string` with `replacement`.
* *
@@ -19,8 +17,7 @@ import toString from './toString.js'
* // => 'Hi Barney' * // => 'Hi Barney'
*/ */
function replace(...args) { function replace(...args) {
const string = toString(args[0]) const string = `${ args[0] }`
return args.length < 3 ? string : string.replace(args[1], args[2]) return args.length < 3 ? string : string.replace(args[1], args[2])
} }

View File

@@ -1,9 +1,7 @@
import baseToString from './.internal/baseToString.js'
import castSlice from './.internal/castSlice.js' import castSlice from './.internal/castSlice.js'
import hasUnicode from './.internal/hasUnicode.js' import hasUnicode from './.internal/hasUnicode.js'
import isRegExp from './isRegExp.js' import isRegExp from './isRegExp.js'
import stringToArray from './.internal/stringToArray.js' import stringToArray from './.internal/stringToArray.js'
import toString from './toString.js'
/** Used as references for the maximum length and index of an array. */ /** Used as references for the maximum length and index of an array. */
const MAX_ARRAY_LENGTH = 4294967295 const MAX_ARRAY_LENGTH = 4294967295
@@ -30,12 +28,10 @@ function split(string, separator, limit) {
if (!limit) { if (!limit) {
return [] return []
} }
string = toString(string)
if (string && ( if (string && (
typeof separator == 'string' || typeof separator == 'string' ||
(separator != null && !isRegExp(separator)) (separator != null && !isRegExp(separator))
)) { )) {
separator = baseToString(separator)
if (!separator && hasUnicode(string)) { if (!separator && hasUnicode(string)) {
return castSlice(stringToArray(string), 0, limit) return castSlice(stringToArray(string), 0, limit)
} }

View File

@@ -6,7 +6,6 @@ import isError from './isError.js'
import keys from './keys.js' import keys from './keys.js'
import reInterpolate from './.internal/reInterpolate.js' import reInterpolate from './.internal/reInterpolate.js'
import templateSettings from './templateSettings.js' import templateSettings from './templateSettings.js'
import toString from './toString.js'
/** Used to match empty string literals in compiled template source. */ /** Used to match empty string literals in compiled template source. */
const reEmptyStringLeading = /\b__p \+= '';/g const reEmptyStringLeading = /\b__p \+= '';/g
@@ -142,7 +141,6 @@ function template(string, options) {
// and Laura Doktorova's doT.js (https://github.com/olado/doT). // and Laura Doktorova's doT.js (https://github.com/olado/doT).
const settings = templateSettings.imports.templateSettings || templateSettings const settings = templateSettings.imports.templateSettings || templateSettings
string = toString(string)
options = assignInWith({}, options, settings, customDefaultsAssignIn) options = assignInWith({}, options, settings, customDefaultsAssignIn)
const imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn) const imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn)

View File

@@ -3,7 +3,6 @@ import copyArray from './.internal/copyArray.js'
import isSymbol from './isSymbol.js' import isSymbol from './isSymbol.js'
import stringToPath from './.internal/stringToPath.js' import stringToPath from './.internal/stringToPath.js'
import toKey from './.internal/toKey.js' import toKey from './.internal/toKey.js'
import toString from './toString.js'
/** /**
* Converts `value` to a property path array. * Converts `value` to a property path array.
@@ -24,7 +23,7 @@ function toPath(value) {
if (Array.isArray(value)) { if (Array.isArray(value)) {
return arrayMap(value, toKey) return arrayMap(value, toKey)
} }
return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value))) return isSymbol(value) ? [value] : copyArray(stringToPath(value))
} }
export default toPath export default toPath

View File

@@ -1,4 +1,4 @@
import toString from './toString.js'
/** /**
* Converts `string`, as a whole, to upper case just like * Converts `string`, as a whole, to upper case just like

View File

@@ -1,9 +1,7 @@
import baseToString from './.internal/baseToString.js'
import castSlice from './.internal/castSlice.js' import castSlice from './.internal/castSlice.js'
import charsEndIndex from './.internal/charsEndIndex.js' import charsEndIndex from './.internal/charsEndIndex.js'
import charsStartIndex from './.internal/charsStartIndex.js' import charsStartIndex from './.internal/charsStartIndex.js'
import stringToArray from './.internal/stringToArray.js' import stringToArray from './.internal/stringToArray.js'
import toString from './toString.js'
/** /**
* Removes leading and trailing whitespace or specified characters from `string`. * Removes leading and trailing whitespace or specified characters from `string`.
@@ -26,11 +24,10 @@ import toString from './toString.js'
* // => ['foo', 'bar'] * // => ['foo', 'bar']
*/ */
function trim(string, chars) { function trim(string, chars) {
string = toString(string)
if (string && chars === undefined) { if (string && chars === undefined) {
return string.trim() return string.trim()
} }
if (!string || !(chars = baseToString(chars))) { if (!string || !chars) {
return string return string
} }
const strSymbols = stringToArray(string) const strSymbols = stringToArray(string)

View File

@@ -1,8 +1,6 @@
import baseToString from './.internal/baseToString.js'
import castSlice from './.internal/castSlice.js' import castSlice from './.internal/castSlice.js'
import charsEndIndex from './.internal/charsEndIndex.js' import charsEndIndex from './.internal/charsEndIndex.js'
import stringToArray from './.internal/stringToArray.js' import stringToArray from './.internal/stringToArray.js'
import toString from './toString.js'
const methodName = ''.trimRight ? 'trimRight': 'trimEnd' const methodName = ''.trimRight ? 'trimRight': 'trimEnd'
@@ -24,11 +22,10 @@ const methodName = ''.trimRight ? 'trimRight': 'trimEnd'
* // => '-_-abc' * // => '-_-abc'
*/ */
function trimEnd(string, chars) { function trimEnd(string, chars) {
string = toString(string)
if (string && chars === undefined) { if (string && chars === undefined) {
return string[methodName]() return string[methodName]()
} }
if (!string || !(chars = baseToString(chars))) { if (!string || !chars) {
return string return string
} }
const strSymbols = stringToArray(string) const strSymbols = stringToArray(string)

View File

@@ -1,8 +1,6 @@
import baseToString from './.internal/baseToString.js'
import castSlice from './.internal/castSlice.js' import castSlice from './.internal/castSlice.js'
import charsStartIndex from './.internal/charsStartIndex.js' import charsStartIndex from './.internal/charsStartIndex.js'
import stringToArray from './.internal/stringToArray.js' import stringToArray from './.internal/stringToArray.js'
import toString from './toString.js'
const methodName = ''.trimLeft ? 'trimLeft' : 'trimStart' const methodName = ''.trimLeft ? 'trimLeft' : 'trimStart'
@@ -24,11 +22,10 @@ const methodName = ''.trimLeft ? 'trimLeft' : 'trimStart'
* // => 'abc-_-' * // => 'abc-_-'
*/ */
function trimStart(string, chars) { function trimStart(string, chars) {
string = toString(string)
if (string && chars === undefined) { if (string && chars === undefined) {
return string[methodName]() return string[methodName]()
} }
if (!string || !(chars = baseToString(chars))) { if (!string || !chars) {
return string return string
} }
const strSymbols = stringToArray(string) const strSymbols = stringToArray(string)

View File

@@ -1,5 +1,3 @@
import toString from './toString.js'
/** Used to map HTML entities to characters. */ /** Used to map HTML entities to characters. */
const htmlUnescapes = { const htmlUnescapes = {
'&amp;': '&', '&amp;': '&',
@@ -32,7 +30,6 @@ const reHasEscapedHtml = RegExp(reEscapedHtml.source)
* // => 'fred, barney, & pebbles' * // => 'fred, barney, & pebbles'
*/ */
function unescape(string) { function unescape(string) {
string = toString(string)
return (string && reHasEscapedHtml.test(string)) return (string && reHasEscapedHtml.test(string))
? string.replace(reEscapedHtml, (entity) => htmlUnescapes[entity]) ? string.replace(reEscapedHtml, (entity) => htmlUnescapes[entity])
: string : string

View File

@@ -1,5 +1,3 @@
import toString from './toString.js'
/** Used to generate unique IDs. */ /** Used to generate unique IDs. */
let idCounter = 0 let idCounter = 0
@@ -21,7 +19,7 @@ let idCounter = 0
*/ */
function uniqueId(prefix) { function uniqueId(prefix) {
const id = ++idCounter const id = ++idCounter
return toString(prefix) + id return `${ prefix + id }`
} }
export default uniqueId export default uniqueId

View File

@@ -1,6 +1,5 @@
import asciiWords from './.internal/asciiWords.js' import asciiWords from './.internal/asciiWords.js'
import hasUnicodeWord from './.internal/hasUnicodeWord.js' import hasUnicodeWord from './.internal/hasUnicodeWord.js'
import toString from './toString.js'
import unicodeWords from './.internal/unicodeWords.js' import unicodeWords from './.internal/unicodeWords.js'
/** /**
@@ -20,7 +19,6 @@ import unicodeWords from './.internal/unicodeWords.js'
* // => ['fred', 'barney', '&', 'pebbles'] * // => ['fred', 'barney', '&', 'pebbles']
*/ */
function words(string, pattern) { function words(string, pattern) {
string = toString(string)
if (pattern === undefined) { if (pattern === undefined) {
return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string) return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string)
} }