Adjust spacing in template string expressions.

This commit is contained in:
John-David Dalton
2017-04-08 22:41:48 -07:00
parent 303502efa7
commit d10b44bdef
29 changed files with 90 additions and 90 deletions

View File

@@ -24,7 +24,7 @@ function arrayLikeKeys(value, inherited) {
const result = new Array(skipIndexes ? length : 0) const result = new Array(skipIndexes ? length : 0)
let index = skipIndexes ? -1 : length let index = skipIndexes ? -1 : length
while (++index < length) { while (++index < length) {
result[index] = `${ index }` result[index] = `${index}`
} }
for (const key in value) { for (const key in value) {
if ((inherited || hasOwnProperty.call(value, key)) && if ((inherited || hasOwnProperty.call(value, key)) &&

View File

@@ -27,7 +27,7 @@ function baseMerge(object, source, srcIndex, customizer, stack) {
} }
else { else {
let newValue = customizer let newValue = customizer
? customizer(object[key], srcValue, `${ key }`, object, source, stack) ? customizer(object[key], srcValue, `${key}`, object, source, stack)
: undefined : undefined
if (newValue === undefined) { if (newValue === undefined) {

View File

@@ -36,7 +36,7 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, sta
return return
} }
let newValue = customizer let newValue = customizer
? customizer(objValue, srcValue, `${ key }`, object, source, stack) ? customizer(objValue, srcValue, `${key}`, object, source, stack)
: undefined : undefined
let isCommon = newValue === undefined let isCommon = newValue === undefined

View File

@@ -22,12 +22,12 @@ function baseToString(value) {
} }
if (Array.isArray(value)) { if (Array.isArray(value)) {
// Recursively convert values (susceptible to call stack limits). // Recursively convert values (susceptible to call stack limits).
return `${ value.map(baseToString) }` return `${value.map(baseToString)}`
} }
if (isSymbol(value)) { if (isSymbol(value)) {
return symbolToString ? symbolToString.call(value) : '' return symbolToString ? symbolToString.call(value) : ''
} }
const result = `${ value }` const result = `${value}`
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result
} }

View File

@@ -12,11 +12,11 @@ function createRound(methodName) {
if (precision) { if (precision) {
// Shift with exponential notation to avoid floating-point issues. // Shift with exponential notation to avoid floating-point issues.
// See [MDN](https://mdn.io/round#Examples) for more details. // See [MDN](https://mdn.io/round#Examples) for more details.
let pair = `${ number }e`.split('e') let pair = `${number}e`.split('e')
const value = func(`${ pair[0] }e${ +pair[1] + precision }`) const value = func(`${pair[0]}e${ +pair[1] + precision }`)
pair = `${ value }e`.split('e') pair = `${value}e`.split('e')
return +`${ pair[0] }e${ +pair[1] - precision }` return +`${pair[0]}e${+pair[1] - precision}`
} }
return func(number) return func(number)
} }

View File

@@ -74,7 +74,7 @@ function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
// Coerce regexes to strings and treat strings, primitives and objects, // Coerce regexes to strings and treat strings, primitives and objects,
// as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
// for more details. // for more details.
return object == `${ other }` return object == `${other}`
case mapTag: case mapTag:
let convert = mapToArray let convert = mapToArray

View File

@@ -9,11 +9,11 @@ const setTag = '[object Set]'
const weakMapTag = '[object WeakMap]' const weakMapTag = '[object WeakMap]'
/** Used to detect maps, sets, and weakmaps. */ /** Used to detect maps, sets, and weakmaps. */
const dataViewCtorString = `${ DataView }` const dataViewCtorString = `${DataView}`
const mapCtorString = `${ Map }` const mapCtorString = `${Map}`
const promiseCtorString = `${ Promise }` const promiseCtorString = `${Promise}`
const setCtorString = `${ Set }` const setCtorString = `${Set}`
const weakMapCtorString = `${ WeakMap }` const weakMapCtorString = `${WeakMap}`
/** /**
* Gets the `toStringTag` of `value`. * Gets the `toStringTag` of `value`.
@@ -33,7 +33,7 @@ if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
getTag = (value) => { getTag = (value) => {
const result = baseGetTag(value) const result = baseGetTag(value)
const Ctor = result == objectTag ? value.constructor : undefined const Ctor = result == objectTag ? value.constructor : undefined
const ctorString = Ctor ? `${ Ctor }` : '' const ctorString = Ctor ? `${Ctor}` : ''
if (ctorString) { if (ctorString) {
switch (ctorString) { switch (ctorString) {

View File

@@ -10,7 +10,7 @@ const rsVarRange = '\\ufe0e\\ufe0f'
const rsZWJ = '\\u200d' const rsZWJ = '\\u200d'
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
const reHasUnicode = RegExp(`[${ rsZWJ + rsAstralRange + rsComboRange + rsVarRange }]`) const reHasUnicode = RegExp(`[${rsZWJ + rsAstralRange + rsComboRange + rsVarRange}]`)
/** /**
* Checks if `string` contains Unicode symbols. * Checks if `string` contains Unicode symbols.

View File

@@ -14,7 +14,7 @@ function toKey(value) {
if (typeof value == 'string' || isSymbol(value)) { if (typeof value == 'string' || isSymbol(value)) {
return value return value
} }
const result = `${ value }` const result = `${value}`
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result
} }

View File

@@ -7,25 +7,25 @@ const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsR
const rsVarRange = '\\ufe0e\\ufe0f' const rsVarRange = '\\ufe0e\\ufe0f'
/** Used to compose unicode capture groups. */ /** Used to compose unicode capture groups. */
const rsAstral = `[${ rsAstralRange }]` const rsAstral = `[${rsAstralRange}]`
const rsCombo = `[${ rsComboRange }]` const rsCombo = `[${rsComboRange}]`
const rsFitz = '\\ud83c[\\udffb-\\udfff]' const rsFitz = '\\ud83c[\\udffb-\\udfff]'
const rsModifier = `(?:${ rsCombo }|${ rsFitz })` const rsModifier = `(?:${rsCombo}|${rsFitz})`
const rsNonAstral = `[^${ rsAstralRange }]` const rsNonAstral = `[^${rsAstralRange}]`
const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}' const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}'
const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]' const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]'
const rsZWJ = '\\u200d' const rsZWJ = '\\u200d'
/** Used to compose unicode regexes. */ /** Used to compose unicode regexes. */
const reOptMod = `${ rsModifier }?` const reOptMod = `${rsModifier}?`
const rsOptVar = `[${ rsVarRange }]?` const rsOptVar = `[${rsVarRange}]?`
const rsOptJoin = `(?:${ rsZWJ }(?:${ [rsNonAstral, rsRegional, rsSurrPair].join('|') })${ rsOptVar + reOptMod })*` const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*`
const rsSeq = rsOptVar + reOptMod + rsOptJoin const rsSeq = rsOptVar + reOptMod + rsOptJoin
const rsNonAstralCombo = `${ rsNonAstral }${ rsCombo }?` const rsNonAstralCombo = `${rsNonAstral}${rsCombo}?`
const rsSymbol = `(?:${ [rsNonAstralCombo, rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') })` const rsSymbol = `(?:${[rsNonAstralCombo, rsCombo, rsRegional, rsSurrPair, rsAstral].join('|')})`
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
const reUnicode = RegExp(`${ rsFitz }(?=${ rsFitz })|${ rsSymbol + rsSeq }`, 'g') const reUnicode = RegExp(`${rsFitz}(?=${rsFitz})|${rsSymbol + rsSeq}`, 'g')
/** /**
* Gets the size of a Unicode `string`. * Gets the size of a Unicode `string`.

View File

@@ -7,25 +7,25 @@ const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsR
const rsVarRange = '\\ufe0e\\ufe0f' const rsVarRange = '\\ufe0e\\ufe0f'
/** Used to compose unicode capture groups. */ /** Used to compose unicode capture groups. */
const rsAstral = `[${ rsAstralRange }]` const rsAstral = `[${rsAstralRange}]`
const rsCombo = `[${ rsComboRange }]` const rsCombo = `[${rsComboRange}]`
const rsFitz = '\\ud83c[\\udffb-\\udfff]' const rsFitz = '\\ud83c[\\udffb-\\udfff]'
const rsModifier = `(?:${ rsCombo }|${ rsFitz })` const rsModifier = `(?:${rsCombo}|${rsFitz})`
const rsNonAstral = `[^${ rsAstralRange }]` const rsNonAstral = `[^${rsAstralRange}]`
const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}' const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}'
const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]' const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]'
const rsZWJ = '\\u200d' const rsZWJ = '\\u200d'
/** Used to compose unicode regexes. */ /** Used to compose unicode regexes. */
const reOptMod = `${ rsModifier }?` const reOptMod = `${rsModifier}?`
const rsOptVar = `[${ rsVarRange }]?` const rsOptVar = `[${rsVarRange}]?`
const rsOptJoin = `(?:${ rsZWJ }(?:${ [rsNonAstral, rsRegional, rsSurrPair].join('|') })${ rsOptVar + reOptMod })*` const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*`
const rsSeq = rsOptVar + reOptMod + rsOptJoin const rsSeq = rsOptVar + reOptMod + rsOptJoin
const rsNonAstralCombo = `${ rsNonAstral }${ rsCombo }?` const rsNonAstralCombo = `${rsNonAstral}${rsCombo}?`
const rsSymbol = `(?:${ [rsNonAstralCombo, rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') })` const rsSymbol = `(?:${[rsNonAstralCombo, rsCombo, rsRegional, rsSurrPair, rsAstral].join('|')})`
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
const reUnicode = RegExp(`${ rsFitz }(?=${ rsFitz })|${ rsSymbol + rsSeq }`, 'g') const reUnicode = RegExp(`${rsFitz}(?=${rsFitz})|${rsSymbol + rsSeq}`, 'g')
/** /**
* Converts a Unicode `string` to an array. * Converts a Unicode `string` to an array.

View File

@@ -16,32 +16,32 @@ const rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpa
/** Used to compose unicode capture groups. */ /** Used to compose unicode capture groups. */
const rsApos = "['\u2019]" const rsApos = "['\u2019]"
const rsBreak = `[${ rsBreakRange }]` const rsBreak = `[${rsBreakRange}]`
const rsCombo = `[${ rsComboRange }]` const rsCombo = `[${rsComboRange}]`
const rsDigits = '\\d+' const rsDigits = '\\d+'
const rsDingbat = `[${ rsDingbatRange }]` const rsDingbat = `[${rsDingbatRange}]`
const rsLower = `[${ rsLowerRange }]` const rsLower = `[${rsLowerRange}]`
const rsMisc = `[^${ rsAstralRange }${ rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange }]` const rsMisc = `[^${rsAstralRange}${rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange}]`
const rsFitz = '\\ud83c[\\udffb-\\udfff]' const rsFitz = '\\ud83c[\\udffb-\\udfff]'
const rsModifier = `(?:${ rsCombo }|${ rsFitz })` const rsModifier = `(?:${rsCombo}|${rsFitz})`
const rsNonAstral = `[^${ rsAstralRange }]` const rsNonAstral = `[^${rsAstralRange}]`
const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}' const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}'
const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]' const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]'
const rsUpper = `[${ rsUpperRange }]` const rsUpper = `[${rsUpperRange}]`
const rsZWJ = '\\u200d' const rsZWJ = '\\u200d'
/** Used to compose unicode regexes. */ /** Used to compose unicode regexes. */
const rsMiscLower = `(?:${ rsLower }|${ rsMisc })` const rsMiscLower = `(?:${rsLower}|${rsMisc})`
const rsMiscUpper = `(?:${ rsUpper }|${ rsMisc })` const rsMiscUpper = `(?:${rsUpper}|${rsMisc})`
const rsOptContrLower = `(?:${ rsApos }(?:d|ll|m|re|s|t|ve))?` const rsOptContrLower = `(?:${rsApos}(?:d|ll|m|re|s|t|ve))?`
const rsOptContrUpper = `(?:${ rsApos }(?:D|LL|M|RE|S|T|VE))?` const rsOptContrUpper = `(?:${rsApos}(?:D|LL|M|RE|S|T|VE))?`
const reOptMod = `${ rsModifier }?` const reOptMod = `${rsModifier}?`
const rsOptVar = `[${ rsVarRange }]?` const rsOptVar = `[${rsVarRange}]?`
const rsOptJoin = `(?:${ rsZWJ }(?:${ [rsNonAstral, rsRegional, rsSurrPair].join('|') })${ rsOptVar + reOptMod })*` const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*`
const rsOrdLower = '\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)' const rsOrdLower = '\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)'
const rsOrdUpper = '\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)' const rsOrdUpper = '\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)'
const rsSeq = rsOptVar + reOptMod + rsOptJoin const rsSeq = rsOptVar + reOptMod + rsOptJoin
const rsEmoji = `(?:${ [rsDingbat, rsRegional, rsSurrPair].join('|') })${ rsSeq }` const rsEmoji = `(?:${[rsDingbat, rsRegional, rsSurrPair].join('|')})${rsSeq}`
/** /**
* Splits a Unicode `string` into an array of its words. * Splits a Unicode `string` into an array of its words.
@@ -51,10 +51,10 @@ const rsEmoji = `(?:${ [rsDingbat, rsRegional, rsSurrPair].join('|') })${ rsSeq
* @returns {Array} Returns the words of `string`. * @returns {Array} Returns the words of `string`.
*/ */
const unicodeWords = RegExp.prototype.exec.bind(RegExp([ const unicodeWords = RegExp.prototype.exec.bind(RegExp([
`${ rsUpper }?${ rsLower }+${ rsOptContrLower }(?=${ [rsBreak, rsUpper, '$'].join('|') })`, `${rsUpper}?${rsLower}+${rsOptContrLower}(?=${[rsBreak, rsUpper, '$'].join('|')})`,
`${ rsMiscUpper }+${ rsOptContrUpper }(?=${ [rsBreak, rsUpper + rsMiscLower, '$'].join('|') })`, `${rsMiscUpper}+${rsOptContrUpper}(?=${[rsBreak, rsUpper + rsMiscLower, '$'].join('|')})`,
`${ rsUpper }?${ rsMiscLower }+${ rsOptContrLower }`, `${rsUpper}?${rsMiscLower}+${rsOptContrLower}`,
`${ rsUpper }+${ rsOptContrUpper }`, `${rsUpper}+${rsOptContrUpper}`,
rsOrdUpper, rsOrdUpper,
rsOrdLower, rsOrdLower,
rsDigits, rsDigits,

View File

@@ -21,7 +21,7 @@ import words from './words.js'
* // => 'fooBar' * // => 'fooBar'
*/ */
const camelCase = (string) => ( const camelCase = (string) => (
words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => { words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => {
word = word.toLowerCase() word = word.toLowerCase()
return result + (index ? capitalize(word) : word) return result + (index ? capitalize(word) : word)
}, '') }, '')

View File

@@ -10,7 +10,7 @@ const rsComboSymbolsRange = '\\u20d0-\\u20ff'
const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange
/** Used to compose unicode capture groups. */ /** Used to compose unicode capture groups. */
const rsCombo = `[${ rsComboRange }]` const rsCombo = `[${rsComboRange}]`
/** /**
* Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and

View File

@@ -17,7 +17,7 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
* *
* const object = { 'a': 1, 'b': 2, 'c': 1 } * const object = { 'a': 1, 'b': 2, 'c': 1 }
* *
* invertBy(object, value => `group${ value }`) * invertBy(object, value => `group${value}`)
* // => { 'group1': ['a', 'c'], 'group2': ['b'] } * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
*/ */
function invertBy(object, iteratee) { function invertBy(object, iteratee) {

View File

@@ -21,7 +21,7 @@ import words from './words.js'
* // => 'foo-bar' * // => 'foo-bar'
*/ */
const kebabCase = (string) => ( const kebabCase = (string) => (
words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => (
result + (index ? '-' : '') + word.toLowerCase() result + (index ? '-' : '') + word.toLowerCase()
), '') ), '')
) )

View File

@@ -20,7 +20,7 @@ import words from './words.js'
* // => 'foo bar' * // => 'foo bar'
*/ */
const lowerCase = (string) => ( const lowerCase = (string) => (
words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => (
result + (index ? ' ' : '') + word.toLowerCase() result + (index ? ' ' : '') + word.toLowerCase()
), '') ), '')
) )

View File

@@ -33,7 +33,7 @@ function parseInt(string, radix) {
} else if (radix) { } else if (radix) {
radix = +radix radix = +radix
} }
return nativeParseInt(`${ string }`.replace(reTrimStart, ''), radix || 0) return nativeParseInt(`${string}`.replace(reTrimStart, ''), radix || 0)
} }
export default parseInt export default parseInt

View File

@@ -64,8 +64,8 @@ function random(lower, upper, floating) {
} }
if (floating || lower % 1 || upper % 1) { if (floating || lower % 1 || upper % 1) {
const rand = Math.random() const rand = Math.random()
const randLength = `${ rand }`.length - 1 const randLength = `${rand}`.length - 1
return Math.min(lower + (rand * (upper - lower + freeParseFloat(`1e-${ randLength }`)), upper)) return Math.min(lower + (rand * (upper - lower + freeParseFloat(`1e-${randLength}`)), upper))
} }
return lower + Math.floor(Math.random() * (upper - lower + 1)) return lower + Math.floor(Math.random() * (upper - lower + 1))
} }

View File

@@ -17,7 +17,7 @@
* // => 'Hi Barney' * // => 'Hi Barney'
*/ */
function replace(...args) { function replace(...args) {
const string = `${ 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

@@ -21,7 +21,7 @@ import words from './words.js'
* // => 'foo_bar' * // => 'foo_bar'
*/ */
const snakeCase = (string) => ( const snakeCase = (string) => (
words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => (
result + (index ? '_' : '') + word.toLowerCase() result + (index ? '_' : '') + word.toLowerCase()
), '') ), '')
) )

View File

@@ -22,7 +22,7 @@ import words from './words.js'
* // => 'FOO BAR' * // => 'FOO BAR'
*/ */
const startCase = (string) => ( const startCase = (string) => (
words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => (
result + (index ? ' ' : '') + upperFirst(word) result + (index ? ' ' : '') + upperFirst(word)
), '') ), '')
) )

View File

@@ -29,7 +29,7 @@ function startsWith(string, target, position) {
else if (position > length) { else if (position > length) {
position = length position = length
} }
target = `${ target }` target = `${target}`
return string.slice(position, position + target.length) == target return string.slice(position, position + target.length) == target
} }

View File

@@ -155,16 +155,16 @@ function template(string, options) {
let source = "__p += '" let source = "__p += '"
// Compile the regexp to match each delimiter. // Compile the regexp to match each delimiter.
const reDelimiters = RegExp(`${ [ const reDelimiters = RegExp(`${[
(options.escape || reNoMatch).source, (options.escape || reNoMatch).source,
interpolate.source, interpolate.source,
(interpolate === reInterpolate ? reEsTemplate : reNoMatch).source, (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source,
(options.evaluate || reNoMatch).source (options.evaluate || reNoMatch).source
].join('|') }|$`, 'g') ].join('|')}|$`, 'g')
// Use a sourceURL for easier debugging. // Use a sourceURL for easier debugging.
const sourceURL = 'sourceURL' in options const sourceURL = 'sourceURL' in options
? `//# sourceURL=${ options.sourceURL }\n` ? `//# sourceURL=${options.sourceURL}\n`
: '' : ''
string.replace(reDelimiters, ( string.replace(reDelimiters, (
@@ -180,19 +180,19 @@ function template(string, options) {
// Escape characters that can't be included in string literals. // Escape characters that can't be included in string literals.
source += string source += string
.slice(index, offset) .slice(index, offset)
.replace(reUnescapedString, (chr) => `\\${ stringEscapes[chr] }`) .replace(reUnescapedString, (chr) => `\\${stringEscapes[chr]}`)
// Replace delimiters with snippets. // Replace delimiters with snippets.
if (escapeValue) { if (escapeValue) {
isEscaping = true isEscaping = true
source += `' +\n__e(${ escapeValue }) +\n'` source += `' +\n__e(${escapeValue}) +\n'`
} }
if (evaluateValue) { if (evaluateValue) {
isEvaluating = true isEvaluating = true
source += `';\n${ evaluateValue };\n__p += '` source += `';\n${evaluateValue};\n__p += '`
} }
if (interpolateValue) { if (interpolateValue) {
source += `' +\n((__t = (${ interpolateValue })) == null ? '' : __t) +\n'` source += `' +\n((__t = (${interpolateValue})) == null ? '' : __t) +\n'`
} }
index = offset + match.length index = offset + match.length
@@ -207,7 +207,7 @@ function template(string, options) {
// code to add the data object to the top of the scope chain. // code to add the data object to the top of the scope chain.
const variable = options.variable const variable = options.variable
if (!variable) { if (!variable) {
source = `with (obj) {\n${ source }\n}\n` source = `with (obj) {\n${source}\n}\n`
} }
// Cleanup code by stripping empty strings. // Cleanup code by stripping empty strings.
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source) source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
@@ -215,15 +215,15 @@ function template(string, options) {
.replace(reEmptyStringTrailing, '$1;') .replace(reEmptyStringTrailing, '$1;')
// Frame code as the function body. // Frame code as the function body.
source = `function(${ variable || 'obj' }) {\n` + source = `function(${variable || 'obj'}) {\n` +
`${ variable ? '' : 'obj || (obj = {});\n' }` + `${variable ? '' : 'obj || (obj = {});\n'}` +
`var __t, __p = ''` + `var __t, __p = ''` +
`${ isEscaping ? ', __e = _.escape' : '' }` + `${isEscaping ? ', __e = _.escape' : ''}` +
`${ isEvaluating ? ', __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, \'\') }\n' : ';\n' }` + `${isEvaluating ? ', __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, \'\') }\n' : ';\n'}` +
`${ source } return __p;\n}` `${source} return __p;\n}`
const result = attempt(() => ( const result = attempt(() => (
Function(importsKeys, `${ sourceURL }return ${ source }`))(...importsValues) Function(importsKeys, `${sourceURL}return ${source}`))(...importsValues)
) )
// Provide the compiled function's source by its `toString` method or // Provide the compiled function's source by its `toString` method or

View File

@@ -50,7 +50,7 @@ function toNumber(value) {
} }
if (isObject(value)) { if (isObject(value)) {
const other = typeof value.valueOf == 'function' ? value.valueOf() : value const other = typeof value.valueOf == 'function' ? value.valueOf() : value
value = isObject(other) ? `${ other }` : other value = isObject(other) ? `${other}` : other
} }
if (typeof value != 'string') { if (typeof value != 'string') {
return value === 0 ? value : +value return value === 0 ? value : +value

View File

@@ -37,12 +37,12 @@ function toString(value) {
} }
if (Array.isArray(value)) { if (Array.isArray(value)) {
// Recursively convert values (susceptible to call stack limits). // Recursively convert values (susceptible to call stack limits).
return `${ arrayMap(value, (other) => other == null ? other : toString(other)) }` return `${arrayMap(value, (other) => other == null ? other : toString(other))}`
} }
if (isSymbol(value)) { if (isSymbol(value)) {
return symbolToString ? symbolToString.call(value) : '' return symbolToString ? symbolToString.call(value) : ''
} }
const result = `${ value }` const result = `${value}`
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result
} }

View File

@@ -89,7 +89,7 @@ function truncate(string, options) {
const substring = result const substring = result
if (!separator.global) { if (!separator.global) {
separator = RegExp(separator.source, `${ reFlags.exec(separator) || '' }g`) separator = RegExp(separator.source, `${reFlags.exec(separator) || ''}g`)
} }
separator.lastIndex = 0 separator.lastIndex = 0
while ((match = separator.exec(substring))) { while ((match = separator.exec(substring))) {

View File

@@ -19,7 +19,7 @@ let idCounter = 0
*/ */
function uniqueId(prefix) { function uniqueId(prefix) {
const id = ++idCounter const id = ++idCounter
return `${ prefix + id }` return `${prefix + id}`
} }
export default uniqueId export default uniqueId

View File

@@ -20,7 +20,7 @@ import words from './words.js'
* // => 'FOO BAR' * // => 'FOO BAR'
*/ */
const upperCase = (string) => ( const upperCase = (string) => (
words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => (
result + (index ? ' ' : '') + word.toUpperCase() result + (index ? ' ' : '') + word.toUpperCase()
), '') ), '')
) )