visionmedia/bytes.js

improve string error message

Closed this issue · 4 comments

It would be nice if the error message for an unknown parse would be nicer. Currently it is a bit confusing, I think:

$ node -pe 'require("bytes")("56r")'

node_modules\bytes\index.js:13
    , n = parseFloat(parts[1])
                          ^
TypeError: Cannot read property '1' of null
    at module.exports (node_modules\bytes\index.js:13:27)
    at [eval]:1:17
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:532:25)
    at startup (node.js:80:7)
    at node.js:902:3

Fixed in my fork https://github.com/theofidry/bytes.js, waiting for merge.

@tj do you feel like added me to the npm module :)?

Hm after some thoughts I'm still changing a few things. It will be up in an hour I think.

@tj @dougwilson Ok it should be good, cf PR #20. Should not cause any backward incompatibility.