6 ms·
seems like a real missed opportunity to add string.leftPad()
by ZenPsycho 7y ago
seems like a real missed opportunity to add string.leftPad()
- davman 7y agoYou mean https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... ?
- alexlur 7y agoString#padStart already exists: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- soulofmischief 7y agoBut we still have trimLeft() and trimRight() and in true JS tradition we need some more redundancy for symmetry's sake.
- deleted 7y ago[deleted]
- STRML 7y agoAs 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.
- soulofmischief 7y agoYou're right, I was just being tongue-in-cheek.
- ZenPsycho 7y agoThat makes sense, "left" trimming rtl text could be confusing.
- AsusFan 7y agoSeems 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.
- snek 7y agoYou can use regex for other characters, the point of the trim functions is that they match the somewhat complex unicode whitespace.