Use built-in String#trim methods when possible.

This commit is contained in:
John-David Dalton
2017-02-03 22:49:18 -08:00
parent 9d445ec238
commit f3a8e55e70
3 changed files with 9 additions and 9 deletions

View File

@@ -4,8 +4,8 @@ import charsStartIndex from './.internal/charsStartIndex.js';
import stringToArray from './.internal/stringToArray.js';
import toString from './toString.js';
/** Used to match leading and trailing whitespace. */
const reTrimStart = /^\s+/;
const stringProto = String.prototype;
const nativeTrimStart = stringProto.trimLeft || stringProto.trimStart;
/**
* Removes leading whitespace or specified characters from `string`.
@@ -28,7 +28,7 @@ const reTrimStart = /^\s+/;
function trimStart(string, chars, guard) {
string = toString(string);
if (string && (guard || chars === undefined)) {
return string.replace(reTrimStart, '');
return nativeTrimStart.call(string);
}
if (!string || !(chars = baseToString(chars))) {
return string;