From b8a3a42278f606b25c47ed6ae30e8b114a3a3ec4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 14 Mar 2017 23:27:37 -0700 Subject: [PATCH] Remove `toString` coercion method use. --- capitalize.js | 3 +-- deburr.js | 2 -- escape.js | 3 --- escapeRegExp.js | 3 --- parseInt.js | 3 +-- replace.js | 5 +---- split.js | 4 ---- template.js | 2 -- toPath.js | 3 +-- toUpper.js | 2 +- trim.js | 5 +---- trimEnd.js | 5 +---- trimStart.js | 5 +---- unescape.js | 3 --- uniqueId.js | 4 +--- words.js | 2 -- 16 files changed, 9 insertions(+), 45 deletions(-) diff --git a/capitalize.js b/capitalize.js index 54adb5736..46b11435b 100644 --- a/capitalize.js +++ b/capitalize.js @@ -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 diff --git a/deburr.js b/deburr.js index 50a40b34a..0a6a4bcce 100644 --- a/deburr.js +++ b/deburr.js @@ -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, '') } diff --git a/escape.js b/escape.js index e3fdc5e2e..6392bda41 100644 --- a/escape.js +++ b/escape.js @@ -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 diff --git a/escapeRegExp.js b/escapeRegExp.js index f2cb434b6..503a103c7 100644 --- a/escapeRegExp.js +++ b/escapeRegExp.js @@ -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 diff --git a/parseInt.js b/parseInt.js index f8384785f..b496ef4c3 100644 --- a/parseInt.js +++ b/parseInt.js @@ -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 diff --git a/replace.js b/replace.js index d41b23e68..165acfbd3 100644 --- a/replace.js +++ b/replace.js @@ -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]) } diff --git a/split.js b/split.js index 46e0fed42..44da94e1b 100644 --- a/split.js +++ b/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) } diff --git a/template.js b/template.js index 7ce21a245..a4715fb72 100644 --- a/template.js +++ b/template.js @@ -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) diff --git a/toPath.js b/toPath.js index 708a982d0..b69f15772 100644 --- a/toPath.js +++ b/toPath.js @@ -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 diff --git a/toUpper.js b/toUpper.js index 4ef28a8c1..8ad9b8303 100644 --- a/toUpper.js +++ b/toUpper.js @@ -1,4 +1,4 @@ -import toString from './toString.js' + /** * Converts `string`, as a whole, to upper case just like diff --git a/trim.js b/trim.js index 101f21aae..82bc6cd55 100644 --- a/trim.js +++ b/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) diff --git a/trimEnd.js b/trimEnd.js index f4a2a758b..caba219cf 100644 --- a/trimEnd.js +++ b/trimEnd.js @@ -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) diff --git a/trimStart.js b/trimStart.js index 7ce23153c..2d232a888 100644 --- a/trimStart.js +++ b/trimStart.js @@ -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) diff --git a/unescape.js b/unescape.js index cb3c09ece..9644f395c 100644 --- a/unescape.js +++ b/unescape.js @@ -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 diff --git a/uniqueId.js b/uniqueId.js index 3dd1bec84..c785f8b39 100644 --- a/uniqueId.js +++ b/uniqueId.js @@ -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 diff --git a/words.js b/words.js index a182b48c6..def6ed396 100644 --- a/words.js +++ b/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) }