countries-api

2.0.2 • Public • Published

Countries-Api

Module which expose some usefull Api's that can be very handy when dealing with countries

Country JSON object will be like

{
  "name": {
    "common": "Aruba",
    "official": "Aruba",
    "native": {
      "nld": {
        "official": "Aruba",
        "common": "Aruba"
      },
      "pap": {
        "official": "Aruba",
        "common": "Aruba"
      }
    }
  },
  "tld": [".aw"],
  "cca2": "AW",
  "ccn3": "533",
  "cca3": "ABW",
  "cioc": "ARU",
  "currency": ["AWG"],
  "callingCode": ["297"],
  "capital": "Oranjestad",
  "altSpellings": ["AW"],
  "region": "Americas",
  "subregion": "Caribbean",
  "languages": {
    "nld": "Dutch",
    "pap": "Papiamento"
  },
  "translations": {
    "deu": {"official": "Aruba", "common": "Aruba"},
    "fra": {"official": "Aruba", "common": "Aruba"},
    "hrv": {"official": "Aruba", "common": "Aruba"},
    "ita": {"official": "Aruba", "common": "Aruba"},
    "jpn": {"official": "\u30a2\u30eb\u30d0", "common": "\u30a2\u30eb\u30d0"},
    "nld": {"official": "Aruba", "common": "Aruba"},
    "por": {"official": "Aruba", "common": "Aruba"},
    "rus": {"official": "\u0410\u0440\u0443\u0431\u0430", "common": "\u0410\u0440\u0443\u0431\u0430"},
    "spa": {"official": "Aruba", "common": "Aruba"},
    "fin": {"official": "Aruba", "common": "Aruba"},
    "zho": {"official": "\u963F\u9C81\u5DF4", "common": "\u963F\u9C81\u5DF4"}
  },
  "latlng": [12.5, -69.96666666],
  "demonym": "Aruban",
  "landlocked": false,
  "borders": [],
  "area": 180
}

Author: Gaurav Joshi

Start

const Countries = require('Countries-Api');

Uses https://github.com/GJ2511/response-format module for formating results

Methods

findByCountryCode(countryCode)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByCountryCode('AW');

Generates the following response payload:

{"statusCode":200,"error":false,"data":[{"name":{"common":"Aruba","official":"Aruba","native":{"nld":{"official":"Aruba","common":"Aruba"},"pap":{"official":"Aruba","common":"Aruba"}}},"tld":[".aw"],"cca2":"AW","ccn3":"533","cca3":"ABW","cioc":"ARU","currency":["AWG"],"callingCode":["297"],"capital":"Oranjestad","altSpellings":["AW"],"region":"Americas","subregion":"Caribbean","languages":{"nld":"Dutch","pap":"Papiamento"},"translations":{"deu":{"official":"Aruba","common":"Aruba"},"fra":{"official":"Aruba","common":"Aruba"},"hrv":{"official":"Aruba","common":"Aruba"},"ita":{"official":"Aruba","common":"Aruba"},"jpn":{"official":"アルバ","common":"アルバ"},"nld":{"official":"Aruba","common":"Aruba"},"por":{"official":"Aruba","common":"Aruba"},"rus":{"official":"Аруба","common":"Аруба"},"spa":{"official":"Aruba","common":"Aruba"},"fin":{"official":"Aruba","common":"Aruba"},"zho":{"official":"阿鲁巴","common":"阿鲁巴"}},"latlng":[12.5,-69.96666666],"demonym":"Aruban","landlocked":false,"borders":[],"area":180}],"message":"OK"}

findByCCN3(ccn3)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByCCN3(533);

Generates the same response as: findByCountryCode(countryCode)

findByCCA3(cca3)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByCCA3('ABW');

Generates the same response as: findByCountryCode(countryCode)

findByCIOC(cioc)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByCIOC('ARU');

Generates the same response as: findByCountryCode(countryCode)

findByCapital(capital)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByCapital('Oranjestad');

Generates the same response as: findByCountryCode(countryCode)

findBySubRegion(subRegion)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findBySubRegion('Caribbean');

Generates the same response as (May have multiple entries): findByCountryCode(countryCode)

findByRegion(region)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByRegion('Americas');

Generates the same response as (May have multiple entries): findByCountryCode(countryCode)

findByResidentName(name)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByResidentName('Aruban');

Generates the same response as (May have multiple entries): findByCountryCode(countryCode)

findByLandLock(boolean)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByLandLock(false);

Generates the same response as (May have multiple entries): findByCountryCode(countryCode)

findByArea(area)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByArea(180);

Generates the same response as (May have multiple entries): findByCountryCode(countryCode)

findByCurrency(currency)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByCurrency("AWG");

Generates the same response as (May have multiple entries): findByCountryCode(countryCode)

findByCallingCode(code)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByCallingCode("297");

Generates the same response as (May have multiple entries): findByCountryCode(countryCode)

findBySpellings(spells)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findBySpellings("ZW", "Republic of Zimbabwe");
Countries.findBySpellings("ZW");

Generates the same response as (May have multiple entries): findByCountryCode(countryCode)

findByBorders(borders)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByBorders("AGO", "BWA",);
Countries.findByBorders("AGO");

Generates the same response as (May have multiple entries): findByCountryCode(countryCode)

findByLat(latitude)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByLat(12);

Generates the same response as : findByCountryCode(countryCode)

findByLong(longitude)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByLong(-69.96666666);

Generates the same response as : findByCountryCode(countryCode)

findByLatLong(array)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByLatLong([12.5, -69.96666666]);

Generates the same response as : findByCountryCode(countryCode)

findByName(name)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByName('Aruba');

Generates the same response as : findByCountryCode(countryCode)

findByOfficialName(officialName)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByOfficialName('Aruba');

Generates the same response as : findByCountryCode(countryCode)

findByLanguage(name)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findByLanguage('Dutch');

Generates the same response as : findByCountryCode(countryCode)

findAll()

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findAll();

Generates the same response as (Whole Country data): findByCountryCode(countryCode)

findById(id)

Returns a 200 Success where:

  • statusCode - 200
  • error - false
  • message - optional message.
  • data - optional payload.
Countries.findById(1);

Generates the same response as : findByCountryCode(countryCode)

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.2
    86
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.2
    86
  • 2.0.1
    7
  • 2.0.0
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i countries-api

Weekly Downloads

93

Version

2.0.2

License

ISC

Unpacked Size

377 kB

Total Files

12

Last publish

Collaborators

  • gj2511