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

terra-pack

v1.2.0

Published

Geographical Data Processing Package

Downloads

447

Readme

Geographical Data Processing Package

This package provides a set of utilities for handling and processing geographical data such as countries, states, cities, and more. The functions allow you to filter and map countries based on different criteria, calculate distances between coordinates, and retrieve specific geographical data.

Installation

To install the package, run:

npm install terra-pack

Usage

Importing Functions

You can import the functions you need from the package as follows:

import { getCountry, listContinents } from "terra-pack";

Available Functions

  • countriesByContinent(continent: string, filter?: exclusion): Get countries by continent.
  • countriesBySubContinent(subContinent: string, filter?: exclusion): Get countries by subcontinent.
  • listContinents(): List all continents.
  • listSubContinents(): List all subcontinents.
  • getCountry(countryName: string, filter?: exclusion): Get a country by its name.
  • getAllCountries(filter?: exclusion): Get all countries.
  • getCountryByISO2(ISO2: string, filter?: exclusion): Get a country by its ISO2 code.
  • reverseGeoLocate(latitude: number, longitude: number, extend?: boolean): Find the closest city to a set of coordinates.
  • getStatesOfCountry(countryName: string, includeRegions?: boolean): Get states of a specific country.
  • getRegionsOfState(stateName: string): Get regions (cities) of a specific state.
  • getCountryByCityName(cityName: string, filter?: exclusion): Get a country by a city's name.
  • getCountryByStateName(stateName: string, filter?: exclusion): Get a country by a state's name.
  • distanceBetweenCoordinates(lat1: number, lon1: number, lat2: number, lon2: number): Calculate the distance between two coordinates.
  • getAllStates(filter?: exclusion): Get all states.
  • getAllCities(filter?: exclusion): Get all cities.

TypeScript Interfaces

Country

export interface Country {
  name: string;
  iso3: string;
  iso2: string;
  phone_code: string;
  capital: string;
  currency: string;
  currency_name: string;
  tld: string;
  native: string;
  region: string;
  subregion: string;
  nationality: string;
  timezones?: TimeZone[];
  translations?: { [key: string]: string };
  latitude: string;
  longitude: string;
  emoji: string;
  emojiU: string;
  states?: State[];
}

State

export interface State {
  name: string;
  state_code: string;
  latitude: string;
  longitude: string;
  type: "city" | "province" | null;
  cities?: City[];
}

City

export interface City {
  name: string;
  latitude: string;
  longitude: string;
}

GeoLocate

export interface GeoLocate extends City {
  distance: number;
  state?: State;
  country?: Country;
  closestHit?: GeoLocate[];
}

FilterOptions

export type exclusion = Exclude<keyof Country, 'name'>[];

License

This package is licensed under the MIT License.

This README provides a clear overview of the package, instructions on how to install and use it, and details on the available functions and interfaces.