bd-geo-location 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mazharul Islam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,485 @@
1
+ # BD Geo Location
2
+
3
+ A comprehensive TypeScript package for Bangladesh's geographical administrative divisions. This package provides complete hierarchical data for Divisions, Districts, Upazilas/Thanas, City Corporations, Unions, Pourosovas, and Villages.
4
+
5
+ ## Features
6
+
7
+ - **Complete data for Bangladesh**: 8 Divisions, 68 Districts, 531 Upazilas, 4,916 Unions
8
+ - **JSON-based data format** - Easy to edit and extend without recompiling
9
+ - **JSON Schema validation** - Ensures data integrity
10
+ - TypeScript support with full type definitions
11
+ - Framework-specific integrations:
12
+ - React Hooks
13
+ - Vue 3 Composables
14
+ - Works with Angular, React Native, and any JavaScript framework
15
+ - Support for both English and Bengali names
16
+ - Tree-shakeable and optimized bundle size
17
+ - ES Modules and CommonJS support
18
+
19
+ ## Data Coverage
20
+
21
+ | Division | Districts | Upazilas | Unions |
22
+ |----------|-----------|----------|--------|
23
+ | Barisal | 6 | 42 | 355 |
24
+ | Chittagong | 12 | 117 | 1,052 |
25
+ | Dhaka | 16 | 112 | 1,142 |
26
+ | Khulna | 10 | 59 | 580 |
27
+ | Mymensingh | 4 | 35 | 351 |
28
+ | Rajshahi | 8 | 67 | 567 |
29
+ | Rangpur | 8 | 58 | 533 |
30
+ | Sylhet | 4 | 41 | 336 |
31
+ | **Total** | **68** | **531** | **4,916** |
32
+
33
+ ## Working with JSON Data
34
+
35
+ The package data is stored in JSON format, making it easy to:
36
+
37
+ 1. **View and edit directly** - No TypeScript compilation needed
38
+ 2. **Validate easily** - Use any JSON validator
39
+ 3. **Extend data** - Add new divisions, districts, upazilas, etc.
40
+ 4. **Import from other sources** - Convert CSV, Excel, or other formats to JSON
41
+
42
+ ### Access Raw JSON Data
43
+
44
+ You can import the raw JSON data directly:
45
+
46
+ ```typescript
47
+ import bangladeshData from 'bd-geo-location/dist/data/bangladesh.json';
48
+
49
+ console.log(bangladeshData.divisions);
50
+ // [
51
+ // { id: '30', name: 'Dhaka', nameBn: 'ঢাকা', districts: [...] },
52
+ // { id: '20', name: 'Chittagong', nameBn: 'চট্টগ্রাম', districts: [...] },
53
+ // ...
54
+ // ]
55
+ ```
56
+
57
+ ### Custom Data Processing
58
+
59
+ ```typescript
60
+ import bangladeshData from 'bd-geo-location/dist/data/bangladesh.json';
61
+
62
+ // Count all districts
63
+ const totalDistricts = bangladeshData.divisions.reduce((sum, division) => {
64
+ return sum + (division.districts?.length || 0);
65
+ }, 0);
66
+
67
+ // Get all upazilas in a division
68
+ function getAllUpazilasInDivision(divisionId: string) {
69
+ const division = bangladeshData.divisions.find(d => d.id === divisionId);
70
+ const upazilas = [];
71
+
72
+ division?.districts?.forEach(district => {
73
+ if (district.upazilas) {
74
+ upazilas.push(...district.upazilas);
75
+ }
76
+ });
77
+
78
+ return upazilas;
79
+ }
80
+ ```
81
+
82
+ For more details on the JSON structure and how to extend it, see [DATA_STRUCTURE.md](./DATA_STRUCTURE.md).
83
+
84
+ ## Data Validation
85
+
86
+ The package includes JSON Schema validation to ensure data integrity:
87
+
88
+ ```bash
89
+ # Validate the JSON data
90
+ npm run data:validate
91
+
92
+ # Test the data
93
+ npm run data:test
94
+ ```
95
+
96
+ ## Installation
97
+
98
+ ```bash
99
+ npm install bd-geo-location
100
+ # or
101
+ yarn add bd-geo-location
102
+ # or
103
+ pnpm add bd-geo-location
104
+ ```
105
+
106
+ ## Data Hierarchy
107
+
108
+ ```
109
+ Division (বিভাগ)
110
+ └── District (জেলা)
111
+ ├── City Corporation (সিটি কর্পোরেশন)
112
+ │ └── Thana
113
+ └── Upazila/Thana (উপজেলা/থানা)
114
+ ├── Union (ইউনিয়ন)
115
+ │ └── Village (গ্রাম)
116
+ └── Pourosova (পৌরসভা)
117
+ └── Village (গ্রাম)
118
+ ```
119
+
120
+ ## Basic Usage
121
+
122
+ ### TypeScript/JavaScript (Vanilla)
123
+
124
+ ```typescript
125
+ import {
126
+ getAllDivisions,
127
+ getDivisionById,
128
+ getDistrictsByDivision,
129
+ getUpazilasByDistrict,
130
+ getUnionsByUpazila,
131
+ getPourosovasByUpazila,
132
+ getCityCorporationsByDistrict,
133
+ searchByName
134
+ } from 'bd-geo-location';
135
+
136
+ // Get all divisions
137
+ const divisions = getAllDivisions();
138
+ console.log(divisions);
139
+
140
+ // Get districts by division ID
141
+ const dhakaDistricts = getDistrictsByDivision('30');
142
+ console.log(dhakaDistricts);
143
+
144
+ // Get upazilas by district ID
145
+ const dhakaUpazilas = getUpazilasByDistrict('26');
146
+ console.log(dhakaUpazilas);
147
+
148
+ // Search locations
149
+ const results = searchByName('Dhaka');
150
+ console.log(results);
151
+ ```
152
+
153
+ ### React
154
+
155
+ ```tsx
156
+ import {
157
+ useDivisions,
158
+ useDistricts,
159
+ useUpazilas,
160
+ useUnions,
161
+ useSearch
162
+ } from 'bd-geo-location/react';
163
+
164
+ function LocationSelector() {
165
+ const divisions = useDivisions();
166
+ const [selectedDivision, setSelectedDivision] = useState(null);
167
+ const districts = useDistricts(selectedDivision);
168
+
169
+ return (
170
+ <div>
171
+ <select onChange={(e) => setSelectedDivision(e.target.value)}>
172
+ <option value="">Select Division</option>
173
+ {divisions.map(division => (
174
+ <option key={division.id} value={division.id}>
175
+ {division.name} ({division.nameBn})
176
+ </option>
177
+ ))}
178
+ </select>
179
+
180
+ <select>
181
+ <option value="">Select District</option>
182
+ {districts.map(district => (
183
+ <option key={district.id} value={district.id}>
184
+ {district.name} ({district.nameBn})
185
+ </option>
186
+ ))}
187
+ </select>
188
+ </div>
189
+ );
190
+ }
191
+
192
+ // Search example
193
+ function SearchComponent() {
194
+ const [searchTerm, setSearchTerm] = useState('');
195
+ const results = useSearch(searchTerm);
196
+
197
+ return (
198
+ <div>
199
+ <input
200
+ type="text"
201
+ value={searchTerm}
202
+ onChange={(e) => setSearchTerm(e.target.value)}
203
+ placeholder="Search locations..."
204
+ />
205
+
206
+ <div>
207
+ <h3>Divisions</h3>
208
+ {results.divisions.map(division => (
209
+ <div key={division.id}>{division.name}</div>
210
+ ))}
211
+
212
+ <h3>Districts</h3>
213
+ {results.districts.map(district => (
214
+ <div key={district.id}>{district.name}</div>
215
+ ))}
216
+ </div>
217
+ </div>
218
+ );
219
+ }
220
+ ```
221
+
222
+ ### Vue 3
223
+
224
+ ```vue
225
+ <script setup lang="ts">
226
+ import { ref } from 'vue';
227
+ import {
228
+ useDivisions,
229
+ useDistricts,
230
+ useUpazilas,
231
+ useSearch
232
+ } from 'bd-geo-location/vue';
233
+
234
+ const selectedDivision = ref(null);
235
+ const { divisions } = useDivisions();
236
+ const { districts } = useDistricts(selectedDivision);
237
+ const searchTerm = ref('');
238
+ const { results } = useSearch(searchTerm);
239
+ </script>
240
+
241
+ <template>
242
+ <div>
243
+ <select v-model="selectedDivision">
244
+ <option value="">Select Division</option>
245
+ <option v-for="division in divisions" :key="division.id" :value="division.id">
246
+ {{ division.name }} ({{ division.nameBn }})
247
+ </option>
248
+ </select>
249
+
250
+ <select>
251
+ <option value="">Select District</option>
252
+ <option v-for="district in districts" :key="district.id" :value="district.id">
253
+ {{ district.name }} ({{ district.nameBn }})
254
+ </option>
255
+ </select>
256
+
257
+ <!-- Search -->
258
+ <input v-model="searchTerm" type="text" placeholder="Search locations..." />
259
+
260
+ <div>
261
+ <h3>Search Results</h3>
262
+ <div v-for="division in results.divisions" :key="division.id">
263
+ {{ division.name }}
264
+ </div>
265
+ </div>
266
+ </div>
267
+ </template>
268
+ ```
269
+
270
+ ### Angular
271
+
272
+ ```typescript
273
+ import { Component } from '@angular/core';
274
+ import {
275
+ getAllDivisions,
276
+ getDistrictsByDivision
277
+ } from 'bd-geo-location';
278
+
279
+ @Component({
280
+ selector: 'app-location',
281
+ template: `
282
+ <select (change)="onDivisionChange($event)">
283
+ <option value="">Select Division</option>
284
+ <option *ngFor="let division of divisions" [value]="division.id">
285
+ {{ division.name }} ({{ division.nameBn }})
286
+ </option>
287
+ </select>
288
+
289
+ <select>
290
+ <option value="">Select District</option>
291
+ <option *ngFor="let district of districts" [value]="district.id">
292
+ {{ district.name }} ({{ district.nameBn }})
293
+ </option>
294
+ </select>
295
+ `
296
+ })
297
+ export class LocationComponent {
298
+ divisions = getAllDivisions();
299
+ districts: any[] = [];
300
+
301
+ onDivisionChange(event: any) {
302
+ const divisionId = event.target.value;
303
+ this.districts = getDistrictsByDivision(divisionId);
304
+ }
305
+ }
306
+ ```
307
+
308
+ ### React Native
309
+
310
+ ```tsx
311
+ import React, { useState } from 'react';
312
+ import { View, Picker, Text } from 'react-native';
313
+ import { useDivisions, useDistricts } from 'bd-geo-location/react';
314
+
315
+ function LocationScreen() {
316
+ const divisions = useDivisions();
317
+ const [selectedDivision, setSelectedDivision] = useState(null);
318
+ const districts = useDistricts(selectedDivision);
319
+
320
+ return (
321
+ <View>
322
+ <Picker
323
+ selectedValue={selectedDivision}
324
+ onValueChange={(itemValue) => setSelectedDivision(itemValue)}
325
+ >
326
+ <Picker.Item label="Select Division" value="" />
327
+ {divisions.map(division => (
328
+ <Picker.Item
329
+ key={division.id}
330
+ label={`${division.name} (${division.nameBn})`}
331
+ value={division.id}
332
+ />
333
+ ))}
334
+ </Picker>
335
+
336
+ <Picker>
337
+ <Picker.Item label="Select District" value="" />
338
+ {districts.map(district => (
339
+ <Picker.Item
340
+ key={district.id}
341
+ label={`${district.name} (${district.nameBn})`}
342
+ value={district.id}
343
+ />
344
+ ))}
345
+ </Picker>
346
+ </View>
347
+ );
348
+ }
349
+ ```
350
+
351
+ ## API Reference
352
+
353
+ ### Core Functions
354
+
355
+ #### `getAllDivisions()`
356
+ Returns all divisions in Bangladesh.
357
+
358
+ #### `getDivisionById(id: string)`
359
+ Get a division by its ID.
360
+
361
+ #### `getDivisionByName(name: string)`
362
+ Get a division by English or Bengali name.
363
+
364
+ #### `getDistrictsByDivision(divisionId: string)`
365
+ Get all districts in a division.
366
+
367
+ #### `getDistrictById(id: string, divisionId?: string)`
368
+ Get a district by ID.
369
+
370
+ #### `getUpazilasByDistrict(districtId: string)`
371
+ Get all upazilas in a district.
372
+
373
+ #### `getUnionsByUpazila(upazilaId: string, districtId: string)`
374
+ Get all unions in an upazila.
375
+
376
+ #### `getPourosovasByUpazila(upazilaId: string, districtId: string)`
377
+ Get all pourosovas in an upazila.
378
+
379
+ #### `getCityCorporationsByDistrict(districtId: string)`
380
+ Get all city corporations in a district.
381
+
382
+ #### `searchByName(searchTerm: string)`
383
+ Search for locations by name. Returns an object with divisions, districts, upazilas, unions, pourosovas, and city corporations.
384
+
385
+ #### `getGeoHierarchy(locationId: string, level: 'division' | 'district' | 'upazila')`
386
+ Get the complete geographical hierarchy for a location.
387
+
388
+ ### React Hooks
389
+
390
+ - `useDivisions()` - Get all divisions
391
+ - `useDistricts(divisionId)` - Get districts by division ID
392
+ - `useUpazilas(districtId, divisionId)` - Get upazilas by district ID
393
+ - `useUnions(upazilaId, districtId, divisionId)` - Get unions by upazila ID
394
+ - `usePourosovas(upazilaId, districtId, divisionId)` - Get pourosovas by upazila ID
395
+ - `useCityCorporations(districtId, divisionId)` - Get city corporations by district ID
396
+ - `useSearch(searchTerm)` - Search locations by name
397
+ - `useLocationById(id, type)` - Get location by ID and type
398
+
399
+ ### Vue Composables
400
+
401
+ - `useDivisions()` - Get all divisions
402
+ - `useDistricts(divisionId)` - Get districts by division ID
403
+ - `useUpazilas(districtId, divisionId)` - Get upazilas by district ID
404
+ - `useUnions(upazilaId, districtId, divisionId)` - Get unions by upazila ID
405
+ - `usePourosovas(upazilaId, districtId, divisionId)` - Get pourosovas by upazila ID
406
+ - `useCityCorporations(districtId, divisionId)` - Get city corporations by district ID
407
+ - `useSearch(searchTerm)` - Search locations by name
408
+ - `useLocationById(id, type)` - Get location by ID and type
409
+
410
+ ## Types
411
+
412
+ ```typescript
413
+ interface Village {
414
+ id: string;
415
+ name: string;
416
+ nameBn: string;
417
+ }
418
+
419
+ interface Union {
420
+ id: string;
421
+ name: string;
422
+ nameBn: string;
423
+ villages?: Village[];
424
+ }
425
+
426
+ interface Pourosova {
427
+ id: string;
428
+ name: string;
429
+ nameBn: string;
430
+ villages?: Village[];
431
+ }
432
+
433
+ interface Upazila {
434
+ id: string;
435
+ name: string;
436
+ nameBn: string;
437
+ unions?: Union[];
438
+ pourosovas?: Pourosova[];
439
+ }
440
+
441
+ interface CityCorporation {
442
+ id: string;
443
+ name: string;
444
+ nameBn: string;
445
+ thanas?: Upazila[];
446
+ }
447
+
448
+ interface District {
449
+ id: string;
450
+ name: string;
451
+ nameBn: string;
452
+ upazilas?: Upazila[];
453
+ cityCorporations?: CityCorporation[];
454
+ }
455
+
456
+ interface Division {
457
+ id: string;
458
+ name: string;
459
+ nameBn: string;
460
+ districts?: District[];
461
+ }
462
+ ```
463
+
464
+ ## Data Source
465
+
466
+ This package contains geographical administrative data for Bangladesh. The data is structured following the official administrative hierarchy.
467
+
468
+ **Note:** The current version includes sample data for demonstration purposes. To make this package production-ready, you'll need to add complete data for all divisions, districts, upazilas, unions, and villages.
469
+
470
+ ## Contributing
471
+
472
+ Contributions are welcome! To add complete data:
473
+
474
+ 1. Fork the repository
475
+ 2. Add data to `src/data/bangladesh.ts`
476
+ 3. Ensure data follows the TypeScript types
477
+ 4. Submit a pull request
478
+
479
+ ## License
480
+
481
+ MIT
482
+
483
+ ## Support
484
+
485
+ For issues, questions, or contributions, please visit the GitHub repository.
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Represents a Village in Bangladesh
3
+ */
4
+ interface Village {
5
+ id: string;
6
+ name: string;
7
+ nameBn: string;
8
+ }
9
+ /**
10
+ * Represents a Union Council (lowest rural administrative unit)
11
+ */
12
+ interface Union {
13
+ id: string;
14
+ name: string;
15
+ nameBn: string;
16
+ villages?: Village[];
17
+ }
18
+ /**
19
+ * Represents a Pourosova (Municipality)
20
+ */
21
+ interface Pourosova {
22
+ id: string;
23
+ name: string;
24
+ nameBn: string;
25
+ villages?: Village[];
26
+ }
27
+ /**
28
+ * Represents an Upazila (Sub-district) or Thana
29
+ */
30
+ interface Upazila {
31
+ id: string;
32
+ name: string;
33
+ nameBn: string;
34
+ unions?: Union[];
35
+ pourosovas?: Pourosova[];
36
+ }
37
+ /**
38
+ * Represents a City Corporation
39
+ */
40
+ interface CityCorporation {
41
+ id: string;
42
+ name: string;
43
+ nameBn: string;
44
+ thanas?: Upazila[];
45
+ }
46
+ /**
47
+ * Represents a District (Zila)
48
+ */
49
+ interface District {
50
+ id: string;
51
+ name: string;
52
+ nameBn: string;
53
+ upazilas?: Upazila[];
54
+ cityCorporations?: CityCorporation[];
55
+ }
56
+ /**
57
+ * Represents a Division (primary administrative division)
58
+ */
59
+ interface Division {
60
+ id: string;
61
+ name: string;
62
+ nameBn: string;
63
+ districts?: District[];
64
+ }
65
+ /**
66
+ * Complete geographical hierarchy of Bangladesh
67
+ */
68
+ interface BangladeshGeoData {
69
+ divisions: Division[];
70
+ }
71
+ /**
72
+ * Filter options for querying geographical data
73
+ */
74
+ interface FilterOptions {
75
+ language?: 'en' | 'bn';
76
+ searchTerm?: string;
77
+ }
78
+ /**
79
+ * Geographic location response
80
+ */
81
+ type GeoLocation = Division | District | Upazila | Union | Pourosova | CityCorporation;
82
+ /**
83
+ * Geographic level type
84
+ */
85
+ type GeoLevel = 'division' | 'district' | 'upazila' | 'thana' | 'union' | 'pourosova' | 'cityCorporation' | 'village';
86
+
87
+ export type { BangladeshGeoData as B, CityCorporation as C, Division as D, FilterOptions as F, GeoLevel as G, Pourosova as P, Upazila as U, Village as V, District as a, Union as b, GeoLocation as c };
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Represents a Village in Bangladesh
3
+ */
4
+ interface Village {
5
+ id: string;
6
+ name: string;
7
+ nameBn: string;
8
+ }
9
+ /**
10
+ * Represents a Union Council (lowest rural administrative unit)
11
+ */
12
+ interface Union {
13
+ id: string;
14
+ name: string;
15
+ nameBn: string;
16
+ villages?: Village[];
17
+ }
18
+ /**
19
+ * Represents a Pourosova (Municipality)
20
+ */
21
+ interface Pourosova {
22
+ id: string;
23
+ name: string;
24
+ nameBn: string;
25
+ villages?: Village[];
26
+ }
27
+ /**
28
+ * Represents an Upazila (Sub-district) or Thana
29
+ */
30
+ interface Upazila {
31
+ id: string;
32
+ name: string;
33
+ nameBn: string;
34
+ unions?: Union[];
35
+ pourosovas?: Pourosova[];
36
+ }
37
+ /**
38
+ * Represents a City Corporation
39
+ */
40
+ interface CityCorporation {
41
+ id: string;
42
+ name: string;
43
+ nameBn: string;
44
+ thanas?: Upazila[];
45
+ }
46
+ /**
47
+ * Represents a District (Zila)
48
+ */
49
+ interface District {
50
+ id: string;
51
+ name: string;
52
+ nameBn: string;
53
+ upazilas?: Upazila[];
54
+ cityCorporations?: CityCorporation[];
55
+ }
56
+ /**
57
+ * Represents a Division (primary administrative division)
58
+ */
59
+ interface Division {
60
+ id: string;
61
+ name: string;
62
+ nameBn: string;
63
+ districts?: District[];
64
+ }
65
+ /**
66
+ * Complete geographical hierarchy of Bangladesh
67
+ */
68
+ interface BangladeshGeoData {
69
+ divisions: Division[];
70
+ }
71
+ /**
72
+ * Filter options for querying geographical data
73
+ */
74
+ interface FilterOptions {
75
+ language?: 'en' | 'bn';
76
+ searchTerm?: string;
77
+ }
78
+ /**
79
+ * Geographic location response
80
+ */
81
+ type GeoLocation = Division | District | Upazila | Union | Pourosova | CityCorporation;
82
+ /**
83
+ * Geographic level type
84
+ */
85
+ type GeoLevel = 'division' | 'district' | 'upazila' | 'thana' | 'union' | 'pourosova' | 'cityCorporation' | 'village';
86
+
87
+ export type { BangladeshGeoData as B, CityCorporation as C, Division as D, FilterOptions as F, GeoLevel as G, Pourosova as P, Upazila as U, Village as V, District as a, Union as b, GeoLocation as c };