Gathering detailed insights and metrics for @weston/react-world-flags
Gathering detailed insights and metrics for @weston/react-world-flags
Gathering detailed insights and metrics for @weston/react-world-flags
Gathering detailed insights and metrics for @weston/react-world-flags
Fork of `react-world-flags` with dramatically smaller bundles 🎉
npm install @weston/react-world-flags
Typescript
Module System
Node Version
NPM Version
64.2
Supply Chain
97.5
Quality
75
Maintenance
100
Vulnerability
87.1
License
JavaScript (100%)
Total Downloads
10,259
Last Day
3
Last Week
176
Last Month
1,222
Last Year
8,290
3 Stars
248 Commits
1 Forks
1 Watching
1 Branches
1 Contributors
Latest Version
2.0.0
Package Id
@weston/react-world-flags@2.0.0
Unpacked Size
31.07 MB
Size
15.59 MB
File Count
2,782
NPM Version
8.15.0
Node Version
16.17.1
Cumulative downloads
Total Downloads
Last day
-94.6%
3
Compared to previous day
Last week
-33.8%
176
Compared to previous week
Last month
-31.5%
1,222
Compared to previous month
Last year
321%
8,290
Compared to previous year
2
1
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
Easy to use SVG flags of the world for react
npm install --save @weston/react-world-flags
1import Flag from '@weston/react-world-flags' 2 3<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:
1import Flag from '@weston/react-world-flags' 2 3<Flag code="foo" fallback={ <span>Unknown</span> } />
All props but code
and fallback
are passed through to the rendered img
1<Flag code="nor" height="16" /> 2 3// <img src="data:image/svg+xml..." height="16">
SVG's are inlined using Data_URIs.
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
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).
1// Only import flags for USA and Canada 2import { FlagUS, FlagCA } from '@weston/react-world-flags' 3 4<FlagUS /> 5<FlagCA />
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:
1import { Flag128 as Flag } from '@weston/react-world-flags' 2 3// Mexico's flag is detailed and always smaller as WebP 4<Flag code="mx" /> 5// result: <img src="data:image/webp..." height="128"> 6 7// Japan's flag is simple and always smaller as SVG 8<Flag code="jp" /> 9// result: <img src="data:image/svg+xml..." height="128"> 10 11// Still able to customize image height 12<Flag code="mx" height="100" /> 13// 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
).
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%) |
No vulnerabilities found.
No security vulnerabilities found.