Okay, I’m sure we’ve all seen the npm drama that’s gone down in the past week. Azer had a npm module called left-pad, an 11 line function as a module that should have been in the JavaScript standard library. He also had a module called kik, which clashed with the messaging company Kik’s plans to make their own fancy npm module. So Kik went into

lawyer up

mode which didn’t go over well with Azer, so when they asked if he would change his module name to something else to appease their trademark he was all

and NPM got involved. And like any company would they bent over backwards for Kik and the lawyers and removed kik (the module) from NPM. Then Azer ragequit and removed all of his ~200 modules from npm. Which broke the internet even more effectively than Kim Kardashian’s big ass (NSFW).

Libraries like Babel and React Native were unable to build at all, which stalled them from making new releases, all because of this 11 lines of code that should have been a) in the standard library or b) included in a npm string utility module, not as some silly standalone function. The code in question:

module.exports = 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;

There are a lot of examples of this in npm such as the brilliant one-liners and small functions like is-positive-integer, positive-zero, isArray and is-thirteen (okay that one was made up after all this stuff went down).

I get the idea of small modules of reusable code, really I do, but this one function stuff is kind of crazy when you think about it. The more dependencies you add to your project, the more can go wrong. As babel et. al. found out the other day. If you are going to add more dependencies to your project you should be sure that it’s worth it by checking out the source code, how many issues the project has, and how many recent commits it’s had. And if it would really be that worthwile to include 11 lines of code instead of using something like…


Go check out lodash if you haven’t already, seriously. It is one of the most used NPM modules and contains utility functions for just about everything that you could ever want. It’s well maintained and tested, and if you are worried about file size you can include individual functions from lodash instead of the whole project. It even includes padStart!

So, there’s my 2c on the issue, as everyone else is putting in right now. Feel free to call me out for being a quack!

dr. nick riviera, quack