4 ms·
It's because there are so many of these warts and gaps that a Javascript dev has two options: write their own left-pad (and array.includes, and range iterator l
by shmageggy 11y ago
It's because there are so many of these warts and gaps that a Javascript dev has two options: write their own left-pad (and array.includes, and range iterator like I did yesterday, and so on...) every 5 minutes, or use the one you can reasonably assume already works without bugs.
- mayank 11y agoYou should check out lodash/underscore [1]. Not only is the codebase well reviewed, but there is a _.pad function in there (left and right!), and the maintainers are open to additions if core functionality is truly missing. You'll also get functional primitives that will actually make JS fun. [1] https://lodash.com/docs https://lodash.com/docs Edit: FWIW, lodash also has _.isInteger(), _.range(), and _.inRange().
- shmageggy 11y agoYup I looked there first, but there was no iterator-based range function. lodash/underscore were built for a pre-ES6 world, so they don't cover all the nice iterator/generator stuff that I like from python (yet? hopefully!)
- aumerle 11y agoI suggest you look at using a python like language that transpiles into javascript. For example, https://github.com/kovidgoyal/rapydscript-ng https://github.com/kovidgoyal/rapydscript-ng which supports iterators/generators on both ES 5 and ES 6 runtimes. Using a python like language greatly eases my pain as a primarily python developer that has to code significant amounts of javascript.
- deleted 11y ago[deleted]
- jlarocco 11y agoI don't think that explains it at all. If Javascript string manipulation sucks, there should be a single string manipulation library that fills in the gaps, not 50 different libraries to work around 50 different gaps. Ditto every other class of deficiency.
- 8note 11y agoyou could also have 1 library that depends on 50 different libraries, where you trust somebody to lock and update them responsibly
- 8note 11y agoyou could also have 1 library that depends on 50 different libraries, where you trust somebody to lock and update them responsibly
- sotojuan 11y agoThere's really only lodash now that individual functions can be imported without bringing the rest in.
- coldtea 11y agoAnd what's wrong with Lodash, which contains pad and all the above, and loads more besides? https://lodash.com/docs#pad https://lodash.com/docs#pad