damascus 1.2.0 → 1.3.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 +1 -1
- package/README.md +47 -37
- package/package.json +7 -2
- package/src/index.d.ts +13 -1
- package/src/index.js +26 -39
- package/src/react/index.d.ts +11 -0
- package/src/react/index.js +41 -0
- package/src/syria.js +100956 -0
- package/src/syria.json +0 -1441
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Damascus (Syrian Regional Data API)
|
|
2
2
|
|
|
3
3
|
[](https://snyk.io/test/github/hadabo/damascus)
|
|
4
4
|
[![Build Status][build-badge]][build]
|
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
[![Damascus package][npm-dm]][damascus]
|
|
8
8
|
[![Coverage Status][coveralls-badge]][coveralls]
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
The ultimate **environment-agnostic source of truth** for Syrian administrative data.
|
|
11
|
+
|
|
12
|
+
This package provides a meticulously standardized, deeply hierarchical dataset covering all of Syria (Governorates ➔ Districts ➔ Municipalities ➔ Neighborhoods/Populated Places).
|
|
13
|
+
|
|
14
|
+
It is completely aligned with **UN OCHA Common Operational Datasets (COD)**, featuring official P-Codes and geo-spatial coordinates. It's the perfect backbone for cascading dropdowns, map plots, and autocompletes in applications like real estate listings, directories, and delivery platforms.
|
|
11
15
|
|
|
12
16
|
## Installation
|
|
13
17
|
|
|
@@ -16,64 +20,70 @@ This package is distributed via npm:
|
|
|
16
20
|
npm install damascus
|
|
17
21
|
```
|
|
18
22
|
|
|
19
|
-
## Usage (
|
|
23
|
+
## Usage (Core API)
|
|
20
24
|
|
|
21
25
|
Modern projects should import the package via ES Modules. Full TypeScript definitions (`.d.ts`) are included natively for excellent IDE support.
|
|
22
26
|
|
|
23
27
|
```typescript
|
|
24
|
-
import { search, getAll, getGovernorates, getMunicipalities, getNeighborhoods
|
|
28
|
+
import { search, getAll, getGovernorates, getDistricts, getMunicipalities, getNeighborhoods } from 'damascus';
|
|
25
29
|
|
|
26
30
|
// 1. Search API (Perfect for Autocomplete)
|
|
27
|
-
const result
|
|
28
|
-
|
|
29
|
-
// 2. Get all structured data
|
|
30
|
-
const allData = getAll();
|
|
31
|
+
const result = search('دمشق');
|
|
31
32
|
|
|
32
|
-
//
|
|
33
|
+
// 2. Get the 14 Syrian governorates
|
|
33
34
|
const governorates = getGovernorates();
|
|
34
35
|
/*
|
|
35
36
|
[
|
|
36
|
-
{
|
|
37
|
-
|
|
37
|
+
{
|
|
38
|
+
id: 'dam',
|
|
39
|
+
pcode: 'SY01',
|
|
40
|
+
coordinates: { lat: 33.5138, lng: 36.2765 },
|
|
41
|
+
name: { en: 'Damascus', ar: 'دمشق' }
|
|
42
|
+
},
|
|
38
43
|
...
|
|
39
44
|
]
|
|
40
45
|
*/
|
|
41
46
|
|
|
42
|
-
//
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
{ id: 'dam-municipality-ancient-city-old-city', name: { en: 'Ancient City (Old City)', ar: 'المدينة القديمة' } },
|
|
47
|
-
...
|
|
48
|
-
]
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
const oldCityNeighborhoods = getNeighborhoods('dam-municipality-ancient-city-old-city');
|
|
52
|
-
/*
|
|
53
|
-
[
|
|
54
|
-
{ id: 'dam-districts-bab-tuma', name: { en: 'Bab Tuma', ar: 'باب توما' } },
|
|
55
|
-
...
|
|
56
|
-
]
|
|
57
|
-
*/
|
|
47
|
+
// 3. Drill down into the unified hierarchy
|
|
48
|
+
const damascusDistricts = getDistricts('dam');
|
|
49
|
+
const municipalities = getMunicipalities('dam-damascus');
|
|
50
|
+
const neighborhoods = getNeighborhoods('dam-municipality-ancient-city-old-city');
|
|
58
51
|
```
|
|
59
52
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
## Usage (React Hooks)
|
|
54
|
+
|
|
55
|
+
To eliminate boilerplate when building cascading dropdowns, we provide highly-optimized React hooks out of the box!
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { useGovernorates, useDistricts, useMunicipalities } from 'damascus/react';
|
|
59
|
+
import { useState } from 'react';
|
|
60
|
+
|
|
61
|
+
function LocationSelector() {
|
|
62
|
+
const [govId, setGovId] = useState('dam');
|
|
63
|
+
const [distId, setDistId] = useState('dam-damascus');
|
|
64
|
+
|
|
65
|
+
const governorates = useGovernorates();
|
|
66
|
+
const districts = useDistricts(govId); // Automatically reacts to govId changes!
|
|
67
|
+
const municipalities = useMunicipalities(distId);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
// Render your dropdowns...
|
|
71
|
+
)
|
|
72
|
+
}
|
|
65
73
|
```
|
|
66
74
|
|
|
67
75
|
## Features
|
|
68
76
|
|
|
69
|
-
- **
|
|
70
|
-
- **
|
|
77
|
+
- **Whole of Syria Coverage**: Includes massive generated datasets for all 14 governorates down to populated places.
|
|
78
|
+
- **UN OCHA P-Codes**: Built-in standard `pcode` identifiers for reliable cross-dataset interoperability.
|
|
79
|
+
- **Geo-Spatial Coordinates**: Every level includes precise `{ lat, lng }` coordinates.
|
|
80
|
+
- **React Hooks included**: Exported via `damascus/react` for instant UI integration.
|
|
81
|
+
- **Search Utility**: Built-in search function to easily query the deep data tree.
|
|
71
82
|
- **Bilingual**: All items include English (`en`) and Arabic (`ar`) names.
|
|
72
|
-
- **TypeScript Support**:
|
|
73
|
-
- **Backward Compatible**: Maintains support for legacy `getDistricts()` API.
|
|
83
|
+
- **TypeScript Support**: First-class types mapping the entire hierarchy.
|
|
74
84
|
|
|
75
85
|
## Other
|
|
76
|
-
This library was developed by [
|
|
86
|
+
This library was developed by [Abdulhadi Hawari](https://twitter.com/@hadabo) as a PoC to learn [semantic-release](https://www.npmjs.com/package/semantic-release), and expanded to be a robust source of truth for Syrian regional data.
|
|
77
87
|
|
|
78
88
|
[build-badge]: https://img.shields.io/github/actions/workflow/status/hadabo/damascus/ci.yml?style=flat-square
|
|
79
89
|
[build]: https://github.com/hadabo/damascus/actions
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "damascus",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Hierarchical source of truth for Syrian regional data, focusing on Damascus municipalities and neighborhoods aligned with UN OCHA standards.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
7
|
-
".": "./src/index.js"
|
|
7
|
+
".": "./src/index.js",
|
|
8
|
+
"./react": "./src/react/index.js"
|
|
8
9
|
},
|
|
9
10
|
"type": "module",
|
|
10
11
|
"engines": {
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
"lint:fix": "eslint --fix src/*.js test/*.js",
|
|
21
22
|
"test": "c8 mocha",
|
|
22
23
|
"coverage": "c8 report --reporter=text-lcov | coveralls",
|
|
24
|
+
"import-un-data": "node tools/import-un-data.js",
|
|
23
25
|
"prepare": "husky"
|
|
24
26
|
},
|
|
25
27
|
"repository": {
|
|
@@ -44,6 +46,9 @@
|
|
|
44
46
|
},
|
|
45
47
|
"homepage": "https://github.com/hadabo/damascus#readme",
|
|
46
48
|
"dependencies": {},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
51
|
+
},
|
|
47
52
|
"devDependencies": {
|
|
48
53
|
"chai": "^5.1.1",
|
|
49
54
|
"commitizen": "^4.3.0",
|
package/src/index.d.ts
CHANGED
|
@@ -3,26 +3,38 @@ export interface LocalizedName {
|
|
|
3
3
|
ar: string;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
export interface Coordinates {
|
|
7
|
+
lat: number;
|
|
8
|
+
lng: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export interface Neighborhood {
|
|
7
12
|
id: string;
|
|
13
|
+
pcode?: string;
|
|
14
|
+
coordinates?: Coordinates;
|
|
8
15
|
name: LocalizedName;
|
|
9
16
|
}
|
|
10
17
|
|
|
11
18
|
export interface Municipality {
|
|
12
19
|
id: string;
|
|
20
|
+
pcode?: string;
|
|
21
|
+
coordinates?: Coordinates;
|
|
13
22
|
name: LocalizedName;
|
|
14
23
|
neighborhoods?: Neighborhood[];
|
|
15
24
|
}
|
|
16
25
|
|
|
17
26
|
export interface District {
|
|
18
27
|
id: string;
|
|
28
|
+
pcode?: string;
|
|
29
|
+
coordinates?: Coordinates;
|
|
19
30
|
name: LocalizedName;
|
|
20
31
|
}
|
|
21
32
|
|
|
22
33
|
export interface Governorate {
|
|
23
34
|
id: string;
|
|
35
|
+
pcode?: string;
|
|
36
|
+
coordinates?: Coordinates;
|
|
24
37
|
name: LocalizedName;
|
|
25
|
-
municipalities?: Municipality[];
|
|
26
38
|
districts?: District[];
|
|
27
39
|
}
|
|
28
40
|
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { fileURLToPath } from 'url'
|
|
3
|
-
import { dirname, join } from 'path'
|
|
4
|
-
|
|
5
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
6
|
-
const syriaData = JSON.parse(readFileSync(join(__dirname, 'syria.json'), 'utf8'))
|
|
1
|
+
import syriaData from './syria.js'
|
|
7
2
|
|
|
8
3
|
function getAll () {
|
|
9
4
|
return syriaData
|
|
@@ -20,39 +15,31 @@ function getDistricts (governorateId) {
|
|
|
20
15
|
if (governorateId) {
|
|
21
16
|
const gov = syriaData.find(g => g.id === governorateId)
|
|
22
17
|
if (!gov) return []
|
|
23
|
-
// Backward compatibility for Damascus
|
|
24
|
-
if (gov.municipalities) {
|
|
25
|
-
return gov.municipalities.reduce((acc, mun) => {
|
|
26
|
-
acc.push({ id: mun.id, name: mun.name })
|
|
27
|
-
return acc.concat(mun.neighborhoods)
|
|
28
|
-
}, [])
|
|
29
|
-
}
|
|
30
18
|
return gov.districts || []
|
|
31
19
|
}
|
|
32
20
|
|
|
33
21
|
return syriaData.reduce((allDistricts, gov) => {
|
|
34
|
-
if (gov.municipalities) {
|
|
35
|
-
const flatDamascus = gov.municipalities.reduce((acc, mun) => {
|
|
36
|
-
acc.push({ id: mun.id, name: mun.name })
|
|
37
|
-
return acc.concat(mun.neighborhoods || [])
|
|
38
|
-
}, [])
|
|
39
|
-
return allDistricts.concat(flatDamascus)
|
|
40
|
-
}
|
|
41
22
|
return allDistricts.concat(gov.districts || [])
|
|
42
23
|
}, [])
|
|
43
24
|
}
|
|
44
25
|
|
|
45
|
-
function getMunicipalities (governorateId = '
|
|
26
|
+
function getMunicipalities (governorateId = 'gov-damascus') {
|
|
46
27
|
const gov = syriaData.find(g => g.id === governorateId)
|
|
47
|
-
if (!gov || !gov.
|
|
48
|
-
return gov.
|
|
28
|
+
if (!gov || !gov.districts) return []
|
|
29
|
+
return gov.districts.reduce((acc, dist) => {
|
|
30
|
+
return acc.concat(dist.municipalities || [])
|
|
31
|
+
}, []).map(m => ({ id: m.id, name: m.name, pcode: m.pcode, coordinates: m.coordinates }))
|
|
49
32
|
}
|
|
50
33
|
|
|
51
34
|
function getNeighborhoods (municipalityId) {
|
|
52
35
|
for (const gov of syriaData) {
|
|
53
|
-
if (gov.
|
|
54
|
-
const
|
|
55
|
-
|
|
36
|
+
if (gov.districts) {
|
|
37
|
+
for (const dist of gov.districts) {
|
|
38
|
+
if (dist.municipalities) {
|
|
39
|
+
const mun = dist.municipalities.find(m => m.id === municipalityId)
|
|
40
|
+
if (mun) return mun.neighborhoods || []
|
|
41
|
+
}
|
|
42
|
+
}
|
|
56
43
|
}
|
|
57
44
|
}
|
|
58
45
|
return []
|
|
@@ -65,7 +52,7 @@ function search (query) {
|
|
|
65
52
|
|
|
66
53
|
syriaData.forEach(gov => {
|
|
67
54
|
if (gov.name.en.toLowerCase().includes(q) || gov.name.ar.includes(q)) {
|
|
68
|
-
results.push({ type: 'governorate', item: { id: gov.id, name: gov.name } })
|
|
55
|
+
results.push({ type: 'governorate', item: { id: gov.id, name: gov.name, pcode: gov.pcode, coordinates: gov.coordinates } })
|
|
69
56
|
}
|
|
70
57
|
|
|
71
58
|
if (gov.districts) {
|
|
@@ -73,18 +60,18 @@ function search (query) {
|
|
|
73
60
|
if (dist.name.en.toLowerCase().includes(q) || dist.name.ar.includes(q)) {
|
|
74
61
|
results.push({ type: 'district', item: dist })
|
|
75
62
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
63
|
+
|
|
64
|
+
if (dist.municipalities) {
|
|
65
|
+
dist.municipalities.forEach(mun => {
|
|
66
|
+
if (mun.name.en.toLowerCase().includes(q) || mun.name.ar.includes(q)) {
|
|
67
|
+
results.push({ type: 'municipality', item: { id: mun.id, name: mun.name, pcode: mun.pcode, coordinates: mun.coordinates } })
|
|
68
|
+
}
|
|
69
|
+
if (mun.neighborhoods) {
|
|
70
|
+
mun.neighborhoods.forEach(neigh => {
|
|
71
|
+
if (neigh.name.en.toLowerCase().includes(q) || neigh.name.ar.includes(q)) {
|
|
72
|
+
results.push({ type: 'neighborhood', item: neigh, municipalityId: mun.id })
|
|
73
|
+
}
|
|
74
|
+
})
|
|
88
75
|
}
|
|
89
76
|
})
|
|
90
77
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Governorate, District, Municipality, Neighborhood } from '../index.js';
|
|
2
|
+
|
|
3
|
+
export function useGovernorates(): Pick<Governorate, 'id' | 'name' | 'pcode' | 'coordinates'>[];
|
|
4
|
+
export function useDistricts(governorateId?: string): District[];
|
|
5
|
+
export function useMunicipalities(governorateId?: string): Pick<Municipality, 'id' | 'name' | 'pcode' | 'coordinates'>[];
|
|
6
|
+
export function useNeighborhoods(municipalityId: string): Neighborhood[];
|
|
7
|
+
export function useSyriaSearch(query: string): Array<{
|
|
8
|
+
type: 'governorate' | 'district' | 'municipality' | 'neighborhood';
|
|
9
|
+
item: any;
|
|
10
|
+
municipalityId?: string;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import * as syria from '../index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns all 14 Syrian governorates.
|
|
6
|
+
*/
|
|
7
|
+
export function useGovernorates() {
|
|
8
|
+
return useMemo(() => syria.getGovernorates(), []);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns districts for a given governorate ID.
|
|
13
|
+
* @param {string} governorateId
|
|
14
|
+
*/
|
|
15
|
+
export function useDistricts(governorateId) {
|
|
16
|
+
return useMemo(() => syria.getDistricts(governorateId), [governorateId]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns all municipalities for a given governorate ID.
|
|
21
|
+
* @param {string} governorateId
|
|
22
|
+
*/
|
|
23
|
+
export function useMunicipalities(governorateId) {
|
|
24
|
+
return useMemo(() => syria.getMunicipalities(governorateId), [governorateId]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns all neighborhoods for a given municipality ID.
|
|
29
|
+
* @param {string} municipalityId
|
|
30
|
+
*/
|
|
31
|
+
export function useNeighborhoods(municipalityId) {
|
|
32
|
+
return useMemo(() => syria.getNeighborhoods(municipalityId), [municipalityId]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Real-time search across the entire hierarchical dataset.
|
|
37
|
+
* @param {string} query Search text (Arabic or English)
|
|
38
|
+
*/
|
|
39
|
+
export function useSyriaSearch(query) {
|
|
40
|
+
return useMemo(() => syria.search(query), [query]);
|
|
41
|
+
}
|