country.js
A Node.js module for returning data about countries, ISO info and states/provinces within them.
Table of Contents
Install
npm install countryjs
Using with browserify
To run in-browser, you'll need the bulkify
transform for browserify
, as it pairs with bulk-require
, to staticly resolve each country JSON.
npm install bulkify
var bulkify = require('bulkify')
var bundle = browserify({
entries: [...],
})
.transform(bulkify, {
global: true
})
Usage
To access one of the country properties available, you'll need to use one of the API methods listed below and pass a country in either way:
- Using the ISO-alpha2 code:
country.population('US', 'ISO2')
or country.area('JP')
(defaults) - Using the ISO-alpha3 code:
country.capital('GBR', 'ISO3)
- Using the country name:
country.wiki('france', 'name')
. The matching is case-insensitive, against the native name, alternative spellings and available transalations.
API
.info()
Returns all available information for a specified country.
var country = require('countryjs');
country.info('US', 'ISO2');
country.info('US');
.states()
Returns all states/provinces for a specified country.
var country = require('countryjs');
country.states('USA', 'ISO3');
country.states('US');
.provinces()
Alias of .states()
.name()
Returns name for a specified country
var country = require('countryjs');
country.name('USA','ISO3');
country.name('US')
.altSpellings()
Returns alternate spellings for the name of a specified country
var country = require('countryjs');
country.altSpellings('USA','ISO3');
country.altSpellings('US')
.area()
Returns area (km²) for a specified country
var country = require('countryjs');
country.area('USA','ISO3');
country.area('US')
.borders()
Returns bordering countries (ISO3) for a specified country
var country = require('countryjs');
country.borders('USA','ISO3');
country.borders('US')
.callingCodes()
Returns international calling codes for a specified country
var country = require('countryjs');
country.callingCodes('USA','ISO3');
country.callingCodes('US')
.capital()
Returns capital city for a specified country
var country = require('countryjs');
country.capital('USA','ISO3');
country.capital('US')
.currencies()
Returns official currencies for a specified country
var country = require('countryjs');
country.currencies('USA','ISO3');
country.currencies('US')
.demonym()
Returns the demonyms for a specified country
var country = require('countryjs');
country.demonym('USA','ISO3');
country.demonym('US')
.flag() - INCOMPLETE
Returns SVG link of the official flag for a specified country
var country = require('countryjs');
country.flag('USA','ISO3');
country.flag('US')
.geoJSON()
Returns geoJSON for a specified country
var country = require('countryjs');
country.geoJSON('USA','ISO3');
country.geoJSON('US')
.ISOcodes()
Returns ISO codes for a specified country
var country = require('countryjs');
country.ISOcodes('USA','ISO3');
country.ISOcodes('US')
.languages()
Returns official languages for a specified country
var country = require('countryjs');
country.languages('USA','ISO3');
country.languages('US')
.latlng()
Returns approx latitude and longitude for a specified country
var country = require('countryjs');
country.latlng('USA','ISO3');
country.latlng('US')
.nativeName()
Returns the name of the country in its native tongue
var country = require('countryjs');
country.nativeName('USA','ISO3');
country.nativeName('US')
.population()
Returns approximate population for a specified country
var country = require('countryjs');
country.population('USA','ISO3');
country.population('US')
.region()
Returns general region for a specified country
var country = require('countryjs');
country.region('USA','ISO3');
country.region('US')
.subregion()
Returns a more specific region for a specified country
var country = require('countryjs');
country.subregion('USA','ISO3');
country.subregion('US')
.timezones()
Returns all timezones for a specified country
var country = require('countryjs');
country.timezones('USA','ISO3');
country.timezones('US')
.tld()
Returns official top level domains for a specified country
var country = require('countryjs');
country.tld('USA','ISO3');
country.tld('US')
.translations()
Returns translations for a specified country name in popular languages
var country = require('countryjs');
country.translations('USA','ISO3');
country.translations('US')
.wiki()
Returns link to wikipedia page for a specified country
var country = require('countryjs');
country.wiki('USA','ISO3');
country.wiki('US')
.all()
Returns array of objects containing all available data for all countries. This will be super big. Not recommended.
var country = require('countryjs');
country.all();
Special Thanks
Special thanks to johan for his work on johan/world.geo.json, who made the geojson portion of this build possible.
Contributing
This project adheres to Javascript Standard style
To contribute code to this module, please follow this workflow:
- fork the repo
- make sure to install dev dependencies using
npm install --dev
- Make the changes you desire
- Ensure all changes have a new test in the
test/
folder, and run:
npm test
This will check do the following:
- After making changes in your fork, open a pull request.
Please note that if your code updates do not pass JS Standard style, mocha tests and code coverage, your PR may be rejected and you'll need to fix any issues listed in it.
Contributors
Changelog
All notable changes to this project will be documented in this file.
This project adheres to Semantic Versioning and Keep A Changelog.
Unreleased
v1.4.2 - 2015-04-14
Added
Fixed
Removed
glob
dep (replaced by bulk-require
)
v1.4.1 - 2015-04-14
Added
- Contributor section to README
- @moimikey to contributor list (
package.json
and README
)
Fixed
Removed
- Yugoslavia from country list, as it's not a country anymore
v1.4.0 - 2015-03-13
Added
mocha.opts
- Added standard dev dep
- Added Changelog to README
.DS_STORE
to .gitignore
Changed
- Updated
test
script - Updated Contributing Doc
Disclaimer
This is being maintained in the contributor's free time, and as such, may contain minor errors in regards to some countries.
Most of the information included in this library is what is listed on Wikipedia. If there is an error,
please let me know and I will do my best to correct it.
License (ISC)
Copyright (c) 2015, Trent Oswald trentoswald@therebelrobot.com
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.