npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@omprakashkumar/countries-flag

v1.0.1

Published

An npm package that provides country flags based on the country code. This package is ideal for applications that need to display flags for various countries.....

Downloads

33

Readme

a basic documentation specifically for the country flags feature in your npm package:

@omprakashkumar/country-flags-package

An npm package that provides country flags based on the country code. This package is ideal for applications that need to display flags for various countries.....

Features

Retrieve the flag of any country using its country code. Simple and lightweight package focused only on country flags.

Usage

First, import the package into your project:

Example

Get a Country Flag by Code

const indianFlag = countryFlags.getFlagByCountryCode('IN'); console.log(indianFlag); // Output: 🇮🇳

Get Multiple Country Flags

const flags = countryFlags.getFlagsByCountryCodes(['US', 'GB', 'FR']); console.log(flags); // Output: ['🇺🇸', '🇬🇧', '🇫🇷']

Supported Country Codes

The package supports standard ISO 3166-1 alpha-2 country codes. For example:

IN for India US for United States GB for United Kingdom

Implement In ReactJS Example

App.jsx

import React, { useState, useEffect } from "react"; import { getFlagByCountry } from "@omprakashkumar/countries-flag"; import css from "./App.css";

// Hardcoded list of country codes (ISO 3166-1 alpha-2 codes) const countryCodes = [ "AF", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BA", "BW", "BR", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CO", "KM", "CG", "CR", "HR", "CU", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FJ", "FI", "FR", "GA", "GM", "GE", "DE", "GH", "GR", "GD", "GT", "GN", "GW", "GY", "HT", "VA", "HN", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IL", "IT", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LI", "LT", "LU", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MR", "MU", "MX", "FM", "MD", "MC", "MN", "ME", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NZ", "NI", "NE", "NG", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PL", "PT", "QA", "RO", "RU", "RW", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SD", "SS", "SE", "SG", "SB", "SO", "ZA", "SS", "ES", "LK", "SD", "SR", "SE", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TO", "TT", "TN", "TR", "TM", "TV", "UG", "UA", "AE", "GB", "US", "UY", "UZ", "VU", "VE", "VN", "YE", "ZM", "ZW", ];

function App() { const [flags, setFlags] = useState([]);

useEffect(() => { // Fetch flag images for each country const fetchFlags = () => { const flagData = countryCodes.map((code) => ({ code, flag: getFlagByCountry(code), })); setFlags(flagData); };

fetchFlags();

}, []);

return ( All Country Flags {flags.map(({ code, flag }) => ( <img src={flag} alt={Flag of ${code}} /> {code} ))} ); }

export default App;

CSS (App.css)

.flags-container { display: flex; flex-wrap: wrap; justify-content: center; } .App h1{ text-align: center; border: dashed; }

.flag-item { margin: 10px; text-align: center; }

.flag-item img { width: 50px; /* Adjust the size as needed */ height: auto; }