feat: added helper to valid number to svg attributes

This commit is contained in:
Shivam Mishra 2020-07-08 21:16:59 +05:30
parent d6c33a1e36
commit 9d03d502d9

View File

@ -92,3 +92,16 @@ export function getPositionByAngle(angle, radius) {
y: Math.cos(angle * ANGLE_RATIO) * radius,
};
}
/**
* Check if a number is valid for svg attributes
* @param {object} candidate Candidate to test
* @param {Boolean} nonNegative flag to treat negative number as invalid
*/
export function isValidNumber(candidate, nonNegative=false) {
if (Number.isNaN(candidate)) return false;
else if (candidate === undefined) return false;
else if (!Number.isFinite(candidate)) return false;
else if (nonNegative && candidate < 0) return false;
else return true;
}