damascus 1.0.0 → 1.2.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/README.md CHANGED
@@ -1,10 +1,13 @@
1
- # Damascus
1
+ # Syria Regions (focusing on Damascus)
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]
6
9
 
7
- Get random districts names of Damascus.
10
+ Get standardized, structured data for the governorates, districts, municipalities, and neighborhoods of Syria, with a **deep-dive into Damascus**. The data is bilingual (Arabic and English) and structured to align with UN OCHA Common Operational Datasets (COD), making it the perfect source of truth for cascading dropdowns and autocompletes in applications like real estate listings, directories, and delivery platforms.
8
11
 
9
12
  ## Installation
10
13
 
@@ -13,23 +16,72 @@ This package is distributed via npm:
13
16
  npm install damascus
14
17
  ```
15
18
 
16
- ## Usage
19
+ ## Usage (ES Modules & TypeScript)
20
+
21
+ Modern projects should import the package via ES Modules. Full TypeScript definitions (`.d.ts`) are included natively for excellent IDE support.
22
+
23
+ ```typescript
24
+ import { search, getAll, getGovernorates, getMunicipalities, getNeighborhoods, SearchResult } from 'damascus';
25
+
26
+ // 1. Search API (Perfect for Autocomplete)
27
+ const result: SearchResult[] = search('دمشق');
28
+
29
+ // 2. Get all structured data
30
+ const allData = getAll();
31
+
32
+ // 3. Get an array of the 14 Syrian governorates
33
+ const governorates = getGovernorates();
34
+ /*
35
+ [
36
+ { id: 'dam', name: { en: 'Damascus', ar: 'دمشق' } },
37
+ { id: 'ale', name: { en: 'Aleppo', ar: 'حلب' } },
38
+ ...
39
+ ]
40
+ */
41
+
42
+ // 4. Damascus Specific APIs (Hierarchical)
43
+ const damascusMunicipalities = getMunicipalities('dam');
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
+ */
58
+ ```
59
+
60
+ ### Legacy CommonJS Usage
61
+ If you are still using CommonJS:
17
62
  ```javascript
