Apply more let/const transforms.

This commit is contained in:
John-David Dalton
2017-01-08 23:38:19 -08:00
parent ca9e6fa087
commit 4d0c15b49e
115 changed files with 621 additions and 613 deletions

View File

@@ -9,11 +9,11 @@ import toInteger from './toInteger.js';
import toString from './toString.js';
/** Used as default options for `_.truncate`. */
var DEFAULT_TRUNC_LENGTH = 30,
DEFAULT_TRUNC_OMISSION = '...';
const DEFAULT_TRUNC_LENGTH = 30;
const DEFAULT_TRUNC_OMISSION = '...';
/** Used to match `RegExp` flags from their coerced string values. */
var reFlags = /\w*$/;
const reFlags = /\w*$/;
/**
* Truncates `string` if it's longer than the given maximum string length.
@@ -53,29 +53,31 @@ var reFlags = /\w*$/;
* // => 'hi-diddly-ho there, neig [...]'
*/
function truncate(string, options) {
var length = DEFAULT_TRUNC_LENGTH,
omission = DEFAULT_TRUNC_OMISSION;
let separator;
let length = DEFAULT_TRUNC_LENGTH;
let omission = DEFAULT_TRUNC_OMISSION;
if (isObject(options)) {
var separator = 'separator' in options ? options.separator : separator;
separator = 'separator' in options ? options.separator : separator;
length = 'length' in options ? toInteger(options.length) : length;
omission = 'omission' in options ? baseToString(options.omission) : omission;
}
string = toString(string);
var strLength = string.length;
let strSymbols;
let strLength = string.length;
if (hasUnicode(string)) {
var strSymbols = stringToArray(string);
strSymbols = stringToArray(string);
strLength = strSymbols.length;
}
if (length >= strLength) {
return string;
}
var end = length - stringSize(omission);
let end = length - stringSize(omission);
if (end < 1) {
return omission;
}
var result = strSymbols
let result = strSymbols
? castSlice(strSymbols, 0, end).join('')
: string.slice(0, end);
@@ -87,20 +89,21 @@ function truncate(string, options) {
}
if (isRegExp(separator)) {
if (string.slice(end).search(separator)) {
var match,
substring = result;
let match;
let newEnd;
const substring = result;
if (!separator.global) {
separator = RegExp(separator.source, `${ toString(reFlags.exec(separator)) }g`);
}
separator.lastIndex = 0;
while ((match = separator.exec(substring))) {
var newEnd = match.index;
newEnd = match.index;
}
result = result.slice(0, newEnd === undefined ? end : newEnd);
}
} else if (string.indexOf(baseToString(separator), end) != end) {
var index = result.lastIndexOf(separator);
const index = result.lastIndexOf(separator);
if (index > -1) {
result = result.slice(0, index);
}