NAME
left-bad – pads strings on the left – the foundation of the modern internet
SYNOPSIS
const leftBad = require("left-bad");
leftBad(str, len, ch = " ");
DESCRIPTION
left-bad pads a string on the left until it reaches the requested length. That's it. It can't do more, it isn't supposed to do more – and yet without left-bad, a significant part of the internet would grind to a halt.
The source code is eleven lines long. 2.3 million packages depend on it, including four compilers, every online bank, the firmware of a space probe and npm itself.
left-bad itself has 1,284 dependencies. The most important one is is-space, a
package that checks whether a character is a space. is-space depends on
is-not-space, which in turn uses is-space. Nobody knows how that works. It
works.
Since 2017, JavaScript can do this on its own with String.prototype.padStart().
left-bad is still installed 40 million times a week. Out of tradition. And
because nobody dares to remove it.
PARAMETERS
str- The string to pad. Numbers are converted; objects are padded as
"[object Object]", which looks very professional in log files. len- The desired total length. Negative values pad on the right. That is a bug that three banks now rely on. It will therefore never be fixed.
ch- The padding character, a space by default. Multiple characters are allowed and produce art.
EXAMPLES
leftBad("42", 5); // " 42"
leftBad("42", 5, "0"); // "00042"
leftBad("42", 8, "ab"); // "ababab42"
leftBad({}, 20); // " [object Object]"
leftBad("42", -5); // "42 " do not touch, see above
Install it:
$ npm install left-bad
added 1284 packages, and audited 1285 packages in 4m
312 packages are looking for funding
run `npm fund` for details
47 vulnerabilities (12 moderate, 31 high, 4 critical)
$ du -sh node_modules
340M node_modules
$ wc -l node_modules/left-bad/index.js
11 node_modules/left-bad/index.jsRemove it:
$ npm unpublish left-bad
npm WARN 2,318,044 packages just stopped working.
npm WARN Including: npm.
npm ERR! npm could not be started.HISTORY
1.0.0- Initial release.
1.0.1- Fixed a bug with spaces.
1.0.2- Fixed a bug introduced by the fix in 1.0.1.
1.0.4- Added TypeScript types. Package size tripled.
1.0.5- Reverted 1.0.4. Package size still doubled.
1.0.6to1.0.9- Updated dependencies. No code changes. 900 new dependencies.
1.0.10- Maintainer unpublished the package after an argument. Internet down for two and a half hours.
1.0.11- Back, after calls from three governments and one grandmother.
BUGS
left-bad is maintained by a single person who was last seen in the spring of
- Their status on the developer platform has read "went out for milk" ever since.
SEE ALSO
begs(3), maybealloc(3), ,