damascus 1.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017 Abdul-hadi Hawari
3
+ Copyright (c) 2017 Abdulhadi Hawari
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,10 +1,17 @@
1
- # Damascus
1
+ # Damascus (Syrian Regional Data API)
2
+
3
+ [![Snyk Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/hadabo/damascus.svg?style=flat-square)](https://snyk.io/test/github/hadabo/damascus)
2
4
  [![Build Status][build-badge]][build]
3
5
  [![MIT License][license-badge]][LICENSE]
4
6
  [![Semantic release][semantic-release]][semantic]
5
7
  [![Damascus package][npm-dm]][damascus]
8
+ [![Coverage Status][coveralls-badge]][coveralls]
9
+
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).
6
13
 
7
- Get random districts names of Damascus.
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.
8
15
 
9
16
  ## Installation
10
17
 
@@ -13,23 +20,78 @@ This package is distributed via npm:
13
20
  npm install damascus
14
21
  ```
15
22
 
16
- ## Usage
17
- ```javascript
18
- var damascus = require('damascus');
19
- var allNames = damascus.all;
20
- var randomName = damascus.random();
21
- var threeRandomNames = damascus.random(3);
23
+ ## Usage (Core API)
24
+
25
+ Modern projects should import the package via ES Modules. Full TypeScript definitions (`.d.ts`) are included natively for excellent IDE support.
26
+
27
+ ```typescript
28
+ import { search, getAll, getGovernorates, getDistricts, getMunicipalities, getNeighborhoods } from 'damascus';
29
+
30
+ // 1. Search API (Perfect for Autocomplete)
31
+ const result = search('دمشق');
32
+
33
+ // 2. Get the 14 Syrian governorates
34
+ const governorates = getGovernorates();
35
+ /*
36
+ [
37
+ {
38
+ id: 'dam',
39
+ pcode: 'SY01',
40
+ coordinates: { lat: 33.5138, lng: 36.2765 },
41
+ name: { en: 'Damascus', ar: 'دمشق' }
42
+ },
43
+ ...
44
+ ]
45
+ */
46
+
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');
22
51
  ```
23
52
 
