nepal-places 0.1.1
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/dist/data/districts.d.ts +2 -0
- package/dist/data/districts.js +625 -0
- package/dist/data/index.d.ts +3 -0
- package/dist/data/index.js +3 -0
- package/dist/data/municipalities.d.ts +2 -0
- package/dist/data/municipalities.js +1961 -0
- package/dist/data/provinces.d.ts +2 -0
- package/dist/data/provinces.js +72 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +85 -0
- package/package.json +60 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export const provinces = [
|
|
2
|
+
{
|
|
3
|
+
id: 1,
|
|
4
|
+
name: 'Koshi',
|
|
5
|
+
alt_name: 'Province No. 1',
|
|
6
|
+
name_np: 'कोशी',
|
|
7
|
+
headquarters: 'Biratnagar',
|
|
8
|
+
area_km2: 25905,
|
|
9
|
+
population: 4972021,
|
|
10
|
+
district_count: 14,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: 2,
|
|
14
|
+
name: 'Madhesh',
|
|
15
|
+
alt_name: 'Province No. 2',
|
|
16
|
+
name_np: 'मधेश',
|
|
17
|
+
headquarters: 'Janakpur',
|
|
18
|
+
area_km2: 9661,
|
|
19
|
+
population: 6126288,
|
|
20
|
+
district_count: 8,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 3,
|
|
24
|
+
name: 'Bagmati',
|
|
25
|
+
alt_name: 'Province No. 3',
|
|
26
|
+
name_np: 'बागमती',
|
|
27
|
+
headquarters: 'Hetauda',
|
|
28
|
+
area_km2: 20300,
|
|
29
|
+
population: 6084042,
|
|
30
|
+
district_count: 13,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 4,
|
|
34
|
+
name: 'Gandaki',
|
|
35
|
+
alt_name: 'Province No. 4',
|
|
36
|
+
name_np: 'गण्डकी',
|
|
37
|
+
headquarters: 'Pokhara',
|
|
38
|
+
area_km2: 21504,
|
|
39
|
+
population: 2479745,
|
|
40
|
+
district_count: 11,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 5,
|
|
44
|
+
name: 'Lumbini',
|
|
45
|
+
alt_name: 'Province No. 5',
|
|
46
|
+
name_np: 'लुम्बिनी',
|
|
47
|
+
headquarters: 'Deukhuri',
|
|
48
|
+
area_km2: 22288,
|
|
49
|
+
population: 5124225,
|
|
50
|
+
district_count: 12,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 6,
|
|
54
|
+
name: 'Karnali',
|
|
55
|
+
alt_name: 'Province No. 6',
|
|
56
|
+
name_np: 'कर्णाली',
|
|
57
|
+
headquarters: 'Birendranagar',
|
|
58
|
+
area_km2: 27984,
|
|
59
|
+
population: 1694889,
|
|
60
|
+
district_count: 10,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 7,
|
|
64
|
+
name: 'Sudurpashchim',
|
|
65
|
+
alt_name: 'Province No. 7',
|
|
66
|
+
name_np: 'सुदूरपश्चिम',
|
|
67
|
+
headquarters: 'Godawari',
|
|
68
|
+
area_km2: 19999.28,
|
|
69
|
+
population: 2711270,
|
|
70
|
+
district_count: 9,
|
|
71
|
+
},
|
|
72
|
+
];
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface Province {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
name_np: string;
|
|
5
|
+
alt_name?: string;
|
|
6
|
+
headquarters: string;
|
|
7
|
+
area_km2: number;
|
|
8
|
+
population: number;
|
|
9
|
+
district_count: number;
|
|
10
|
+
}
|
|
11
|
+
export interface District {
|
|
12
|
+
id: number;
|
|
13
|
+
province_id: number;
|
|
14
|
+
name: string;
|
|
15
|
+
name_np?: string;
|
|
16
|
+
headquarters: string;
|
|
17
|
+
area_km2: number;
|
|
18
|
+
population: number;
|
|
19
|
+
}
|
|
20
|
+
export type LocalLevelType = 'metropolitan' | 'sub_metropolitan' | 'municipality' | 'rural_municipality';
|
|
21
|
+
export interface LocalLevel {
|
|
22
|
+
id: number;
|
|
23
|
+
district_id: number;
|
|
24
|
+
name: string;
|
|
25
|
+
name_np?: string;
|
|
26
|
+
type: LocalLevelType;
|
|
27
|
+
wards: number;
|
|
28
|
+
}
|
|
29
|
+
export interface Ward {
|
|
30
|
+
id: number;
|
|
31
|
+
local_level_id: number;
|
|
32
|
+
ward_number: number;
|
|
33
|
+
}
|
|
34
|
+
export type Depth = 1 | 2 | 3 | 4 | 5;
|
|
35
|
+
export interface PlaceResponse<TDepth extends Depth = 4> {
|
|
36
|
+
province: Province;
|
|
37
|
+
district: TDepth extends 1 ? never : District;
|
|
38
|
+
localLevel: TDepth extends 1 | 2 ? never : LocalLevel;
|
|
39
|
+
ward: TDepth extends 1 | 2 | 3 ? never : Ward;
|
|
40
|
+
}
|
|
41
|
+
export interface PlaceFlat {
|
|
42
|
+
province_id?: number;
|
|
43
|
+
district_id?: number;
|
|
44
|
+
local_level_id?: number;
|
|
45
|
+
ward_id?: number;
|
|
46
|
+
code?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface HierarchyOptions {
|
|
49
|
+
depth?: Depth;
|
|
50
|
+
flat?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface FilterOptions {
|
|
53
|
+
provinceId?: number;
|
|
54
|
+
districtId?: number;
|
|
55
|
+
localLevelId?: number;
|
|
56
|
+
type?: LocalLevelType;
|
|
57
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { District, HierarchyOptions, LocalLevel, PlaceFlat, Province, Ward } from './types.js';
|
|
2
|
+
export declare function getProvinces(): Province[];
|
|
3
|
+
export declare function getProvince(id: number): Province | undefined;
|
|
4
|
+
export declare function getDistricts(provinceId?: number): District[];
|
|
5
|
+
export declare function getDistrict(id: number): District | undefined;
|
|
6
|
+
export declare function getMunicipalities(districtId?: number): LocalLevel[];
|
|
7
|
+
export declare function getMunicipality(id: number): LocalLevel | undefined;
|
|
8
|
+
export declare function getWards(municipalityId: number): Ward[];
|
|
9
|
+
export declare function getHierarchy(options: HierarchyOptions & {
|
|
10
|
+
flat: true;
|
|
11
|
+
}): PlaceFlat | null;
|
|
12
|
+
export declare function getHierarchy(options?: HierarchyOptions): Record<string, unknown> | null;
|
|
13
|
+
export declare function toFlat(obj: Record<string, {
|
|
14
|
+
id: number;
|
|
15
|
+
}>, depth: number): PlaceFlat;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { districts, municipalities, provinces } from './data/index.js';
|
|
2
|
+
export function getProvinces() {
|
|
3
|
+
return provinces;
|
|
4
|
+
}
|
|
5
|
+
export function getProvince(id) {
|
|
6
|
+
return provinces.find((p) => p.id === id);
|
|
7
|
+
}
|
|
8
|
+
export function getDistricts(provinceId) {
|
|
9
|
+
if (provinceId)
|
|
10
|
+
return districts.filter((d) => d.province_id === provinceId);
|
|
11
|
+
return districts;
|
|
12
|
+
}
|
|
13
|
+
export function getDistrict(id) {
|
|
14
|
+
return districts.find((d) => d.id === id);
|
|
15
|
+
}
|
|
16
|
+
export function getMunicipalities(districtId) {
|
|
17
|
+
if (districtId)
|
|
18
|
+
return municipalities.filter((m) => m.district_id === districtId);
|
|
19
|
+
return municipalities;
|
|
20
|
+
}
|
|
21
|
+
export function getMunicipality(id) {
|
|
22
|
+
return municipalities.find((m) => m.id === id);
|
|
23
|
+
}
|
|
24
|
+
export function getWards(municipalityId) {
|
|
25
|
+
const m = getMunicipality(municipalityId);
|
|
26
|
+
if (!m || m.wards === 0)
|
|
27
|
+
return [];
|
|
28
|
+
const wards = [];
|
|
29
|
+
for (let i = 1; i <= m.wards; i++) {
|
|
30
|
+
wards.push({ id: i, local_level_id: municipalityId, ward_number: i });
|
|
31
|
+
}
|
|
32
|
+
return wards;
|
|
33
|
+
}
|
|
34
|
+
export function getHierarchy(options = {}) {
|
|
35
|
+
const { depth = 4 } = options;
|
|
36
|
+
// Return all provinces if no filtering
|
|
37
|
+
const firstProvince = provinces[0];
|
|
38
|
+
if (!firstProvince)
|
|
39
|
+
return null;
|
|
40
|
+
const result = {
|
|
41
|
+
province: firstProvince,
|
|
42
|
+
};
|
|
43
|
+
if (depth >= 2) {
|
|
44
|
+
const district = districts.find((d) => d.province_id === firstProvince.id);
|
|
45
|
+
if (district)
|
|
46
|
+
result.district = district;
|
|
47
|
+
}
|
|
48
|
+
if (depth >= 3) {
|
|
49
|
+
const localLevel = municipalities.find((m) => m.district_id === result.district?.id);
|
|
50
|
+
if (localLevel)
|
|
51
|
+
result.localLevel = localLevel;
|
|
52
|
+
}
|
|
53
|
+
if (depth >= 4) {
|
|
54
|
+
const localLevel = result.localLevel;
|
|
55
|
+
if (localLevel && localLevel.wards > 0) {
|
|
56
|
+
result.ward = { id: 1, local_level_id: localLevel.id, ward_number: 1 };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (options.flat) {
|
|
60
|
+
return toFlat(result, depth);
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
export function toFlat(obj, depth) {
|
|
65
|
+
const flat = {};
|
|
66
|
+
const parts = [];
|
|
67
|
+
if (obj.province) {
|
|
68
|
+
flat.province_id = obj.province.id;
|
|
69
|
+
parts.push(String(obj.province.id));
|
|
70
|
+
}
|
|
71
|
+
if (depth >= 2 && obj.district) {
|
|
72
|
+
flat.district_id = obj.district.id;
|
|
73
|
+
parts.push(String(obj.district.id));
|
|
74
|
+
}
|
|
75
|
+
if (depth >= 3 && obj.localLevel) {
|
|
76
|
+
flat.local_level_id = obj.localLevel.id;
|
|
77
|
+
parts.push(String(obj.localLevel.id));
|
|
78
|
+
}
|
|
79
|
+
if (depth >= 4 && obj.ward) {
|
|
80
|
+
flat.ward_id = obj.ward.id;
|
|
81
|
+
parts.push(String(obj.ward.id));
|
|
82
|
+
}
|
|
83
|
+
flat.code = parts.join('/');
|
|
84
|
+
return flat;
|
|
85
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nepal-places",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Zero-dependency Nepal geographical data — Provinces, Districts, Municipalities, Wards. Works with React, Node.js, any JS framework.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"test": "vitest run"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"nepal",
|
|
23
|
+
"nepali",
|
|
24
|
+
"places",
|
|
25
|
+
"provinces",
|
|
26
|
+
"districts",
|
|
27
|
+
"municipalities",
|
|
28
|
+
"wards",
|
|
29
|
+
"geography",
|
|
30
|
+
"nepal-data",
|
|
31
|
+
"nepal-geography",
|
|
32
|
+
"koshi",
|
|
33
|
+
"bagmati",
|
|
34
|
+
"gandaki",
|
|
35
|
+
"lumbini",
|
|
36
|
+
"karnali",
|
|
37
|
+
"madhesh",
|
|
38
|
+
"sudurpashchim",
|
|
39
|
+
"dropdown",
|
|
40
|
+
"location-picker",
|
|
41
|
+
"nepal-places"
|
|
42
|
+
],
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"author": {
|
|
45
|
+
"name": "kushal1o1",
|
|
46
|
+
"url": "https://github.com/kushal1o1"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/kushal1o1/NepalPlaces.git"
|
|
51
|
+
},
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/kushal1o1/NepalPlaces/issues"
|
|
54
|
+
},
|
|
55
|
+
"homepage": "https://github.com/kushal1o1/NepalPlaces#readme",
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"typescript": "^5.4.0",
|
|
58
|
+
"vitest": "^3.0.0"
|
|
59
|
+
}
|
|
60
|
+
}
|