String#trim(chars)

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


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

```js
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
doing.
-----

Isiah Meadows
me at isiahmeadows.com


On Mon, Jun 19, 2017 at 8:51 AM, Michael DeByl <michael.debyl at gmail.com> 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 mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list