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

sl-address-utils

v1.0.0

Published

Complete Sri Lanka address hierarchy data with fast JS & TS access utilities

Downloads

20

Readme

🇱🇰 sl-address-utils

A lightweight, zero-dependency JavaScript & TypeScript package that provides complete, structured access to Sri Lanka’s administrative address hierarchy, extracted from official government sources.

sl-address-utils is designed for forms, address validation, selectors, analytics, and backend services, offering fast in-memory lookups with a clean, typed API.


✨ Features

  • ✅ Supports JavaScript and TypeScript
  • ✅ Fully structured administrative hierarchy
  • ✅ Covers ALL Sri Lankan postal codes
  • ✅ Covers 20,000+ villages / cities
  • ✅ Stable string-based IDs
  • ✅ Zero runtime dependencies
  • ✅ Tree-shakable ES modules
  • ✅ Optimized lookups using prebuilt indexes
  • ✅ Read-only, side-effect-free API

🧭 Administrative Coverage

This package includes complete national coverage:

🏛 Administrative Hierarchy

Province
 └── District
      └── Divisional Secretariat
           └── Grama Niladhari Division
                └── Village / City

📦 Dataset Size

  • 9 Provinces
  • 25 Districts
  • 331+ Divisional Secretariats
  • 14,000+ Grama Niladhari Divisions
  • 20,000+ Villages / Cities
  • 2,050 Postal Codes (full national coverage)

📦 Installation

npm install sl-address-utils

or

yarn add sl-address-utils

📁 Package Structure

src/
├─ data/
│  ├─ provinces.json
│  ├─ districts.json
│  ├─ divisional-secretariats.json
│  ├─ grama-niladhari-divisions.json
│  ├─ villages.json
│  └─ postal-codes.json
│
├─ access/
│  ├─ provinces.ts
│  ├─ districts.ts
│  ├─ divisionalSecretariats.ts
│  ├─ gramaNiladhari.ts
│  ├─ villages.ts
│  └─ postalCodes.ts
│
├─ indexes/
│  └─ buildIndexes.ts
│
├─ types/
│  └─ models.ts
│
└─ index.ts

🧩 TypeScript Models

All entities use string IDs for long-term stability.

export interface Province {
  id: string;
  name: string;
}

export interface District {
  id: string;
  provinceId: string;
  name: string;
}

export interface DivisionalSecretariat {
  id: string;
  districtId: string;
  name: string;
}

export interface GramaNiladhariDivision {
  id: string;
  divisionalSecretariatId: string;
  name: string;
}

export interface Village {
  id: string;
  gramaNiladhariDivisionId: string;
  name: string;
}

export interface PostalCode {
  code: string;
  districtId: string;
  name: string;
}

🚀 Usage Examples

Importing the package

import {
  getProvinces,
  getDistrictsByProvince,
  getDivisionalSecretariatsByDistrict,
  getGramaNiladhariDivisionsByDS,
  getVillagesByGN,
  getVillagesByDistrict,
  getPostalCodesByDistrict
} from "sl-address-utils";

Get all provinces

const provinces = getProvinces();

Get districts by province

const districts = getDistrictsByProvince("P02"); // Central Province

Get Divisional Secretariats by district

const dsList = getDivisionalSecretariatsByDistrict("D04"); // Kandy

Get Grama Niladhari divisions by DS

const gnDivisions = getGramaNiladhariDivisionsByDS("DS015");

Get villages / cities by district

const villages = getVillagesByDistrict("D04");

Get villages / cities by GN division

const villages = getVillagesByGN("GN1023");

Get postal codes by district

const postalCodes = getPostalCodesByDistrict("D04");

Resolve full administrative path for a village

const path = getVillagePath("V20341");

/*
{
  province,
  district,
  divisionalSecretariat,
  gramaNiladhariDivision,
  village
}
*/

⚡ Performance Characteristics

  • Data is loaded once at startup
  • Lookups are O(1) via prebuilt indexes
  • No async operations
  • No filesystem or network access at runtime

Ideal for:

  • Address forms
  • Validation logic
  • Static websites
  • APIs
  • Analytics pipelines

🧪 Testing

This package uses Vitest, ensuring compatibility with both JS and TS consumers.

npm test

Test coverage includes:

  • ID-based lookups
  • Name-based queries
  • Hierarchical mappings
  • Edge-case validations

📊 Data Sources

All data is extracted from official Sri Lankan government sources:


⚠️ Disclaimer

This package provides read-only reference data.

Administrative boundaries, names, or postal codes may change over time. For legal, regulatory, or official use, always verify against the latest government publications.


🤝 Contributions

Contributions are welcome:

  • Data corrections
  • New helper functions
  • Performance improvements
  • Additional test coverage

Please open an issue or submit a pull request.


📄 License

MIT License


👤 Author

Author is looking for full-time software engineering roles. Kindly contact me via [email protected] or LinkedIn: https://www.linkedin.com/in/kushanshamika/