rwanda-geo-data 0.1.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 +110 -0
- package/dist/index.cjs +17614 -0
- package/dist/index.d.cts +61 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +17597 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SHUMBUSHO Irumva
|
|
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,110 @@
|
|
|
1
|
+
# rwanda-locations
|
|
2
|
+
|
|
3
|
+
Typed, zero-dependency data for Rwanda's administrative hierarchy —
|
|
4
|
+
**Province → District → Sector → Cell → Village** — with a fast, indexed
|
|
5
|
+
query API.
|
|
6
|
+
|
|
7
|
+
## Why this structure
|
|
8
|
+
|
|
9
|
+
The data is stored as five flat, normalized arrays (one per level), each
|
|
10
|
+
row carrying an explicit foreign key to its parent (e.g. a `District` has
|
|
11
|
+
a `provinceId`). This is deliberately **not** mirrored as nested
|
|
12
|
+
folders/files per region — at full depth (5 provinces, 30 districts, 416
|
|
13
|
+
sectors, ~2,148 cells, ~14,800+ villages) a one-file-per-region layout
|
|
14
|
+
would mean tens of thousands of files, which hurts install size, git
|
|
15
|
+
performance, and editor responsiveness for no real benefit, since the
|
|
16
|
+
data itself doesn't change per query call.
|
|
17
|
+
|
|
18
|
+
Lookups are backed by `Map`-based indices built once on first use, so
|
|
19
|
+
`getVillages(cellId)` is O(1) + result size, not a full-array `.filter()`
|
|
20
|
+
every call.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install rwanda-locations
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import {
|
|
32
|
+
getProvinces,
|
|
33
|
+
getDistricts,
|
|
34
|
+
getSectors,
|
|
35
|
+
getCells,
|
|
36
|
+
getVillages,
|
|
37
|
+
getLocationPath,
|
|
38
|
+
findProvinceByName,
|
|
39
|
+
} from "rwanda-locations";
|
|
40
|
+
|
|
41
|
+
getProvinces();
|
|
42
|
+
// [{ id: 5, name: "EAST" }, ...]
|
|
43
|
+
|
|
44
|
+
getDistricts(5);
|
|
45
|
+
// all districts where provinceId === 5
|
|
46
|
+
|
|
47
|
+
findProvinceByName("east");
|
|
48
|
+
// case-insensitive match -> { id: 5, name: "EAST" }
|
|
49
|
+
|
|
50
|
+
getLocationPath(501010101);
|
|
51
|
+
// { village, cell, sector, district, province } - full chain in one call
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### API
|
|
55
|
+
|
|
56
|
+
| Function | Description |
|
|
57
|
+
|---|---|
|
|
58
|
+
| `getProvinces()` | All provinces |
|
|
59
|
+
| `getProvinceById(id)` | Single province or `undefined` |
|
|
60
|
+
| `findProvinceByName(name)` | Case-insensitive name match |
|
|
61
|
+
| `getDistricts(provinceId?)` | All districts, or filtered by province |
|
|
62
|
+
| `getDistrictById(id)` | Single district or `undefined` |
|
|
63
|
+
| `findDistrictByName(name, provinceId?)` | Case-insensitive, optionally scoped |
|
|
64
|
+
| `getSectors(districtId?)` | All sectors, or filtered by district |
|
|
65
|
+
| `getSectorById(id)` | Single sector or `undefined` |
|
|
66
|
+
| `findSectorByName(name, districtId?)` | Case-insensitive, optionally scoped |
|
|
67
|
+
| `getCells(sectorId?)` | All cells, or filtered by sector |
|
|
68
|
+
| `getCellById(id)` | Single cell or `undefined` |
|
|
69
|
+
| `findCellByName(name, sectorId?)` | Case-insensitive, optionally scoped |
|
|
70
|
+
| `getVillages(cellId?)` | All villages, or filtered by cell |
|
|
71
|
+
| `getVillageById(id)` | Single village or `undefined` |
|
|
72
|
+
| `findVillageByName(name, cellId?)` | Case-insensitive, optionally scoped |
|
|
73
|
+
| `getLocationPath(villageId)` | Full resolved chain up to province |
|
|
74
|
+
|
|
75
|
+
## Populating the data
|
|
76
|
+
|
|
77
|
+
This repo ships with **empty placeholder data files**. To populate them
|
|
78
|
+
from a raw source JSON (shape: nested `Province[]` with `districts` ->
|
|
79
|
+
`sectors` -> `cells` -> `villages`, each child carrying a `*_id` foreign
|
|
80
|
+
key to its parent):
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm run generate:data -- path/to/raw-source.json
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
This flattens the nested JSON into `src/data/{provinces,districts,sectors,cells,villages}.ts`,
|
|
87
|
+
and throws if it finds duplicate ids or a child whose FK doesn't resolve
|
|
88
|
+
to a real parent — catch those before they ship, not after.
|
|
89
|
+
|
|
90
|
+
## Scripts
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm run build # bundle to dist/ (ESM + CJS + .d.ts) via tsup
|
|
94
|
+
npm run test # run the test suite once
|
|
95
|
+
npm run test:watch # watch mode
|
|
96
|
+
npm run lint # check formatting/lint rules (biome)
|
|
97
|
+
npm run lint:fix # auto-fix
|
|
98
|
+
npm run generate:data -- <path> # regenerate src/data/*.ts from raw JSON
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Testing notes
|
|
102
|
+
|
|
103
|
+
`test/data-integrity.test.ts` validates the **data itself** — uniqueness
|
|
104
|
+
of ids per level, and that every child's foreign key resolves to a real
|
|
105
|
+
parent. Keep this in CI: it's what catches a bad future data refresh
|
|
106
|
+
(duplicate ids, orphaned records) before it ships to consumers.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|