Coder Social home page Coder Social logo

countries's Introduction

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)

countries's People

Contributors

gaurav-daffodil avatar gj2511 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

countries's Issues

Cannot find module '../Countries.json'

The Service.js file in lib > resource should read:

const DATA = require('../Countries') rather than:

const DATA = require('../../Countries.json') as it does currently.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.