geo-sl 1.0.0
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/LICENSE +21 -0
- package/README.md +304 -0
- package/dist/banks.cjs +1 -0
- package/dist/banks.d.cts +50 -0
- package/dist/banks.d.ts +50 -0
- package/dist/banks.js +1 -0
- package/dist/cities.cjs +1 -0
- package/dist/cities.d.cts +89 -0
- package/dist/cities.d.ts +89 -0
- package/dist/cities.js +1 -0
- package/dist/districts.cjs +1 -0
- package/dist/districts.d.cts +43 -0
- package/dist/districts.d.ts +43 -0
- package/dist/districts.js +1 -0
- package/dist/divisions.cjs +1 -0
- package/dist/divisions.d.cts +32 -0
- package/dist/divisions.d.ts +32 -0
- package/dist/divisions.js +1 -0
- package/dist/gn.cjs +1 -0
- package/dist/gn.d.cts +39 -0
- package/dist/gn.d.ts +39 -0
- package/dist/gn.js +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1 -0
- package/dist/provinces.cjs +1 -0
- package/dist/provinces.d.cts +35 -0
- package/dist/provinces.d.ts +35 -0
- package/dist/provinces.js +1 -0
- package/dist/types.cjs +1 -0
- package/dist/types.d.cts +102 -0
- package/dist/types.d.ts +102 -0
- package/dist/types.js +1 -0
- package/dist/validators.cjs +1 -0
- package/dist/validators.d.cts +78 -0
- package/dist/validators.d.ts +78 -0
- package/dist/validators.js +1 -0
- package/package.json +149 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var i=[{id:"1",code:"WP",name_en:"Western",name_si:"\u0DB6\u0DC3\u0DCA\u0DB1\u0DCF\u0DC4\u0DD2\u0DBB",name_ta:"\u0BAE\u0BC7\u0BB1\u0BCD\u0B95\u0BC1"},{id:"2",code:"CP",name_en:"Central",name_si:"\u0DB8\u0DB0\u0DCA\u200D\u0DBA\u0DB8",name_ta:"\u0BAE\u0BA4\u0BCD\u0BA4\u0BBF\u0BAF"},{id:"3",code:"SP",name_en:"Southern",name_si:"\u0DAF\u0D9A\u0DD4\u0DAB",name_ta:"\u0BA4\u0BC6\u0BB1\u0BCD\u0B95\u0BC1"},{id:"4",code:"NP",name_en:"Northern",name_si:"\u0D8B\u0DAD\u0DD4\u0DBB",name_ta:"\u0BB5\u0B9F\u0B95\u0BCD\u0B95\u0BC1"},{id:"5",code:"EP",name_en:"Eastern",name_si:"\u0DB1\u0DD0\u0D9C\u0DD9\u0DB1\u0DC4\u0DD2\u0DBB",name_ta:"\u0B95\u0BBF\u0BB4\u0B95\u0BCD\u0B95\u0BC1"},{id:"6",code:"NWP",name_en:"North Western",name_si:"\u0DC0\u0DBA\u0DB9",name_ta:"\u0BB5\u0B9F \u0BAE\u0BC7\u0BB1\u0BCD\u0B95\u0BC1"},{id:"7",code:"NCP",name_en:"North Central",name_si:"\u0D8B\u0DAD\u0DD4\u0DBB\u0DD4 \u0DB8\u0DD0\u0DAF",name_ta:"\u0BB5\u0B9F \u0BAE\u0BA4\u0BCD\u0BA4\u0BBF\u0BAF"},{id:"8",code:"UP",name_en:"Uva",name_si:"\u0D8C\u0DC0",name_ta:"\u0B8A\u0BB5\u0BBE"},{id:"9",code:"SGP",name_en:"Sabaragamuwa",name_si:"\u0DC3\u0DB6\u0DBB\u0D9C\u0DB8\u0DD4\u0DC0",name_ta:"\u0B9A\u0BAA\u0BB0\u0B95\u0BAE\u0BC1\u0BB5"}];var r=Object.freeze(i.map(e=>Object.freeze({id:e.id,code:e.code,name:e.name_en,name_en:e.name_en,name_si:e.name_si,name_ta:e.name_ta}))),_=Object.freeze(r.reduce((e,n)=>(e[n.code]=n,e),{})),t=new Map;for(let e of r)t.set(e.code.toUpperCase(),e),t.set(e.id,e),t.set(e.name_en.toLowerCase(),e);function m(e){if(!e||typeof e!="string")return;let n=e.trim();return t.get(n.toUpperCase())||t.get(n.toLowerCase())||t.get(n)}function P(e,n="en"){let a=m(e);if(a)return n==="si"?a.name_si:n==="ta"?a.name_ta:a.name_en}function u(e,n){let a=m(e);if(!a)return;let o=n?.lang;return !o||o==="en"?a:{...a,name:o==="si"?a.name_si:a.name_ta}}function f(e){let n=typeof e=="string"?e:e?.lang;return !n||n==="en"?r:r.map(a=>({...a,name:n==="si"?a.name_si:a.name_ta}))}exports.PROVINCES=r;exports.PROVINCE_MAP=_;exports.getProvince=m;exports.getProvinceByCode=u;exports.getProvinceName=P;exports.getProvinces=f;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Province, ProvinceCode, QueryOptions, Language } from './types.cjs';
|
|
2
|
+
|
|
3
|
+
declare const PROVINCES: readonly Province[];
|
|
4
|
+
declare const PROVINCE_MAP: Readonly<Record<ProvinceCode, Province>>;
|
|
5
|
+
/**
|
|
6
|
+
* Finds a province by code (e.g. 'WP'), ID ('1'), or English name ('Western').
|
|
7
|
+
*
|
|
8
|
+
* @param codeOrId - Province code, ID, or name.
|
|
9
|
+
*/
|
|
10
|
+
declare function getProvince(codeOrId: ProvinceCode | string): Province | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the localized province name for a given province code or ID.
|
|
13
|
+
*
|
|
14
|
+
* @param codeOrId - Province code or ID.
|
|
15
|
+
* @param lang - Target language ('en' | 'si' | 'ta'). Default is 'en'.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* getProvinceName('WP', 'si') // => "බස්නාහිර"
|
|
19
|
+
* getProvinceName('WP', 'ta') // => "மேற்கு"
|
|
20
|
+
*/
|
|
21
|
+
declare function getProvinceName(codeOrId: ProvinceCode | string, lang?: Language): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Alias for getProvince.
|
|
24
|
+
*
|
|
25
|
+
* @see getProvince
|
|
26
|
+
*/
|
|
27
|
+
declare function getProvinceByCode(code: string, options?: QueryOptions): Province | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Returns all 9 provinces of Sri Lanka.
|
|
30
|
+
*
|
|
31
|
+
* @param optionsOrLang - Query options or language code.
|
|
32
|
+
*/
|
|
33
|
+
declare function getProvinces(optionsOrLang?: QueryOptions | Language): readonly Province[] | Province[];
|
|
34
|
+
|
|
35
|
+
export { PROVINCES, PROVINCE_MAP, getProvince, getProvinceByCode, getProvinceName, getProvinces };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Province, ProvinceCode, QueryOptions, Language } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare const PROVINCES: readonly Province[];
|
|
4
|
+
declare const PROVINCE_MAP: Readonly<Record<ProvinceCode, Province>>;
|
|
5
|
+
/**
|
|
6
|
+
* Finds a province by code (e.g. 'WP'), ID ('1'), or English name ('Western').
|
|
7
|
+
*
|
|
8
|
+
* @param codeOrId - Province code, ID, or name.
|
|
9
|
+
*/
|
|
10
|
+
declare function getProvince(codeOrId: ProvinceCode | string): Province | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the localized province name for a given province code or ID.
|
|
13
|
+
*
|
|
14
|
+
* @param codeOrId - Province code or ID.
|
|
15
|
+
* @param lang - Target language ('en' | 'si' | 'ta'). Default is 'en'.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* getProvinceName('WP', 'si') // => "බස්නාහිර"
|
|
19
|
+
* getProvinceName('WP', 'ta') // => "மேற்கு"
|
|
20
|
+
*/
|
|
21
|
+
declare function getProvinceName(codeOrId: ProvinceCode | string, lang?: Language): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Alias for getProvince.
|
|
24
|
+
*
|
|
25
|
+
* @see getProvince
|
|
26
|
+
*/
|
|
27
|
+
declare function getProvinceByCode(code: string, options?: QueryOptions): Province | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Returns all 9 provinces of Sri Lanka.
|
|
30
|
+
*
|
|
31
|
+
* @param optionsOrLang - Query options or language code.
|
|
32
|
+
*/
|
|
33
|
+
declare function getProvinces(optionsOrLang?: QueryOptions | Language): readonly Province[] | Province[];
|
|
34
|
+
|
|
35
|
+
export { PROVINCES, PROVINCE_MAP, getProvince, getProvinceByCode, getProvinceName, getProvinces };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=[{id:"1",code:"WP",name_en:"Western",name_si:"\u0DB6\u0DC3\u0DCA\u0DB1\u0DCF\u0DC4\u0DD2\u0DBB",name_ta:"\u0BAE\u0BC7\u0BB1\u0BCD\u0B95\u0BC1"},{id:"2",code:"CP",name_en:"Central",name_si:"\u0DB8\u0DB0\u0DCA\u200D\u0DBA\u0DB8",name_ta:"\u0BAE\u0BA4\u0BCD\u0BA4\u0BBF\u0BAF"},{id:"3",code:"SP",name_en:"Southern",name_si:"\u0DAF\u0D9A\u0DD4\u0DAB",name_ta:"\u0BA4\u0BC6\u0BB1\u0BCD\u0B95\u0BC1"},{id:"4",code:"NP",name_en:"Northern",name_si:"\u0D8B\u0DAD\u0DD4\u0DBB",name_ta:"\u0BB5\u0B9F\u0B95\u0BCD\u0B95\u0BC1"},{id:"5",code:"EP",name_en:"Eastern",name_si:"\u0DB1\u0DD0\u0D9C\u0DD9\u0DB1\u0DC4\u0DD2\u0DBB",name_ta:"\u0B95\u0BBF\u0BB4\u0B95\u0BCD\u0B95\u0BC1"},{id:"6",code:"NWP",name_en:"North Western",name_si:"\u0DC0\u0DBA\u0DB9",name_ta:"\u0BB5\u0B9F \u0BAE\u0BC7\u0BB1\u0BCD\u0B95\u0BC1"},{id:"7",code:"NCP",name_en:"North Central",name_si:"\u0D8B\u0DAD\u0DD4\u0DBB\u0DD4 \u0DB8\u0DD0\u0DAF",name_ta:"\u0BB5\u0B9F \u0BAE\u0BA4\u0BCD\u0BA4\u0BBF\u0BAF"},{id:"8",code:"UP",name_en:"Uva",name_si:"\u0D8C\u0DC0",name_ta:"\u0B8A\u0BB5\u0BBE"},{id:"9",code:"SGP",name_en:"Sabaragamuwa",name_si:"\u0DC3\u0DB6\u0DBB\u0D9C\u0DB8\u0DD4\u0DC0",name_ta:"\u0B9A\u0BAA\u0BB0\u0B95\u0BAE\u0BC1\u0BB5"}];var r=Object.freeze(i.map(e=>Object.freeze({id:e.id,code:e.code,name:e.name_en,name_en:e.name_en,name_si:e.name_si,name_ta:e.name_ta}))),_=Object.freeze(r.reduce((e,n)=>(e[n.code]=n,e),{})),t=new Map;for(let e of r)t.set(e.code.toUpperCase(),e),t.set(e.id,e),t.set(e.name_en.toLowerCase(),e);function m(e){if(!e||typeof e!="string")return;let n=e.trim();return t.get(n.toUpperCase())||t.get(n.toLowerCase())||t.get(n)}function P(e,n="en"){let a=m(e);if(a)return n==="si"?a.name_si:n==="ta"?a.name_ta:a.name_en}function u(e,n){let a=m(e);if(!a)return;let o=n?.lang;return !o||o==="en"?a:{...a,name:o==="si"?a.name_si:a.name_ta}}function f(e){let n=typeof e=="string"?e:e?.lang;return !n||n==="en"?r:r.map(a=>({...a,name:n==="si"?a.name_si:a.name_ta}))}export{r as PROVINCES,_ as PROVINCE_MAP,m as getProvince,u as getProvinceByCode,P as getProvinceName,f as getProvinces};
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';function e(i,n){return n==="si"?i.name_si:n==="ta"?i.name_ta:i.name_en}exports.getName=e;
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
type Language = 'en' | 'si' | 'ta';
|
|
2
|
+
type ProvinceCode = 'WP' | 'CP' | 'SP' | 'NP' | 'EP' | 'NWP' | 'NCP' | 'UP' | 'SGP';
|
|
3
|
+
type DistrictAbbreviation = 'CO' | 'GQ' | 'KT' | 'KY' | 'MT' | 'NW' | 'GL' | 'MH' | 'HB' | 'JA' | 'KO' | 'MB' | 'VA' | 'MP' | 'BC' | 'AR' | 'TC' | 'KG' | 'PX' | 'AD' | 'PR' | 'BD' | 'MJ' | 'RN' | 'KE';
|
|
4
|
+
type DistrictCode = DistrictAbbreviation;
|
|
5
|
+
interface TrilingualName {
|
|
6
|
+
name_en: string;
|
|
7
|
+
name_si: string;
|
|
8
|
+
name_ta: string;
|
|
9
|
+
}
|
|
10
|
+
declare function getName(item: TrilingualName, lang?: Language): string;
|
|
11
|
+
interface Province {
|
|
12
|
+
id: string;
|
|
13
|
+
code: ProvinceCode;
|
|
14
|
+
name: string;
|
|
15
|
+
name_en: string;
|
|
16
|
+
name_si: string;
|
|
17
|
+
name_ta: string;
|
|
18
|
+
}
|
|
19
|
+
interface District {
|
|
20
|
+
id: string;
|
|
21
|
+
code: DistrictAbbreviation;
|
|
22
|
+
name: string;
|
|
23
|
+
name_en: string;
|
|
24
|
+
name_si: string;
|
|
25
|
+
name_ta: string;
|
|
26
|
+
province_id: string;
|
|
27
|
+
province_code: ProvinceCode;
|
|
28
|
+
province_name: string;
|
|
29
|
+
}
|
|
30
|
+
interface City {
|
|
31
|
+
name: string;
|
|
32
|
+
name_en: string;
|
|
33
|
+
name_si: string;
|
|
34
|
+
name_ta: string;
|
|
35
|
+
postal_code: string;
|
|
36
|
+
district: string;
|
|
37
|
+
district_code: string;
|
|
38
|
+
district_abbr: DistrictAbbreviation;
|
|
39
|
+
province: string;
|
|
40
|
+
province_code: ProvinceCode;
|
|
41
|
+
is_sub_post_office: boolean;
|
|
42
|
+
latitude: number | null;
|
|
43
|
+
longitude: number | null;
|
|
44
|
+
}
|
|
45
|
+
interface Division {
|
|
46
|
+
name_en: string;
|
|
47
|
+
name_si: string;
|
|
48
|
+
name_ta: string;
|
|
49
|
+
district: string;
|
|
50
|
+
province: string;
|
|
51
|
+
}
|
|
52
|
+
interface GNDivision {
|
|
53
|
+
code: string;
|
|
54
|
+
name: string;
|
|
55
|
+
name_en: string;
|
|
56
|
+
name_si: string;
|
|
57
|
+
name_ta: string;
|
|
58
|
+
division: string;
|
|
59
|
+
district: string;
|
|
60
|
+
}
|
|
61
|
+
interface GNSearchOptions extends QueryOptions {
|
|
62
|
+
limit?: number;
|
|
63
|
+
division?: string;
|
|
64
|
+
district?: string;
|
|
65
|
+
}
|
|
66
|
+
interface Branch {
|
|
67
|
+
id: number;
|
|
68
|
+
code: string;
|
|
69
|
+
name: string;
|
|
70
|
+
}
|
|
71
|
+
interface Bank {
|
|
72
|
+
id: number;
|
|
73
|
+
code: string;
|
|
74
|
+
name: string;
|
|
75
|
+
branches: Branch[];
|
|
76
|
+
}
|
|
77
|
+
interface QueryOptions {
|
|
78
|
+
lang?: Language;
|
|
79
|
+
}
|
|
80
|
+
interface SearchOptions extends QueryOptions {
|
|
81
|
+
limit?: number;
|
|
82
|
+
district?: string;
|
|
83
|
+
province?: string;
|
|
84
|
+
}
|
|
85
|
+
interface CascadingDistrict {
|
|
86
|
+
id: string;
|
|
87
|
+
code: DistrictAbbreviation;
|
|
88
|
+
name: string;
|
|
89
|
+
cities: Array<{
|
|
90
|
+
name: string;
|
|
91
|
+
postal_code: string;
|
|
92
|
+
is_sub_post_office: boolean;
|
|
93
|
+
}>;
|
|
94
|
+
}
|
|
95
|
+
interface CascadingProvince {
|
|
96
|
+
id: string;
|
|
97
|
+
code: ProvinceCode;
|
|
98
|
+
name: string;
|
|
99
|
+
districts: CascadingDistrict[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { type Bank, type Branch, type CascadingDistrict, type CascadingProvince, type City, type District, type DistrictAbbreviation, type DistrictCode, type Division, type GNDivision, type GNSearchOptions, type Language, type Province, type ProvinceCode, type QueryOptions, type SearchOptions, type TrilingualName, getName };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
type Language = 'en' | 'si' | 'ta';
|
|
2
|
+
type ProvinceCode = 'WP' | 'CP' | 'SP' | 'NP' | 'EP' | 'NWP' | 'NCP' | 'UP' | 'SGP';
|
|
3
|
+
type DistrictAbbreviation = 'CO' | 'GQ' | 'KT' | 'KY' | 'MT' | 'NW' | 'GL' | 'MH' | 'HB' | 'JA' | 'KO' | 'MB' | 'VA' | 'MP' | 'BC' | 'AR' | 'TC' | 'KG' | 'PX' | 'AD' | 'PR' | 'BD' | 'MJ' | 'RN' | 'KE';
|
|
4
|
+
type DistrictCode = DistrictAbbreviation;
|
|
5
|
+
interface TrilingualName {
|
|
6
|
+
name_en: string;
|
|
7
|
+
name_si: string;
|
|
8
|
+
name_ta: string;
|
|
9
|
+
}
|
|
10
|
+
declare function getName(item: TrilingualName, lang?: Language): string;
|
|
11
|
+
interface Province {
|
|
12
|
+
id: string;
|
|
13
|
+
code: ProvinceCode;
|
|
14
|
+
name: string;
|
|
15
|
+
name_en: string;
|
|
16
|
+
name_si: string;
|
|
17
|
+
name_ta: string;
|
|
18
|
+
}
|
|
19
|
+
interface District {
|
|
20
|
+
id: string;
|
|
21
|
+
code: DistrictAbbreviation;
|
|
22
|
+
name: string;
|
|
23
|
+
name_en: string;
|
|
24
|
+
name_si: string;
|
|
25
|
+
name_ta: string;
|
|
26
|
+
province_id: string;
|
|
27
|
+
province_code: ProvinceCode;
|
|
28
|
+
province_name: string;
|
|
29
|
+
}
|
|
30
|
+
interface City {
|
|
31
|
+
name: string;
|
|
32
|
+
name_en: string;
|
|
33
|
+
name_si: string;
|
|
34
|
+
name_ta: string;
|
|
35
|
+
postal_code: string;
|
|
36
|
+
district: string;
|
|
37
|
+
district_code: string;
|
|
38
|
+
district_abbr: DistrictAbbreviation;
|
|
39
|
+
province: string;
|
|
40
|
+
province_code: ProvinceCode;
|
|
41
|
+
is_sub_post_office: boolean;
|
|
42
|
+
latitude: number | null;
|
|
43
|
+
longitude: number | null;
|
|
44
|
+
}
|
|
45
|
+
interface Division {
|
|
46
|
+
name_en: string;
|
|
47
|
+
name_si: string;
|
|
48
|
+
name_ta: string;
|
|
49
|
+
district: string;
|
|
50
|
+
province: string;
|
|
51
|
+
}
|
|
52
|
+
interface GNDivision {
|
|
53
|
+
code: string;
|
|
54
|
+
name: string;
|
|
55
|
+
name_en: string;
|
|
56
|
+
name_si: string;
|
|
57
|
+
name_ta: string;
|
|
58
|
+
division: string;
|
|
59
|
+
district: string;
|
|
60
|
+
}
|
|
61
|
+
interface GNSearchOptions extends QueryOptions {
|
|
62
|
+
limit?: number;
|
|
63
|
+
division?: string;
|
|
64
|
+
district?: string;
|
|
65
|
+
}
|
|
66
|
+
interface Branch {
|
|
67
|
+
id: number;
|
|
68
|
+
code: string;
|
|
69
|
+
name: string;
|
|
70
|
+
}
|
|
71
|
+
interface Bank {
|
|
72
|
+
id: number;
|
|
73
|
+
code: string;
|
|
74
|
+
name: string;
|
|
75
|
+
branches: Branch[];
|
|
76
|
+
}
|
|
77
|
+
interface QueryOptions {
|
|
78
|
+
lang?: Language;
|
|
79
|
+
}
|
|
80
|
+
interface SearchOptions extends QueryOptions {
|
|
81
|
+
limit?: number;
|
|
82
|
+
district?: string;
|
|
83
|
+
province?: string;
|
|
84
|
+
}
|
|
85
|
+
interface CascadingDistrict {
|
|
86
|
+
id: string;
|
|
87
|
+
code: DistrictAbbreviation;
|
|
88
|
+
name: string;
|
|
89
|
+
cities: Array<{
|
|
90
|
+
name: string;
|
|
91
|
+
postal_code: string;
|
|
92
|
+
is_sub_post_office: boolean;
|
|
93
|
+
}>;
|
|
94
|
+
}
|
|
95
|
+
interface CascadingProvince {
|
|
96
|
+
id: string;
|
|
97
|
+
code: ProvinceCode;
|
|
98
|
+
name: string;
|
|
99
|
+
districts: CascadingDistrict[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { type Bank, type Branch, type CascadingDistrict, type CascadingProvince, type City, type District, type DistrictAbbreviation, type DistrictCode, type Division, type GNDivision, type GNSearchOptions, type Language, type Province, type ProvinceCode, type QueryOptions, type SearchOptions, type TrilingualName, getName };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(i,n){return n==="si"?i.name_si:n==="ta"?i.name_ta:i.name_en}export{e as getName};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var m=[31,29,31,30,31,30,31,31,30,31,30,31];function P(e){if(!e||typeof e!="string")return null;let t=e.trim().toUpperCase(),n=/^(\d{2})(\d{3})(\d{4})([VX])$/,i=/^(\d{4})(\d{3})(\d{5})$/,a=0,r=0,o="old",s;if(n.test(t)){o="old";let l=t.match(n);a=1900+parseInt(l[1],10),r=parseInt(l[2],10),s=l[4]==="V";}else if(i.test(t)){o="new";let l=t.match(i);a=parseInt(l[1],10),r=parseInt(l[2],10);}else return null;let p=r>500?"female":"male",u=p==="female"?r-500:r;if(u<1||u>366)return null;let d=u,c=0;for(;c<m.length&&d>m[c];)d-=m[c],c++;let f=c+1,h=d,b=l=>String(l).padStart(2,"0"),N=`${a}-${b(f)}-${b(h)}`,g=new Date,w=g.getFullYear()-a,$=g.getMonth()+1,I=g.getDate();return ($<f||$===f&&I<h)&&w--,{isValid:true,nic:t,format:o,birthYear:a,birthDate:N,gender:p,age:w,...s!==void 0?{canVote:s}:{}}}function M(e){return P(e)!==null}function V(e){let t=P(e);if(!t||t.format!=="old")return null;let n=t.nic.slice(0,9);return `19${n.slice(0,5)}0${n.slice(5,9)}`}var x={70:"Mobitel",71:"Mobitel",72:"Hutch",74:"Dialog",75:"Airtel",76:"Dialog",77:"Dialog",78:"Hutch"},y={11:"Colombo",21:"Jaffna",23:"Mannar",24:"Vavuniya",25:"Anuradhapura",26:"Trincomalee",27:"Polonnaruwa",31:"Negombo",32:"Chilaw",33:"Gampaha",34:"Kalutara",35:"Kegalle",36:"Avissawella",37:"Kurunegala",38:"Panadura",41:"Matara",45:"Ratnapura",47:"Hambantota",51:"Hatton",52:"Nuwara Eliya",54:"Nawalapitiya",55:"Badulla",57:"Bandarawela",63:"Ampara",65:"Batticaloa",66:"Matale",67:"Kalmunai",81:"Kandy",91:"Galle"};function D(e){if(!e||typeof e!="string")return null;let t=e.replace(/[\s\-()]/g,"");if(t.startsWith("+94")?t=t.slice(3):t.startsWith("0094")?t=t.slice(4):t.startsWith("94")?t=t.slice(2):t.startsWith("0")&&(t=t.slice(1)),!/^\d{9}$/.test(t))return null;let n=t.slice(0,2),i=n in x,a=n in y;if(!i&&!a)return null;let r=t.slice(0,2),o=t.slice(2,5),s=t.slice(5);return {isValid:true,raw:e,number:t,type:i?"mobile":"fixed",...i?{operator:x[n]}:{},...a?{area:y[n]}:{},formatted:{international:`+94 ${r} ${o} ${s}`,local:`0${r} ${o} ${s}`,e164:`+94${t}`}}}function A(e){return D(e)!==null}function C(e,t="local"){let n=D(e);return n?n.formatted[t]:null}function R(e){if(!e||typeof e!="string")return false;let t=e.trim();return /^\d{5}$/.test(t)}exports.convertOldNICToNew=V;exports.formatPhone=C;exports.parseNIC=P;exports.parsePhone=D;exports.validateNIC=M;exports.validatePhone=A;exports.validatePostalCode=R;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
interface ParsedNIC {
|
|
2
|
+
isValid: boolean;
|
|
3
|
+
nic: string;
|
|
4
|
+
format: 'old' | 'new';
|
|
5
|
+
birthYear: number;
|
|
6
|
+
birthDate: string;
|
|
7
|
+
gender: 'male' | 'female';
|
|
8
|
+
age: number;
|
|
9
|
+
canVote?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface ParsedPhone {
|
|
12
|
+
isValid: boolean;
|
|
13
|
+
raw: string;
|
|
14
|
+
number: string;
|
|
15
|
+
type: 'mobile' | 'fixed' | 'unknown';
|
|
16
|
+
operator?: string;
|
|
17
|
+
area?: string;
|
|
18
|
+
formatted: {
|
|
19
|
+
international: string;
|
|
20
|
+
local: string;
|
|
21
|
+
e164: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parses a Sri Lankan National Identity Card (NIC) number.
|
|
26
|
+
* Supports both old (9 digits + V/X) and new (12 digits) formats.
|
|
27
|
+
*
|
|
28
|
+
* @param nic - NIC string to parse.
|
|
29
|
+
* @returns ParsedNIC object with extracted demographic fields, or null if invalid.
|
|
30
|
+
*/
|
|
31
|
+
declare function parseNIC(nic: string): ParsedNIC | null;
|
|
32
|
+
/**
|
|
33
|
+
* Validates whether the given string is a valid Sri Lankan NIC.
|
|
34
|
+
*
|
|
35
|
+
* @param nic - NIC string to validate.
|
|
36
|
+
*/
|
|
37
|
+
declare function validateNIC(nic: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Converts a 10-character Old NIC format (e.g. '952134567V') to the 12-digit New standard.
|
|
40
|
+
*
|
|
41
|
+
* @param oldNic - 10-character NIC string.
|
|
42
|
+
* @returns 12-digit NIC string, or null if invalid.
|
|
43
|
+
*/
|
|
44
|
+
declare function convertOldNICToNew(oldNic: string): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* Parses and validates Sri Lankan telephone numbers (mobile and fixed-line).
|
|
47
|
+
* Supports international (+94), local (07X, 011), and plain 9-digit formats.
|
|
48
|
+
*
|
|
49
|
+
* @param phone - Phone number string.
|
|
50
|
+
* @returns ParsedPhone object or null if invalid.
|
|
51
|
+
*/
|
|
52
|
+
declare function parsePhone(phone: string): ParsedPhone | null;
|
|
53
|
+
/**
|
|
54
|
+
* Validates whether the given string is a valid Sri Lankan phone number.
|
|
55
|
+
*
|
|
56
|
+
* @param phone - Phone number string.
|
|
57
|
+
*/
|
|
58
|
+
declare function validatePhone(phone: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Formats a Sri Lankan phone number.
|
|
61
|
+
*
|
|
62
|
+
* @param phone - Phone number string.
|
|
63
|
+
* @param style - Format style ('international' | 'local' | 'e164'). Default is 'local'.
|
|
64
|
+
*/
|
|
65
|
+
declare function formatPhone(phone: string, style?: 'international' | 'local' | 'e164'): string | null;
|
|
66
|
+
/**
|
|
67
|
+
* Validates whether a string matches the Sri Lankan 5-digit postal code format.
|
|
68
|
+
* To check if a code exists in the official postal database, use `isValidPostalCode()`.
|
|
69
|
+
*
|
|
70
|
+
* @param postalCode - Postal code string.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* validatePostalCode('00100') // => true
|
|
74
|
+
* validatePostalCode('123') // => false
|
|
75
|
+
*/
|
|
76
|
+
declare function validatePostalCode(postalCode: string): boolean;
|
|
77
|
+
|
|
78
|
+
export { type ParsedNIC, type ParsedPhone, convertOldNICToNew, formatPhone, parseNIC, parsePhone, validateNIC, validatePhone, validatePostalCode };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
interface ParsedNIC {
|
|
2
|
+
isValid: boolean;
|
|
3
|
+
nic: string;
|
|
4
|
+
format: 'old' | 'new';
|
|
5
|
+
birthYear: number;
|
|
6
|
+
birthDate: string;
|
|
7
|
+
gender: 'male' | 'female';
|
|
8
|
+
age: number;
|
|
9
|
+
canVote?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface ParsedPhone {
|
|
12
|
+
isValid: boolean;
|
|
13
|
+
raw: string;
|
|
14
|
+
number: string;
|
|
15
|
+
type: 'mobile' | 'fixed' | 'unknown';
|
|
16
|
+
operator?: string;
|
|
17
|
+
area?: string;
|
|
18
|
+
formatted: {
|
|
19
|
+
international: string;
|
|
20
|
+
local: string;
|
|
21
|
+
e164: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parses a Sri Lankan National Identity Card (NIC) number.
|
|
26
|
+
* Supports both old (9 digits + V/X) and new (12 digits) formats.
|
|
27
|
+
*
|
|
28
|
+
* @param nic - NIC string to parse.
|
|
29
|
+
* @returns ParsedNIC object with extracted demographic fields, or null if invalid.
|
|
30
|
+
*/
|
|
31
|
+
declare function parseNIC(nic: string): ParsedNIC | null;
|
|
32
|
+
/**
|
|
33
|
+
* Validates whether the given string is a valid Sri Lankan NIC.
|
|
34
|
+
*
|
|
35
|
+
* @param nic - NIC string to validate.
|
|
36
|
+
*/
|
|
37
|
+
declare function validateNIC(nic: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Converts a 10-character Old NIC format (e.g. '952134567V') to the 12-digit New standard.
|
|
40
|
+
*
|
|
41
|
+
* @param oldNic - 10-character NIC string.
|
|
42
|
+
* @returns 12-digit NIC string, or null if invalid.
|
|
43
|
+
*/
|
|
44
|
+
declare function convertOldNICToNew(oldNic: string): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* Parses and validates Sri Lankan telephone numbers (mobile and fixed-line).
|
|
47
|
+
* Supports international (+94), local (07X, 011), and plain 9-digit formats.
|
|
48
|
+
*
|
|
49
|
+
* @param phone - Phone number string.
|
|
50
|
+
* @returns ParsedPhone object or null if invalid.
|
|
51
|
+
*/
|
|
52
|
+
declare function parsePhone(phone: string): ParsedPhone | null;
|
|
53
|
+
/**
|
|
54
|
+
* Validates whether the given string is a valid Sri Lankan phone number.
|
|
55
|
+
*
|
|
56
|
+
* @param phone - Phone number string.
|
|
57
|
+
*/
|
|
58
|
+
declare function validatePhone(phone: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Formats a Sri Lankan phone number.
|
|
61
|
+
*
|
|
62
|
+
* @param phone - Phone number string.
|
|
63
|
+
* @param style - Format style ('international' | 'local' | 'e164'). Default is 'local'.
|
|
64
|
+
*/
|
|
65
|
+
declare function formatPhone(phone: string, style?: 'international' | 'local' | 'e164'): string | null;
|
|
66
|
+
/**
|
|
67
|
+
* Validates whether a string matches the Sri Lankan 5-digit postal code format.
|
|
68
|
+
* To check if a code exists in the official postal database, use `isValidPostalCode()`.
|
|
69
|
+
*
|
|
70
|
+
* @param postalCode - Postal code string.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* validatePostalCode('00100') // => true
|
|
74
|
+
* validatePostalCode('123') // => false
|
|
75
|
+
*/
|
|
76
|
+
declare function validatePostalCode(postalCode: string): boolean;
|
|
77
|
+
|
|
78
|
+
export { type ParsedNIC, type ParsedPhone, convertOldNICToNew, formatPhone, parseNIC, parsePhone, validateNIC, validatePhone, validatePostalCode };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m=[31,29,31,30,31,30,31,31,30,31,30,31];function P(e){if(!e||typeof e!="string")return null;let t=e.trim().toUpperCase(),n=/^(\d{2})(\d{3})(\d{4})([VX])$/,i=/^(\d{4})(\d{3})(\d{5})$/,a=0,r=0,o="old",s;if(n.test(t)){o="old";let l=t.match(n);a=1900+parseInt(l[1],10),r=parseInt(l[2],10),s=l[4]==="V";}else if(i.test(t)){o="new";let l=t.match(i);a=parseInt(l[1],10),r=parseInt(l[2],10);}else return null;let p=r>500?"female":"male",u=p==="female"?r-500:r;if(u<1||u>366)return null;let d=u,c=0;for(;c<m.length&&d>m[c];)d-=m[c],c++;let f=c+1,h=d,b=l=>String(l).padStart(2,"0"),N=`${a}-${b(f)}-${b(h)}`,g=new Date,w=g.getFullYear()-a,$=g.getMonth()+1,I=g.getDate();return ($<f||$===f&&I<h)&&w--,{isValid:true,nic:t,format:o,birthYear:a,birthDate:N,gender:p,age:w,...s!==void 0?{canVote:s}:{}}}function M(e){return P(e)!==null}function V(e){let t=P(e);if(!t||t.format!=="old")return null;let n=t.nic.slice(0,9);return `19${n.slice(0,5)}0${n.slice(5,9)}`}var x={70:"Mobitel",71:"Mobitel",72:"Hutch",74:"Dialog",75:"Airtel",76:"Dialog",77:"Dialog",78:"Hutch"},y={11:"Colombo",21:"Jaffna",23:"Mannar",24:"Vavuniya",25:"Anuradhapura",26:"Trincomalee",27:"Polonnaruwa",31:"Negombo",32:"Chilaw",33:"Gampaha",34:"Kalutara",35:"Kegalle",36:"Avissawella",37:"Kurunegala",38:"Panadura",41:"Matara",45:"Ratnapura",47:"Hambantota",51:"Hatton",52:"Nuwara Eliya",54:"Nawalapitiya",55:"Badulla",57:"Bandarawela",63:"Ampara",65:"Batticaloa",66:"Matale",67:"Kalmunai",81:"Kandy",91:"Galle"};function D(e){if(!e||typeof e!="string")return null;let t=e.replace(/[\s\-()]/g,"");if(t.startsWith("+94")?t=t.slice(3):t.startsWith("0094")?t=t.slice(4):t.startsWith("94")?t=t.slice(2):t.startsWith("0")&&(t=t.slice(1)),!/^\d{9}$/.test(t))return null;let n=t.slice(0,2),i=n in x,a=n in y;if(!i&&!a)return null;let r=t.slice(0,2),o=t.slice(2,5),s=t.slice(5);return {isValid:true,raw:e,number:t,type:i?"mobile":"fixed",...i?{operator:x[n]}:{},...a?{area:y[n]}:{},formatted:{international:`+94 ${r} ${o} ${s}`,local:`0${r} ${o} ${s}`,e164:`+94${t}`}}}function A(e){return D(e)!==null}function C(e,t="local"){let n=D(e);return n?n.formatted[t]:null}function R(e){if(!e||typeof e!="string")return false;let t=e.trim();return /^\d{5}$/.test(t)}export{V as convertOldNICToNew,C as formatPhone,P as parseNIC,D as parsePhone,M as validateNIC,A as validatePhone,R as validatePostalCode};
|
package/package.json
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "geo-sl",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Trilingual (English, සිංහල, தமிழ்) Sri Lanka geographic, postal code, and administrative dataset for TypeScript and JavaScript.",
|
|
5
|
+
"author": "Mahesh Abeykoon",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/mahesh-abeykoon/sl-geo#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/mahesh-abeykoon/sl-geo.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/mahesh-abeykoon/sl-geo/issues"
|
|
14
|
+
},
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=16.0.0"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./provinces": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/provinces.d.ts",
|
|
37
|
+
"default": "./dist/provinces.js"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/provinces.d.cts",
|
|
41
|
+
"default": "./dist/provinces.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"./districts": {
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./dist/districts.d.ts",
|
|
47
|
+
"default": "./dist/districts.js"
|
|
48
|
+
},
|
|
49
|
+
"require": {
|
|
50
|
+
"types": "./dist/districts.d.cts",
|
|
51
|
+
"default": "./dist/districts.cjs"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"./cities": {
|
|
55
|
+
"import": {
|
|
56
|
+
"types": "./dist/cities.d.ts",
|
|
57
|
+
"default": "./dist/cities.js"
|
|
58
|
+
},
|
|
59
|
+
"require": {
|
|
60
|
+
"types": "./dist/cities.d.cts",
|
|
61
|
+
"default": "./dist/cities.cjs"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"./divisions": {
|
|
65
|
+
"import": {
|
|
66
|
+
"types": "./dist/divisions.d.ts",
|
|
67
|
+
"default": "./dist/divisions.js"
|
|
68
|
+
},
|
|
69
|
+
"require": {
|
|
70
|
+
"types": "./dist/divisions.d.cts",
|
|
71
|
+
"default": "./dist/divisions.cjs"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"./banks": {
|
|
75
|
+
"import": {
|
|
76
|
+
"types": "./dist/banks.d.ts",
|
|
77
|
+
"default": "./dist/banks.js"
|
|
78
|
+
},
|
|
79
|
+
"require": {
|
|
80
|
+
"types": "./dist/banks.d.cts",
|
|
81
|
+
"default": "./dist/banks.cjs"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"./validators": {
|
|
85
|
+
"import": {
|
|
86
|
+
"types": "./dist/validators.d.ts",
|
|
87
|
+
"default": "./dist/validators.js"
|
|
88
|
+
},
|
|
89
|
+
"require": {
|
|
90
|
+
"types": "./dist/validators.d.cts",
|
|
91
|
+
"default": "./dist/validators.cjs"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"./gn": {
|
|
95
|
+
"import": {
|
|
96
|
+
"types": "./dist/gn.d.ts",
|
|
97
|
+
"default": "./dist/gn.js"
|
|
98
|
+
},
|
|
99
|
+
"require": {
|
|
100
|
+
"types": "./dist/gn.d.cts",
|
|
101
|
+
"default": "./dist/gn.cjs"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"./types": {
|
|
105
|
+
"import": {
|
|
106
|
+
"types": "./dist/types.d.ts",
|
|
107
|
+
"default": "./dist/types.js"
|
|
108
|
+
},
|
|
109
|
+
"require": {
|
|
110
|
+
"types": "./dist/types.d.cts",
|
|
111
|
+
"default": "./dist/types.cjs"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"files": [
|
|
116
|
+
"dist"
|
|
117
|
+
],
|
|
118
|
+
"keywords": [
|
|
119
|
+
"sri lanka",
|
|
120
|
+
"postal code",
|
|
121
|
+
"postcode",
|
|
122
|
+
"cities",
|
|
123
|
+
"districts",
|
|
124
|
+
"provinces",
|
|
125
|
+
"divisional secretariat",
|
|
126
|
+
"grama niladhari",
|
|
127
|
+
"colombo",
|
|
128
|
+
"sinhala",
|
|
129
|
+
"tamil",
|
|
130
|
+
"lankapay",
|
|
131
|
+
"banks",
|
|
132
|
+
"address autocomplete",
|
|
133
|
+
"checkout"
|
|
134
|
+
],
|
|
135
|
+
"scripts": {
|
|
136
|
+
"build:data": "node scripts/build-datasets.mjs",
|
|
137
|
+
"build": "tsup",
|
|
138
|
+
"test": "vitest run",
|
|
139
|
+
"test:watch": "vitest",
|
|
140
|
+
"prepublishOnly": "npm run build && npm test"
|
|
141
|
+
},
|
|
142
|
+
"devDependencies": {
|
|
143
|
+
"@types/node": "^20.11.24",
|
|
144
|
+
"tsup": "^8.0.2",
|
|
145
|
+
"tsx": "^4.23.13",
|
|
146
|
+
"typescript": "^5.3.3",
|
|
147
|
+
"vitest": "^1.3.1"
|
|
148
|
+
}
|
|
149
|
+
}
|