Re:What’s New in ES2019
by ZenPsycho on Tuesday July 30, 2019 @07:09AM
(#20563720)
seems like a real missed opportunity to add string.leftPad()
[ Parent
| on HN ]
Seems like a real missed opportunity to look at the Python stdlib and add a bunch of missing functionality to JS so that people don't have to import a metric ton of third party libraries (or worse, write it themselves) to add something you get for free in most other scripting languages.
Even the trim operations they added fall short of the target. In Python (and tcl, by the way) you can specify which characters to trim.
So close, yet, so far.
You can use regex for other characters, the point of the trim functions is that they match the somewhat complex unicode whitespace.
String#padStart already exists: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re:What’s New in ES2019
by soulofmischief on Tuesday July 30, 2019 @09:54AM
(#20564852)
But we still have trimLeft() and trimRight() and in true JS tradition we need some more redundancy for symmetry's sake.
As in the MDN article:
All major engines have also implemented corresponding trimLeft and trimRight functions - without any standard specification.
So ES2019 implements trimStart() and trimEnd(), which are symmetrical to padStart() and padEnd(), but trimLeft() and trimRight() aliases are maintained as not to break working code.That makes sense, "left" trimming rtl text could be confusing.
Re:What’s New in ES2019
by soulofmischief on Thursday August 01, 2019 @10:42AM
(#20584095)
You're right, I was just being tongue-in-cheek.