Return falsy when conversion is not supported
MrAmericanMike opened this issue · 3 comments
Would it be possible to make the function return null
or false
when a conversion fails?
For example calling:
convert(360, 'sec').to('min')
will output the whole library code.
Would be nice in it's place to get a falsy value to evaluate against.
@MrAmericanMike - agreed! Just found this library pretty well same time this was opened & first thing I thought!
It would be very nice if @jonahsnider can think about merging / talking to the owner owner of the package / library convert-units to merge these libraries together so they can be used to return the human phrases of the conversion. > Convert-Units does this already, but does not have support for converting via ["seconds", "secs"] etc.. and only one format which is not ideal.
If these libraries merged both of their great features - it would be amazing 🔥.
Would it be possible to make the function return
null
orfalse
when a conversion fails?
Yes, but I don't want to support this. Users should just use the correct units. Forcing everyone to explicitly handle graceful failures because of misspelling the name of a unit is silly, and harms the UX for the vast majority of users. Also, this is only a problem that affects JavaScript users, since TypeScript users will just get a compile-time error if they make the same mistake.
will output the whole library code.
Throwing an error will print the stacktrace of the code where the error occurred. That's built-in JavaScript behavior.
Convert-Units does this already
convert-units is no longer maintained, the last update was more than 5 years ago. If you want functionality to be added you should make a new issue on this repository and request the feature there.
@jonahsnider - sorry to convert / not trying to deter but I highly suggest you look at contributing your project into the Math.JS library (better than my last recommendation!)