Neverending Puppy Marathon

    iso3166-lookup
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.0 • Public • Published

    iso3166-lookup

    ISO 3166-1:2020 country and codes lookup. The supported country code types are alpha-2, alpha-3 and num-3.

    Installation

    Install using npm

    npm install iso3166-lookup

    Usage

    Using ISO 3166-1:2020 Codes lookup package into your code (import / require)

    import iso3166Lookup from "iso3166-lookup";

    OR

    const iso3166Lookup = require('iso3166-lookup');

    Get all countries

    console.log(iso3166Lookup.getAllCountries());
    /** Returns:
      [
        {
          alpha2: "AD",
          alpha3: "AND",
          country: "Andorra",
          num3: "020",
        },
        {
          alpha2: "AE",
          alpha3: "ARE",
          country: "United Arab Emirates",
          num3: "784",
        },...
      ]
    */

    Get all Country Names

    console.log(iso3166Lookup.getAllCountryNames());
    /** Returns:
      [
        "Andorra", "United Arab Emirates",...
      ]
    */

    Get all Alpha-2 Codes

    console.log(iso3166Lookup.getAllAlpha2());
    /** Returns:
      [
        "AD", "AE",...
      ]
    */

    Get all Alpha-3 Codes

    console.log(iso3166Lookup.getAllAlpha2());
    /** Returns:
      [
        "AND", "ARE",...
      ]
    */

    Find country details by country name

    console.log(iso3166Lookup.findCountry('India'));
    /** Returns:
      {
        country: 'India',
        alpha2: 'IN',
        alpha3: 'IND',
        numeric: '356'
      }
    */

    Find country details by ISO 3166-1 Alpha-2

    console.log(iso3166Lookup.findAlpha2('in'));
    /** Returns:
      {
        country: 'India',
        alpha2: 'IN',
        alpha3: 'IND',
        numeric: '356'
      }
    */

    Find country details by ISO 3166-1 Alpha-3

    console.log(iso3166Lookup.findAlpha3('ind'));
    /** Returns:
      {
        country: 'India',
        alpha2: 'IN',
        alpha3: 'IND',
        numeric: '356'
      }
    */

    Find country details by ISO 3166-1 Num-3 (Numeric)

    console.log(iso3166Lookup.findNum3(356));
    /** Returns:
      {
        country: 'India',
        alpha2: 'IN',
        alpha3: 'IND',
        numeric: '356'
      }
    */

    Specify Return/Output types for find functions

    You can optionally pass second param to find functions (viz. - findCountry, findAlpha2, findAlpha3, findNum3) to specify desired output format. By default functions will return country object if the parameter is not supplied. You can specify any value from the following: "obj", "name", "alpha2", "alpha3", "num3".

    For example you can specify "name" to recieve output Country name as string or can specify "obj" to get Country object in return.

    console.log(iso3166Lookup.findCountry("india"));          // will return country object for India
    console.log(iso3166Lookup.findCountry("india", "obj"));   // will return country object for India
    console.log(iso3166Lookup.findAlpha2("in", "name"));      // will return "India"
    console.log(iso3166Lookup.findAlpha3("ind", "alpha2"));   // will return "IN"
    console.log(iso3166Lookup.findNum3(356, "alpha3"));       // will return "IND"
    console.log(iso3166Lookup.findCountry("india", "num3"));  // will return "356"

    References:

    You can check following links for more information:

    License

    MIT License Copyright (c) 2022 Omkar Tapale

    Install

    npm i iso3166-lookup

    DownloadsWeekly Downloads

    4

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    80.8 kB

    Total Files

    14

    Last publish

    Collaborators

    • omkartapale