is-valid-coords
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

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,
});

Package Sidebar

Install

npm i is-valid-coords

Weekly Downloads

591

Version

1.4.0

License

MIT

Unpacked Size

13.8 kB

Total Files

26

Last publish

Collaborators

  • artemfitiskin