UNPKG

coordinate_to_country

Version:

Returns and ISO 3166-1 country code for any given latitude or longitude.

33 lines (25 loc) 1.04 kB
const lookup = require("./index"); test("Groningen is in the Netherlands", () => { expect(lookup(53.218620, 6.567365)).toStrictEqual(["NLD"]); }); test("Groningen is in the Netherlands (alpha-2)", () => { expect(lookup(53.218620, 6.567365, true)).toStrictEqual(["NL"]); }); test("The ocean is nowhere", () => { expect(lookup(0, 0)).toStrictEqual([]); }); test("Baarle-Nassau is in the Netherlands", () => { expect(lookup(51.439391, 4.931514)).toStrictEqual(["NLD"]); }); test("Baarle-Hertog is in Belgium", () => { expect(lookup(51.445161, 4.941440)).toStrictEqual(["BEL"]); }); test("Maseru is only in Lesotho", () => { expect(lookup(-29.311089, 27.501524)).toStrictEqual(["LSO"]); }); test("The Croatian-Serbian border dispute works", () => { expect(new Set(lookup(45.739518, 18.953996))).toStrictEqual(new Set(["HRV", "SRB"])); }); test("The parts of Palestine that OSM handles weirdly still work", () => { expect(new Set(lookup(32.073797, 35.406270))).toStrictEqual(new Set(["PSE"])); });