A lightweight, zero-dependency TypeScript/JavaScript library for accessing African countries, states, and tribal data by country code. Includes metadata (name, capital, currency, ISO codes) and supports geographic hierarchies and ethnic group distributions across the continent.
# African-states-and-tribes
A lightweight zero-dependency JavaScript/TypeScript utility library for African countries and their corresponding states and tribes, dynamically loaded by country code. It provides structured access to comprehensive data on African countries and their administrative geography and ethnic groups.
The library includes country-level metadata (such as name, capital, currency, phone code, flag, and ISO codes), supports geographic hierarchies including local government areas (LGAs) and other administrative subdivisions across all countries, and offers detailed tribal distributions by region or state, as well as major ethnic group data per country.
## 🚀 Features
✅ List all African countries
✅ Fetch a single country by its ISO code
✅ Get state/tribal data for each country (on-demand)
✅ Lightweight and async — loads only what you need
✅ Simple, modular, and TypeScript-friendly
✅ **NEW:** Modular imports — import only specific countries to reduce bundle size
# Install
`npm i african-states-and-tribes`
# 📚 Documentation
- Modular Imports Guide - Complete guide on using modular imports to optimize bundle size
- Usage Examples - Real-world examples and use cases
# Usage
## 🎯 Modular Imports (Recommended for Bundle Size Optimization)
Import only the countries you need to keep your bundle size minimal:
```js
// Import specific country
import { getCountry, getStates, getCountryAndStates } from 'african-states-and-tribes/countries/ng';
// Get Nigeria data
const nigeria = await getCountry();
console.log(nigeria); // { name: 'Nigeria', countryCode: 'NG', ... }
// Get Nigeria states/tribes
const states = await getStates();
console.log(states); // [{ name: 'Abia', tribes: ['Igbo'], ... }, ...]
// Get Nigeria with states
const nigeriaWithStates = await getCountryAndStates();
console.log(nigeriaWithStates); // { name: 'Nigeria', states: [...], ... }
```
**Bundle Size Benefits:**
- Default import (all countries): **~337KB**
- Single coun …