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

india-states-districts

v1.8.0

Published

A npm package to get all Indian states and their districts

Readme

India States and Districts

A lightweight npm package to retrieve all Indian states and their districts.

Installation

npm install india-states-districts

Features

  • ✅ Get all 28 Indian states
  • ✅ Get districts for any state or union territory
  • ✅ Case-insensitive state name search
  • ✅ Support for both CommonJS and ESM
  • ✅ TypeScript definitions included
  • ✅ Zero dependencies

Usage

CommonJS (require)

const { getAllStates, getDistrictsByState, getAllStatesWithDistricts, stateExists } = require('india-states-districts');

// Get all states
const allStates = getAllStates();
console.log(allStates);
// ['Andhra Pradesh', 'Arunachal Pradesh', 'Assam', ...]

// Get districts for a specific state
const districts = getDistrictsByState('Kerala');
console.log(districts);
// ['Alappuzha', 'Ernakulam', 'Idukki', ...]

// Get all states with their districts
const allData = getAllStatesWithDistricts();
console.log(allData);
// [{ name: 'Andhra Pradesh', districts: [...] }, ...]

// Check if a state exists
const exists = stateExists('Tamil Nadu');
console.log(exists);
// true

ESM (import)

import { getAllStates, getDistrictsByState, getAllStatesWithDistricts, stateExists } from 'india-states-districts';

// Get all states
const allStates = getAllStates();
console.log(allStates);

// Get districts for a specific state (case-insensitive)
const districts = getDistrictsByState('karnataka');
console.log(districts);

// Get all states with their districts
const allData = getAllStatesWithDistricts();
console.log(allData);

// Check if a state exists
const exists = stateExists('Kerala');
console.log(exists);

TypeScript

import { getAllStates, getDistrictsByState, stateExists } from 'india-states-districts';

const states: string[] = getAllStates();
const districts: string[] | null = getDistrictsByState('Maharashtra');
const exists: boolean = stateExists('Goa');

API Reference

getAllStates()

Returns an array of all Indian states.

  • Returns: string[] - Array of state names

Example:

const states = getAllStates();
// ['Andhra Pradesh', 'Arunachal Pradesh', ..., 'West Bengal']

getDistrictsByState(stateName)

Returns an array of districts for a given state.

  • Parameters:
    • stateName (string) - The name of the state
  • Returns: string[] | null - Array of district names or null if state not found

Example:

const districts = getDistrictsByState('Kerala');
// ['Alappuzha', 'Ernakulam', 'Idukki', ...]

const notFound = getDistrictsByState('Invalid State');
// null

getAllStatesWithDistricts()

Returns an array of all states with their districts.

  • Returns: Array<{name: string, districts: string[]}> - Array of objects containing state name and districts

Example:

const allData = getAllStatesWithDistricts();
// [
//   { name: 'Andhra Pradesh', districts: ['Anantapur', ...] },
//   { name: 'Arunachal Pradesh', districts: ['Anjaw', ...] },
//   ...
// ]

stateExists(stateName)

Checks if a state exists.

  • Parameters:
    • stateName (string) - The name of the state
  • Returns: boolean - true if state exists, false otherwise

Example:

const exists = stateExists('Tamil Nadu');
// true

const notExists = stateExists('Invalid State');
// false

Notes

  • State name searches are case-insensitive
  • The package includes all 28 states of India
  • All data is loaded once at module initialization for optimal performance
  • Invalid inputs (null, undefined, empty string) return appropriate default values

Data Source

The package uses a comprehensive JSON file containing all Indian states and union territories with their respective districts.

License

ISC

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.