Documentation · itzsa

Nepal Geo

Nepal administrative geography — provinces, districts, local levels (metropolitan, sub-metropolitan, municipality, rural municipality), and wards — with searchable React selects and a data-only package.

@itzsa/nepal-geo@itzsa/nepal-geo-data7 · 77 · 753 · ~6839en / ne

Installation#

UI package includes React selects. Install the data package alone when you only need queries.

pnpm add @itzsa/nepal-geo
pnpm add @itzsa/nepal-geo-data
@import "tailwindcss";
@source "../node_modules/@itzsa/nepal-geo";
@import "@itzsa/nepal-geo/styles.css";

Data helpers#

Queryable without mounting any UI. Same API on both packages.

import {
  getProvinces,
  getDistricts,
  getLocalLevels,
  getWards,
  getMetropolitanCities,
  getSubMetropolitanCities,
  getMunicipalities,
  getRuralMunicipalities,
  resolveLocalHierarchy,
} from "@itzsa/nepal-geo";
// Prefer data-only when you do not need React:
// import { … } from "@itzsa/nepal-geo-data";

getProvinces();
getDistricts(3);
getLocalLevels(27, { typeKeys: ["municipality", "rural_municipality"] });
getMetropolitanCities();
getSubMetropolitanCities();
getMunicipalities(27);
getRuralMunicipalities(27);
getWards(5);                 // Ward 1…N for a local
resolveLocalHierarchy(5, 12);

IDs

Values are numeric ids (provinceId, districtId, localId, wardId). Ward ids are localId * 1000 + number.

Data-only package#

Use @itzsa/nepal-geo-data when you do not need React selects.

pnpm add @itzsa/nepal-geo-data

import { getLocalLevels, getWards, GEO_META } from "@itzsa/nepal-geo-data";

// No React peer dependency — safe for Node, workers, APIs.

Local types & filters#

Filter to metropolitan, sub-metropolitan, municipality, or rural municipality.

type LocalLevelTypeKey =
  | "metropolitan"
  | "sub_metropolitan"
  | "municipality"
  | "rural_municipality";

// On selects:
<NepalLocalSelect typeKeys={["metropolitan", "sub_metropolitan"]} />
<NepalLocationSelect typeKeys={["municipality", "rural_municipality"]} />

Wards#

Ward lists are expanded from per-local counts — no huge static ward table.

import { getWards, encodeWardId } from "@itzsa/nepal-geo-data";

const wards = getWards(localId); // [{ id, localId, number, nameEn, nameNe }, …]
encodeWardId(5, 12); // → 5012
import { useState } from "react";
import {
  NepalLocationSelect,
  type NepalLocationValue,
} from "@itzsa/nepal-geo";
import "@itzsa/nepal-geo/styles.css";

export function AddressFields() {
  const [location, setLocation] = useState<NepalLocationValue>({});

  return (
    <NepalLocationSelect
      value={location}
      onChange={setLocation}
      levels={["province", "district", "local", "ward"]}
      labels={{ local: "Palika", ward: "Ward" }}
      locale="ne"
    />
  );
}

Examples#

Searchable selects — single level, cascade with wards, type filters, and custom CSS.

Single select#

label prop on each field; district waits until a province is chosen.

provinceId: · districtId:

Hierarchy + ward#

Province → district → local → ward. Changing a parent clears children.

{}

Type filters#

Limit locals to urban types, then pick a ward.

Dataset helpers: 6 metro · 276 municipalities · 460 rural · 0 wards for selection

Custom CSS#

vars and classNames without forking styles.css.

Use vars and classNames — same pattern as the datepicker.

Locale#

English or Nepali labels from the same dataset.

Dataset: 7 provinces · 77 districts · 753 local levels · 6839 wards

Sample: 7 / 77 loaded

Styling API#

Same pattern as @itzsa/nepali-datepicker.

<NepalProvinceSelect
  label="Province"
  vars={{ accent: "#0f766e", radius: "12px" }}
  classNames={{ trigger: "my-trigger", label: "my-label" }}
/>

classNames keys

root, trigger, label, popover, search, option, optionMeta, empty, clear, field, cascade

vars keys

accent, background, foreground, muted, border, surface, radius, font

Props API#

Full prop tables for selects and data helpers.

NepalGeoSelect (and Province / District / Local / Ward aliases)

PropTypeDefaultDescription
level"province" | "district" | "local" | "ward"Which administrative level to list.
valuenumber | nullnullSelected entity id. For wards, use encodeWardId(localId, n).
onChange(id: number | null) => voidCalled when the selection changes or is cleared.
provinceIdnumber | null | undefinedScope districts. null = wait for parent; omit/undefined = list all.
districtIdnumber | null | undefinedScope local levels. null = wait for parent; omit = list all.
localIdnumber | null | undefinedScope wards. null = wait for local; required for ward level.
typeKeysLocalLevelTypeKey[]Filter locals: metropolitan | sub_metropolitan | municipality | rural_municipality.
labelstringVisible field label above the trigger.
locale"en" | "ne""en"English (Outfit) or Nepali (Devanagari) labels.
placeholderstringTrigger placeholder when nothing is selected.
varsNepalGeoVarsCSS variable overrides (accent, border, radius, font, …).
classNamesNepalGeoClassNamesSlot class names: root, trigger, label, popover, option, …
clearablebooleantrueShow Clear in the popover when a value is set.
showLocalTypebooleantrueShow local-level type as option meta (local level only).
disabledbooleanfalseDisable the control (also when waiting on a parent).

NepalLocationSelect

PropTypeDefaultDescription
valueNepalLocationValue{ provinceId?, districtId?, localId?, wardId?, wardNumber? }
defaultValueNepalLocationValueUncontrolled initial value.
onChange(value: NepalLocationValue) => voidFires on any step change; clearing a parent clears children.
levelsGeoLevel[]["province","district","local","ward"]Which steps to show, in order.
typeKeysLocalLevelTypeKey[]Filter the local-level step by type keys.
labelsPartial<Record<GeoLevel, string>>Override the label above each field.
placeholdersPartial<Record<GeoLevel, string>>Per-level placeholder strings.
locale"en" | "ne""en"Locale for all cascade fields.
orientation"vertical" | "horizontal""vertical"Stack fields or row layout from ~720px up.
vars / classNamesNepalGeoVars / NepalGeoClassNamesShared styling applied to each field in the cascade.
clearable / disabled / showLocalTypebooleanForwarded to each NepalGeoSelect in the cascade.

Data helpers (@itzsa/nepal-geo & @itzsa/nepal-geo-data)

PropTypeDefaultDescription
getProvinces / getDistricts / getLocalLevels() => readonly T[]List entities; districts/locals accept an optional parent id.
getLocalLevels(id, { typeKeys })filterFilter by metropolitan, municipality, rural, etc.
getMetropolitanCities() => LocalLevel[]Locals with type key metropolitan.
getSubMetropolitanCities() => LocalLevel[]Locals with type key sub_metropolitan.
getMunicipalities / getRuralMunicipalities() => LocalLevel[]Urban municipality and rural municipality helpers.
getWards(localId)() => Ward[]Expand ward count into Ward 1…N for a local level.
encodeWardId / decodeWardIdnumber helpersUnique ward id = localId * 1000 + wardNumber.
resolveLocalHierarchy(localId, wardNumber?) => …Province + district + local + type (+ optional ward).