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 +60 -58
- package/dist/gn.cjs +1 -1
- package/dist/gn.js +1 -1
- package/package.json +13 -16
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# 🇱🇰 sl
|
|
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
|
-
[](https://www.npmjs.com/package/geo-sl)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
[]()
|
|
8
8
|
[]()
|
|
@@ -10,37 +10,41 @@
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- **
|
|
32
|
-
- **
|
|
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
|
|
43
|
+
npm install geo-sl
|
|
40
44
|
# or
|
|
41
|
-
pnpm add sl
|
|
45
|
+
pnpm add geo-sl
|
|
42
46
|
# or
|
|
43
|
-
yarn add sl
|
|
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
|
|
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
|
|
106
|
+
import { PROVINCES, getProvinces, getProvince } from 'geo-sl/provinces';
|
|
103
107
|
|
|
104
108
|
// Districts only (~7 KB)
|
|
105
|
-
import { DISTRICTS, getDistricts, getDistrictsByProvince } from 'sl
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
* `
|
|
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
|
-
* `
|
|
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
|
-
* `
|
|
249
|
-
* `
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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)
|