sl-address
v1.1.1
Published
A comprehensive Sri Lankan postal code service package. Includes lookup for provinces, districts, cities, and postal codes, as well as searching and autocompleting city names.
Maintainers
Readme
sl-address
TypeScript utilities for exploring Sri Lanka provinces, districts, cities, and postal codes. Ship a single package and unlock lookups, fuzzy search, and readable formatting for any Sri Lankan address workflow.
Features
- Complete dataset covering every Sri Lankan postal code with its city, district, and province
- Friendly lookup helpers for provinces, districts, cities, and postal codes
- JSON-first responses that drop straight into APIs, CLIs, or UIs
- Fuzzy search, auto-complete, and normalization helpers to tidy user input
Install
npm install sl-addressQuick Start
import postalService, { p } from 'sl-address';
// `p` and the default export reference the same PostalService instance.
console.log(p.getProvinces());
console.log(p.getInfoByPostal('10280'));
console.log(postalService.toReadable('10280')); // "Maharagama, Colombo, Western Province"CommonJS usage:
const { p } = require('sl-address');
console.log(p.getDistrictsByProvince('Western Province'));All methods return JSON-friendly data (arrays, objects, or strings) so they can be serialized or sent over the wire without extra work.
API Overview
getProvinces()– every province ("Western Province","Central Province", ...)getDistricts()– every district namegetCities()– every city namegetPostals()– full dataset of postal recordsgetDistrictsByProvince(province)– districts within a provincegetCitiesByDistrict(district)– cities in a districtgetCitiesByProvince(province)– cities in a provincegetPostalsByDistrict(district)– postal records for a districtgetPostalsByProvince(province)– postal records grouped by districtgetPostalsByCity(city)– postal records for a citygetInfoByPostal(code)– full record for a codegetInfoByCity(city)– all records matching a city (handles multiple codes)getDistrictByPostal(code)/getProvinceByPostal(code)/getCityByPostal(code)– individual fieldsisValidPostal(code)– boolean existence checksearchCity(query, limit?)– fuzzy matches with scoresautocompleteCity(prefix, limit?)– suggestion list for partial inputnormalize(input)– best-guess canonical city nametoReadable(code)– formatted string"City, District, Province"
Inputs ignore case, spacing, and whether "Province" is appended (e.g., "Western" works).
Fuzzy helpers
p.normalize('maha ragama'); // "Maharagama"
p.searchCity('galleo'); // close matches with similarity scores
p.autocompleteCity('kan'); // ["Kandy", "Kananke Bazaar", ...]License
MIT © Sumudu Kulathunga
