Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

country-list-js

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

country-list-js

Country list with ISO2, ISO3 code, continent, capital, dialing code

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8K
decreased by-0.57%
Maintainers
1
Weekly downloads
 
Created
Source

Country List JS

Build Status Version Total Downloads License

https://i-rocky.github.io/country-list-js/

https://www.npmjs.com/package/country-list-js

Installation

<script src="/path/to/country.min.js"></script>

or

npm install country-list-js

Basic Usage

Instantiation
var country = new Country; 
Searching
var found = country.find('BD', country.FIND_BY_ISO_ALPHA_2);
var found = country.find('BGD', country.FIND_BY_ISO_ALPHA_3);
var found = country.find('Bangladesh', country.FIND_BY_NAME);
var found = country.find('Capital', country.FIND_BY_CAPITAL);
var found = country.find('BDT', country.FIND_BY_CURRENCY);
  • Note: Search query is case insensitive.

The search option can also be hard coded as following

country.FIND_BY_ALPHA_2 = 1
country.FIND_BY_ALPHA_3 = 2
country.FIND_BY_NAME = 3
country.FIND_BY_CAPITAL = 4
country.FIND_BY_CURRENCY = 5

country.find('BD', country.FIND_BY_ISO_ALPHA_2); can be written as country.find('BD', 1);

If the country was not found, the variable found will be null. The return value of all of those above will be similar to the following

{
    continent: "Asia",
    name: "Bangladesh",
    code: {
        iso_alpha_2: "BD",
        iso_alpha_3: "BGD"
    },
    capital: "Dhaka",
    currency: {
        code: "BDT",
        symbol: "Tk",
        decimal: "2"
    },
    dialing_code: "880"
}

Once the search has been made, if the country was found, the information is stored in the instance. We can retrieve the information without having to search again.

var found = country.info();
var name = country.info('name'); //Bangladesh
var iso_alpha_2 = country.info('iso_alpha_2'); //BD
var iso_alpha_3 = country.info('iso_alpha_3'); //BGD
var continent = country.info('continent'); //Asia
var capital = country.info('capital'); //Dhaka
var currency = country.info('currency'); //{ code: "BDT", symbol: "Tk", decimal: "2"}
currency.code //BDT
currency.symbol //Tk
currency.decimal //2
var dialing_code = country.info('dialing_code'); //880

npm commands

Test
npm run test
Build
npm run build

Keywords

FAQs

Package last updated on 10 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc