`String.prototype.trimStart`/`String.prototype.trimEnd` with a given string

Jordan Harband ljharb at gmail.com
Mon Jun 24 04:45:59 UTC 2019

`trimStart` and `trimEnd` are better-named versions of the very very
long-existing `trimLeft` and `trimRight`, which lack this ability, along
with ES5's `trim`.

It wouldn't make sense for these three to differ.

It certainly seems like a potential language proposal to add a string
argument to all three; however, at what point is that reimplementing
`string.replace(/^(foo)+/, '')`, `string.replace(/(foo)+$/, '')`, and
`string.replace(/^(foo)+|$(foo)+$/, '')`? How common is the use case to
trim matching substrings off of the ends of a string? (the use cases for
padding were quite common)

On Sun, Jun 23, 2019 at 12:14 AM Jacob Pratt <jhprattdev at gmail.com> wrote:

> `String.prototype.padStart` and `String.prototype.padEnd` accept the
> string to pad with as their final parameter. Is there any particular reason
> `String.prototype.trimStart` and `String.prototype.trimEnd` don't do the
> same? It would be nice to have a parallel, such that `'foo'.padEnd(10,
> 'bar').trimEnd('bar') === 'foo'`.
> References:
> - https://github.com/tc39/proposal-string-pad-start-end
> - https://github.com/tc39/proposal-string-left-right-trim
> Jacob Pratt
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190623/91744e33/attachment-0001.html>

More information about the es-discuss mailing list