egydata 1.0.1 → 1.1.1

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,156 +1,156 @@
1
- # Egydata
2
-
3
- [![NPM Version](https://img.shields.io/npm/v/egydata.svg)](https://www.npmjs.com/package/egydata)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ahmed-ashraf-dv/egydata/blob/main/LICENSE)
5
-
6
- Structured Egyptian geographical and timezone data for Node.js and the browser.
7
-
8
- Provides a complete, offline dataset of Egyptian governorates, cities, landline and mobile area codes, and timezone utilities — with zero dependencies.
9
-
10
- [View on GitHub](https://github.com/ahmed-ashraf-dv/egydata) | [View on NPM](https://www.npmjs.com/package/egydata)
11
-
12
- ## Installation
13
-
14
- ```bash
15
- npm install egydata
16
- ```
17
-
18
- ## Quick Start
19
-
20
- ```javascript
21
- // CommonJS
22
- const { governorates, cities, phoneArea, timezone } = require("egydata");
23
-
24
- // ESM
25
- import { governorates, cities, phoneArea, timezone } from "egydata";
26
- ```
27
-
28
- ## Usage
29
-
30
- ### Governorates
31
-
32
- ```javascript
33
- const { governorates } = require("egydata");
34
-
35
- // Get all 27 governorates
36
- const all = governorates.getAll();
37
- // [{ id: 1, code: 'CAI', name: 'القاهرة', nameEn: 'Cairo' }, ...]
38
-
39
- // Find by code
40
- const cairo = governorates.getByCode("CAI");
41
- // { id: 1, code: 'CAI', name: 'القاهرة', nameEn: 'Cairo' }
42
-
43
- // Find by id
44
- const gov = governorates.getById(2);
45
- // { id: 2, code: 'ALX', name: 'الإسكندرية', nameEn: 'Alexandria' }
46
-
47
- // Search (Arabic or English, partial match)
48
- const results = governorates.search("alex");
49
- // [{ id: 2, code: 'ALX', name: 'الإسكندرية', nameEn: 'Alexandria' }]
50
-
51
- const arResults = governorates.search("القاهرة");
52
- // [{ id: 1, code: 'CAI', name: 'القاهرة', nameEn: 'Cairo' }]
53
- ```
54
-
55
- ### Cities
56
-
57
- ```javascript
58
- const { cities } = require("egydata");
59
-
60
- // Get cities by governorate code
61
- const cairoCities = cities.getByGovernorate("CAI");
62
- // [{ id: 1, name: 'مدينة نصر', nameEn: 'Nasr City', governorateCode: 'CAI' }, ...]
63
-
64
- // Find by id
65
- const city = cities.getById(131);
66
- // { id: 131, name: 'شرم الشيخ', nameEn: 'Sharm El Sheikh', governorateCode: 'SIS' }
67
-
68
- // Search cities (Arabic or English, partial match)
69
- const found = cities.search("Maadi");
70
- // [{ id: 3, name: 'المعادي', nameEn: 'Maadi', governorateCode: 'CAI' }]
71
- ```
72
-
73
- ### Phone Area Codes
74
-
75
- ```javascript
76
- const { phoneArea } = require("egydata");
77
-
78
- // Get all area codes (landline and mobile)
79
- const all = phoneArea.getAll();
80
- // [{ code: '02', region: 'القاهرة والجيزة', regionEn: 'Cairo & Giza' }, ...]
81
-
82
- // Look up a region by code
83
- const region = phoneArea.getRegion("03");
84
- // { code: '03', region: 'الإسكندرية', regionEn: 'Alexandria' }
85
-
86
- // Find area code by region name
87
- const entry = phoneArea.getCode("Mansoura");
88
- // { code: '050', region: 'الدقهلية (المنصورة)', regionEn: 'Dakahlia (Mansoura)' }
89
- ```
90
-
91
- ### Timezone
92
-
93
- ```javascript
94
- const { timezone } = require("egydata");
95
-
96
- console.log(timezone.name); // 'Africa/Cairo'
97
- console.log(timezone.offset); // '+02:00'
98
-
99
- const now = timezone.now(); // Current date/time in Egypt (Date object)
100
- console.log(now.toISOString());
101
-
102
- console.log(timezone.isDST()); // true or false depending on current date (Egypt resumed DST in 2023)
103
- ```
104
-
105
- ## API Reference
106
-
107
- ### `governorates`
108
-
109
- | Method | Parameters | Returns | Description |
110
- | ----------------- | ---------- | -------------------- | ------------------------------------------------------------ | --------------------------------------------- | ------------------------------------ |
111
- | `getAll()` | — | `Array<Governorate>` | Returns all 27 Egyptian governorates |
112
- | `getByCode(code)` | `string` | `Governorate | undefined` | Find a governorate by its code (e.g. `'CAI'`) |
113
- | `getById(id)` | `number | string` | `Governorate | undefined` | Find a governorate by its numeric id |
114
- | `search(query)` | `string` | `Array<Governorate>` | Search by Arabic or English name (partial, case-insensitive) |
115
-
116
- **Governorate shape:** `{ id: number, code: string, name: string, nameEn: string }`
117
-
118
- ### `cities`
119
-
120
- | Method | Parameters | Returns | Description |
121
- | --------------------------- | ---------- | ------------- | ------------------------------------------------------------ | ---------- | ----------------------------- |
122
- | `getByGovernorate(govCode)` | `string` | `Array<City>` | Get all cities in a governorate |
123
- | `getById(id)` | `number | string` | `City | undefined` | Find a city by its numeric id |
124
- | `search(query)` | `string` | `Array<City>` | Search by Arabic or English name (partial, case-insensitive) |
125
-
126
- **City shape:** `{ id: number, name: string, nameEn: string, governorateCode: string }`
127
-
128
- ### `phoneArea`
129
-
130
- | Method | Parameters | Returns | Description |
131
- | --------------------- | ---------- | ----------------- | --------------------------------------------------- | ------------------------------------------------------- |
132
- | `getAll()` | — | `Array<AreaCode>` | Returns all Egyptian landline and mobile area codes |
133
- | `getRegion(code)` | `string` | `AreaCode | undefined` | Look up region info by area code |
134
- | `getCode(regionName)` | `string` | `AreaCode | undefined` | Find area code entry by region name (Arabic or English) |
135
-
136
- **AreaCode shape:** `{ code: string, region: string, regionEn: string }`
137
-
138
- ### `timezone`
139
-
140
- | Property / Method | Returns | Description |
141
- | ----------------- | ---------------- | --------------------------------------------------- |
142
- | `name` | `'Africa/Cairo'` | IANA timezone identifier |
143
- | `offset` | `'+02:00'` | UTC offset |
144
- | `now()` | `Date` | Current date/time in Egypt |
145
- | `isDST(date?)` | `boolean` | Whether DST is active (optionally for a given date) |
146
-
147
- ## Data Coverage
148
-
149
- - **27** governorates with Arabic and English names
150
- - **151** cities and districts across all governorates
151
- - **30** landline and mobile area codes
152
- - Full timezone support for `Africa/Cairo`
153
-
154
- ## License
155
-
156
- [MIT](LICENSE)
1
+ # Egydata
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/egydata.svg)](https://www.npmjs.com/package/egydata)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ahmed-ashraf-dv/egydata/blob/main/LICENSE)
5
+
6
+ Structured Egyptian geographical and timezone data for Node.js and the browser.
7
+
8
+ Provides a complete, offline dataset of Egyptian governorates, cities, landline and mobile area codes, and timezone utilities — with zero dependencies.
9
+
10
+ [View on GitHub](https://github.com/ahmed-ashraf-dv/egydata) | [View on NPM](https://www.npmjs.com/package/egydata)
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install egydata
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```javascript
21
+ // CommonJS
22
+ const { governorates, cities, phoneArea, timezone } = require("egydata");
23
+
24
+ // ESM
25
+ import { governorates, cities, phoneArea, timezone } from "egydata";
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ### Governorates
31
+
32
+ ```javascript
33
+ const { governorates } = require("egydata");
34
+
35
+ // Get all 27 governorates
36
+ const all = governorates.getAll();
37
+ // [{ id: 1, code: 'CAI', name: 'القاهرة', nameEn: 'Cairo' }, ...]
38
+
39
+ // Find by code
40
+ const cairo = governorates.getByCode("CAI");
41
+ // { id: 1, code: 'CAI', name: 'القاهرة', nameEn: 'Cairo' }
42
+
43
+ // Find by id
44
+ const gov = governorates.getById(2);
45
+ // { id: 2, code: 'ALX', name: 'الإسكندرية', nameEn: 'Alexandria' }
46
+
47
+ // Search (Arabic or English, partial match)
48
+ const results = governorates.search("alex");
49
+ // [{ id: 2, code: 'ALX', name: 'الإسكندرية', nameEn: 'Alexandria' }]
50
+
51
+ const arResults = governorates.search("القاهرة");
52
+ // [{ id: 1, code: 'CAI', name: 'القاهرة', nameEn: 'Cairo' }]
53
+ ```
54
+
55
+ ### Cities
56
+
57
+ ```javascript
58
+ const { cities } = require("egydata");
59
+
60
+ // Get cities by governorate code
61
+ const cairoCities = cities.getByGovernorate("CAI");
62
+ // [{ id: 1, name: 'مدينة نصر', nameEn: 'Nasr City', governorateCode: 'CAI' }, ...]
63
+
64
+ // Find by id
65
+ const city = cities.getById(131);
66
+ // { id: 131, name: 'شرم الشيخ', nameEn: 'Sharm El Sheikh', governorateCode: 'SIS' }
67
+
68
+ // Search cities (Arabic or English, partial match)
69
+ const found = cities.search("Maadi");
70
+ // [{ id: 3, name: 'المعادي', nameEn: 'Maadi', governorateCode: 'CAI' }]
71
+ ```
72
+
73
+ ### Phone Area Codes
74
+
75
+ ```javascript
76
+ const { phoneArea } = require("egydata");
77
+
78
+ // Get all area codes (landline and mobile)
79
+ const all = phoneArea.getAll();
80
+ // [{ code: '02', region: 'القاهرة والجيزة', regionEn: 'Cairo & Giza' }, ...]
81
+
82
+ // Look up a region by code
83
+ const region = phoneArea.getRegion("03");
84
+ // { code: '03', region: 'الإسكندرية', regionEn: 'Alexandria' }
85
+
86
+ // Find area code by region name
87
+ const entry = phoneArea.getCode("Mansoura");
88
+ // { code: '050', region: 'الدقهلية (المنصورة)', regionEn: 'Dakahlia (Mansoura)' }
89
+ ```
90
+
91
+ ### Timezone
92
+
93
+ ```javascript
94
+ const { timezone } = require("egydata");
95
+
96
+ console.log(timezone.name); // 'Africa/Cairo'
97
+ console.log(timezone.offset); // '+02:00'
98
+
99
+ const now = timezone.now(); // Current date/time in Egypt (Date object)
100
+ console.log(now.toISOString());
101
+
102
+ console.log(timezone.isDST()); // true or false depending on current date (Egypt resumed DST in 2023)
103
+ ```
104
+
105
+ ## API Reference
106
+
107
+ ### `governorates`
108
+
109
+ | Method | Parameters | Returns | Description |
110
+ | ----------------- | ------------------ | -------------------------------- | ------------------------------------------------------------ |
111
+ | `getAll()` | — | `Array<Governorate>` | Returns all 27 Egyptian governorates |
112
+ | `getByCode(code)` | `string` | `Governorate \| undefined` | Find a governorate by its code (e.g. `'CAI'`) |
113
+ | `getById(id)` | `number \| string` | `Governorate \| undefined` | Find a governorate by its numeric id |
114
+ | `search(query)` | `string` | `Array<Governorate>` | Search by Arabic or English name (partial, case-insensitive) |
115
+
116
+ **Governorate shape:** `{ id: number, code: string, name: string, nameEn: string }`
117
+
118
+ ### `cities`
119
+
120
+ | Method | Parameters | Returns | Description |
121
+ | --------------------------- | ------------------ | ----------------------- | ------------------------------------------------------------ |
122
+ | `getByGovernorate(govCode)` | `string` | `Array<City>` | Get all cities in a governorate |
123
+ | `getById(id)` | `number \| string` | `City \| undefined` | Find a city by its numeric id |
124
+ | `search(query)` | `string` | `Array<City>` | Search by Arabic or English name (partial, case-insensitive) |
125
+
126
+ **City shape:** `{ id: number, name: string, nameEn: string, governorateCode: string }`
127
+
128
+ ### `phoneArea`
129
+
130
+ | Method | Parameters | Returns | Description |
131
+ | --------------------- | ---------- | -------------------------- | ------------------------------------------------------- |
132
+ | `getAll()` | — | `Array<AreaCode>` | Returns all Egyptian landline and mobile area codes |
133
+ | `getRegion(code)` | `string` | `AreaCode \| undefined` | Look up region info by area code |
134
+ | `getCode(regionName)` | `string` | `AreaCode \| undefined` | Find area code entry by region name (Arabic or English) |
135
+
136
+ **AreaCode shape:** `{ code: string, region: string, regionEn: string }`
137
+
138
+ ### `timezone`
139
+
140
+ | Property / Method | Returns | Description |
141
+ | ----------------- | ---------------- | --------------------------------------------------- |
142
+ | `name` | `'Africa/Cairo'` | IANA timezone identifier |
143
+ | `offset` | `'+02:00'` | UTC offset |
144
+ | `now()` | `Date` | Current date/time in Egypt |
145
+ | `isDST(date?)` | `boolean` | Whether DST is active (optionally for a given date) |
146
+
147
+ ## Data Coverage
148
+
149
+ - **27** governorates with Arabic and English names
150
+ - **389** cities and districts across all governorates
151
+ - **30** landline and mobile area codes
152
+ - Full timezone support for `Africa/Cairo`
153
+
154
+ ## License
155
+
156
+ [MIT](LICENSE)
@@ -0,0 +1,5 @@
1
+ import type { City } from './types';
2
+ export declare function getByGovernorate(govCode: unknown): City[];
3
+ export declare function getById(id: unknown): City | undefined;
4
+ export declare function search(query: unknown): City[];
5
+ //# sourceMappingURL=cities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cities.d.ts","sourceRoot":"","sources":["../src/cities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAcpC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,EAAE,CAIzD;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAIrD;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,EAAE,CAM7C"}
package/dist/cities.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getByGovernorate = getByGovernorate;
7
+ exports.getById = getById;
8
+ exports.search = search;
9
+ const cities_json_1 = __importDefault(require("./data/cities.json"));
10
+ const cities = cities_json_1.default;
11
+ const idMap = new Map(cities.map((c) => [c.id, c]));
12
+ const govMap = new Map();
13
+ for (const city of cities) {
14
+ const code = city.governorateCode;
15
+ if (!govMap.has(code))
16
+ govMap.set(code, []);
17
+ govMap.get(code).push(city);
18
+ }
19
+ function getByGovernorate(govCode) {
20
+ if (typeof govCode !== 'string')
21
+ return [];
22
+ const list = govMap.get(govCode.toUpperCase());
23
+ return list ? [...list] : [];
24
+ }
25
+ function getById(id) {
26
+ const numId = Number(id);
27
+ if (!Number.isInteger(numId))
28
+ return undefined;
29
+ return idMap.get(numId) || undefined;
30
+ }
31
+ function search(query) {
32
+ if (typeof query !== 'string' || !query.trim())
33
+ return [];
34
+ const q = query.trim().toLowerCase();
35
+ return cities.filter((c) => c.name.includes(q) || c.nameEn.toLowerCase().includes(q));
36
+ }
37
+ //# sourceMappingURL=cities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cities.js","sourceRoot":"","sources":["../src/cities.ts"],"names":[],"mappings":";;;;;AAcA,4CAIC;AAED,0BAIC;AAED,wBAMC;AA/BD,qEAA4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