18
- var damascus = require('damascus');
19
- var allNames = damascus.all;
20
- var randomName = damascus.random();
21
- var threeRandomNames = damascus.random(3);
63
+ const syria = require('damascus');
64
+ const searchResults = syria.search('Bab Tuma');
22
65
  ```
23
66
 
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).
67
+ ## Features
68
+
69
+ - **Hierarchical Damascus Data**: Perfect for UI components (Select Governorate -> Select Municipality -> Select Neighborhood).
70
+ - **Search Utility**: Built-in search function to easily query the data for autocompletes.
71
+ - **Bilingual**: All items include English (`en`) and Arabic (`ar`) names.
72
+ - **TypeScript Support**: Includes type definitions (`.d.ts`) out of the box for excellent IDE support.
73
+ - **Backward Compatible**: Maintains support for legacy `getDistricts()` API.
26
74
 
75
+ ## Other
76
+ 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), and expanded to be a robust source of truth for Syrian regional data.
27
77
 
28
- [build-badge]: https://img.shields.io/travis/hadabo/damascus.svg?style=flat-square
29
- [build]: https://travis-ci.org/hadabo/damascus
78
+ [build-badge]: https://img.shields.io/github/actions/workflow/status/hadabo/damascus/ci.yml?style=flat-square
79
+ [build]: https://github.com/hadabo/damascus/actions
30
80
  [license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
31
81
  [license]: https://github.com/hadabo/damascus/blob/master/LICENSE
32
82
  [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
83
  [semantic]: https://www.npmjs.com/package/semantic-release
34
84
  [npm-dm]: https://img.shields.io/npm/dm/damascus.svg?style=flat-square
35
- [damascus]: https://www.npmjs.com/package/damascus
85
+ [damascus]: https://www.npmjs.com/package/damascus
86
+ [coveralls]: https://coveralls.io/github/hadabo/damascus?branch=master
87
+ [coveralls-badge]: https://coveralls.io/repos/github/hadabo/damascus/badge.svg?branch=master
package/package.json CHANGED
@@ -1,50 +1,64 @@
1
1
  {
2
2
  "name": "damascus",
3
- "version": "1.0.0",
4
- "description": "Get random districts names of Damascus",
3
+ "version": "1.2.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
+ },
9
+ "type": "module",
10
+ "engines": {
11
+ "node": ">=18.0.0"
12
+ },
13
+ "files": [
14
+ "src"
15
+ ],
6
16
  "scripts": {
7
17
  "precommit": "npm test",
8
18
  "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"
19
+ "lint": "eslint src/*.js test/*.js",
20
+ "lint:fix": "eslint --fix src/*.js test/*.js",
21
+ "test": "c8 mocha",
22
+ "coverage": "c8 report --reporter=text-lcov | coveralls",
23
+ "prepare": "husky"
12
24
  },
13
25
  "repository": {
14
26
  "type": "git",
15
27
  "url": "https://github.com/hadabo/damascus.git"
16
28
  },
17
29
  "keywords": [
18
- "random",
19
30
  "damascus",
20
31
  "syria",
21
- "districts"
32
+ "regions",
33
+ "governorates",
34
+ "municipalities",
35
+ "neighborhoods",
36
+ "districts",
37
+ "ocha",
38
+ "data"
22
39
  ],
23
- "author": "Abdul-hadi Hawari <hadabo@gmail.com> (http://hadabo.com/)",
40
+ "author": "Abdulhadi Hawari <hadabo@gmail.com> (http://hadabo.com/)",
24
41
  "license": "MIT",
25
42
  "bugs": {
26
43
  "url": "https://github.com/hadabo/damascus/issues"
27
44
  },
28
45
  "homepage": "https://github.com/hadabo/damascus#readme",
29
- "dependencies": {
30
- "unique-random-array": "1.0.0"
31
- },
46
+ "dependencies": {},
32
47
  "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"
48
+ "chai": "^5.1.1",
49
+ "commitizen": "^4.3.0",
50
+ "coveralls": "^3.1.1",
51
+ "cz-conventional-changelog": "^3.3.0",
52
+ "eslint": "^9.3.0",
53
+ "globals": "^15.3.0",
54
+ "husky": "^9.0.11",
55
+ "mocha": "^10.4.0",
56
+ "c8": "^9.1.0",
57
+ "semantic-release": "^23.1.1"
46
58
  },
47
- "czConfig": {
48
- "path": "node_modules/cz-conventional-changelog"
59
+ "config": {
60
+ "commitizen": {
61
+ "path": "node_modules/cz-conventional-changelog"
62
+ }
49
63
  }
50
64
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ export interface LocalizedName {
2
+ en: string;
3
+ ar: string;
4
+ }
5
+
6
+ export interface Neighborhood {
7
+ id: string;
8
+ name: LocalizedName;
9
+ }
10
+
11
+ export interface Municipality {
12
+ id: string;
13
+ name: LocalizedName;
14
+ neighborhoods?: Neighborhood[];
15
+ }
16
+
17
+ export interface District {
18
+ id: string;
19
+ name: LocalizedName;
20
+ }
21
+
22
+ export interface Governorate {
23
+ id: string;
24
+ name: LocalizedName;
25
+ municipalities?: Municipality[];
26
+ districts?: District[];
27
+ }
28
+
29
+ export interface SearchResult {
30
+ type: 'governorate' | 'district' | 'municipality' | 'neighborhood';
31
+ item: Governorate | District | Municipality | Neighborhood;
32
+ municipalityId?: string;
33
+ }
34
+
35
+ export function getAll(): Governorate[];
36
+ export function getGovernorates(): Array<{ id: string; name: LocalizedName }>;
37
+ export function getDistricts(governorateId?: string): District[];
38
+ export function getMunicipalities(governorateId?: string): Array<{ id: string; name: LocalizedName }>;
39
+ export function getNeighborhoods(municipalityId: string): Neighborhood[];
40
+ export function search(query: string): SearchResult[];
package/src/index.js CHANGED
@@ -1,20 +1,105 @@
1
- const uniqueRandomArray = require('unique-random-array')
2
- const damascusDistrictsNames = require('./damascus.json')
1
+ import { readFileSync } from 'fs'
2
+ import { fileURLToPath } from 'url'
3
+ import { dirname, join } from 'path'
3
4
 
4
- const getRandomItem = uniqueRandomArray(damascusDistrictsNames)
5
+ const __dirname = dirname(fileURLToPath(import.meta.url))
6
+ const syriaData = JSON.parse(readFileSync(join(__dirname, 'syria.json'), 'utf8'))
5
7
 
6
- function random (number) {
7
- if (number === undefined) {
8
- return getRandomItem()
8
+ function getAll () {
9
+ return syriaData
10
+ }
11
+
12
+ function getGovernorates () {
13
+ return syriaData.map(gov => ({
14
+ id: gov.id,
15
+ name: gov.name
16
+ }))
17
+ }
18
+
19
+ function getDistricts (governorateId) {
20
+ if (governorateId) {
21
+ const gov = syriaData.find(g => g.id === governorateId)
22
+ 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
+ return gov.districts || []
9
31
  }
10
- const randomItems = []
11
- for (let i = 0; i < number; i++) {
12
- randomItems.push(getRandomItem())
32
+
33
+ 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
+ return allDistricts.concat(gov.districts || [])
42
+ }, [])
43
+ }
44
+
45
+ function getMunicipalities (governorateId = 'dam') {
46
+ const gov = syriaData.find(g => g.id === governorateId)
47
+ if (!gov || !gov.municipalities) return []
48
+ return gov.municipalities.map(m => ({ id: m.id, name: m.name }))
49
+ }
50
+
51
+ function getNeighborhoods (municipalityId) {
52
+ for (const gov of syriaData) {
53
+ if (gov.municipalities) {
54
+ const mun = gov.municipalities.find(m => m.id === municipalityId)
55
+ if (mun) return mun.neighborhoods || []
56
+ }
13
57
  }
14
- return randomItems
58
+ return []
59
+ }
60
+
61
+ function search (query) {
62
+ if (!query || typeof query !== 'string') return []
63
+ const q = query.toLowerCase()
64
+ const results = []
65
+
66
+ syriaData.forEach(gov => {
67
+ if (gov.name.en.toLowerCase().includes(q) || gov.name.ar.includes(q)) {
68
+ results.push({ type: 'governorate', item: { id: gov.id, name: gov.name } })
69
+ }
70
+
71
+ if (gov.districts) {
72
+ gov.districts.forEach(dist => {
73
+ if (dist.name.en.toLowerCase().includes(q) || dist.name.ar.includes(q)) {
74
+ results.push({ type: 'district', item: dist })
75
+ }
76
+ })
77
+ }
78
+
79
+ if (gov.municipalities) {
80
+ gov.municipalities.forEach(mun => {
81
+ if (mun.name.en.toLowerCase().includes(q) || mun.name.ar.includes(q)) {
82
+ results.push({ type: 'municipality', item: { id: mun.id, name: mun.name } })
83
+ }
84
+ if (mun.neighborhoods) {
85
+ mun.neighborhoods.forEach(neigh => {
86
+ if (neigh.name.en.toLowerCase().includes(q) || neigh.name.ar.includes(q)) {
87
+ results.push({ type: 'neighborhood', item: neigh, municipalityId: mun.id })
88
+ }
89
+ })
90
+ }
91
+ })
92
+ }
93
+ })
94
+
95
+ return results
15
96
  }
16
97
 
17
- module.exports = {
18
- all: damascusDistrictsNames,
19
- random
98
+ export {
99
+ getAll,
100
+ getGovernorates,
101
+ getDistricts,
102
+ getMunicipalities,
103
+ getNeighborhoods,
104
+ search
20
105
  }