checkSanity.js 410 B

123456789101112131415
  1. export default function (point) {
  2. checkCoord(point.x);
  3. checkCoord(point.y);
  4. }
  5. function checkCoord(num) {
  6. if (typeof Number.isFinite === 'function') {
  7. if (Number.isFinite(num)) {
  8. return;
  9. }
  10. throw new TypeError('coordinates must be finite numbers');
  11. }
  12. if (typeof num !== 'number' || num !== num || !isFinite(num)) {
  13. throw new TypeError('coordinates must be finite numbers');
  14. }
  15. }