is-valid-coords
v1.4.0
Published
This simple utility verifies if a given coordinates is valid
Downloads
2,543
Maintainers
Readme
isValidCoords
Tiny dependency-free utility to provide coordinates validation written in TypeScript.
Install
npm
npm install --save is-valid-coords
yarn
yarn add is-valid-coords
Usage
isValidCoords
import isValidCoords from "is-valid-coords";
const latitude = 55.7558;
const longitude = 37.6173;
// true
isValidCoords(latitude, longitude);
isValidCoords(0, 0);
// false
isValidCoords(null);
isValidCoords();
getValidCoords
import { getValidCoords } from "is-valid-coords";
// [latitude, longitude]
const coords1 = getValidCoords(55.7558, 37.6173);
// null
const coords2 = getValidCoords(100, 500);
Variants
// two arguments
isValidCoords(55.7558, 37.6173);
// array
isValidCoords([55.7558, 37.6173]);
// string
isValidCoords("55.7558, 37.6173");
// plain object with keys:
// - latitude, lat
// - longitude, lng, lon, long
isValidCoords({
latitude: 55.7558,
longitude: 37.6173,
});