Complete Nepal location data with provinces, districts, and municipalities. Perfect for address forms and location-based applications.
npm install nepali-locationA complete Nepal location data library with provinces, districts, and municipalities. Perfect for building location-based applications, address forms, or handling geographical data in Nepal.
- Get provinces, districts, and municipalities in Nepal.
- Retrieve municipalities based on districts, and districts based on provinces.
- Location validation and search.
- Hierarchical location data with provinces, districts, and municipalities.
You can install the package using npm or yarn:
```bash
npm install nepali-location
Using yarn:
bash
Copy code
yarn add nepali-location
Usage
Once installed, you can easily access location data and perform operations with the following functions.
Example Code:
1. Get Districts by Province
To get all districts for a specific province:
typescript
Copy code
import { getDistrictsByProvince } from 'nepali-location';
const districts = getDistrictsByProvince('Bagmati');
console.log(districts);
2. Get Municipalities by District
To get all municipalities in a specific district:
typescript
Copy code
import { getMunicipalitiesByDistrict } from 'nepali-location';
const municipalities = getMunicipalitiesByDistrict('Kathmandu');
console.log(municipalities);
3. Get Location Hierarchy
To get the full hierarchy (province, district, municipality) for a specific municipality:
typescript
Copy code
import { getLocationHierarchy } from 'nepali-location';
const locationHierarchy = getLocationHierarchy('Kathmandu');
console.log(locationHierarchy);
// Output: { province: 'Bagmati', district: 'Kathmandu', municipality: 'Kathmandu' }
4. Check if a Location Exists
To check if a province, district, or municipality exists:
typescript
Copy code
import { locationExists } from 'nepali-location';
const exists = locationExists('district', 'Kathmandu');
console.log(exists); // Returns true or false
Data Structure Overview
Province-District Map: Mapping of provinces to their respective districts.
District-Municipality Map: Mapping of districts to their respective municipalities.
Example:
typescript
Copy code
const provinceDistrictMap = {
bagmati: ['Kathmandu', 'Bhaktapur', 'Dhading'],
gandaki: ['Gorkha', 'Kaski', 'Lamjung'],
lumbini: ['Kapilvastu', 'Rupandehi', 'Arghakhanchi']
};
const districtMunicipalityMap = {
kathmandu: ['Kathmandu', 'Kirtipur', 'Shankharapur'],
bhaktapur: ['Bhaktapur', 'Madhyapur Thimi', 'Changunarayan']
};
Contributing
Contributions are welcome! If you'd like to improve this library, feel free to fork the repository, submit issues, or open pull requests.
How to Contribute:
Fork the repository.
Create your branch (e.g., git checkout -b feature-name).
Make your changes and commit them (e.g., git commit -am 'Add new feature').
Push to your branch (e.g., git push origin feature-name).
Open a pull request.
License
This package is licensed under the MIT License.
React Integration Example
Here’s how you can integrate nepali-location in a React + TypeScript app:
1. Install Dependencies
bash
Copy code
npm install nepali-location
2. App Component Code Example
tsx
Copy code
import React, { useState } from "react";
import { getDistrictsByProvince, getMunicipalitiesByDistrict } from "nepali-location";
function App() {
const [province, setProvince] = useState("");
const [district, setDistrict] = useState("");
const [municipality, setMunicipality] = useState("");
const [districts, setDistricts] = useState
const [municipalities, setMunicipalities] = useState
const handleProvinceChange = (e: React.ChangeEvent
const selectedProvince = e.target.value;
setProvince(selectedProvince);
setDistricts(getDistrictsByProvince(selectedProvince));
setMunicipality(""); // Reset municipality when province changes
};
const handleDistrictChange = (e: React.ChangeEvent
const selectedDistrict = e.target.value;
setDistrict(selectedDistrict);
setMunicipalities(getMunicipalitiesByDistrict(selectedDistrict));
};
return (
{/ Province Dropdown /}
{/ District Dropdown /}
{province && (
)}
{/ Municipality Dropdown /}
{district && (
)}
export default App;
This React component allows users to select a province, then a district, and finally a municipality. The nepali-location package is used to fetch the districts for a province and the municipalities for a district.
This README provides an easy-to-follow guide for users to install, use, and contribute to the library. It also includes a full example of integrating the package into a React application.