3 ms·
To be fair, it really shouldn’t be conflated with ‘number’ - it isn’t the same thing, the behavior differs. And you can (and probably should) use small helper f
by jchw 7y ago
To be fair, it really shouldn’t be conflated with ‘number’ - it isn’t the same thing, the behavior differs. And you can (and probably should) use small helper functions for these kinds of checks, pretty much for this kind of flexibility. Kind of curious what other libs (like lodash) will do.
- wvenable 7y agoIf you're really going to do it right, that small function should also be published as npm package (isnumeric) that takes at least 2 other packages (isnumber and isbigint) as dependencies.
- jchw 7y agoI’m super strongly against this concept actually, which you might gather from mention of lodash.
- coolreader18 7y agoI think they were making a joke.
- jchw 7y agoObviously it was some degree of tongue-in-cheek, but I’m not really that amused, to be honest. It needs a leftpad reference or something.
- jchw 7y agoI see I’ve struck a nerve of some kind so I’d just like to clarify that I am not sorry.
- fgonzag 7y agoAnybody who thinks that's actually good (or even real) advice is going to write horrible code regardless, IMHO.
- wvenable 7y agohttps://www.npmjs.com/browse/depended/is-number https://www.npmjs.com/browse/depended/is-number
- fgonzag 7y agoThat's horrifying, I thought the whole isNumber thing was a joke. Do these guys assemble their application as hundreds (or thousands) of NPM packages containing single functions and then import them together? Because now I actually believe they are capable of it.
- wvenable 7y agoYou might enjoy this as well: https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/ https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/ And this: https://dev.to/leoat12/the-nodemodules-problem-29dc https://dev.to/leoat12/the-nodemodules-problem-29dc
- SomeOldThrow 7y agoI'm still holding out for an int type, I use a double about once a year but I'm completely insecure about using integer operations (e.g. div, mod, as an offset-based index) in javascript.
- jchw 7y agoYou can use w3c typed array stuff at least... though its obviously cumbersome. Bitwise operators also coerce to integer, so they should roughly always be OK.