what bothers me the most about leftpad is that it isn’t even good

this is the code for leftpad 

function leftpad (str, len, ch) {
str = String(str);

var i = -1;

if (!ch && ch !== 0) ch = ' ';

len = len - str.length;

while (++i < len) {
str = ch + str;
}

return str;
}

here is how i would write that 

function leftpad (str, len, ch) {
if ( str.length < len ) {
var fillChar = !ch ? " " : String(ch)[0];
return Array(len - str.length).fill(fillChar).join("") + str;
} else {
return str;
}
}

what bothers me the second most about leftpad is that packages released “stable” versions while having a dependency on something versioned 0.0.3

Follow

and these are the same people who argue semantic versioning is “important” and “meaningful”

· · Web · 1 · 0 · 1

what bothers me third most about leftpad is that this is not a situation where DRY is applicable; it is clearer and less ambiguous to just write this as a one‐to‐three‐liner directly in your code

the number of times when i have written

const hex = codepoint.toString(16);
return `U+${hex.length >= 4 ? "" : Array(4 - hex.length).fill(0).join("")}${hex.toUpperCase()}`;

it’s not that hard

what bothers me the zeroth most about leftpad is that the criticisms of this thread are not in any way specific to leftpad

and what actually got me thinking about this was the YAML processor which ships by default in Ruby and is used in virtually every Rails application

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.