mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
Simplify method juggle in trim modules.
This commit is contained in:
4
trim.js
4
trim.js
@@ -5,8 +5,6 @@ import charsStartIndex from './.internal/charsStartIndex.js'
|
||||
import stringToArray from './.internal/stringToArray.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
const nativeTrim = String.prototype.trim
|
||||
|
||||
/**
|
||||
* Removes leading and trailing whitespace or specified characters from `string`.
|
||||
*
|
||||
@@ -31,7 +29,7 @@ const nativeTrim = String.prototype.trim
|
||||
function trim(string, chars, guard) {
|
||||
string = toString(string)
|
||||
if (string && (guard || chars === undefined)) {
|
||||
return nativeTrim.call(string)
|
||||
return string.trim()
|
||||
}
|
||||
if (!string || !(chars = baseToString(chars))) {
|
||||
return string
|
||||
|
||||
@@ -4,8 +4,7 @@ import charsEndIndex from './.internal/charsEndIndex.js'
|
||||
import stringToArray from './.internal/stringToArray.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
const stringProto = String.prototype
|
||||
const nativeTrimEnd = stringProto.trimRight || stringProto.trimEnd
|
||||
const methodName = ''.trimRight ? 'trimRight': 'trimEnd'
|
||||
|
||||
/**
|
||||
* Removes trailing whitespace or specified characters from `string`.
|
||||
@@ -28,7 +27,7 @@ const nativeTrimEnd = stringProto.trimRight || stringProto.trimEnd
|
||||
function trimEnd(string, chars, guard) {
|
||||
string = toString(string)
|
||||
if (string && (guard || chars === undefined)) {
|
||||
return nativeTrimEnd.call(string)
|
||||
return string[methodName]()
|
||||
}
|
||||
if (!string || !(chars = baseToString(chars))) {
|
||||
return string
|
||||
|
||||
@@ -4,8 +4,7 @@ import charsStartIndex from './.internal/charsStartIndex.js'
|
||||
import stringToArray from './.internal/stringToArray.js'
|
||||
import toString from './toString.js'
|
||||
|
||||
const stringProto = String.prototype
|
||||
const nativeTrimStart = stringProto.trimLeft || stringProto.trimStart
|
||||
const methodName = ''.trimLeft ? 'trimLeft' : 'trimStart'
|
||||
|
||||
/**
|
||||
* Removes leading whitespace or specified characters from `string`.
|
||||
@@ -28,7 +27,7 @@ const nativeTrimStart = stringProto.trimLeft || stringProto.trimStart
|
||||
function trimStart(string, chars, guard) {
|
||||
string = toString(string)
|
||||
if (string && (guard || chars === undefined)) {
|
||||
return nativeTrimStart.call(string)
|
||||
return string[methodName]()
|
||||
}
|
||||
if (!string || !(chars = baseToString(chars))) {
|
||||
return string
|
||||
|
||||
Reference in New Issue
Block a user