Created
November 11, 2016 08:48
-
-
Save jaycody/cccbeefe6f6083a4b0559670b672acb2 to your computer and use it in GitHub Desktop.
validation function for permissive inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////// | |
// Validate point & point-like objects | |
////////////////////////////// | |
static isPointLike(thing) { | |
// RETURNS true if exactly what we want | |
if (thing instanceof Point) return true; | |
////////////////////// | |
// RETURNS true if its kinda-like what we want, that is: | |
// has properties x,y oftype 'number' but not NaN numbers | |
// RETURNS false if thing is neither a point nor point-like, | |
// or is empty string, undefined, NaN, null | |
return !!thing | |
&& typeof thing.x === "number" | |
&& !isNaN(thing.x) | |
&& typeof thing.y === "number" | |
&& !isNaN(thing.y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment