-
Notifications
You must be signed in to change notification settings - Fork 942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type Checking for Coordinates and NaN #914
Comments
@DenisCarriere I noticed you actually removed that check here (@markmeyerphoto this change is not in the current/latest release, as you can see). If we did want to have a reliable check for numbers, I tested this function: https://repl.it/KXcu/4 |
👍 Looks like it was removed by accident 🤦♂️ , that was a big commit and I might of missed that when I committed that change. As for more advanced type checking, we shouldn't be doing anything more than the basic If one wants advanced Type checking then use
I would recommend we stick with the current style of basic validation:
|
@stebogit 👍 Sweet method! 👏 Maybe we can add that to function isNumber(x) {
return !isNaN(x) && x !== null && !Array.isArray(x);
} |
To-Do list
|
It should be added to JavaScript!!! 😆 |
HAHA Agreed! SOOO many things should be added to Javascript. Today I was annoyed that I couldn't do |
could we have this update on npm too please? npm remains on version 4.6.0 (that does not exist on github???) |
@barbalex very strange on NPM, the newest version was able to be downloaded using This was the same with all the Turf modules, I republished all the TurfJS modules, |
I agree with @strech345 on this one. I think one of our guiding principles in Turf is that people pass in valid geojson. I think we've made that call elsewhere not to handle errors due to invalid inputs. I'm not sure if @strech345 suggestion of adding an option is viable just because of the sheer number of entry points so I'd be in favour of removing the checks. But I wonder if we could have a
Something similar to this repairGeometry function in Esri world |
@rowanwins yes u right, a |
👍 @rowanwins we can definitely assume/require Turf inputs to be valid GeoJSON, and we might want to mention it in the docs to make it official. A validating tool has always been needed though 😄 |
|
Creating points doesn't coerce strings into numbers but instead gives an error:
That's a little unjavascript-like, but reasonable enough. A common way of dealing with this is to coerce numbers with
parseInt()
or:This works, but creates a false sense of security. Because turf's error checking depends on
typeof
,this works with no error:
+"Foo"
returnsNaN
which istypeof number
. I wonder if it would be possible for turf to fail here when givenNaN
to make it easier to pass in converted strings without type checking. If Turf is going to do type checking, it would be great if it was a little more thorough.The text was updated successfully, but these errors were encountered: