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

@weston/react-world-flags

v2.0.0

Published

SVG flags of the world for react

Downloads

681

Readme

CircleCI

Attention! This is a fork of react-world-flags and provides two alternative methods of usage which can greatly reduce bundle size when using ESM-friendly bundlers: Cherry-Picking and Raster Flags

react-world-flags

Easy to use SVG flags of the world for react

Demo

Installation

npm install --save @weston/react-world-flags

Usage

import Flag from '@weston/react-world-flags'

<Flag code={ code } />

Where code is the two letter, three letter or three digit country code.

You can also pass an optional fallback which renders if the given code doesn't correspond to a flag:

import Flag from '@weston/react-world-flags'

<Flag code="foo" fallback={ <span>Unknown</span> } />

All props but code and fallback are passed through to the rendered img

<Flag code="nor" height="16" />

// <img src="data:image/svg+xml..." height="16">

SVG's are inlined using Data_URIs.

Alternative Usage

By default, bundlers will include all flags provided by this library which will add about 1.2 MB gzipped to your application.

This fork (@weston/react-world-flags) provides two alternative methods of usage which can greatly reduce bundle size when using ESM-friendly bundlers: Cherry-Picking and Raster Flags

Option 1: Cherry-Picking

Import just the flags needed for your application. This is useful for scenarios in which you only need a small subset of available flags and don't need to look them up by country code. Unused flags should automatically be omitted by your bundler via static analysis (tree-shaking).

// Only import flags for USA and Canada
import { FlagUS, FlagCA } from '@weston/react-world-flags'

<FlagUS />
<FlagCA />

Option 2: Raster Flags

Substitute default SVG flags with raster versions for flags having large amounts of detail (highly detailed images are generally more compact when represented as bitmaps). This approach automatically replaces these flags with WebP versions which can significantly reduce bundle size. Use this for scenarios where your application still needs the entire catalog of flags but having flags of fixed size is acceptable (e.g. icons).

The following example will produce either an SVG or WebP (of height 128px) depending on which is more compact given a particular country's flag:

import { Flag128 as Flag } from '@weston/react-world-flags'

// Mexico's flag is detailed and always smaller as WebP
<Flag code="mx" />
// result: <img src="data:image/webp..." height="128">

// Japan's flag is simple and always smaller as SVG
<Flag code="jp" />
// result: <img src="data:image/svg+xml..." height="128">

// Still able to customize image height
<Flag code="mx" height="100" />
// result: <img src="data:image/webp..." height="100">

Rasters are available in 32px, 64px, 128px, 256px, and 512px versions (i.e. Flag32, Flag64, Flag128, Flag256, or Flag512).

Bundle Footprint

| Import | Image Type | Bundle Size (gzip) | |:------:|:----------:|:--------------------:| | Flag | Default, SVG | 1.18 MB | | { Flag512 } | SVG or WebP (512px) | 0.80 MB (68%) | | { Flag256 } | SVG or WebP (256px) | 0.52 MB (44%) | | { Flag128 } | SVG or WebP (128px) | 0.30 MB (26%) | | { Flag64 } | SVG or WebP (64px) | 0.19 MB (16%) | | { Flag32 } | SVG or WebP (32px) | 0.13 MB (11%) |