Skip to content

Instantly share code, notes, and snippets.

@jaycody
Created November 11, 2016 08:48
Show Gist options
  • Save jaycody/cccbeefe6f6083a4b0559670b672acb2 to your computer and use it in GitHub Desktop.
Save jaycody/cccbeefe6f6083a4b0559670b672acb2 to your computer and use it in GitHub Desktop.
validation function for permissive inputs
//////////////////////////////
// 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