mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Remove native trim, trimLeft, & trimRight use.
This commit is contained in:
113
lodash.js
113
lodash.js
@@ -463,69 +463,6 @@
|
|||||||
return typeof value.toString != 'function' && typeof (value + '') == 'string';
|
return typeof value.toString != 'function' && typeof (value + '') == 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A fallback implementation of `String#trim` to remove leading and trailing
|
|
||||||
* whitespace or specified characters from `string`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {string} string The string to trim.
|
|
||||||
* @param {string} [chars=whitespace] The characters to trim.
|
|
||||||
* @returns {string} Returns the trimmed string.
|
|
||||||
*/
|
|
||||||
function shimTrim(string, chars) {
|
|
||||||
string = string == null ? '' : String(string);
|
|
||||||
if (!string) {
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
if (chars == null) {
|
|
||||||
return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
|
|
||||||
}
|
|
||||||
chars = String(chars);
|
|
||||||
return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A fallback implementation of `String#trimLeft` to remove leading whitespace
|
|
||||||
* or specified characters from `string`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {string} string The string to trim.
|
|
||||||
* @param {string} [chars=whitespace] The characters to trim.
|
|
||||||
* @returns {string} Returns the trimmed string.
|
|
||||||
*/
|
|
||||||
function shimTrimLeft(string, chars) {
|
|
||||||
string = string == null ? '' : String(string);
|
|
||||||
if (!string) {
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
if (chars == null) {
|
|
||||||
return string.slice(trimmedLeftIndex(string))
|
|
||||||
}
|
|
||||||
chars = String(chars);
|
|
||||||
return string.slice(charsLeftIndex(string, chars));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A fallback implementation of `String#trimRight` to remove trailing whitespace
|
|
||||||
* or specified characters from `string`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {string} string The string to trim.
|
|
||||||
* @param {string} [chars=whitespace] The characters to trim.
|
|
||||||
* @returns {string} Returns the trimmed string.
|
|
||||||
*/
|
|
||||||
function shimTrimRight(string, chars) {
|
|
||||||
string = string == null ? '' : String(string);
|
|
||||||
if (!string) {
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
if (chars == null) {
|
|
||||||
return string.slice(0, trimmedRightIndex(string) + 1)
|
|
||||||
}
|
|
||||||
chars = String(chars);
|
|
||||||
return string.slice(0, charsRightIndex(string, chars) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the index of the first non-whitespace character of `string`.
|
* Gets the index of the first non-whitespace character of `string`.
|
||||||
*
|
*
|
||||||
@@ -672,10 +609,7 @@
|
|||||||
nativeMin = Math.min,
|
nativeMin = Math.min,
|
||||||
nativeNow = isNative(nativeNow = Date.now) && nativeNow,
|
nativeNow = isNative(nativeNow = Date.now) && nativeNow,
|
||||||
nativeParseInt = context.parseInt,
|
nativeParseInt = context.parseInt,
|
||||||
nativeRandom = Math.random,
|
nativeRandom = Math.random;
|
||||||
nativeTrim = isNative(nativeTrim = stringProto.trim) && !nativeTrim.call(whitespace) && nativeTrim,
|
|
||||||
nativeTrimLeft = isNative(nativeTrimLeft = stringProto.trimLeft) && !nativeTrimLeft.call(whitespace) && nativeTrimLeft,
|
|
||||||
nativeTrimRight = isNative(nativeTrimRight = stringProto.trimRight) && !nativeTrimRight.call(whitespace) && nativeTrimRight;
|
|
||||||
|
|
||||||
/** Used to lookup built-in constructors by `[[Class]]` */
|
/** Used to lookup built-in constructors by `[[Class]]` */
|
||||||
var ctorByClass = {};
|
var ctorByClass = {};
|
||||||
@@ -7583,12 +7517,17 @@
|
|||||||
* _.trim('-_-fred-_-', '_-');
|
* _.trim('-_-fred-_-', '_-');
|
||||||
* // => 'fred'
|
* // => 'fred'
|
||||||
*/
|
*/
|
||||||
var trim = !nativeTrim ? shimTrim : function(string, chars) {
|
function trim(string, chars) {
|
||||||
if (string == null) {
|
string = string == null ? '' : String(string);
|
||||||
return '';
|
if (!string) {
|
||||||
|
return string;
|
||||||
}
|
}
|
||||||
return chars == null ? nativeTrim.call(string) : shimTrim(string, chars);
|
if (chars == null) {
|
||||||
};
|
return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
|
||||||
|
}
|
||||||
|
chars = String(chars);
|
||||||
|
return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes leading whitespace or specified characters from `string`.
|
* Removes leading whitespace or specified characters from `string`.
|
||||||
@@ -7607,12 +7546,17 @@
|
|||||||
* _.trimLeft('-_-fred-_-', '_-');
|
* _.trimLeft('-_-fred-_-', '_-');
|
||||||
* // => 'fred-_-'
|
* // => 'fred-_-'
|
||||||
*/
|
*/
|
||||||
var trimLeft = !nativeTrimLeft ? shimTrimLeft : function(string, chars) {
|
function trimLeft(string, chars) {
|
||||||
if (string == null) {
|
string = string == null ? '' : String(string);
|
||||||
return '';
|
if (!string) {
|
||||||
|
return string;
|
||||||
}
|
}
|
||||||
return chars == null ? nativeTrimLeft.call(string) : shimTrimLeft(string, chars);
|
if (chars == null) {
|
||||||
};
|
return string.slice(trimmedLeftIndex(string))
|
||||||
|
}
|
||||||
|
chars = String(chars);
|
||||||
|
return string.slice(charsLeftIndex(string, chars));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes trailing whitespace or specified characters from `string`.
|
* Removes trailing whitespace or specified characters from `string`.
|
||||||
@@ -7631,12 +7575,17 @@
|
|||||||
* _.trimRight('-_-fred-_-', '_-');
|
* _.trimRight('-_-fred-_-', '_-');
|
||||||
* // => '-_-fred'
|
* // => '-_-fred'
|
||||||
*/
|
*/
|
||||||
var trimRight = !nativeTrimRight ? shimTrimRight : function(string, chars) {
|
function trimRight(string, chars) {
|
||||||
if (string == null) {
|
string = string == null ? '' : String(string);
|
||||||
return '';
|
if (!string) {
|
||||||
|
return string;
|
||||||
}
|
}
|
||||||
return chars == null ? nativeTrimRight.call(string) : shimTrimRight(string, chars);
|
if (chars == null) {
|
||||||
};
|
return string.slice(0, trimmedRightIndex(string) + 1)
|
||||||
|
}
|
||||||
|
chars = String(chars);
|
||||||
|
return string.slice(0, charsRightIndex(string, chars) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Truncates `string` if it is longer than the given maximum string length.
|
* Truncates `string` if it is longer than the given maximum string length.
|
||||||
|
|||||||
Reference in New Issue
Block a user