A modern TypeScript package providing data for all provinces and districts in Sri Lanka.
- TypeScript First: Complete type definitions for enhanced developer experience
- Dual Package Format: Both ES Modules and CommonJS support for any project
- Framework Agnostic: Works with Node.js, React, Next.js, Nest.js, and more
- Complete Data: All 9 provinces and 25 districts of Sri Lanka with metadata
- Developer Friendly: Case-insensitive lookups, helpful error handling
- Zero Dependencies: Lightweight and clean implementation
- Backward Compatible: All v1.x API functions still work
# Using npm
npm install srilankan-provinces-districts
// CommonJS require syntax
const provinceDistricts = require('srilankan-provinces-districts');
// Get all province names as an array
const provinces = provinceDistricts.getProvinces();
console.log(provinces);
## Output
["Western", "Central", "Southern", "Northern", "Eastern", ...]
// Get district names in a province
const westernDistricts = provinceDistricts.getDistricts("Western");
console.log(westernDistricts);
## Output
["Colombo", "Gampaha", "Kalutara"]
// ES Modules import syntax
import {
// Types
Province,
District,
// Functions - Legacy API
getProvinces,
getDistricts,
// Functions - New TypeScript API
getProvince,
getAllProvinces,
getAllDistricts,
getDistrictsByProvince
} from 'srilankan-provinces-districts';
// Get all provinces with detailed data
const provinces: Province[] = getAllProvinces();
console.log(provinces);
## Output
[
{ id: "western", name: "Western", code: "WP" },
{ id: "central", name: "Central", code: "CP" },
...
]
// Get a specific province by name (case-insensitive)
const western: Province | undefined = getProvince('Western');
console.log(western);
### Output
{
id: "western",
name: "Western",
code: "WP"
}
// Get districts in Western province with detailed data
const westernDistricts: District[] = getDistrictsByProvince('Western');
console.log(westernDistricts);
## Output
[
{ id: "colombo", provinceId: "western", name: "Colombo", code: "CMB" },
{ id: "gampaha", provinceId: "western", name: "Gampaha", code: "GMP" },
{ id: "kalutara", provinceId: "western", name: "Kalutara", code: "KLT" }
]
const provinces = getProvinces();
## Output
// ["Western", "Central", "Southern", "Northern", "Eastern", ...]
const districts = getDistricts("Western");
## Output
// ["Colombo", "Gampaha", "Kalutara"]
const province = getProvince("Western"); // Also works with "western" or "WESTERN"
## Output
// { id: "western", name: "Western", code: "WP" }
const provinces = getAllProvinces();
## Output
// [{ id: "western", name: "Western", code: "WP" }, ...]
const districts = getAllDistricts();
##Output
// [{ id: "colombo", provinceId: "western", name: "Colombo", code: "CMB" }, ...]
const westernDistricts = getDistrictsByProvince("Western");
## Output
[
{ id: "colombo", provinceId: "western", name: "Colombo", code: "CMB" },
{ id: "gampaha", provinceId: "western", name: "Gampaha", code: "GMP" },
{ id: "kalutara", provinceId: "western", name: "Kalutara", code: "KLT" }
]
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ & β by Dinush Chathurya