geo-sl 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # 🇱🇰 sl-geo
1
+ # 🇱🇰 geo-sl
2
2
 
3
3
  > Trilingual (**English**, **සිංහල**, **தமிழ்**) Sri Lanka geographic, postal code, and administrative dataset for TypeScript & JavaScript with zero runtime dependencies.
4
4
 
5
- [![npm version](https://img.shields.io/npm/v/sl-geo.svg)](https://www.npmjs.com/package/sl-geo)
5
+ [![npm version](https://img.shields.io/npm/v/geo-sl.svg)](https://www.npmjs.com/package/geo-sl)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
  [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)]()
8
8
  [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)]()
@@ -10,37 +10,41 @@
10
10
 
11
11
  ---
12
12
 
13
- ## Features
14
-
15
- - **Zero Runtime Dependencies** Pure TypeScript with pre-indexed datasets and type definitions.
16
- - **Complete Administrative & Postal Coverage**:
17
- - **2,500+ Post Offices & 5-digit Postal Codes** from the Department of Posts (`slpost.gov.lk`).
18
- - **9 Provinces, 25 Districts, 340 Divisional Secretariats (DSD)** from the Ministry of Home Affairs (`moha.gov.lk`).
19
- - **14,000+ Grama Niladhari (GN) divisions** available via dedicated subpath export (`sl-geo/gn`).
20
- - **Official Bank Codes & Branch Codes** from the Central Bank of Sri Lanka (`cbsl.gov.lk`) / LankaPay via (`sl-geo/banks`).
21
- - **GPS Latitude & Longitude** centroids for 2,100+ cities and towns.
22
- - **Trilingual Support** Complete coverage across **English**, **Sinhala (සිංහල)**, and **Tamil (தமிழ்)**.
23
- - **Modular Subpath Exports** Optimized for tree-shaking:
24
- - `sl-geo/provinces`
25
- - `sl-geo/districts`
26
- - `sl-geo/cities`
27
- - `sl-geo/divisions`
28
- - `sl-geo/banks`
29
- - `sl-geo/gn`
30
- - `sl-geo/validators`
31
- - **Cascading Hierarchy Helper** – Built-in utility for multi-level Province District City form selectors.
32
- - **Relevance-Ranked Search** – Multi-lingual search matching by English name, Sinhala, Tamil, and 5-digit postal code with exact/prefix prioritization.
13
+ ## 🗺️ 100% Comprehensive Island-wide Coverage
14
+
15
+ `geo-sl` covers the entire territory of Sri Lanka not just major cities and urban centers. It provides complete, authoritative, and verified geographic data from provincial capitals all the way down to individual rural villages and remote Grama Niladhari divisions:
16
+
17
+ | Administrative / Geographic Level | Total Count | Scope & Details | Supported Languages |
18
+ |---|---|---|---|
19
+ | **Provinces** | **9** | All 9 provinces (WP, CP, SP, NP, EP, NWP, NCP, UP, SGP) | English, සිංහල, தமிழ் |
20
+ | **Districts** | **25** | All 25 administrative districts across the island | English, සිංහල, தமிழ் |
21
+ | **Divisional Secretariats (DSD)** | **340** | 100% of Divisional Secretariat Divisions (MOHA) | English, සිංහල, தமிழ் |
22
+ | **Grama Niladhari (GN) Divisions** | **14,020** | Every single village, ward, and local community | English, සිංහල, தமிழ் |
23
+ | **Cities, Towns & Post Offices** | **2,598** | Main post offices, towns, and sub-post offices | English, සිංහල, தமிழ் |
24
+ | **GPS Centroids** | **2,100+** | Accurate Latitude & Longitude coordinates | WGS84 coordinates |
25
+ | **Licensed Banks & Branches** | **45 Banks / 582+ Branches** | Complete CBSL & LankaPay routing codes | Official routing codes |
26
+
27
+ ---
28
+
29
+ ## ⚡ Key Highlights
30
+
31
+ - **Zero Runtime Dependencies** – Pure TypeScript with pre-indexed lookup maps. Ultra-fast, deterministic performance.
32
+ - **Trilingual First-Class Support** – Seamless lookups in **English**, **Sinhala (සිංහල)**, and **Tamil (தமிழ்)** with native scripts.
33
+ - **Optimized Subpath Tree-Shaking** – Import only what you need. Lightweight modules like validators are only **~2.3 KB**.
34
+ - **Cascading Form Helper** – Out-of-the-box hierarchy builder (`Province ➔ District ➔ City`) for checkout address selectors.
35
+ - **Intelligent Relevance Search** – Multi-lingual search prioritizing exact matches, prefixes, and postal codes over broad substring matches.
36
+ - **Built-in Validators & Parsers** – National Identity Card (Old 9-digit + New 12-digit NIC), Sri Lankan mobile & landline phone numbers, and postal codes.
33
37
 
34
38
  ---
35
39
 
36
40
  ## Installation
37
41
 
38
42
  ```bash
39
- npm install sl-geo
43
+ npm install geo-sl
40
44
  # or
41
- pnpm add sl-geo
45
+ pnpm add geo-sl
42
46
  # or
43
- yarn add sl-geo
47
+ yarn add geo-sl
44
48
  ```
45
49
 
46
50
  ---
@@ -58,7 +62,7 @@ import {
58
62
  PROVINCE_MAP,
59
63
  DISTRICT_MAP,
60
64
  search
61
- } from 'sl-geo';
65
+ } from 'geo-sl';
62
66
 
63
67
  // 1. Province Lookup
64
68
  const wp = getProvince('WP');
@@ -88,7 +92,7 @@ getPostalCode('මහනුවර'); // => "20000"
88
92
  // 5. Search with Relevance Ranking
89
93
  search('colombo'); // => [ { name_en: 'Colombo 1', ... }, { name_en: 'Colombo 2', ... } ]
90
94
  search('nawala'); // => [ { name_en: 'Nawala', ... }, ... ]
91
- search('කොළඹ'); // Sinhala search
95
+ search('කොළඹ'); // => [ { name_en: 'Colombo 1', ... }, ... ] (Sinhala search)
92
96
  ```
93
97
 
94
98
  ---
@@ -99,25 +103,25 @@ To keep client bundles minimal, import only the modules your application needs:
99
103
 
100
104
  ```typescript
101
105
  // Provinces only (~2 KB)
102
- import { PROVINCES, getProvinces, getProvince } from 'sl-geo/provinces';
106
+ import { PROVINCES, getProvinces, getProvince } from 'geo-sl/provinces';
103
107
 
104
108
  // Districts only (~7 KB)
105
- import { DISTRICTS, getDistricts, getDistrictsByProvince } from 'sl-geo/districts';
109
+ import { DISTRICTS, getDistricts, getDistrictsByProvince } from 'geo-sl/districts';
106
110
 
107
111
  // Cities & Postal Codes (~900 KB)
108
- import { CITIES, getCityByPostalCode, getPostalCode, search } from 'sl-geo/cities';
112
+ import { CITIES, getCityByPostalCode, getPostalCode, search } from 'geo-sl/cities';
109
113
 
110
114
  // Divisional Secretariats (~68 KB)
111
- import { DIVISIONS, getDivisions, getDivisionsByDistrict } from 'sl-geo/divisions';
115
+ import { DIVISIONS, getDivisions, getDivisionsByDistrict } from 'geo-sl/divisions';
112
116
 
113
117
  // CBSL Bank & Branch Codes (~140 KB)
114
- import { BANKS, getBanks, getBankByCode, getBranches } from 'sl-geo/banks';
118
+ import { BANKS, getBanks, getBankByCode, getBranches } from 'geo-sl/banks';
115
119
 
116
120
  // Grama Niladhari Divisions (14,000+ entries, ~3 MB)
117
- import { GN_DIVISIONS, getGNDivisions, searchGN } from 'sl-geo/gn';
121
+ import { GN_DIVISIONS, getGNDivisions, searchGN } from 'geo-sl/gn';
118
122
 
119
123
  // Validators & Parsers (~2.3 KB)
120
- import { validateNIC, parseNIC, validatePhone, parsePhone, validatePostalCode } from 'sl-geo/validators';
124
+ import { validateNIC, parseNIC, convertOldNICToNew, validatePhone, parsePhone, formatPhone, validatePostalCode } from 'geo-sl/validators';
121
125
  ```
122
126
 
123
127
  ---
@@ -128,7 +132,7 @@ The easiest way to build a Sri Lankan checkout address form:
128
132
 
129
133
  ```tsx
130
134
  import React, { useState } from 'react';
131
- import { getCascadingData } from 'sl-geo';
135
+ import { getCascadingData } from 'geo-sl';
132
136
 
133
137
  const addressData = getCascadingData({ lang: 'en' });
134
138
 
@@ -193,19 +197,19 @@ export function SriLankaAddressForm() {
193
197
 
194
198
  ---
195
199
 
196
- ## 🏦 CBSL Bank & Branch Codes (`sl-geo/banks`)
200
+ ## 🏦 CBSL Bank & Branch Codes (`geo-sl/banks`)
197
201
 
198
202
  Essential for fintech, payment gateway integrations, and bank transfer checkouts:
199
203
 
200
204
  ```typescript
201
- import { getBanks, getBankByCode, getBranches } from 'sl-geo/banks';
205
+ import { getBanks, getBankByCode, getBranches } from 'geo-sl/banks';
202
206
 
203
207
  // List all licensed banks
204
208
  const allBanks = getBanks();
205
209
 
206
210
  // Find Bank of Ceylon
207
211
  const boc = getBankByCode('7010');
208
- console.log(boc.name); // "Bank of Ceylon"
212
+ console.log(boc?.name); // "Bank of Ceylon"
209
213
 
210
214
  // Get all branches for a bank
211
215
  const branches = getBranches('7010');
@@ -218,12 +222,16 @@ const branches = getBranches('7010');
218
222
 
219
223
  ### Provinces
220
224
  * `getProvinces(options?: { lang?: 'en' | 'si' | 'ta' }): Province[]`
221
- * `getProvinceByCode(code: string, options?: { lang?: 'en' | 'si' | 'ta' }): Province | undefined`
225
+ * `getProvince(codeOrId: string): Province | undefined` primary lookup by code (e.g. `'WP'`), ID, or English name.
226
+ * `getProvinceName(codeOrId: string, lang?: Language): string | undefined`
227
+ * `getProvinceByCode(code: string, options?: { lang?: 'en' | 'si' | 'ta' }): Province | undefined` – alias for `getProvince`
222
228
 
223
229
  ### Districts
224
230
  * `getDistricts(province?: string, options?: { lang?: 'en' | 'si' | 'ta' }): District[]`
225
- * `getDistrictByCode(code: string, options?: { lang?: 'en' | 'si' | 'ta' }): District | undefined`
231
+ * `getDistrict(codeOrId: string): District | undefined` primary lookup by abbreviation (e.g. `'CO'`), ID, or English name.
232
+ * `getDistrictName(codeOrId: string, lang?: Language): string | undefined`
226
233
  * `getDistrictsByProvince(province: string, options?: { lang?: 'en' | 'si' | 'ta' }): District[]`
234
+ * `getDistrictByCode(code: string, options?: { lang?: 'en' | 'si' | 'ta' }): District | undefined` – alias for `getDistrict`
227
235
 
228
236
  ### Cities & Postal Codes
229
237
  * `getCities(district?: string, options?: { lang?: 'en' | 'si' | 'ta' }): City[]`
@@ -231,9 +239,9 @@ const branches = getBranches('7010');
231
239
  * `getCitiesByProvince(province: string, options?: { lang?: 'en' | 'si' | 'ta' }): City[]`
232
240
  * `getPostalCode(cityName: string): string | undefined`
233
241
  * `getCityByPostalCode(postalCode: string | number, lang?: 'en' | 'si' | 'ta'): City | undefined`
234
- * `isValidPostalCode(postalCode: string | number): boolean`
235
- * `lookupPostalCode(code: string | number, options?: { lang?: 'en' | 'si' | 'ta' }): City | undefined`
236
- * `lookupAllByPostalCode(code: string | number, options?: { lang?: 'en' | 'si' | 'ta' }): City[]`
242
+ * `isValidPostalCode(postalCode: string | number): boolean` – checks existence against the Sri Lanka Post database.
243
+ * `lookupPostalCode(code: string | number, options?: { lang?: 'en' | 'si' | 'ta' }): City | undefined` – alias for `getCityByPostalCode`
244
+ * `lookupAllByPostalCode(code: string | number, options?: { lang?: 'en' | 'si' | 'ta' }): City[]` – returns all offices sharing a postal code.
237
245
  * `search(query: string, options?: { limit?: number; lang?: 'en' | 'si' | 'ta'; district?: string; province?: string }): City[]`
238
246
 
239
247
  ### Cascading Hierarchy
@@ -242,25 +250,27 @@ const branches = getBranches('7010');
242
250
  ### Administrative Divisions (MOHA)
243
251
  * `getDivisions(district?: string, options?: { lang?: 'en' | 'si' | 'ta' }): Division[]`
244
252
  * `getDivisionsByDistrict(district: string, options?: { lang?: 'en' | 'si' | 'ta' }): Division[]`
253
+ * `getDivisionsByProvince(province: string, options?: { lang?: 'en' | 'si' | 'ta' }): Division[]`
245
254
 
246
255
  ### Financial Institutions (CBSL / LankaPay)
247
- * `getBanks(): Bank[]`
248
- * `getBankByCode(code: string | number): Bank | undefined`
249
- * `getBranches(bankCode: string | number): Branch[]`
256
+ * `getBanks(): readonly Bank[]`
257
+ * `getBank(codeOrId: string | number): Bank | undefined` – primary lookup by 4-digit CBSL code, ID, or bank name.
258
+ * `getBankByCode(codeOrId: string | number): Bank | undefined` – alias for `getBank`
259
+ * `getBranches(bankCode: string | number): readonly Branch[]`
250
260
  * `getBranchByCode(bankCode: string | number, branchCode: string | number): Branch | undefined`
251
261
  * `searchBranches(bankCode: string | number, query: string): Branch[]`
252
262
 
253
- ### Grama Niladhari (GN) Divisions (`sl-geo/gn`)
263
+ ### Grama Niladhari (GN) Divisions (`geo-sl/gn`)
254
264
  * `getGNDivisions(options?: { lang?: 'en' | 'si' | 'ta' }): GNDivision[]`
255
265
  * `getGNDivisionsByDSD(divisionName: string, options?: { lang?: 'en' | 'si' | 'ta' }): GNDivision[]`
256
266
  * `getGNDivisionsByDistrict(districtName: string, options?: { lang?: 'en' | 'si' | 'ta' }): GNDivision[]`
257
267
  * `findGNByCode(code: string, options?: { lang?: 'en' | 'si' | 'ta' }): GNDivision | undefined`
258
268
  * `searchGN(query: string, options?: { limit?: number; lang?: 'en' | 'si' | 'ta'; district?: string; division?: string }): GNDivision[]`
259
269
 
260
- ### Sri Lanka Validators & Parsers (`sl-geo/validators`)
270
+ ### Sri Lanka Validators & Parsers (`geo-sl/validators`)
261
271
  * `validateNIC(nic: string): boolean`
262
272
  * `parseNIC(nic: string): ParsedNIC | null` – parses birthdate, gender, age, voter eligibility from Old (9+V/X) and New (12 digits) NICs.
263
- * `convertOldNICToNew(oldNic: string): string | null` – converts 9-digit old NIC to 12-digit format.
273
+ * `convertOldNICToNew(oldNic: string): string | null` – converts 10-character old NIC (9 digits + V/X) to 12-digit new format.
264
274
  * `validatePhone(phone: string): boolean`
265
275
  * `parsePhone(phone: string): ParsedPhone | null` – parses operator (Dialog, Mobitel, Hutch, Airtel), type (mobile/fixed), and formats.
266
276
  * `formatPhone(phone: string, style?: 'international' | 'local' | 'e164'): string | null`
@@ -286,19 +296,11 @@ import type {
286
296
  DistrictCode,
287
297
  QueryOptions,
288
298
  SearchOptions
289
- } from 'sl-geo';
299
+ } from 'geo-sl';
290
300
  ```
291
301
 
292
302
  ---
293
303
 
294
- ## 🏛️ Data Sources & Attribution
295
-
296
- - **Postal Data**: [Department of Posts, Sri Lanka](https://slpost.gov.lk)
297
- - **Administrative Hierarchy**: [Ministry of Public Administration & Home Affairs](http://moha.gov.lk) & [Department of Census and Statistics](http://www.statistics.gov.lk)
298
- - **Bank & Branch Codes**: [Central Bank of Sri Lanka](https://www.cbsl.gov.lk) & [LankaPay](https://www.lankapay.net)
299
-
300
- ---
301
-
302
304
  ## 📄 License
303
305
 
304
306
  MIT © [Mahesh Abeykoon](https://github.com/mahesh-abeykoon)