proj4js / mgrs

Utility for converting between WGS84 lat/lng and MGRS coordinates
MIT License
105 stars 45 forks source link

mgrs.inverse(uuidString) returns an array of NaN values #69

Open matthias-ccri opened 2 years ago

matthias-ccri commented 2 years ago

Calling mgrs.inverse('1fcd3c38-ef3d-462d-8fd4-6191bde89736') returns [NaN, NaN, NaN, NaN].

The input string is not a mgrs string so it's expected that mgrs would fail to parse it. But could the library fail in a more obvious way, such as returning undefined or throwing an error?

Our company got bitten by this, since we were using mgrs to detect whether a string was mgrs. We have a search field where the user can enter latlon coordinates, mgrs, and place names, and so our code tries to detect whether a string is mgrs. Unfortunately, we considered an array return value to be a successful parse. We now have code to check for the NaNs. Should this failure case be improved?

Thanks.

DanielJDufour commented 2 years ago

Hi, @matthias-ccri . That's a great suggestion! Would you like to work on a contribution and submit a Pull Request? If not, I can try to get to it, but I can't promise that would happen soon.

DanielJDufour commented 2 years ago

If you (or whoever) works on this, please also add a test case to https://github.com/proj4js/mgrs/blob/master/test/test.js