DEV Community

Cover image for Country Phone Extension Search Javascript package.
Mayank
Mayank

Posted on

5 1

Country Phone Extension Search Javascript package.

Country Detail

Purpose to provide SVG Flags, Unicode flag (emojis), Country code, Phone extension

Install using npm

npm i country-code-flag-phone-extension-json
Enter fullscreen mode Exit fullscreen mode

Methods & Options

const country = require("country-code-flag-phone-extension-json");

// Get all countries.
country.all();


const options  = {
    filter: "", // If pass as string then full text search on db (name, subregion, region, currency)
    filter: [], // if pass as array filter by ISO2 codes 
    keys: [], // define object keys to minify records,
    sortBy: [], // sort by priortiy of mentioned ISO2 code.
    limit: 5 // limit the returned object
}
Enter fullscreen mode Exit fullscreen mode

Usage

Get all Countries

List all the countries with details object

const country = require("country-code-flag-phone-extension-json");

country.all();

// Return all the country with full detailed object
Enter fullscreen mode Exit fullscreen mode

Filter Countries by ISO2 Code

Filter country by country codes

const country = require("country-code-flag-phone-extension-json");

country.all({
  filter: ["IN", "US"],
});

// Return only two records filter by India and United States
Enter fullscreen mode Exit fullscreen mode

Filter Countries by plain text search

Quick search in database

const country = require("country-code-flag-phone-extension-json");

country.all({
  filter: "india",
});

// Return only one records filter search by india
// It search on name, region, subregion, currency name
Enter fullscreen mode Exit fullscreen mode

Sort by Country

In some case, we want specific country to be on top of the dropdown and followed by all others.

const country = require("country-code-flag-phone-extension-json");

country.all({
  sortBy: ["US", "IN"],
});

// Return all countried sort by US, IN and
// all remaining countries ..
Enter fullscreen mode Exit fullscreen mode

Limit the record by Country

Top 5 records

const country = require("country-code-flag-phone-extension-json");

country.all({
    limit: 5
})
// Return top 5 countries from DB

country.all({
    limit: 5,
    sortBy: ["US", "IN"]
})
// Return top 5 followed by - US, IN
// and reminaing 3 countries from DB

country.all({
    filter: ["IN", "US", "ZW", "YE", "AD"]
    limit: 5,
    sortBy: ["US", "IN"]
})

// Return  5 records followed by - US, IN
// and reminaing 3 filtered (AD, YE, ZW) countries from DB

Enter fullscreen mode Exit fullscreen mode

Minified the filted object or all countried from DV

const country = require("country-code-flag-phone-extension-json");

country.all({
    keys: ["id", "name", "dail_code", "mask", "emoji", "translations.kr"],
    limit: 5
})
// output
/*
{
    "rows": [
        {
            "id": 1,
            "name": "Afghanistan",
            "dail_code": "+93",
            "mask": "+93-##-###-####",
            "emoji": "πŸ‡¦πŸ‡«",
            "translations": {
                "kr": "μ•„ν”„κ°€λ‹ˆμŠ€νƒ„"
            }
        },
        {
            "id": 2,
            "name": "Aland Islands",
            "dail_code": "+358",
            "emoji": "πŸ‡¦πŸ‡½",
            "translations": {
                "kr": "μ˜¬λž€λ“œ μ œλ„"
            }
        },
        {
            "id": 3,
            "name": "Albania",
            "dail_code": "+355",
            "mask": "+355(###)###-###",
            "emoji": "πŸ‡¦πŸ‡±",
            "translations": {
                "kr": "μ•Œλ°”λ‹ˆμ•„"
            }
        },
        {
            "id": 4,
            "name": "Algeria",
            "dail_code": "+213",
            "mask": "+213-##-###-####",
            "emoji": "πŸ‡©πŸ‡Ώ",
            "translations": {
                "kr": "μ•Œμ œλ¦¬"
            }
        },
        {
            "id": 5,
            "name": "American Samoa",
            "dail_code": "+1684",
            "mask": "+1(684)###-####",
            "emoji": "πŸ‡¦πŸ‡Έ",
            "translations": {
                "kr": "아메리칸사λͺ¨μ•„"
            }
        }
    ],
    "count": 5
}
*/

country.all({
    limit: 5,
    sortBy: ["US", "IN"]
})
// Return top 5 followed by - US, IN
// and reminaing 3 countries from DB

country.all({
    filter: ["IN", "US", "ZW", "YE", "AD"]
    limit: 5,
    sortBy: ["US", "IN"]
})

// Return  5 records followed by - US, IN
// and reminaing 3 filtered (AD, YE, ZW) countries from DB

Enter fullscreen mode Exit fullscreen mode

If you like it

You can buy me coffee
https://www.buymeacoffee.com/mayankjhawar

Support me at Patreon
https://patreon.com/mayank120

License

MIT

Billboard image

Imagine monitoring that's actually built for developers

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (4)

Collapse
 
amedalen profile image
Aj β€’ β€’ Edited

Thank you for this wonderful post I got really inspired so I created a web app in python to retrieve time of any city

dev.to/amedalen/time-finder-of-any...

Thank you so much.

Collapse
 
mayank30 profile image
Mayank β€’

Really Great !!

Collapse
 
anujjhawar28 profile image
Anuj β€’

Awesome Really helpful.

Thanks :)

Collapse
 
mayank30 profile image
Mayank β€’

Guys

you can also download the json from here
cdn.jsdelivr.net/npm/country-code-...

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay