pak-geodata 0.0.0-stage → 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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +238 -2
  3. package/dist/areas/faisalabad.cjs +562 -0
  4. package/dist/areas/faisalabad.d.ts +3 -0
  5. package/dist/areas/faisalabad.d.ts.map +1 -0
  6. package/dist/areas/faisalabad.js +2 -0
  7. package/dist/areas/faisalabad.js.map +1 -0
  8. package/dist/areas/islamabad.cjs +852 -0
  9. package/dist/areas/islamabad.d.ts +3 -0
  10. package/dist/areas/islamabad.d.ts.map +1 -0
  11. package/dist/areas/islamabad.js +2 -0
  12. package/dist/areas/islamabad.js.map +1 -0
  13. package/dist/areas/karachi.cjs +1153 -0
  14. package/dist/areas/karachi.d.ts +3 -0
  15. package/dist/areas/karachi.d.ts.map +1 -0
  16. package/dist/areas/karachi.js +2 -0
  17. package/dist/areas/karachi.js.map +1 -0
  18. package/dist/areas/lahore.cjs +1155 -0
  19. package/dist/areas/lahore.d.ts +3 -0
  20. package/dist/areas/lahore.d.ts.map +1 -0
  21. package/dist/areas/lahore.js +2 -0
  22. package/dist/areas/lahore.js.map +1 -0
  23. package/dist/areas/rawalpindi.cjs +657 -0
  24. package/dist/areas/rawalpindi.d.ts +3 -0
  25. package/dist/areas/rawalpindi.d.ts.map +1 -0
  26. package/dist/areas/rawalpindi.js +2 -0
  27. package/dist/areas/rawalpindi.js.map +1 -0
  28. package/dist/data/areas/faisalabad.d.ts +3 -0
  29. package/dist/data/areas/faisalabad.d.ts.map +1 -0
  30. package/dist/data/areas/faisalabad.js +532 -0
  31. package/dist/data/areas/faisalabad.js.map +1 -0
  32. package/dist/data/areas/index.d.ts +9 -0
  33. package/dist/data/areas/index.d.ts.map +1 -0
  34. package/dist/data/areas/index.js +14 -0
  35. package/dist/data/areas/index.js.map +1 -0
  36. package/dist/data/areas/islamabad.d.ts +3 -0
  37. package/dist/data/areas/islamabad.d.ts.map +1 -0
  38. package/dist/data/areas/islamabad.js +822 -0
  39. package/dist/data/areas/islamabad.js.map +1 -0
  40. package/dist/data/areas/karachi.d.ts +3 -0
  41. package/dist/data/areas/karachi.d.ts.map +1 -0
  42. package/dist/data/areas/karachi.js +1123 -0
  43. package/dist/data/areas/karachi.js.map +1 -0
  44. package/dist/data/areas/lahore.d.ts +3 -0
  45. package/dist/data/areas/lahore.d.ts.map +1 -0
  46. package/dist/data/areas/lahore.js +1125 -0
  47. package/dist/data/areas/lahore.js.map +1 -0
  48. package/dist/data/areas/rawalpindi.d.ts +3 -0
  49. package/dist/data/areas/rawalpindi.d.ts.map +1 -0
  50. package/dist/data/areas/rawalpindi.js +627 -0
  51. package/dist/data/areas/rawalpindi.js.map +1 -0
  52. package/dist/data/cities.d.ts +3 -0
  53. package/dist/data/cities.d.ts.map +1 -0
  54. package/dist/data/cities.js +923 -0
  55. package/dist/data/cities.js.map +1 -0
  56. package/dist/data/index.d.ts +4 -0
  57. package/dist/data/index.d.ts.map +1 -0
  58. package/dist/data/index.js +4 -0
  59. package/dist/data/index.js.map +1 -0
  60. package/dist/data/provinces.d.ts +3 -0
  61. package/dist/data/provinces.d.ts.map +1 -0
  62. package/dist/data/provinces.js +52 -0
  63. package/dist/data/provinces.js.map +1 -0
  64. package/dist/geo.d.ts +19 -0
  65. package/dist/geo.d.ts.map +1 -0
  66. package/dist/geo.js +71 -0
  67. package/dist/geo.js.map +1 -0
  68. package/dist/index.cjs +5538 -0
  69. package/dist/index.d.ts +54 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +130 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/search.d.ts +12 -0
  74. package/dist/search.d.ts.map +1 -0
  75. package/dist/search.js +166 -0
  76. package/dist/search.js.map +1 -0
  77. package/dist/types.d.ts +54 -0
  78. package/dist/types.d.ts.map +1 -0
  79. package/dist/types.js +2 -0
  80. package/dist/types.js.map +1 -0
  81. package/package.json +61 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sohaib Bin Mohsin, The Mohsin Project Global (https://themohsinproject.org)
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 CHANGED
@@ -1,3 +1,239 @@
1
- # Temporary Holding Version
1
+ # pak-geodata
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Comprehensive, typed, offline geographic data for all areas and cities in Pakistan.
4
+
5
+ `pak-geodata` is an open-source, production-grade TypeScript and JavaScript client library providing offline access to verified geographic data for Pakistan, created and maintained by [Sohaib Bin Mohsin](https://sohaibbinmohsin.com) at [The Mohsin Project Global](https://themohsinproject.org).
6
+
7
+ It covers all administrative provinces, 40 major cities, and 189 foundational flagship metropolitan areas (sectors, housing schemes, neighborhoods, and commercial centers).
8
+
9
+ Designed with **zero runtime dependencies**, strict geofencing, sub-millisecond lookups, and modular tree-shakeable subpath exports.
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ - **Zero Runtime Dependencies**: Completely self-contained with 0 runtime dependencies.
16
+ - **Dual Module Support**: Full ESM (`import`) and CommonJS (`require`) support.
17
+ - **Subpath Tree-Shaking**: Import only the areas you need (e.g. `pak-geodata/areas/lahore`) to keep your bundle footprint under a few kilobytes.
18
+ - **Offline & Self-Contained**: All verified golden datasets are bundled with the library: no remote API calls or latency.
19
+ - **Strict Geofencing & Validation**: Every coordinate is rigorously validated within Pakistan territorial boundaries (`23.5 <= lat <= 37.1`, `60.8 <= lng <= 77.8`) and city district bounding boxes.
20
+ - **Canonical Slugs**: Standardized `<city-slug>-<area-slug>` identifiers across all datasets (e.g. `lahore-dha-phase-5`).
21
+ - **Multi-Script & Alias Search**: Full support for English queries, colloquial aliases (e.g. `"dha 5"`), Urdu script queries (e.g. `"گلبرگ"`), and fuzzy typo tolerance.
22
+ - **Spatial Nearest Neighbor**: Instant reverse geocoding via spherical Haversine distance calculations.
23
+ - **Postal Code Resolution**: 5-digit Pakistan Post postal code lookup and reverse mapping.
24
+ - **Fully Typed**: Written in TypeScript with complete type definitions (`.d.ts`).
25
+
26
+ ---
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install pak-geodata
32
+ ```
33
+
34
+ ```bash
35
+ yarn add pak-geodata
36
+ ```
37
+
38
+ ```bash
39
+ pnpm add pak-geodata
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Quick Start
45
+
46
+ ### 1. Provinces & Cities
47
+
48
+ ```typescript
49
+ import {
50
+ getAllProvinces,
51
+ getProvinceById,
52
+ getAllCities,
53
+ getCitiesByProvince,
54
+ getCityById
55
+ } from 'pak-geodata';
56
+
57
+ // List all 7 provinces and federal territories
58
+ const provinces = getAllProvinces();
59
+ for (const p of provinces) {
60
+ console.log(`${p.name} (${p.urduName}) - Capital: ${p.capitalCityId}`);
61
+ }
62
+
63
+ // Find a province by ID
64
+ const punjab = getProvinceById('punjab');
65
+ console.log(punjab?.name); // "Punjab"
66
+
67
+ // Retrieve all cities in a province
68
+ const punjabCities = getCitiesByProvince('punjab');
69
+ console.log(`Found ${punjabCities.length} cities in Punjab`);
70
+
71
+ // Get specific city details
72
+ const lahore = getCityById('lahore');
73
+ console.log(`${lahore?.name} coordinates:`, lahore?.coordinates);
74
+ console.log(`Verified areas count: ${lahore?.totalAreasCount}`);
75
+ ```
76
+
77
+ ### 2. Areas by City
78
+
79
+ ```typescript
80
+ import { getAreasByCity, getAllAreas } from 'pak-geodata';
81
+
82
+ // Retrieve all verified areas for a city
83
+ const lahoreAreas = getAreasByCity('lahore');
84
+ for (const area of lahoreAreas.slice(0, 5)) {
85
+ console.log(`${area.name} [${area.id}] - Postal Code: ${area.postalCode}`);
86
+ }
87
+
88
+ // Total verified areas in Pakistan
89
+ const allAreas = getAllAreas();
90
+ console.log(`Total verified areas: ${allAreas.length}`); // 189
91
+ ```
92
+
93
+ ### 3. Modular Subpath Imports (Tree-Shaking)
94
+
95
+ To minimize browser bundle size, import areas for specific cities directly without bundling the rest of the country:
96
+
97
+ ```typescript
98
+ // Only imports Lahore areas (~24 KB)
99
+ import { lahoreAreas } from 'pak-geodata/areas/lahore';
100
+
101
+ // Only imports Karachi areas (~26 KB)
102
+ import { karachiAreas } from 'pak-geodata/areas/karachi';
103
+
104
+ // Available subpaths:
105
+ // pak-geodata/areas/lahore
106
+ // pak-geodata/areas/karachi
107
+ // pak-geodata/areas/islamabad
108
+ // pak-geodata/areas/rawalpindi
109
+ // pak-geodata/areas/faisalabad
110
+ ```
111
+
112
+ ### 4. Intelligent Search
113
+
114
+ The search engine ranks results across multiple matching tiers:
115
+ 1. Exact match on name, ID, Urdu name, or alias
116
+ 2. Prefix match
117
+ 3. Substring / multi-word token match
118
+ 4. Fuzzy edit-distance fallback for typos
119
+
120
+ ```typescript
121
+ import { searchAreas } from 'pak-geodata';
122
+
123
+ // Search by colloquial alias scoped to a city
124
+ const results = searchAreas('dha 5', { cityId: 'lahore' });
125
+ console.log(results[0].id); // "lahore-dha-phase-5"
126
+ console.log(results[0].name); // "DHA Phase 5"
127
+
128
+ // Search using Urdu script
129
+ const urduResults = searchAreas('کلفٹن');
130
+ for (const r of urduResults) {
131
+ console.log(`${r.name} (${r.urduName}) in ${r.cityId}`);
132
+ }
133
+
134
+ // Scoped search with limit
135
+ const limited = searchAreas('phase', { cityId: 'islamabad', limit: 3 });
136
+ ```
137
+
138
+ ### 5. Reverse Geocoding & Spatial Nearest Neighbor
139
+
140
+ ```typescript
141
+ import { getNearestArea, haversineDistanceKm } from 'pak-geodata';
142
+
143
+ // Coordinates near Liberty Market, Gulberg, Lahore
144
+ const userLocation = { lat: 31.512, lng: 74.343 };
145
+
146
+ // Find closest verified area
147
+ const nearest = getNearestArea(userLocation);
148
+ console.log(`Nearest area: ${nearest?.name} (${nearest?.id})`);
149
+
150
+ // Find nearest area within a specific city and max radius (km)
151
+ const nearestInLahore = getNearestArea(userLocation, {
152
+ cityId: 'lahore',
153
+ maxDistanceKm: 5.0
154
+ });
155
+
156
+ // Calculate distance between two coordinate pairs
157
+ const lahoreCenter = { lat: 31.5204, lng: 74.3587 };
158
+ const karachiCenter = { lat: 24.8607, lng: 67.0011 };
159
+ const distance = haversineDistanceKm(lahoreCenter, karachiCenter);
160
+ console.log(`Distance: ${Math.round(distance)} km`); // ~1025 km
161
+ ```
162
+
163
+ ### 6. Postal Code Resolution
164
+
165
+ ```typescript
166
+ import { findAreaByPostalCode, findAreasByPostalCode } from 'pak-geodata';
167
+
168
+ // Resolve area by 5-digit Pakistan Post postal code (string or number)
169
+ const area = findAreaByPostalCode('54000');
170
+ console.log(`Postal code 54000: ${area?.name} (${area?.cityId})`);
171
+
172
+ // Find all areas sharing a postal code
173
+ const areas = findAreasByPostalCode(54000);
174
+ ```
175
+
176
+ ---
177
+
178
+ ## Data Schema
179
+
180
+ ### `PakistanArea`
181
+ ```typescript
182
+ interface PakistanArea {
183
+ id: string; // Canonical: <city-slug>-<area-slug>
184
+ cityId: string; // e.g. "lahore", "karachi"
185
+ provinceId: string; // e.g. "punjab", "sindh"
186
+ name: string; // Primary English name
187
+ urduName?: string; // Urdu Nastaliq / Naskh name
188
+ aliases: string[]; // Common alternative names and abbreviations
189
+ coordinates: {
190
+ lat: number; // Latitude (WGS 84)
191
+ lng: number; // Longitude (WGS 84)
192
+ };
193
+ postalCode?: string; // 5-digit Pakistan Post postal code
194
+ type?: 'neighborhood' | 'sector' | 'commercial' | 'housing_scheme' | 'suburb' | 'industrial' | 'administrative';
195
+ verified: boolean; // True if verified via triangulation pipeline
196
+ sources: string[]; // Verification sources (e.g. "survey", "curated", "osm")
197
+ }
198
+ ```
199
+
200
+ ### `PakistanCity`
201
+ ```typescript
202
+ interface PakistanCity {
203
+ id: string; // Canonical city slug (e.g. "lahore")
204
+ name: string; // English name
205
+ urduName: string; // Urdu name
206
+ provinceId: string; // Province ID
207
+ division?: string; // Administrative division
208
+ district?: string; // District name
209
+ coordinates: {
210
+ lat: number; // City centroid latitude
211
+ lng: number; // City centroid longitude
212
+ };
213
+ postalCodeRange?: [string, string]; // [minPostalCode, maxPostalCode]
214
+ bounds?: {
215
+ minLat: number;
216
+ maxLat: number;
217
+ minLng: number;
218
+ maxLng: number;
219
+ };
220
+ totalAreasCount: number; // Number of verified areas in dataset
221
+ }
222
+ ```
223
+
224
+ ### `PakistanProvince`
225
+ ```typescript
226
+ interface PakistanProvince {
227
+ id: string; // e.g. "punjab", "sindh", "islamabad-ict"
228
+ name: string; // English name
229
+ urduName: string; // Urdu name
230
+ capitalCityId: string; // Capital city slug
231
+ type: 'province' | 'federal_capital' | 'autonomous_territory';
232
+ }
233
+ ```
234
+
235
+ ---
236
+
237
+ ## License
238
+
239
+ MIT © 2026 [Sohaib Bin Mohsin](https://sohaibbinmohsin.com) • [The Mohsin Project Global](https://themohsinproject.org)