
Security News
PHP Foundation Says Chainguard Broke Security Embargo Ahead of Emergency Patches
The PHP Foundation says Chainguard broke a security embargo ahead of critical RCE patches, as leaks disrupted the coordinated release.
country-coder
Advanced tools
📍 ➡️ 🇩🇰 Convert longitude-latitude pairs to ISO 3166-1 codes quickly and locally
country-coder is a lightweight package that looks up region identifiers for geographic points without calling a server. It can code and convert between several common IDs:
ZA)ZAF)710)Q258)Results can optionally include non-country ISO 3166-1 features, such as Puerto Rico (PR) or the Isle of Man (IM). Some unofficial yet exceptionally-reserved or user-assigned ISO codes are also supported, such as the European Union (EU) and Kosovo (XK).
Client-side coding has a number of benefits over server-side solutions:
country-coder prioritizes package size and lookup speed over precision. Thus, it's not suitable for some situations and use cases:
npm install country-coder
This library is available in both ES5/CommonJS and ES6 module formats.
const CountryCoder = require('country-coder').CountryCoder; // CommonJS
// or
import { CountryCoder } from 'country-coder'; // ES6
Simply pass in a [longitude, latitude] to iso1A2Code to get the country code.
const coder = new CountryCoder();
coder.iso1A2Code([-4.5, 54.2]); // returns 'GB'
To include non-country regions, pass in region for the level option.
const coder = new CountryCoder();
coder.iso1A2Code([-4.5, 54.2], { level: 'region' }); // returns 'IM'
The same method can convert from other identifiers.
const coder = new CountryCoder();
coder.iso1A2Code('Q145'); // returns 'GB'
Read the full API reference to see everything country-coder can do.
This package is kept intentionally minimal. However, if you find a bug or have an interesting idea for an enhancement, feel free to open an Issue and/or Pull Request.
Constructs a new CountryCoder.
const coder = new CountryCoder();
# feature(arg: string | Location, opts?: CodingOptions): RegionFeature? <>
Returns the GeoJSON feature from borders for the given location or identifier and options, if found.
const coder = new CountryCoder();
coder.feature([-4.5, 54.2]); // returns United Kingdom feature
coder.feature([-4.5, 54.2], { level: 'region' }); // returns Isle of Man feature
coder.feature([0, 90]); // returns null
coder.feature('GB'); // returns United Kingdom feature
coder.feature('GBR'); // returns United Kingdom feature
coder.feature('826'); // returns United Kingdom feature
coder.feature('Q145'); // returns United Kingdom feature
coder.feature('🇬🇧'); // returns United Kingdom feature
coder.feature('UK'); // returns United Kingdom feature
coder.feature('IM'); // returns Isle of Man feature
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [-4.5, 54.2] } };
coder.feature(pointGeoJSON); // returns United Kingdom feature
coder.feature(pointGeoJSON.geometry); // returns United Kingdom feature
# iso1A2Code(arg: string | Location, opts?: CodingOptions): string? <>
Returns the ISO 3166-1 alpha-2 code for the given location or identifier and options, if found.
const coder = new CountryCoder();
coder.iso1A2Code([-4.5, 54.2]); // returns 'GB'
coder.iso1A2Code([-4.5, 54.2], { level: 'region' }); // returns 'IM'
coder.iso1A2Code([0, 90]); // returns null
coder.iso1A2Code('GBR'); // returns 'GB'
coder.iso1A2Code('826'); // returns 'GB'
coder.iso1A2Code('Q145'); // returns 'GB'
coder.iso1A2Code('🇬🇧'); // returns 'GB'
coder.iso1A2Code('UK'); // returns 'GB'
coder.iso1A2Code('IMN'); // returns 'IM'
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [-4.5, 54.2] } };
coder.iso1A2Code(pointGeoJSON); // returns 'GB'
coder.iso1A2Code(pointGeoJSON.geometry); // returns 'GB'
# iso1A3Code(arg: string | Location, opts?: CodingOptions): string? <>
Returns the ISO 3166-1 alpha-3 code for the given location or identifier and options, if found.
const coder = new CountryCoder();
coder.iso1A3Code([-4.5, 54.2]); // returns 'GBR'
coder.iso1A3Code([-4.5, 54.2], { level: 'region' }); // returns 'IMN'
coder.iso1A3Code([0, 90]); // returns null
coder.iso1A3Code('GB'); // returns 'GBR'
coder.iso1A3Code('826'); // returns 'GBR'
coder.iso1A3Code('Q145'); // returns 'GBR'
coder.iso1A3Code('🇬🇧'); // returns 'GBR'
coder.iso1A3Code('UK'); // returns 'GBR'
coder.iso1A3Code('IM'); // returns 'IMN'
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [-4.5, 54.2] } };
coder.iso1A3Code(pointGeoJSON); // returns 'GBR'
coder.iso1A3Code(pointGeoJSON.geometry); // returns 'GBR'
# iso1N3Code(arg: string | Location, opts?: CodingOptions): string? <>
Returns the ISO 3166-1 numeric-3 code for the given location or identifier and options, if found.
const coder = new CountryCoder();
coder.iso1N3Code([-4.5, 54.2]); // returns '826'
coder.iso1N3Code([-4.5, 54.2], { level: 'region' }); // returns '833'
coder.iso1N3Code([0, 90]); // returns null
coder.iso1N3Code('GB'); // returns '826'
coder.iso1N3Code('GBR'); // returns '826'
coder.iso1N3Code('Q145'); // returns '826'
coder.iso1N3Code('🇬🇧'); // returns '826'
coder.iso1N3Code('UK'); // returns '826'
coder.iso1N3Code('IM'); // returns '833'
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [-4.5, 54.2] } };
coder.iso1N3Code(pointGeoJSON); // returns '826'
coder.iso1N3Code(pointGeoJSON.geometry); // returns '826'
# wikidataQID(arg: string | Location, opts?: CodingOptions): string? <>
Returns the Wikidata QID for the given location or identifier and options, if found.
const coder = new CountryCoder();
coder.wikidataQID([-4.5, 54.2]); // returns 'Q145'
coder.wikidataQID([-4.5, 54.2], { level: 'region' }); // returns 'Q9676'
coder.wikidataQID([0, 90]); // returns null
coder.wikidataQID('GB'); // returns 'Q145'
coder.wikidataQID('GBR'); // returns 'Q145'
coder.wikidataQID('826'); // returns 'Q145'
coder.wikidataQID('🇬🇧'); // returns 'Q145'
coder.wikidataQID('UK'); // returns 'Q145'
coder.wikidataQID('IM'); // returns 'Q9676'
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [-4.5, 54.2] } };
coder.wikidataQID(pointGeoJSON); // returns 'Q145'
coder.wikidataQID(pointGeoJSON.geometry); // returns 'Q145'
# emojiFlag(arg: string | Location, opts?: CodingOptions): string? <>
Returns the emoji flag sequence for the given location or identifier and options, if found.
const coder = new CountryCoder();
coder.emojiFlag([-4.5, 54.2]); // returns '🇬🇧'
coder.emojiFlag([-4.5, 54.2], { level: 'region' }); // returns '🇮🇲'
coder.emojiFlag([0, 90]); // returns null
coder.emojiFlag('GB'); // returns '🇬🇧'
coder.emojiFlag('GBR'); // returns '🇬🇧'
coder.emojiFlag('826'); // returns '🇬🇧'
coder.emojiFlag('Q145'); // returns '🇬🇧'
coder.emojiFlag('UK'); // returns '🇬🇧'
coder.emojiFlag('IM'); // returns '🇮🇲'
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [-4.5, 54.2] } };
coder.emojiFlag(pointGeoJSON); // returns '🇬🇧'
coder.emojiFlag(pointGeoJSON.geometry); // returns '🇬🇧'
# features(loc: Location): [RegionFeature] <>
Returns all the the features containing the given location.
const coder = new CountryCoder();
coder.features([-4.5, 54.2]); // returns [{Isle of Man feature}, {United Kingdom feature}]
coder.features([0, 51.5]); // returns [{United Kingdom feature}, {European Union feature}]
coder.features([6.1, 46.2]); // returns [{Switzerland feature}]
coder.features([0, 90]); // returns []
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [6.1, 46.2] } };
coder.features(pointGeoJSON); // returns [{Switzerland feature}]
coder.features(pointGeoJSON.geometry); // returns [{Switzerland feature}]
# iso1A2Codes(loc: Location): [string] <>
Returns the ISO 3166-1 alpha-2 codes for all the the features containing the given location.
const coder = new CountryCoder();
coder.iso1A2Codes([-4.5, 54.2]); // returns ['IM', 'GB']
coder.iso1A2Codes([0, 51.5]); // returns ['GB', 'EU']
coder.iso1A2Codes([6.1, 46.2]); // returns ['CH']
coder.iso1A2Codes([0, 90]); // returns []
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [-4.5, 54.2] } };
coder.iso1A2Codes(pointGeoJSON); // returns ['IM', 'GB']
coder.iso1A2Codes(pointGeoJSON.geometry); // returns ['IM', 'GB']
# isInEuropeanUnion(arg: string | Location): boolean <>
Returns true if the feature with the given location or identifier is found to be part of the European Union.
const coder = new CountryCoder();
coder.isInEuropeanUnion([0, 51.5]); // returns true (Britain)
coder.isInEuropeanUnion([-4.5, 54.2]); // returns false (Isle of Man)
coder.isInEuropeanUnion([6.1, 46.2]); // returns false (Switzerland)
coder.isInEuropeanUnion([0, 90]); // returns false (North Pole)
coder.isInEuropeanUnion('EU'); // returns true
coder.isInEuropeanUnion('GB'); // returns true
coder.isInEuropeanUnion('GBR'); // returns true
coder.isInEuropeanUnion('826'); // returns true
coder.isInEuropeanUnion('Q145'); // returns true
coder.isInEuropeanUnion('🇬🇧'); // returns true
coder.isInEuropeanUnion('UK'); // returns true
coder.isInEuropeanUnion('IM'); // returns false
coder.isInEuropeanUnion('CH'); // returns false
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [0, 51.5] } };
coder.isInEuropeanUnion(pointGeoJSON); // returns true (Britain)
coder.isInEuropeanUnion(pointGeoJSON.geometry); // returns true (Britain)
# borders: RegionFeatureCollection
<>
The base GeoJSON feature collection used for feature lookup. While this property is public, modifying it is not recommended and may have unintended effects.
# Vec2
An array of two numbers as [longitude, latitude] referenced to the WGS 84 datum.
[number, number]
# PointGeometry
GeoJSON Point geometry as specified by RFC 7946.
# PointFeature
A GeoJSON Feature with Point geometry as specified by RFC 7946.
# Location
A geographic location in one of the supported formats.
Vec2 | PointGeometry | PointFeature
# CodingOptions
An object containing options used for geocoding.
level: string, for overlapping features, the division level of the one to get
country (default): the "sovereign state" featureregion: the lowest-level feature with an official or user-assigned ISO code# RegionFeature
A GeoJSON feature representing a codable geographic area.
# RegionFeatureProperties
An object containing the attributes of a RegionFeature object.
iso1A2: string, ISO 3166-1 alpha-2 codeiso1A3: string, ISO 3166-1 alpha-3 codeiso1N3: string, ISO 3166-1 numeric-3 codewikidata: string, Wikidata QIDemojiFlag: string, the emoji flag sequence derived from this feature's ISO 3166-1 alpha-2 codealiases: [string], additional identifiers which can be used to look up this featurecountry: string, for features entirely within a country, the ISO 3166-1 alpha-2 code for that countrygroups: [string], the ISO 3166-1 alpha-2 codes of other features this feature is entirely within, other than its countryisoStatus: string, the status of this feature's ISO 3166-1 code(s) if they are not officially-assigned
excRes: exceptionally-reservedusrAssn: user-assigned# RegionFeatureCollection
A GeoJSON feature collection containing RegionFeature objects.
FAQs
Convert longitude-latitude pairs to ISO 3166-1 codes quickly and locally
The npm package country-coder receives a total of 0 weekly downloads. As such, country-coder popularity was classified as not popular.
We found that country-coder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.

Security News
The PHP Foundation says Chainguard broke a security embargo ahead of critical RCE patches, as leaks disrupted the coordinated release.

Security News
PHP releases emergency patches for two critical RCE vulnerabilities as agencies urge organizations to take unpatched sites offline.

Threat Research
/Security News
A supply chain attack compromised LiteLLM 1.107.0 on PyPI and Docker, spreading malware that steals cloud credentials, developer secrets, and AI provider keys.