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

  • 3.1.1
  • Source
  • npm
  • Socket score

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

Country List JS

npm version Build Status Version Total Downloads License

This module contains country information including 2 and 3 character ISO codes, country and capital names, currency information, telephone calling codes, and provinces (first-tier political subdivisions)

Install

Add to your project from the NPM repository:

npm install --save country-list-js

And get an instance of the module:

// using ES6 modules

import country from 'country-list-js';

// using CommonJS modules
var country = require('country-list-js'); 

In a web page, you can include the modulelike this:

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

Basic Usage

The following methods are available:

Searching

Searches can be conducted by any of the following methods:

var found = country.findByIso2('BD');
var found = country.findByIso3('BGD');
var found = country.findByName('Bangladesh');
var found = country.findByCapital('Dakha');
var found = country.findByCurrency('BDT');
var found = country.findByPhoneNbr('+8804005050');
var found = country.findByProvince('Steiermark');

If the country cannot be found, the return value is undefined. If a single value is found, it is returned as an object similar to the one shown below, and if multiple matches are made, an array of such objects is returned

{ 
    name: 'Denmark',
    continent: 'Europe',
    region: 'Scandinavia, Nordic Countries',
    capital: 'Copenhagen',
    currency: { code: 'DKK', symbol: 'Dkr', decimal: '2' },
    dialing_code: '45',
    provinces: [
        { name: 'Hovedstaden', alias: null },
        { name: 'Midtjylland', alias: null },
        { name: 'Nordjylland', alias: null },
        { name: 'Sjælland', alias: [ 'Zealand' ] },
        { name: 'Syddanmark', alias: null }
    ],
    code: { iso_alpha_2: 'DK', iso_alpha_3: 'DNK' } 
}

Notes

  • Queries are cached so only the first time a country is searched by requires traversal of the internal structures and thus calls will resolve very quickly

  • Search queries are case insensitive

  • Province searches include aliases so you may search for either Sjælland or Zealand

NPM Commands

The built-in test suite may be run in the traditional way

npm run test

and to build the minified file for web run:

npm run build

and retrieve it from dist/country.min.js

Keywords

FAQs

Package last updated on 28 Mar 2019

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