From bb7c95947914d12af5f79e7369dd59ce29bc61a8 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 13 Mar 2017 20:49:45 -0700 Subject: [PATCH] Remove coercion method use. --- .internal/baseRepeat.js | 35 ----------------------------------- .internal/createRound.js | 11 +++-------- after.js | 3 --- before.js | 3 --- chunk.js | 9 ++------- clamp.js | 9 +++------ debounce.js | 11 +++-------- delay.js | 4 +--- drop.js | 9 +++------ dropRight.js | 2 -- endsWith.js | 13 +++---------- findLastIndex.js | 10 ++-------- flatMapDepth.js | 3 +-- flattenDepth.js | 3 +-- gt.js | 6 ++---- gte.js | 6 ++---- inRange.js | 8 +------- indexOf.js | 8 ++------ lastIndexOf.js | 8 +------- lt.js | 6 ++---- lte.js | 6 ++---- nth.js | 2 -- pad.js | 13 ++----------- padEnd.js | 5 ----- padStart.js | 5 ----- repeat.js | 23 +++++++++++++++++------ sampleSize.js | 2 -- slice.js | 5 ++--- startsWith.js | 10 ++-------- take.js | 2 -- takeRight.js | 2 -- times.js | 3 --- truncate.js | 8 ++------ 33 files changed, 59 insertions(+), 194 deletions(-) delete mode 100644 .internal/baseRepeat.js diff --git a/.internal/baseRepeat.js b/.internal/baseRepeat.js deleted file mode 100644 index b518457bc..000000000 --- a/.internal/baseRepeat.js +++ /dev/null @@ -1,35 +0,0 @@ -/** Used as references for various `Number` constants. */ -const MAX_SAFE_INTEGER = 9007199254740991 - -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeFloor = Math.floor - -/** - * The base implementation of `repeat` which doesn't coerce arguments. - * - * @private - * @param {string} string The string to repeat. - * @param {number} n The number of times to repeat the string. - * @returns {string} Returns the repeated string. - */ -function baseRepeat(string, n) { - let result = '' - if (!string || n < 1 || n > MAX_SAFE_INTEGER) { - return result - } - // Leverage the exponentiation by squaring algorithm for a faster repeat. - // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. - do { - if (n % 2) { - result += string - } - n = nativeFloor(n / 2) - if (n) { - string += string - } - } while (n) - - return result -} - -export default baseRepeat diff --git a/.internal/createRound.js b/.internal/createRound.js index c8b9c8575..28708cffa 100644 --- a/.internal/createRound.js +++ b/.internal/createRound.js @@ -1,7 +1,3 @@ -import toInteger from '../toInteger.js' -import toNumber from '../toNumber.js' -import toString from '../toString.js' - /** * Creates a function like `round`. * @@ -12,15 +8,14 @@ import toString from '../toString.js' function createRound(methodName) { const func = Math[methodName] return (number, precision) => { - number = toNumber(number) - precision = precision == null ? 0 : Math.min(toInteger(precision), 292) + precision = precision == null ? 0 : Math.min(precision, 292) if (precision) { // Shift with exponential notation to avoid floating-point issues. // See [MDN](https://mdn.io/round#Examples) for more details. - let pair = `${ toString(number) }e`.split('e') + let pair = `${ number }e`.split('e') const value = func(`${ pair[0] }e${ +pair[1] + precision }`) - pair = `${ toString(value) }e`.split('e') + pair = `${ value }e`.split('e') return +`${ pair[0] }e${ +pair[1] - precision }` } return func(number) diff --git a/after.js b/after.js index 694d8d28f..58cd5964e 100644 --- a/after.js +++ b/after.js @@ -1,5 +1,3 @@ -import toInteger from './toInteger.js' - /** * The opposite of `before`his method creates a function that invokes * `func` once it's called `n` or more times. @@ -21,7 +19,6 @@ function after(n, func) { if (typeof func != 'function') { throw new TypeError('Expected a function') } - n = toInteger(n) return function(...args) { if (--n < 1) { return func.apply(this, args) diff --git a/before.js b/before.js index 2747496a4..b6cd3e149 100644 --- a/before.js +++ b/before.js @@ -1,5 +1,3 @@ -import toInteger from './toInteger.js' - /** * Creates a function that invokes `func`, with the `this` binding and arguments * of the created function, while it's called less than `n` times. Subsequent @@ -20,7 +18,6 @@ function before(n, func) { if (typeof func != 'function') { throw new TypeError('Expected a function') } - n = toInteger(n) return function(...args) { if (--n > 0) { result = func.apply(this, args) diff --git a/chunk.js b/chunk.js index c81afcee2..5e4b50a02 100644 --- a/chunk.js +++ b/chunk.js @@ -1,9 +1,4 @@ import baseSlice from './.internal/baseSlice.js' -import toInteger from './toInteger.js' - -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeCeil = Math.ceil -const nativeMax = Math.max /** * Creates an array of elements split into groups the length of `size`. @@ -24,14 +19,14 @@ const nativeMax = Math.max * // => [['a', 'b', 'c'], ['d']] */ function chunk(array, size) { - size = nativeMax(toInteger(size), 0) + size = Math.max(size, 0) const length = array == null ? 0 : array.length if (!length || size < 1) { return [] } let index = 0 let resIndex = 0 - const result = new Array(nativeCeil(length / size)) + const result = new Array(Math.ceil(length / size)) while (index < length) { result[resIndex++] = baseSlice(array, index, (index += size)) diff --git a/clamp.js b/clamp.js index bb7075d69..602377136 100644 --- a/clamp.js +++ b/clamp.js @@ -1,5 +1,3 @@ -import toNumber from './toNumber.js' - /** * Clamps `number` within the inclusive `lower` and `upper` bounds. * @@ -18,10 +16,9 @@ import toNumber from './toNumber.js' * // => 5 */ function clamp(number, lower, upper) { - number = toNumber(number) - lower = toNumber(lower) - upper = toNumber(upper) - + number = +number + lower = +lower + upper = +upper lower = lower === lower ? lower : 0 upper = upper === upper ? upper : 0 if (number === number) { diff --git a/debounce.js b/debounce.js index 66948dd3b..7ef138c8a 100644 --- a/debounce.js +++ b/debounce.js @@ -1,9 +1,4 @@ import isObject from './isObject.js' -import toNumber from './toNumber.js' - -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMax = Math.max -const nativeMin = Math.min /** * Creates a debounced function that delays invoking `func` until after `wait` @@ -73,11 +68,11 @@ function debounce(func, wait, options) { if (typeof func != 'function') { throw new TypeError('Expected a function') } - wait = toNumber(wait) || 0 + wait = +wait || 0 if (isObject(options)) { leading = !!options.leading maxing = 'maxWait' in options - maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait + maxWait = maxing ? Math.max(+options.maxWait || 0, wait) : maxWait trailing = 'trailing' in options ? !!options.trailing : trailing } @@ -105,7 +100,7 @@ function debounce(func, wait, options) { const timeSinceLastInvoke = time - lastInvokeTime const result = wait - timeSinceLastCall - return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result + return maxing ? Math.min(result, maxWait - timeSinceLastInvoke) : result } function shouldInvoke(time) { diff --git a/delay.js b/delay.js index 3b9559b65..377517c79 100644 --- a/delay.js +++ b/delay.js @@ -1,5 +1,3 @@ -import toNumber from './toNumber.js' - /** * Invokes `func` after `wait` milliseconds. Any additional arguments are * provided to `func` when it's invoked. @@ -19,7 +17,7 @@ function delay(func, wait, ...args) { if (typeof func != 'function') { throw new TypeError('Expected a function') } - return setTimeout(func, toNumber(wait) || 0, ...args) + return setTimeout(func, +wait || 0, ...args) } export default delay diff --git a/drop.js b/drop.js index cf335cc66..0ebeb09cc 100644 --- a/drop.js +++ b/drop.js @@ -1,5 +1,4 @@ import baseSlice from './.internal/baseSlice.js' -import toInteger from './toInteger.js' /** * Creates a slice of `array` with `n` elements dropped from the beginning. @@ -25,11 +24,9 @@ import toInteger from './toInteger.js' */ function drop(array, n=1) { const length = array == null ? 0 : array.length - if (!length) { - return [] - } - n = toInteger(n) - return baseSlice(array, n < 0 ? 0 : n, length) + return length + ? baseSlice(array, n < 0 ? 0 : n, length) + : [] } export default drop diff --git a/dropRight.js b/dropRight.js index b08bc88c9..3198d97e4 100644 --- a/dropRight.js +++ b/dropRight.js @@ -1,5 +1,4 @@ import baseSlice from './.internal/baseSlice.js' -import toInteger from './toInteger.js' /** * Creates a slice of `array` with `n` elements dropped from the end. @@ -28,7 +27,6 @@ function dropRight(array, n=1) { if (!length) { return [] } - n = toInteger(n) n = length - n return baseSlice(array, 0, n < 0 ? 0 : n) } diff --git a/endsWith.js b/endsWith.js index 60736f478..9fcf9efd3 100644 --- a/endsWith.js +++ b/endsWith.js @@ -1,7 +1,3 @@ -import baseToString from './.internal/baseToString.js' -import toInteger from './toInteger.js' -import toString from './toString.js' - /** * Checks if `string` ends with the given target string. * @@ -24,13 +20,10 @@ import toString from './toString.js' * endsWith('abc', 'b', 2) * // => true */ -function endsWith(string, target, position) { - string = toString(string) - target = baseToString(target) - +function endsWith(string, target, position) {) const { length } = string - position = position === undefined ? length : toInteger(position) - if (position < 0) { + position = position === undefined ? length : +position + if (position < 0 || position != position) { position = 0 } else if (position > length) { diff --git a/findLastIndex.js b/findLastIndex.js index 8fd340d4e..98a358e02 100644 --- a/findLastIndex.js +++ b/findLastIndex.js @@ -1,9 +1,4 @@ import baseFindIndex from './.internal/baseFindIndex.js' -import toInteger from './toInteger.js' - -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMax = Math.max -const nativeMin = Math.min /** * This method is like `findIndex` except that it iterates over elements @@ -34,10 +29,9 @@ function findLastIndex(array, predicate, fromIndex) { } let index = length - 1 if (fromIndex !== undefined) { - index = toInteger(fromIndex) index = fromIndex < 0 - ? nativeMax(length + index, 0) - : nativeMin(index, length - 1) + ? Math.max(length + fromIndex, 0) + : Math.min(fromIndex, length - 1) } return baseFindIndex(array, predicate, index, true) } diff --git a/flatMapDepth.js b/flatMapDepth.js index 6c8867eb0..8a1ee20c9 100644 --- a/flatMapDepth.js +++ b/flatMapDepth.js @@ -1,6 +1,5 @@ import baseFlatten from './.internal/baseFlatten.js' import map from './map.js' -import toInteger from './toInteger.js' /** * This method is like `flatMap` except that it recursively flattens the @@ -23,7 +22,7 @@ import toInteger from './toInteger.js' * // => [[1, 1], [2, 2]] */ function flatMapDepth(collection, iteratee, depth) { - depth = depth === undefined ? 1 : toInteger(depth) + depth = depth === undefined ? 1 : +depth return baseFlatten(map(collection, iteratee), depth) } diff --git a/flattenDepth.js b/flattenDepth.js index 4d71f19d4..0a8c4564b 100644 --- a/flattenDepth.js +++ b/flattenDepth.js @@ -1,5 +1,4 @@ import baseFlatten from './.internal/baseFlatten.js' -import toInteger from './toInteger.js' /** * Recursively flatten `array` up to `depth` times. @@ -25,7 +24,7 @@ function flattenDepth(array, depth) { if (!length) { return [] } - depth = depth === undefined ? 1 : toInteger(depth) + depth = depth === undefined ? 1 : +depth return baseFlatten(array, depth) } diff --git a/gt.js b/gt.js index 3f241386d..242d96461 100644 --- a/gt.js +++ b/gt.js @@ -1,5 +1,3 @@ -import toNumber from './toNumber.js' - /** * Checks if `value` is greater than `other`. * @@ -23,8 +21,8 @@ import toNumber from './toNumber.js' */ function gt(value, other) { if (!(typeof value == 'string' && typeof other == 'string')) { - value = toNumber(value) - other = toNumber(other) + value = +value + other = +other } return value > other } diff --git a/gte.js b/gte.js index 872d6b12f..1e8980efd 100644 --- a/gte.js +++ b/gte.js @@ -1,5 +1,3 @@ -import toNumber from './toNumber.js' - /** * Checks if `value` is greater than or equal to `other`. * @@ -23,8 +21,8 @@ import toNumber from './toNumber.js' */ function gte(value, other) { if (!(typeof value == 'string' && typeof other == 'string')) { - value = toNumber(value) - other = toNumber(other) + value = +value + other = +other } return value >= other } diff --git a/inRange.js b/inRange.js index 88457c714..08680371d 100644 --- a/inRange.js +++ b/inRange.js @@ -1,6 +1,4 @@ import baseInRange from './.internal/baseInRange.js' -import toFinite from './toFinite.js' -import toNumber from './toNumber.js' /** * Checks if `n` is between `start` and up to, but not including, `end`. If @@ -39,15 +37,11 @@ import toNumber from './toNumber.js' * // => true */ function inRange(number, start, end) { - start = toFinite(start) if (end === undefined) { end = start start = 0 - } else { - end = toFinite(end) } - number = toNumber(number) - return baseInRange(number, start, end) + return baseInRange(+number, +start, +end) } export default inRange diff --git a/indexOf.js b/indexOf.js index 25c668cb1..f5fe63110 100644 --- a/indexOf.js +++ b/indexOf.js @@ -1,8 +1,4 @@ import baseIndexOf from './.internal/baseIndexOf.js' -import toInteger from './toInteger.js' - -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMax = Math.max /** * Gets the index at which the first occurrence of `value` is found in `array` @@ -30,9 +26,9 @@ function indexOf(array, value, fromIndex) { if (!length) { return -1 } - let index = fromIndex == null ? 0 : toInteger(fromIndex) + let index = fromIndex == null ? 0 : +fromIndex if (index < 0) { - index = nativeMax(length + index, 0) + index = Math.max(length + index, 0) } return baseIndexOf(array, value, index) } diff --git a/lastIndexOf.js b/lastIndexOf.js index c01cbaf18..e5894f4fb 100644 --- a/lastIndexOf.js +++ b/lastIndexOf.js @@ -1,11 +1,6 @@ import baseFindIndex from './.internal/baseFindIndex.js' import baseIsNaN from './.internal/baseIsNaN.js' import strictLastIndexOf from './.internal/strictLastIndexOf.js' -import toInteger from './toInteger.js' - -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMax = Math.max -const nativeMin = Math.min /** * This method is like `indexOf` except that it iterates over elements of @@ -33,8 +28,7 @@ function lastIndexOf(array, value, fromIndex) { } let index = length if (fromIndex !== undefined) { - index = toInteger(fromIndex) - index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1) + index = index < 0 ? Math.max(length + index, 0) : Math.min(index, length - 1) } return value === value ? strictLastIndexOf(array, value, index) diff --git a/lt.js b/lt.js index 560c79073..303bc56a0 100644 --- a/lt.js +++ b/lt.js @@ -1,5 +1,3 @@ -import toNumber from './toNumber.js' - /** * Checks if `value` is less than `other`. * @@ -23,8 +21,8 @@ import toNumber from './toNumber.js' */ function lt(value, other) { if (!(typeof value == 'string' && typeof other == 'string')) { - value = toNumber(value) - other = toNumber(other) + value = +value + other = +other } return value < other } diff --git a/lte.js b/lte.js index 4a4b4416b..1e5abfadb 100644 --- a/lte.js +++ b/lte.js @@ -1,5 +1,3 @@ -import toNumber from './toNumber.js' - /** * Checks if `value` is less than or equal to `other`. * @@ -23,8 +21,8 @@ import toNumber from './toNumber.js' */ function lte(value, other) { if (!(typeof value == 'string' && typeof other == 'string')) { - value = toNumber(value) - other = toNumber(other) + value = +value + other = +other } return value <= other } diff --git a/nth.js b/nth.js index 66e66328a..b2425a7dd 100644 --- a/nth.js +++ b/nth.js @@ -1,5 +1,4 @@ import isIndex from './.internal/isIndex.js' -import toInteger from './toInteger.js' /** * Gets the element at index `n` of `array`. If `n` is negative, the nth @@ -25,7 +24,6 @@ function nth(array, n) { if (!length) { return } - n = toInteger(n) n += n < 0 ? length : 0 return isIndex(n, length) ? array[n] : undefined } diff --git a/pad.js b/pad.js index 216ff864a..639b896c0 100644 --- a/pad.js +++ b/pad.js @@ -1,11 +1,5 @@ import createPadding from './.internal/createPadding.js' import stringSize from './.internal/stringSize.js' -import toInteger from './toInteger.js' -import toString from './toString.js' - -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeCeil = Math.ceil -const nativeFloor = Math.floor /** * Pads `string` on the left and right sides if it's shorter than `length`. @@ -29,18 +23,15 @@ const nativeFloor = Math.floor * // => 'abc' */ function pad(string, length, chars) { - string = toString(string) - length = toInteger(length) - const strLength = length ? stringSize(string) : 0 if (!length || strLength >= length) { return string } const mid = (length - strLength) / 2 return ( - createPadding(nativeFloor(mid), chars) + + createPadding(Math.floor(mid), chars) + string + - createPadding(nativeCeil(mid), chars) + createPadding(Math.ceil(mid), chars) ) } diff --git a/padEnd.js b/padEnd.js index 8795bc5cb..69a6137ef 100644 --- a/padEnd.js +++ b/padEnd.js @@ -1,7 +1,5 @@ import createPadding from './.internal/createPadding.js' import stringSize from './.internal/stringSize.js' -import toInteger from './toInteger.js' -import toString from './toString.js' /** * Pads `string` on the right side if it's shorter than `length`. Padding @@ -25,9 +23,6 @@ import toString from './toString.js' * // => 'abc' */ function padEnd(string, length, chars) { - string = toString(string) - length = toInteger(length) - const strLength = length ? stringSize(string) : 0 return (length && strLength < length) ? (string + createPadding(length - strLength, chars)) diff --git a/padStart.js b/padStart.js index 704b71822..c2141b56b 100644 --- a/padStart.js +++ b/padStart.js @@ -1,7 +1,5 @@ import createPadding from './.internal/createPadding.js' import stringSize from './.internal/stringSize.js' -import toInteger from './toInteger.js' -import toString from './toString.js' /** * Pads `string` on the left side if it's shorter than `length`. Padding @@ -25,9 +23,6 @@ import toString from './toString.js' * // => 'abc' */ function padStart(string, length, chars) { - string = toString(string) - length = toInteger(length) - const strLength = length ? stringSize(string) : 0 return (length && strLength < length) ? (createPadding(length - strLength, chars) + string) diff --git a/repeat.js b/repeat.js index 0e3d51d6e..99dc942f7 100644 --- a/repeat.js +++ b/repeat.js @@ -1,7 +1,3 @@ -import baseRepeat from './.internal/baseRepeat.js' -import toInteger from './toInteger.js' -import toString from './toString.js' - /** * Repeats the given string `n` times. * @@ -22,8 +18,23 @@ import toString from './toString.js' * // => '' */ function repeat(string, n) { - n = toInteger(n) - return baseRepeat(toString(string), n) + let result = '' + if (!string || n < 1 || n > MAX_SAFE_INTEGER) { + return result + } + // Leverage the exponentiation by squaring algorithm for a faster repeat. + // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. + do { + if (n % 2) { + result += string + } + n = nativeFloor(n / 2) + if (n) { + string += string + } + } while (n) + + return result } export default repeat diff --git a/sampleSize.js b/sampleSize.js index a903edbf0..aba63eb42 100644 --- a/sampleSize.js +++ b/sampleSize.js @@ -1,5 +1,4 @@ import copyArray from './.internal/copyArray.js' -import toInteger from './toInteger.js' /** * Gets `n` random elements at unique keys from `array` up to the @@ -19,7 +18,6 @@ import toInteger from './toInteger.js' * // => [2, 3, 1] */ function sampleSize(array, n) { - n = toInteger(n) const length = array == null ? 0 : array.length if (!length || n < 1) { return [] diff --git a/slice.js b/slice.js index 2f344d1aa..cc89999d4 100644 --- a/slice.js +++ b/slice.js @@ -1,5 +1,4 @@ import baseSlice from './.internal/baseSlice.js' -import toInteger from './toInteger.js' /** * Creates a slice of `array` from `start` up to, but not including, `end`. @@ -20,8 +19,8 @@ function slice(array, start, end) { if (!length) { return [] } - start = start == null ? 0 : toInteger(start) - end = end === undefined ? length : toInteger(end) + start = start == null ? 0 : start + end = end === undefined ? length : end return baseSlice(array, start, end) } diff --git a/startsWith.js b/startsWith.js index 5174c2202..e135c4a86 100644 --- a/startsWith.js +++ b/startsWith.js @@ -1,7 +1,3 @@ -import baseToString from './.internal/baseToString.js' -import toInteger from './toInteger.js' -import toString from './toString.js' - /** * Checks if `string` starts with the given target string. * @@ -25,17 +21,15 @@ import toString from './toString.js' * // => true */ function startsWith(string, target, position) { - string = toString(string) - const { length } = string - position = position == null ? 0 : toInteger(position) + position = position == null ? 0 : position if (position < 0) { position = 0 } else if (position > length) { position = length } - target = baseToString(target) + target = (target + '') return string.slice(position, position + target.length) == target } diff --git a/take.js b/take.js index 8593f19de..0579de172 100644 --- a/take.js +++ b/take.js @@ -1,5 +1,4 @@ import baseSlice from './.internal/baseSlice.js' -import toInteger from './toInteger.js' /** * Creates a slice of `array` with `n` elements taken from the beginning. @@ -27,7 +26,6 @@ function take(array, n=1) { if (!(array != null && array.length)) { return [] } - n = toInteger(n) return baseSlice(array, 0, n < 0 ? 0 : n) } diff --git a/takeRight.js b/takeRight.js index de512478b..fb09b1b01 100644 --- a/takeRight.js +++ b/takeRight.js @@ -1,5 +1,4 @@ import baseSlice from './.internal/baseSlice.js' -import toInteger from './toInteger.js' /** * Creates a slice of `array` with `n` elements taken from the end. @@ -28,7 +27,6 @@ function takeRight(array, n=1) { if (!length) { return [] } - n = toInteger(n) n = length - n return baseSlice(array, n < 0 ? 0 : n, length) } diff --git a/times.js b/times.js index 6dd87e1c9..da1d72f31 100644 --- a/times.js +++ b/times.js @@ -1,5 +1,3 @@ -import toInteger from './toInteger.js' - /** Used as references for various `Number` constants. */ const MAX_SAFE_INTEGER = 9007199254740991 @@ -24,7 +22,6 @@ const MAX_ARRAY_LENGTH = 4294967295 * // => [0, 0, 0, 0] */ function times(n, iteratee) { - n = toInteger(n) if (n < 1 || n > MAX_SAFE_INTEGER) { return [] } diff --git a/truncate.js b/truncate.js index 32fb29b94..febac16d1 100644 --- a/truncate.js +++ b/truncate.js @@ -5,8 +5,6 @@ import isObject from './isObject.js' import isRegExp from './isRegExp.js' import stringSize from './.internal/stringSize.js' import stringToArray from './.internal/stringToArray.js' -import toInteger from './toInteger.js' -import toString from './toString.js' /** Used as default options for `truncate`. */ const DEFAULT_TRUNC_LENGTH = 30 @@ -58,11 +56,9 @@ function truncate(string, options) { if (isObject(options)) { separator = 'separator' in options ? options.separator : separator - length = 'length' in options ? toInteger(options.length) : length + 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)) { @@ -93,7 +89,7 @@ function truncate(string, options) { const substring = result if (!separator.global) { - separator = RegExp(separator.source, `${ toString(reFlags.exec(separator)) }g`) + separator = RegExp(separator.source, `${ reFlags.exec(separator) || '' }g`) } separator.lastIndex = 0 while ((match = separator.exec(substring))) {