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 🙏

© 2026 – Pkg Stats / Ryan Hefner

br-state-flags

v0.1.0

Published

Brazilian state flags as React SVG components

Readme

Brazilian State Flags

npm version License Live Demo

React SVG components for all 27 Brazilian state flags with multilingual labels and geographical data. Explore the live demo to see flags, props, and locales in action.

Try it Live

React SVG components for all 27 Brazilian state flags with geographical data and multilingual support.

Installation

npm install br-state-flags

Usage

Using Individual Components

import { SP, RJ, MG } from 'br-state-flags';

function App() {
  return (
    <div>
      <SP width={100} />
      <RJ width={100} />
      <MG width={100} />
    </div>
  );
}

Using the Dynamic Flag Component

The Flag component accepts a UF code as a prop, making it easier to render flags dynamically:

import { Flag } from 'br-state-flags';

function App() {
  const states = ['SP', 'RJ', 'MG'];
  
  return (
    <div>
      {states.map(uf => (
        <Flag key={uf} uf={uf} width={100} />
      ))}
    </div>
  );
}

// With locale for accessibility labels
<Flag uf="SP" width={100} locale="pt-BR" />

Next.js

Works with both App Router and Pages Router:

import { SP, RJ } from 'br-state-flags';
// or
import { Flag } from 'br-state-flags';

export default function Page() {
  return (
    <div>
      <SP width={100} />
      <RJ width={100} />
      {/* or */}
      <Flag uf="SP" width={100} />
    </div>
  );
}

Available Components

All 27 Brazilian state flags are available as components:

AC, AL, AP, AM, BA, CE, DF, ES, GO, MA, MT, MS, MG, PA, PB, PR, PE, PI, RJ, RN, RS, RO, RR, SC, SP, SE, TO

Props

Each component accepts standard SVG props:

<SP 
  width={200}
  height={150}
  style={{ border: '1px solid black' }}
  className="flag"
/>

Internationalization

The package supports English, Portuguese (Brazil), and Finnish translations:

import { getStateName, getRegionName } from 'br-state-flags';

// English (default)
getStateName('SP'); // "São Paulo"
getStateName('DF'); // "Federal District"
getRegionName('Southeast'); // "Southeast"

// Portuguese
getStateName('SP', 'pt-BR'); // "São Paulo"
getStateName('DF', 'pt-BR'); // "Distrito Federal"
getRegionName('Southeast', 'pt-BR'); // "Sudeste"

// Finnish
getStateName('DF', 'fi'); // "Liittovaltioalue"
getRegionName('South', 'fi'); // "Etelä"

Geographical Data

The package includes data for each state including population, area, coordinates, and timezone:

import { statesData, getStateData } from 'br-state-flags';

const spData = statesData.SP;
console.log(spData);
// {
//   uf: 'SP',
//   name: 'São Paulo',
//   capital: 'São Paulo',
//   region: 'Southeast',
//   coordinates: { latitude: -23.5505, longitude: -46.6333 },
//   population: 46649132,
//   area: 248219.485,
//   timezone: 'America/Sao_Paulo',
//   utcOffset: -3,
//   iso: 'BR-SP'
// }

const localizedData = getStateData('SP', 'pt-BR');

Create Interactive Maps

Combine flags with coordinates:

import { Flag, statesData } from 'br-state-flags';

function BrazilMap() {
  const states = ['SP', 'RJ', 'MG'] as const;
  
  return (
    <div style={{ position: 'relative', width: '800px', height: '600px' }}>
      {states.map(uf => {
        const data = statesData[uf];
        
        return (
          <div
            key={uf}
            style={{
              position: 'absolute',
              left: `${(data.coordinates.longitude + 75) * 10}px`,
              top: `${(-data.coordinates.latitude + 5) * 10}px`,
            }}
            title={`${data.name} - ${data.capital}`}
          >
            <Flag uf={uf} width={40} />
          </div>
        );
      })}
    </div>
  );
}

Filter by Region

import { getStatesByRegion } from 'br-state-flags';

const southStates = getStatesByRegion('South');
const northeastStates = getStatesByRegion('Northeast');

Validate State Codes

import { isValidStateUF, validateStateUF, normalizeStateUF } from 'br-state-flags';

// Type guard
if (isValidStateUF(userInput)) {
  // TypeScript knows userInput is BRStateUF here
  console.log(`Valid state: ${userInput}`);
}

// Validate with error handling
try {
  const validUF = validateStateUF(userInput);
  // Use validUF safely
} catch (error) {
  console.error('Invalid state code:', error.message);
}

// Normalize input
const normalized = normalizeStateUF('  sp  '); // "SP"

Use Cases

For International Users

Useful for companies and developers working with Brazil:

  • Import/Export Dashboards: Track suppliers by Brazilian state
  • Market Analysis Tools: Visualize regional data
  • Logistics Platforms: Display delivery coverage by region
  • E-commerce: Show business locations with flags

Example: Shipping Timezone Calculator

import { statesData } from 'br-state-flags';

function getDeliveryTime(stateUF: string) {
  const state = statesData[stateUF];
  return {
    state: state.name,
    timezone: state.timezone,
    offset: state.utcOffset
  };
}

API Reference

Components

  • Individual flag components: AC, AL, AP, AM, BA, CE, DF, ES, GO, MA, MT, MS, MG, PA, PB, PR, PE, PI, RJ, RN, RS, RO, RR, SC, SP, SE, TO
  • Flag component: Dynamic component that accepts a uf prop (e.g., <Flag uf="SP" width={100} />)

Data Functions

  • statesData - Data object for all states
  • getStateData(uf, locale?) - Get data for a specific state
  • getStatesByRegion(region) - Get all states in a region
  • getAllStateUFs() - Get array of all state codes

i18n Functions

  • getStateName(uf, locale) - Get state name in specified language
  • getRegionName(region, locale) - Get region name in specified language
  • getAvailableLocales() - Get list of supported locales

Validation Utilities

  • isValidStateUF(value) - Type guard to check if a string is a valid UF code
  • validateStateUF(value) - Validates and returns a BRStateUF, throws error if invalid
  • normalizeStateUF(value) - Normalizes UF code (uppercase, trim)

TypeScript Types

import type { 
  BRStateUF,
  BRStateData,
  BRStateCoordinates,
  BRRegion,
  Locale
} from 'br-state-flags';

Features

  • 27 Brazilian state flags as React components
  • Dynamic Flag component for easy dynamic rendering
  • Geographical data for all states
  • Multilingual support (English, Portuguese, Finnish)
  • Input validation utilities
  • Accessibility support (ARIA labels, roles)
  • TypeScript support
  • Tree-shakeable
  • Optimized SVGs
  • Works with React, Next.js, Vite
  • SSR compatible
  • No runtime dependencies

Package Info

  • Size: ~577 KB
  • Format: ESM + CJS
  • React: >=17

License

MIT

Links