Isiah Meadows isiahmeadows at
Tue Jun 20 09:49:00 UTC 2017

To be clear, `trim` could easily be implemented like this:

function trim(str) {
    return str.replace(/^\s+|\s+$/g, "")

If you need something similar, you can alter that regular expression
accordingly to get what you want.

As for performance, if you really get to the point where that becomes
your bottleneck, you should really reconsider what you're actually

Isiah Meadows
me at

On Mon, Jun 19, 2017 at 8:51 AM, Michael DeByl <michael.debyl at> wrote:
> Generally `trim()` will only operate on the start and end of the strings
> (also why `trimLeft()` and `trimRight()`.
> All that needs to be done is allow specifying a string or array of
> characters to trim as an argument – which should not break anything as the
> `trim()` method currently accepts nothing. If nothing specified, use [\r,
> \n, \t, ‘ ‘] – or whatever it currently does as to once again not break
> anything.
> As a sidenote; traditionally `trim` will use text transforms first from the
> start, and then from the end of the string. I’m not sure in JS if a regex is
> faster, or if it even matters overall.
> -Michael
> _______________________________________________
> es-discuss mailing list
> es-discuss at

More information about the es-discuss mailing list