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

countrydata.js

v1.0.6

Published

An offline JavaScript library for getting Global Country , iso3166 Data

Downloads

540

Readme

CountryData.js

| CI Status | Code Coverage | Quality Gate Status | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | CI | codecov | Quality Gate Status |

CountryData.js is a comprehensive Node.js package designed to provide easy access to detailed country information. It supports both JavaScript and TypeScript, making it versatile for various project needs. Whether you're building a web application, API, or any other project that requires country data, this package offers a simple and efficient solution.

Make sure to compile TypeScript files to JavaScript before running the code.

Features

  • Comprehensive Country Data: Access detailed information including country names, short codes, phone codes, regions, and flags.
  • JavaScript and TypeScript Support: Use the package in both JavaScript and TypeScript projects.
  • Easy Integration: Seamlessly integrate with any Node.js project using ES modules.
  • Asynchronous Operations: All methods return promises for efficient data handling.
  • Lightweight: Minimal dependencies to keep your project lean.

Installation

Install CountryData.js using npm:

npm install countrydata.js

Usage

JavaScript Version

import { CountryHelper } from "countrydata.js";

const countryHelper = new CountryHelper();

// Get all countries
(async () => {
  const allCountries = await countryHelper.getCountries();
  console.log(JSON.stringify(allCountries, null, 2));
})();

// Get country by short code
(async () => {
  const country = await countryHelper.getCountryByShortCode('US');
  console.log(country);
})();

TypeScript Version


import { CountryHelper } from 'countrydata.js';

(async () => {
  const countryHelper = new CountryHelper();
  const allCountries = await countryHelper.getCountries();
  console.log(JSON.stringify(allCountries, null, 2));
})();

// Get country by short code
(async () => {
  const countryHelper = new CountryHelper();
  const countryData = await countryHelper.getCountryByShortCode('US');
  console.log(countryData);
})();

You can check the sample code in the example folder. With this sample code, you can see how to use the package in your project both in JavaScript and TypeScript.

Make sure to check how the Sample has been implemented .

API

CountryHelper

The main class that provides access to country data. It works the same way in both JavaScript and TypeScript.

Methods

| Method | Description | |--------|-------------| | getCountries(): Promise<Country[]> | Fetches and returns a promise that resolves to an array of all countries. | | getCountryByShortCode(shortCode: string): Promise<Country | null>| Fetches and returns a promise that resolves to a country object based on the provided country short code (e.g., "US"). Returnsnullif the country is not found. | |getRegionsByCountryShortCode(shortCode: string): Promise<Region[]>| Fetches and returns a promise that resolves to an array of regions for the specified country short code (e.g., "US"). | |getCountryByPhoneCode(phoneCode: string): Promise<Country| null> | Fetches and returns a promise that resolves to a country object based on the provided phone code (e.g., "1" for the US). Returnsnullif the country is not found. | |getCountryPhoneCodeByShortCode(shortCode: string): Promise<string | null> | Fetches and returns a promise that resolves to the phone code of a country based on the provided country short code (e.g., "US"). Returns null if the country is not found. |

Contributing

We welcome contributions to CountryData.js! Please read our contributing guidelines for details on how to submit pull requests, report issues, or request features.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions about using CountryData.js, please open an issue on our GitHub repository or contact us directly through our support channels.