4 ms·
The isArray package has 72 dependent NPM packages, it's certainly not undiscoverable. The leftpad package gets 5000 downloads a month, that's quite a bit of tes
by CGamesPlay 11y ago
The isArray package has 72 dependent NPM packages, it's certainly not undiscoverable. The leftpad package gets 5000 downloads a month, that's quite a bit of testing for edge cases, compared to the none that I would have gotten had I implemented this myself.
Intuitively, this thread wouldn't exist if your assertion were correct.
- vacri 11y agoAnd when a bug is found, instead of fixing it in one place once, you now have to hope that all of your deps and all of their deps update themselves appropriately.
- rycfan 11y agoWhich is great if you are one person and you fix the bug in your own code. What you're ignoring is that if everyone writes their own version, then the same problem exists. That bug has to be fixed across every (buggy) implementation. A well-defined dependency system where it is easy to discover and update to a new version isn't a matter of hope.
- hacknat 11y agoEdge cases for a padding function? Your comments make me think that the author's point is valid.
- mirekrusin 11y agoEdge case for left padding - when you provide empty string as padding filler. It can go into infinite loop if not written correctly.
- deleted 11y ago[deleted]
- kislotnik 11y agoWrite a damn unit test for your padding function. We should share unit tests, not one-line libs. Libs with unit tests can be one-liners and be as fine-grained as we like, since it's something your users don't have to download
- nailer 11y ago> We should share unit tests, not one-line libs. Most of the small libs I've shared are mainly sharing unit tests. Here's a function I've shared on npm: var kind = function(item) { var getPrototype = function(item) { return Object.prototype.toString.call(item).slice(8, -1); }; var kind, Undefined; if (item === null ) { kind = 'null'; } else { if ( item === Undefined ) { kind = 'undefined'; } else { var prototype = getPrototype(item); if ( ( prototype === 'Number' ) && isNaN(item) ) { kind = 'NaN'; } else { kind = prototype; } } } return kind; }; The tests: suite('kind', function(){ test('shows number-like things as numbers', function(){ assert(avkind(37) === 'Number'); assert(avkind(3.14) === 'Number'); assert(avkind(Math.LN2) === 'Number'); assert(avkind(Infinity) === 'Number'); assert(avkind(Number(1)) === 'Number'); assert(avkind(new Number(1)) === 'Number'); }); test('shows NaN as NaN', function(){ assert(avkind(NaN) === 'NaN'); }); test('Shows strings as strings', function(){ assert(avkind('') === 'String'); assert(avkind('bla') === 'String'); assert(avkind(String("abc")) === 'String'); assert(avkind(new String("abc")) === 'String'); }); test('shows strings accurately', function(){ assert(avkind(true) === 'Boolean'); assert(avkind(false) === 'Boolean'); assert(avkind(new Boolean(true)) === 'Boolean'); }); test('shows arrays accurately', function(){ assert(avkind([1, 2, 4]) === 'Array'); assert(avkind(new Array(1, 2, 3)) === 'Array'); }); test('shows objects accurately', function(){ assert(avkind({a:1}) === 'Object'); assert(avkind(new Object()) === 'Object'); }); test('shows dates accurately', function(){ assert(avkind(new Date()) === 'Date'); }); test('loves Functions too', function(){ assert(avkind(function(){}) === 'Function'); assert(avkind(new Function("console.log(arguments)")) === 'Function'); assert(avkind(Math.sin) === 'Function'); }); test('shows undefined accurately', function(){ assert(avkind(undefined) === 'undefined'); }); test('shows null accurately', function(){ assert(avkind(null) === 'null'); }); });
- takno 11y agoIf you've called it with an empty string there's probably a bug in your calling code which you'll want to test for anyway.
- ubernostrum 11y agoRemember that download counts for package indexes are often misleading. Between scrapers, deployments and continuous-integration systems (all of which download a package -- in the case of CI, sometimes it downloads on every single test run), hitting the thousands-of-downloads level is not hard at all.