npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@geoapify/un-locode

v1.0.2

Published

A Node.js library for querying United Nations Location Code (UN/LOCODE) data

Downloads

177

Readme

@geoapify/un-locode

A Node.js library for querying United Nations Location Code (UN/LOCODE) data. This library provides easy access to UN/LOCODE data, allowing users to retrieve location details using country and location codes.

Installation

Install the package via npm:

npm install @geoapify/un-locode

Usage

Import the query function from the package. Use the function with await to fetch location details by specifying the country code and location code.

const { query } = require('@geoapify/un-locode');

(async () => {
  try {
    const result = query('US', 'APG');
    console.log(result);
  } catch (error) {
    console.error('Error fetching location data:', error);
  }
})();

Parameters

  • countryCode (string): The ISO 3166-1 alpha-2 country code, such as US for the United States.
  • locationCode (string): The three-character location code, such as APG for Aberdeen.

Response

The query function returns a Promise resolving to an object with location data. If the specified code is not found, it returns null. Example response:

{
  "country": "US",
  "location": "APG",
  "locationName": "Aberdeen",
  "subdivision": "MD",
  "status": "AI",
  "functionCodes": ["3", "4"],
  "coordinates": {
    "lat": 39.5120347,
    "lon": -76.1643289
  }
}
  • country: The ISO country code of the location.
  • location: The location code within the specified country.
  • locationName: The name of the location.
  • subdivision: Subdivision code (e.g., state or province), if available.
  • status: Location status code.
  • functionCodes: Array of strings representing functional designation codes.
  • coordinates: An object with lat (latitude) and lon (longitude) for geographic coordinates.

Note: Some rows in the original UN/LOCODE data lack coordinates. We used the Geoapify Geocoding API to find corresponding coordinates for these entries.

Function Codes

Each defined function has a classifier; the most important are:

  • 1 = Port (for any kind of waterborne transport)
  • 2 = Rail terminal
  • 3 = Road terminal
  • 4 = Airport
  • 5 = Postal exchange office
  • 6 = Inland Clearance Depot (ICD) or "Dry Port", "Inland Clearance Terminal"
  • 7 = Fixed transport functions (e.g., oil platform); the classifier "7" is reserved for this function. This includes terminals like oil pipelines and can be extended to electric power lines or ropeway terminals.
  • B = Border crossing function
  • 0 = Function not known, to be specified

Status Codes

The status of the entry is indicated by a 2-character code, with the following codes currently in use:

  • AA: Approved by a competent national government agency
  • AC: Approved by Customs Authority
  • AF: Approved by a national facilitation body
  • AI: Code adopted by an international organization (e.g., IATA or ECLAC)
  • AM: Approved by the UN/LOCODE Maintenance Agency
  • AQ: Entry approved, functions not verified
  • AS: Approved by a national standardization body
  • RL: Recognized location; existence and representation confirmed by a nominated gazetteer or other reference
  • RN: Request from credible national sources for locations within their own country
  • RQ: Request under consideration
  • UR: Entry included on user’s request; not officially approved
  • RR: Request rejected
  • QQ: Original entry not verified since the date indicated
  • XX: Entry to be removed in the next issue of UN/LOCODE

Error Handling

The function returns null if the location is not found. Ensure your application handles this scenario accordingly.

Contributing

Contributions are welcome! Please fork the repository, make your changes, and submit a pull request.