24
- ## Other
25
- This library was developed by [Abdul-hadi Hawari](https://twitter.com/@hadabo) as a PoC to learn [semantic-release](https://www.npmjs.com/package/semantic-release).
53
+ ## Usage (React Hooks)
26
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
+ }
73
+ ```
74
+
75
+ ## Features
76
+
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.
82
+ - **Bilingual**: All items include English (`en`) and Arabic (`ar`) names.
83
+ - **TypeScript Support**: First-class types mapping the entire hierarchy.
84
+
85
+ ## Other
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.
27
87
 
28
- [build-badge]: https://img.shields.io/travis/hadabo/damascus.svg?style=flat-square
29
- [build]: https://travis-ci.org/hadabo/damascus
88
+ [build-badge]: https://img.shields.io/github/actions/workflow/status/hadabo/damascus/ci.yml?style=flat-square
89
+ [build]: https://github.com/hadabo/damascus/actions
30
90
  [license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
31
91
  [license]: https://github.com/hadabo/damascus/blob/master/LICENSE
32
92
  [semantic-release]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square
33
93
  [semantic]: https://www.npmjs.com/package/semantic-release
34
94
  [npm-dm]: https://img.shields.io/npm/dm/damascus.svg?style=flat-square
35
- [damascus]: https://www.npmjs.com/package/damascus
95
+ [damascus]: https://www.npmjs.com/package/damascus
96
+ [coveralls]: https://coveralls.io/github/hadabo/damascus?branch=master
97
+ [coveralls-badge]: https://coveralls.io/repos/github/hadabo/damascus/badge.svg?branch=master
package/package.json CHANGED
@@ -1,50 +1,69 @@
1
1
  {
2
2
  "name": "damascus",
3
- "version": "1.0.0",
4
- "description": "Get random districts names of Damascus",
3
+ "version": "1.3.0",
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
+ "exports": {
7
+ ".": "./src/index.js",
8
+ "./react": "./src/react/index.js"
9
+ },
10
+ "type": "module",
11
+ "engines": {
12
+ "node": ">=18.0.0"
13
+ },
14
+ "files": [
15
+ "src"
16
+ ],
6
17
  "scripts": {
7
18
  "precommit": "npm test",
8
19
  "commit": "git-cz",
9
- "lint": "eslint --fix src/*.js",
10
- "test": "istanbul cover -x *.test.js _mocha -- -R spec src/index.test.js",
11
- "semantic-release": "semantic-release pre && npm publish && semantic-release post"
20
+ "lint": "eslint src/*.js test/*.js",
21
+ "lint:fix": "eslint --fix src/*.js test/*.js",
22
+ "test": "c8 mocha",
23
+ "coverage": "c8 report --reporter=text-lcov | coveralls",
24
+ "import-un-data": "node tools/import-un-data.js",
25
+ "prepare": "husky"
12
26
  },
13
27
  "repository": {
14
28
  "type": "git",
15
29
  "url": "https://github.com/hadabo/damascus.git"
16
30
  },
17
31
  "keywords": [
18
- "random",
19
32
  "damascus",
20
33
  "syria",
21
- "districts"
34
+ "regions",
35
+ "governorates",
36
+ "municipalities",
37
+ "neighborhoods",
38
+ "districts",
39
+ "ocha",
40
+ "data"
22
41
  ],
23
- "author": "Abdul-hadi Hawari <hadabo@gmail.com> (http://hadabo.com/)",
42
+ "author": "Abdulhadi Hawari <hadabo@gmail.com> (http://hadabo.com/)",
24
43
  "license": "MIT",
25
44
  "bugs": {
26
45
  "url": "https://github.com/hadabo/damascus/issues"
27
46
  },
28
47
  "homepage": "https://github.com/hadabo/damascus#readme",
29
- "dependencies": {
30
- "unique-random-array": "1.0.0"
48
+ "dependencies": {},
49
+ "peerDependencies": {
50
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
31
51
  },
32
52
  "devDependencies": {
33
- "chai": "4.1.2",
34
- "commitizen": "2.9.6",
35
- "cz-conventional-changelog": "2.0.0",
36
- "eslint": "4.9.0",
37
- "eslint-config-standard": "10.2.1",
38
- "eslint-plugin-import": "2.8.0",
39
- "eslint-plugin-node": "5.2.1",
40
- "eslint-plugin-promise": "3.6.0",
41
- "eslint-plugin-standard": "3.0.1",
42
- "husky": "0.14.3",
43
- "istanbul": "0.4.5",
44
- "mocha": "4.0.1",
45
- "semantic-release": "8.2.2"
53
+ "chai": "^5.1.1",
54
+ "commitizen": "^4.3.0",
55
+ "coveralls": "^3.1.1",
56
+ "cz-conventional-changelog": "^3.3.0",
57
+ "eslint": "^9.3.0",
58
+ "globals": "^15.3.0",
59
+ "husky": "^9.0.11",
60
+ "mocha": "^10.4.0",
61
+ "c8": "^9.1.0",
62
+ "semantic-release": "^23.1.1"
46
63
  },
47
- "czConfig": {
48
- "path": "node_modules/cz-conventional-changelog"
64
+ "config": {
65
+ "commitizen": {
66
+ "path": "node_modules/cz-conventional-changelog"
67
+ }
49
68
  }
50
69
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ export interface LocalizedName {
2
+ en: string;
3
+ ar: string;
4
+ }
5
+
6
+ export interface Coordinates {
7
+ lat: number;
8
+ lng: number;
9
+ }
10
+
11
+ export interface Neighborhood {
12
+ id: string;
13
+ pcode?: string;
14
+ coordinates?: Coordinates;
15
+ name: LocalizedName;
16
+ }
17
+
18
+ export interface Municipality {
19
+ id: string;
20
+ pcode?: string;
21
+ coordinates?: Coordinates;
22
+ name: LocalizedName;
23
+ neighborhoods?: Neighborhood[];
24
+ }
25
+
26
+ export interface District {
27
+ id: string;
28
+ pcode?: string;
29
+ coordinates?: Coordinates;
30
+ name: LocalizedName;
31
+ }
32
+
33
+ export interface Governorate {
34
+ id: string;
35
+ pcode?: string;
36
+ coordinates?: Coordinates;
37
+ name: LocalizedName;
38
+ districts?: District[];
39
+ }
40
+
41
+ export interface SearchResult {
42
+ type: 'governorate' | 'district' | 'municipality' | 'neighborhood';
43
+ item: Governorate | District | Municipality | Neighborhood;
44
+ municipalityId?: string;
45
+ }
46
+
47
+ export function getAll(): Governorate[];
48
+ export function getGovernorates(): Array<{ id: string; name: LocalizedName }>;
49
+ export function getDistricts(governorateId?: string): District[];
50
+ export function getMunicipalities(governorateId?: string): Array<{ id: string; name: LocalizedName }>;
51
+ export function getNeighborhoods(municipalityId: string): Neighborhood[];
52
+ export function search(query: string): SearchResult[];
package/src/index.js CHANGED
@@ -1,20 +1,92 @@
1
- const uniqueRandomArray = require('unique-random-array')
2
- const damascusDistrictsNames = require('./damascus.json')
1
+ import syriaData from './syria.js'
3
2
 
4
- const getRandomItem = uniqueRandomArray(damascusDistrictsNames)
3
+ function getAll () {
4
+ return syriaData
5
+ }
6
+
7
+ function getGovernorates () {
8
+ return syriaData.map(gov => ({
9
+ id: gov.id,
10
+ name: gov.name
11
+ }))
12
+ }
5
13
 
6
- function random (number) {
7
- if (number === undefined) {
8
- return getRandomItem()
14
+ function getDistricts (governorateId) {
15
+ if (governorateId) {
16
+ const gov = syriaData.find(g => g.id === governorateId)
17
+ if (!gov) return []
18
+ return gov.districts || []
9
19
  }
10
- const randomItems = []
11
- for (let i = 0; i < number; i++) {
12
- randomItems.push(getRandomItem())
20
+
21
+ return syriaData.reduce((allDistricts, gov) => {
22
+ return allDistricts.concat(gov.districts || [])
23
+ }, [])
24
+ }
25
+
26
+ function getMunicipalities (governorateId = 'gov-damascus') {
27
+ const gov = syriaData.find(g => g.id === governorateId)
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 }))
32
+ }
33
+
34
+ function getNeighborhoods (municipalityId) {
35
+ for (const gov of syriaData) {
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
+ }
43
+ }
13
44
  }
14
- return randomItems
45
+ return []
46
+ }
47
+
48
+ function search (query) {
49
+ if (!query || typeof query !== 'string') return []
50
+ const q = query.toLowerCase()
51
+ const results = []
52
+
53
+ syriaData.forEach(gov => {
54
+ if (gov.name.en.toLowerCase().includes(q) || gov.name.ar.includes(q)) {
55
+ results.push({ type: 'governorate', item: { id: gov.id, name: gov.name, pcode: gov.pcode, coordinates: gov.coordinates } })
56
+ }
57
+
58
+ if (gov.districts) {
59
+ gov.districts.forEach(dist => {
60
+ if (dist.name.en.toLowerCase().includes(q) || dist.name.ar.includes(q)) {
61
+ results.push({ type: 'district', item: dist })
62
+ }
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
+ })
75
+ }
76
+ })
77
+ }
78
+ })
79
+ }
80
+ })
81
+
82
+ return results
15
83
  }
16
84
 
17
- module.exports = {
18
- all: damascusDistrictsNames,
19
- random
85
+ export {
86
+ getAll,
87
+ getGovernorates,
88
+ getDistricts,
89
+ getMunicipalities,
90
+ getNeighborhoods,
91
+ search
20
92
  }
@@ -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
+ }