4 ms·
it happened, https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/ https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/
by dpeck 7y ago
it happened, https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/ https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/
- jhabdas 7y agoThere are some good threads (if we could call them that) on GH related to how LeftPad "broke the Internet" and the original stories about it from Kik are/were on Medium. Surfing through the related GH threads lead me to ZeroNet[1], which is fantastic P2P web alternative which works offline and updates in real-time. It also has a decentralized GitHub alternative which would mitigate situations like LeftPad. [1]: https://zeronet.io https://zeronet.io
- goldenkey 7y agoI couldn't help but revise the code because it failed to even use minus-equals and is severely unoptimized. Here is my rendition. Mind you, this is mainly for IE as ES6 has a String.padStart method. I would also use Array(n).fill() but again, IE does not support it, so manual string appending is the sacrifice to make.. module.exports = function(str, len, ch) { if (ch === undefined || ch === '') ch = ' '; str += ""; len -= str.length; len /= ch.length; var pre = ""; while (--len >= 0) pre += ch; return pre + str; }