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

@yimnai-dev/country-validator

v1.2.0

Published

@yimnai-dev/country-validator is a javascript library that helps in working with basic data about world countries such as names, country code, dial code and continent.

Downloads

15

Readme

@yimnai-dev/country-validator is a javascript library that helps in working with basic data about world countries such as names, country code, dial code and continent.

installation

npm install @yimnai-dev/country-validator --save OR pnpm install @yimnai-dev/country-validator OR yarn install@yimnai-dev/country-validator

GITHUB

API Reference

Get all countries

  getAllCountries(limit)

| Parameter | Type | Description | | :-------- | :------- | :------------------------- | | limit | number | Optional. The number of countries you want to get. The absence of a limit will return all countries |

Get sorted countries

  sortCountries({name, code, dial_code, continent}, limit)

The absence of any of the parameters listed above will simply return a sorted list of all countries. You can limit the number of countries with the limit parameter. You do not need to pass all of the object parameters as any of them can be used to query the countries

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | name | string | Optional | | code | string | Optional | | dial_code | string | Optional | | continent | string | Optional |

Get Countries of a continent

   getCountriesOfContinent(continent, limit)

Takes a continent and a limit and returns all countries that satisfy that condition. | Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | continent | string | Required | | limit | number | Required |

Get the continent of a particular country

   getContinentOfCountry({name, dial_code, code})

Passing either the name, dial_code or code of a country will return its continent if it exists. At least one of the parameters must be passed for it to work as intended | Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | name | string | Optional | | dial_code | string | Optional | | code | string | Optional |

Verify if particular country is in passed continent

   verifyIfCountryInContinent({name, dial_code, code}, continent)

Passing either the name, dial_code or code of a country and the continent against which you are testing it will return a boolean value indicating whether or not the country is in that particular continent. At least one of the parameters must be passed for it to work as intended | Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | name | string | Optional | | dial_code | string | Optional | | code | string | Optional | | continent | string | Required |

Get information about a particular country

   getCountryInfo({name, dial_code, code})

Passing either the name, dial_code or code of a country will return an object containing the basic information about that country | Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | name | string | Optional | | dial_code | string | Optional | | code | string | Optional |

Get the name of a country

   getCountryName({dial_code, code})

Passing either the dial_code or code of a country will return the name of the country if it exists. At least one parameter must be passed. | Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | dial_code | string | Optional | | code | string | Optional |

Get the country code of a country

   getCountryCode({dial_code, name})

Passing either the dial_code or name of a country will return the country Code of the country if it exists. At least one parameter must be passed. | Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | dial_code | string | Optional | | name | string | Optional |

Get the dial code of a country

   getCountryDialCode({name, code})

Passing either the name or code of a country will return the Dial Dial Code of the country if it exists. At least one parameter must be passed. | Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | name | string | Optional | | code | string | Optional |

Verify if a country exists

   verifyCountryExistence(country: string)

Passing the name of the country will return a boolean indicating whether or not the country exists or not. | Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | country | string | Required |

Get list of states in country

   getCountryStates(countryObj: NameOrCodeOrDialCode)

Passing any of these parameters will return an array of all the states in the country. Passing none of them will return undefined. | Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | name | string | Optional | | code | string | Optional | | dial_code | string | Optional |

Make sure to enter the full name of a country when checking with a name parameter. Also, empty objects will be returned if nothing could be found.

Appendix

This library was put together by Yimnai Nerus. If you want to contribute, you can always fork the project to do so. Constructive feedback and criticism is highly valued. Thank you for using our library.

Authors

🚀 About Me

Web developer and software engineer