News for hackers. Stuff that matters.
Re:JavaScript Growing Pains: From 0 to 13,000 Dependencies by onion2k on Sunday June 14, 2020 @10:55AM (#23518080)
Anyone who needs to test an input is an odd number using vanilla JS will eventually end up rolling something that looks a lot like isOdd() themselves (or they'll just ignore a set of potential problems, which definitely is worse). It's very obvious when you read the code - https://github.com/jonschlinkert/is-odd/blob/master/index.js.

Utilities like that are a function of using a weakly typed language. "Just use TypeScript" is an alternative solution, but even in TS you should still check the number is within the bounds of isSafeInteger.

Re:JavaScript Growing Pains: From 0 to 13,000 Dependencies by Carpetsmoker on Sunday June 14, 2020 @11:48PM (#23523606)
Are those checks actually needed?

"2.2 % 2 === 1" works just as well, so why is the isInteger check needed? Why is the isSafeInteger check needed? And "a % 2" is already NaN (and thus false), although an explicit error is arguably better than silently eating it.

Re:JavaScript Growing Pains: From 0 to 13,000 Dependencies by rozab on Sunday June 14, 2020 @11:37AM (#23518453)
But why should isOdd, isEven and isNumber reside in seperate packages? Surely a single math tools package should cover all of this?
Re:JavaScript Growing Pains: From 0 to 13,000 Dependencies by onion2k on Sunday June 14, 2020 @04:00PM (#23520828)
Surely a single math tools package should cover all of this?

They shouldn't. It's silly. You're right that there should be "math"[1], but while those things aren't part of the main JS ecosystem people write utility libraries and publish them.

[1] There is, it's https://mathjs.org/. More people should use it.

Re:JavaScript Growing Pains: From 0 to 13,000 Dependencies by wongarsu on Sunday June 14, 2020 @12:07PM (#23518777)
It's an overreaction to the critizism of bloated libraries like JQuery. Dead code removal with tree shaking is a relatively recent feature in JS toolchains, so instead you have single-function libraries. For example there are also npm packages with each lodash function as its own package [1]

1: https://www.npmjs.com/search?q=keywords:lodash-modularized

Re:JavaScript Growing Pains: From 0 to 13,000 Dependencies by z3t4 on Sunday June 14, 2020 @01:12PM (#23519391)
Think of it like being able to pull any function from a global scope. eg. var/const foo = require("bar") Its one gigantic standard library.