bharat-pincode 1.0.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 +289 -0
- package/data/pincodes.json +1 -0
- package/dist/index.d.mts +121 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.js +151 -0
- package/dist/index.mjs +113 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# india-pincode
|
|
2
|
+
|
|
3
|
+
> 🇮🇳 Offline-first Indian pincode lookup — city, state, district, nearby search, distance calculation & more. **Zero dependencies. TypeScript-first.**
|
|
4
|
+
|
|
5
|
+
[](https://npmjs.com/package/india-pincode)
|
|
6
|
+
[](https://npmjs.com/package/india-pincode)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## ✨ Features
|
|
13
|
+
|
|
14
|
+
- 🔌 **Offline-first** — no API calls, no rate limits, works anywhere
|
|
15
|
+
- ⚡ **Instant lookups** — O(1) hashmap access
|
|
16
|
+
- 🗺️ **Nearby search** — find pincodes within N km using Haversine formula
|
|
17
|
+
- 📏 **Distance calculator** — km between any two pincodes
|
|
18
|
+
- 🔍 **Fuzzy search** — partial city / state / district name matching
|
|
19
|
+
- 🏙️ **Rich data** — city, district, state, state code, region, lat/lng, office type
|
|
20
|
+
- 🧩 **Tree-shakable** — ESM + CJS dual build
|
|
21
|
+
- 💪 **TypeScript** — full types included, no `@types/` install needed
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 📦 Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install india-pincode
|
|
29
|
+
# or
|
|
30
|
+
pnpm add india-pincode
|
|
31
|
+
# or
|
|
32
|
+
yarn add india-pincode
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 🚀 Quick Start
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import pincode from "india-pincode";
|
|
41
|
+
|
|
42
|
+
// Single lookup
|
|
43
|
+
const result = pincode.lookup("400001");
|
|
44
|
+
// → { pincode: "400001", city: "Mumbai", district: "Mumbai City",
|
|
45
|
+
// state: "Maharashtra", state_code: "MH", region: "West",
|
|
46
|
+
// lat: 18.9388, lng: 72.8354, type: "HO" }
|
|
47
|
+
|
|
48
|
+
// Validate
|
|
49
|
+
pincode.isValid("400001"); // → true
|
|
50
|
+
pincode.isValid("000000"); // → false
|
|
51
|
+
|
|
52
|
+
// Distance between two cities
|
|
53
|
+
pincode.distanceBetween("400001", "560001"); // → 981.4 (km)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 📖 API Reference
|
|
59
|
+
|
|
60
|
+
### `lookup(pincode: string): PincodeResult | null`
|
|
61
|
+
Lookup a single pincode. Returns `null` if not found.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { lookup } from "india-pincode";
|
|
65
|
+
|
|
66
|
+
lookup("800001");
|
|
67
|
+
// → { pincode: "800001", city: "Patna", state: "Bihar", ... }
|
|
68
|
+
|
|
69
|
+
lookup("000000"); // → null
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### `lookupMany(pincodes: string[]): Map<string, PincodeResult | null>`
|
|
75
|
+
Batch lookup — returns a Map.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const results = lookupMany(["400001", "560001", "999999"]);
|
|
79
|
+
results.get("400001"); // → { city: "Mumbai", ... }
|
|
80
|
+
results.get("999999"); // → null
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
### `isValid(pincode: string): boolean`
|
|
86
|
+
Checks both format and dataset existence.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
isValid("400001"); // → true
|
|
90
|
+
isValid("12345"); // → false (not 6 digits)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
### `isValidFormat(pincode: string): boolean`
|
|
96
|
+
Checks only format (6 digits) without dataset lookup.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
isValidFormat("123456"); // → true (format ok, may not exist)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### `getByCity(city: string): PincodeResult[]`
|
|
105
|
+
All pincodes for a city (partial, case-insensitive).
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
getByCity("Mumbai"); // → all Mumbai pincodes
|
|
109
|
+
getByCity("banga"); // → matches Bengaluru
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
### `getByState(state: string): PincodeResult[]`
|
|
115
|
+
By state name or 2-letter state code.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
getByState("Bihar"); // → all Bihar pincodes
|
|
119
|
+
getByState("BR"); // → same result
|
|
120
|
+
getByState("MH"); // → Maharashtra pincodes
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
### `getByDistrict(district: string): PincodeResult[]`
|
|
126
|
+
All pincodes in a district.
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
getByDistrict("Patna"); // → all Patna district pincodes
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
### `getByRegion(region: Region): PincodeResult[]`
|
|
135
|
+
Filter by geographic region.
|
|
136
|
+
|
|
137
|
+
Regions: `"North"` | `"South"` | `"East"` | `"West"` | `"Central"` | `"Northeast"`
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
getByRegion("South"); // → all South India pincodes
|
|
141
|
+
getByRegion("Northeast"); // → Assam, Meghalaya, Mizoram, etc.
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
### `nearby(pincode: string, options?: NearbyOptions): PincodeResult[]`
|
|
147
|
+
Find pincodes within a radius. Sorted by distance.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
nearby("400001", { radiusKm: 15, limit: 5 });
|
|
151
|
+
// → up to 5 pincodes within 15 km of Mumbai GPO
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Options:
|
|
155
|
+
| Option | Default | Description |
|
|
156
|
+
|--------|---------|-------------|
|
|
157
|
+
| `radiusKm` | `20` | Search radius in km |
|
|
158
|
+
| `limit` | `10` | Max results |
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### `distanceBetween(pin1: string, pin2: string): number | null`
|
|
163
|
+
Straight-line distance (km) between two pincodes.
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
distanceBetween("110001", "400001"); // → 1148.32 (Delhi → Mumbai)
|
|
167
|
+
distanceBetween("400001", "invalid"); // → null
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### `search(query: string): PincodeResult[]`
|
|
173
|
+
Fuzzy search across pincode, city, district, state.
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
search("bhopal"); // → Bhopal pincodes
|
|
177
|
+
search("110"); // → all pincodes starting with 110
|
|
178
|
+
search("south"); // → matches states/cities with "south"
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
### `getAllStates(): { state: string, state_code: string }[]`
|
|
184
|
+
List of all states in the dataset.
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
getAllStates();
|
|
188
|
+
// → [{ state: "Andhra Pradesh", state_code: "AP" }, ...]
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 📐 TypeScript Types
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
export interface PincodeResult {
|
|
197
|
+
pincode: string;
|
|
198
|
+
city: string;
|
|
199
|
+
district: string;
|
|
200
|
+
state: string;
|
|
201
|
+
state_code: string;
|
|
202
|
+
region: "North" | "South" | "East" | "West" | "Central" | "Northeast";
|
|
203
|
+
lat: number;
|
|
204
|
+
lng: number;
|
|
205
|
+
type: "HO" | "SO" | "BO"; // Head Office | Sub Office | Branch Office
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## 💡 Real-world Examples
|
|
212
|
+
|
|
213
|
+
### Address form auto-fill
|
|
214
|
+
```ts
|
|
215
|
+
const handlePincodeChange = async (pin: string) => {
|
|
216
|
+
if (pin.length === 6) {
|
|
217
|
+
const result = lookup(pin);
|
|
218
|
+
if (result) {
|
|
219
|
+
setCity(result.city);
|
|
220
|
+
setState(result.state);
|
|
221
|
+
setDistrict(result.district);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### E-commerce delivery zone check
|
|
228
|
+
```ts
|
|
229
|
+
const warehousePincode = "400001"; // Mumbai warehouse
|
|
230
|
+
|
|
231
|
+
const isDeliverable = (customerPin: string): boolean => {
|
|
232
|
+
const dist = distanceBetween(warehousePincode, customerPin);
|
|
233
|
+
return dist !== null && dist <= 500; // 500 km delivery radius
|
|
234
|
+
};
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Find nearest service center
|
|
238
|
+
```ts
|
|
239
|
+
const serviceCenters = ["560001", "600001", "500001"];
|
|
240
|
+
|
|
241
|
+
const nearest = (userPin: string) => {
|
|
242
|
+
return serviceCenters
|
|
243
|
+
.map(sc => ({ pincode: sc, dist: distanceBetween(userPin, sc) }))
|
|
244
|
+
.filter(s => s.dist !== null)
|
|
245
|
+
.sort((a, b) => (a.dist ?? 0) - (b.dist ?? 0))[0];
|
|
246
|
+
};
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## 🗃️ Dataset Coverage
|
|
252
|
+
|
|
253
|
+
Covers all 28 states + 8 UTs including major cities and districts:
|
|
254
|
+
|
|
255
|
+
| Region | States Covered |
|
|
256
|
+
|--------|---------------|
|
|
257
|
+
| North | Delhi, UP, Rajasthan, Punjab, Haryana, HP, Uttarakhand, J&K |
|
|
258
|
+
| South | Karnataka, Tamil Nadu, Telangana, Kerala, Andhra Pradesh |
|
|
259
|
+
| East | Bihar, West Bengal, Odisha, Jharkhand, Assam + NE states |
|
|
260
|
+
| West | Maharashtra, Gujarat, Goa |
|
|
261
|
+
| Central | Madhya Pradesh, Chhattisgarh |
|
|
262
|
+
|
|
263
|
+
> 📝 Want your city added? [Open an issue](https://github.com/AshutoshIITP1234/india-pincode/issues) or submit a PR!
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## 🤝 Contributing
|
|
268
|
+
|
|
269
|
+
PRs welcome! Especially for:
|
|
270
|
+
- Adding more pincodes (submit a JSON patch)
|
|
271
|
+
- Adding `type: "BO"` (Branch Office) entries
|
|
272
|
+
- Improving coordinate accuracy
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
git clone https://github.com/AshutoshIITP1234/india-pincode
|
|
276
|
+
cd india-pincode
|
|
277
|
+
npm install
|
|
278
|
+
npm run dev
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## 📄 License
|
|
284
|
+
|
|
285
|
+
MIT © [Ashutosh Kumar Tripathi](https://ashutosh.social)
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
<p align="center">Made with ❤️ in India — from IIT Patna</p>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"110001": {"city": "New Delhi", "district": "Central Delhi", "state": "Delhi", "state_code": "DL", "region": "North", "lat": 28.6139, "lng": 77.209, "type": "HO"}, "110002": {"city": "Delhi", "district": "Central Delhi", "state": "Delhi", "state_code": "DL", "region": "North", "lat": 28.6328, "lng": 77.2197, "type": "SO"}, "110011": {"city": "New Delhi", "district": "South Delhi", "state": "Delhi", "state_code": "DL", "region": "North", "lat": 28.5918, "lng": 77.1674, "type": "SO"}, "110048": {"city": "New Delhi", "district": "South West Delhi", "state": "Delhi", "state_code": "DL", "region": "North", "lat": 28.5245, "lng": 77.1855, "type": "SO"}, "110092": {"city": "Delhi", "district": "East Delhi", "state": "Delhi", "state_code": "DL", "region": "North", "lat": 28.6692, "lng": 77.3005, "type": "SO"}, "400001": {"city": "Mumbai", "district": "Mumbai City", "state": "Maharashtra", "state_code": "MH", "region": "West", "lat": 18.9388, "lng": 72.8354, "type": "HO"}, "400051": {"city": "Mumbai", "district": "Mumbai Suburban", "state": "Maharashtra", "state_code": "MH", "region": "West", "lat": 19.0596, "lng": 72.8295, "type": "SO"}, "400076": {"city": "Mumbai", "district": "Mumbai Suburban", "state": "Maharashtra", "state_code": "MH", "region": "West", "lat": 19.1136, "lng": 72.8697, "type": "SO"}, "411001": {"city": "Pune", "district": "Pune", "state": "Maharashtra", "state_code": "MH", "region": "West", "lat": 18.5204, "lng": 73.8567, "type": "HO"}, "411014": {"city": "Pune", "district": "Pune", "state": "Maharashtra", "state_code": "MH", "region": "West", "lat": 18.5642, "lng": 73.914, "type": "SO"}, "440001": {"city": "Nagpur", "district": "Nagpur", "state": "Maharashtra", "state_code": "MH", "region": "West", "lat": 21.1458, "lng": 79.0882, "type": "HO"}, "431001": {"city": "Aurangabad", "district": "Aurangabad", "state": "Maharashtra", "state_code": "MH", "region": "West", "lat": 19.8762, "lng": 75.3433, "type": "HO"}, "560001": {"city": "Bengaluru", "district": "Bengaluru Urban", "state": "Karnataka", "state_code": "KA", "region": "South", "lat": 12.9716, "lng": 77.5946, "type": "HO"}, "560029": {"city": "Bengaluru", "district": "Bengaluru Urban", "state": "Karnataka", "state_code": "KA", "region": "South", "lat": 12.925, "lng": 77.5938, "type": "SO"}, "560034": {"city": "Bengaluru", "district": "Bengaluru Urban", "state": "Karnataka", "state_code": "KA", "region": "South", "lat": 12.9352, "lng": 77.6245, "type": "SO"}, "560066": {"city": "Bengaluru", "district": "Bengaluru Urban", "state": "Karnataka", "state_code": "KA", "region": "South", "lat": 13.0358, "lng": 77.597, "type": "SO"}, "570001": {"city": "Mysuru", "district": "Mysuru", "state": "Karnataka", "state_code": "KA", "region": "South", "lat": 12.2958, "lng": 76.6394, "type": "HO"}, "580001": {"city": "Hubli", "district": "Dharwad", "state": "Karnataka", "state_code": "KA", "region": "South", "lat": 15.3647, "lng": 75.124, "type": "HO"}, "600001": {"city": "Chennai", "district": "Chennai", "state": "Tamil Nadu", "state_code": "TN", "region": "South", "lat": 13.0827, "lng": 80.2707, "type": "HO"}, "600020": {"city": "Chennai", "district": "Chennai", "state": "Tamil Nadu", "state_code": "TN", "region": "South", "lat": 13.0569, "lng": 80.2425, "type": "SO"}, "600042": {"city": "Chennai", "district": "Chennai", "state": "Tamil Nadu", "state_code": "TN", "region": "South", "lat": 13.0067, "lng": 80.2206, "type": "SO"}, "641001": {"city": "Coimbatore", "district": "Coimbatore", "state": "Tamil Nadu", "state_code": "TN", "region": "South", "lat": 11.0168, "lng": 76.9558, "type": "HO"}, "625001": {"city": "Madurai", "district": "Madurai", "state": "Tamil Nadu", "state_code": "TN", "region": "South", "lat": 9.9252, "lng": 78.1198, "type": "HO"}, "620001": {"city": "Tiruchirappalli", "district": "Tiruchirappalli", "state": "Tamil Nadu", "state_code": "TN", "region": "South", "lat": 10.7905, "lng": 78.7047, "type": "HO"}, "500001": {"city": "Hyderabad", "district": "Hyderabad", "state": "Telangana", "state_code": "TS", "region": "South", "lat": 17.385, "lng": 78.4867, "type": "HO"}, "500018": {"city": "Hyderabad", "district": "Hyderabad", "state": "Telangana", "state_code": "TS", "region": "South", "lat": 17.44, "lng": 78.3489, "type": "SO"}, "500081": {"city": "Hyderabad", "district": "Rangareddy", "state": "Telangana", "state_code": "TS", "region": "South", "lat": 17.4947, "lng": 78.3996, "type": "SO"}, "506001": {"city": "Warangal", "district": "Warangal Urban", "state": "Telangana", "state_code": "TS", "region": "South", "lat": 17.9784, "lng": 79.5941, "type": "HO"}, "226001": {"city": "Lucknow", "district": "Lucknow", "state": "Uttar Pradesh", "state_code": "UP", "region": "North", "lat": 26.8467, "lng": 80.9462, "type": "HO"}, "226010": {"city": "Lucknow", "district": "Lucknow", "state": "Uttar Pradesh", "state_code": "UP", "region": "North", "lat": 26.8631, "lng": 80.9176, "type": "SO"}, "208001": {"city": "Kanpur", "district": "Kanpur Nagar", "state": "Uttar Pradesh", "state_code": "UP", "region": "North", "lat": 26.4499, "lng": 80.3319, "type": "HO"}, "201301": {"city": "Noida", "district": "Gautam Buddha Nagar", "state": "Uttar Pradesh", "state_code": "UP", "region": "North", "lat": 28.5355, "lng": 77.391, "type": "HO"}, "211001": {"city": "Prayagraj", "district": "Prayagraj", "state": "Uttar Pradesh", "state_code": "UP", "region": "North", "lat": 25.4358, "lng": 81.8463, "type": "HO"}, "221001": {"city": "Varanasi", "district": "Varanasi", "state": "Uttar Pradesh", "state_code": "UP", "region": "North", "lat": 25.3176, "lng": 82.9739, "type": "HO"}, "282001": {"city": "Agra", "district": "Agra", "state": "Uttar Pradesh", "state_code": "UP", "region": "North", "lat": 27.1767, "lng": 78.0081, "type": "HO"}, "800001": {"city": "Patna", "district": "Patna", "state": "Bihar", "state_code": "BR", "region": "East", "lat": 25.5941, "lng": 85.1376, "type": "HO"}, "800020": {"city": "Patna", "district": "Patna", "state": "Bihar", "state_code": "BR", "region": "East", "lat": 25.6138, "lng": 85.0783, "type": "SO"}, "842001": {"city": "Muzaffarpur", "district": "Muzaffarpur", "state": "Bihar", "state_code": "BR", "region": "East", "lat": 26.1209, "lng": 85.3647, "type": "HO"}, "843302": {"city": "Sitamarhi", "district": "Sitamarhi", "state": "Bihar", "state_code": "BR", "region": "East", "lat": 26.5942, "lng": 85.489, "type": "HO"}, "824101": {"city": "Gaya", "district": "Gaya", "state": "Bihar", "state_code": "BR", "region": "East", "lat": 24.7914, "lng": 85.0002, "type": "HO"}, "700001": {"city": "Kolkata", "district": "Kolkata", "state": "West Bengal", "state_code": "WB", "region": "East", "lat": 22.5726, "lng": 88.3639, "type": "HO"}, "700019": {"city": "Kolkata", "district": "Kolkata", "state": "West Bengal", "state_code": "WB", "region": "East", "lat": 22.5093, "lng": 88.3639, "type": "SO"}, "700091": {"city": "Kolkata", "district": "North 24 Parganas", "state": "West Bengal", "state_code": "WB", "region": "East", "lat": 22.6467, "lng": 88.4296, "type": "SO"}, "713101": {"city": "Burdwan", "district": "Purba Bardhaman", "state": "West Bengal", "state_code": "WB", "region": "East", "lat": 23.2324, "lng": 87.8615, "type": "HO"}, "302001": {"city": "Jaipur", "district": "Jaipur", "state": "Rajasthan", "state_code": "RJ", "region": "North", "lat": 26.9124, "lng": 75.7873, "type": "HO"}, "302017": {"city": "Jaipur", "district": "Jaipur", "state": "Rajasthan", "state_code": "RJ", "region": "North", "lat": 26.8742, "lng": 75.8074, "type": "SO"}, "342001": {"city": "Jodhpur", "district": "Jodhpur", "state": "Rajasthan", "state_code": "RJ", "region": "North", "lat": 26.2389, "lng": 73.0243, "type": "HO"}, "313001": {"city": "Udaipur", "district": "Udaipur", "state": "Rajasthan", "state_code": "RJ", "region": "North", "lat": 24.5854, "lng": 73.7125, "type": "HO"}, "334001": {"city": "Bikaner", "district": "Bikaner", "state": "Rajasthan", "state_code": "RJ", "region": "North", "lat": 28.0229, "lng": 73.3119, "type": "HO"}, "380001": {"city": "Ahmedabad", "district": "Ahmedabad", "state": "Gujarat", "state_code": "GJ", "region": "West", "lat": 23.0225, "lng": 72.5714, "type": "HO"}, "380015": {"city": "Ahmedabad", "district": "Ahmedabad", "state": "Gujarat", "state_code": "GJ", "region": "West", "lat": 23.0376, "lng": 72.5269, "type": "SO"}, "395001": {"city": "Surat", "district": "Surat", "state": "Gujarat", "state_code": "GJ", "region": "West", "lat": 21.1702, "lng": 72.8311, "type": "HO"}, "390001": {"city": "Vadodara", "district": "Vadodara", "state": "Gujarat", "state_code": "GJ", "region": "West", "lat": 22.3072, "lng": 73.1812, "type": "HO"}, "360001": {"city": "Rajkot", "district": "Rajkot", "state": "Gujarat", "state_code": "GJ", "region": "West", "lat": 22.3039, "lng": 70.8022, "type": "HO"}, "462001": {"city": "Bhopal", "district": "Bhopal", "state": "Madhya Pradesh", "state_code": "MP", "region": "Central", "lat": 23.2599, "lng": 77.4126, "type": "HO"}, "452001": {"city": "Indore", "district": "Indore", "state": "Madhya Pradesh", "state_code": "MP", "region": "Central", "lat": 22.7196, "lng": 75.8577, "type": "HO"}, "474001": {"city": "Gwalior", "district": "Gwalior", "state": "Madhya Pradesh", "state_code": "MP", "region": "Central", "lat": 26.2183, "lng": 78.1828, "type": "HO"}, "492001": {"city": "Raipur", "district": "Raipur", "state": "Chhattisgarh", "state_code": "CG", "region": "Central", "lat": 21.2514, "lng": 81.6296, "type": "HO"}, "160001": {"city": "Chandigarh", "district": "Chandigarh", "state": "Chandigarh", "state_code": "CH", "region": "North", "lat": 30.7333, "lng": 76.7794, "type": "HO"}, "141001": {"city": "Ludhiana", "district": "Ludhiana", "state": "Punjab", "state_code": "PB", "region": "North", "lat": 30.901, "lng": 75.8573, "type": "HO"}, "143001": {"city": "Amritsar", "district": "Amritsar", "state": "Punjab", "state_code": "PB", "region": "North", "lat": 31.634, "lng": 74.8723, "type": "HO"}, "122001": {"city": "Gurugram", "district": "Gurugram", "state": "Haryana", "state_code": "HR", "region": "North", "lat": 28.4595, "lng": 77.0266, "type": "HO"}, "121001": {"city": "Faridabad", "district": "Faridabad", "state": "Haryana", "state_code": "HR", "region": "North", "lat": 28.4089, "lng": 77.3178, "type": "HO"}, "695001": {"city": "Thiruvananthapuram", "district": "Thiruvananthapuram", "state": "Kerala", "state_code": "KL", "region": "South", "lat": 8.5241, "lng": 76.9366, "type": "HO"}, "682001": {"city": "Ernakulam", "district": "Ernakulam", "state": "Kerala", "state_code": "KL", "region": "South", "lat": 9.9312, "lng": 76.2673, "type": "HO"}, "673001": {"city": "Kozhikode", "district": "Kozhikode", "state": "Kerala", "state_code": "KL", "region": "South", "lat": 11.2588, "lng": 75.7804, "type": "HO"}, "520001": {"city": "Vijayawada", "district": "Krishna", "state": "Andhra Pradesh", "state_code": "AP", "region": "South", "lat": 16.5062, "lng": 80.648, "type": "HO"}, "530001": {"city": "Visakhapatnam", "district": "Visakhapatnam", "state": "Andhra Pradesh", "state_code": "AP", "region": "South", "lat": 17.6868, "lng": 83.2185, "type": "HO"}, "515001": {"city": "Anantapur", "district": "Anantapur", "state": "Andhra Pradesh", "state_code": "AP", "region": "South", "lat": 14.6819, "lng": 77.6006, "type": "HO"}, "751001": {"city": "Bhubaneswar", "district": "Khordha", "state": "Odisha", "state_code": "OD", "region": "East", "lat": 20.2961, "lng": 85.8245, "type": "HO"}, "753001": {"city": "Cuttack", "district": "Cuttack", "state": "Odisha", "state_code": "OD", "region": "East", "lat": 20.4625, "lng": 85.8828, "type": "HO"}, "781001": {"city": "Guwahati", "district": "Kamrup Metropolitan", "state": "Assam", "state_code": "AS", "region": "Northeast", "lat": 26.1445, "lng": 91.7362, "type": "HO"}, "793001": {"city": "Shillong", "district": "East Khasi Hills", "state": "Meghalaya", "state_code": "ML", "region": "Northeast", "lat": 25.5788, "lng": 91.8933, "type": "HO"}, "796001": {"city": "Aizawl", "district": "Aizawl", "state": "Mizoram", "state_code": "MZ", "region": "Northeast", "lat": 23.7271, "lng": 92.7176, "type": "HO"}, "834001": {"city": "Ranchi", "district": "Ranchi", "state": "Jharkhand", "state_code": "JH", "region": "East", "lat": 23.3441, "lng": 85.3096, "type": "HO"}, "831001": {"city": "Jamshedpur", "district": "East Singhbhum", "state": "Jharkhand", "state_code": "JH", "region": "East", "lat": 22.8046, "lng": 86.2029, "type": "HO"}, "248001": {"city": "Dehradun", "district": "Dehradun", "state": "Uttarakhand", "state_code": "UK", "region": "North", "lat": 30.3165, "lng": 78.0322, "type": "HO"}, "171001": {"city": "Shimla", "district": "Shimla", "state": "Himachal Pradesh", "state_code": "HP", "region": "North", "lat": 31.1048, "lng": 77.1734, "type": "HO"}, "180001": {"city": "Jammu", "district": "Jammu", "state": "Jammu & Kashmir", "state_code": "JK", "region": "North", "lat": 32.7266, "lng": 74.857, "type": "HO"}, "190001": {"city": "Srinagar", "district": "Srinagar", "state": "Jammu & Kashmir", "state_code": "JK", "region": "North", "lat": 34.0837, "lng": 74.7973, "type": "HO"}, "403001": {"city": "Panaji", "district": "North Goa", "state": "Goa", "state_code": "GA", "region": "West", "lat": 15.4909, "lng": 73.8278, "type": "HO"}}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
interface PincodeResult {
|
|
2
|
+
pincode: string;
|
|
3
|
+
city: string;
|
|
4
|
+
district: string;
|
|
5
|
+
state: string;
|
|
6
|
+
state_code: string;
|
|
7
|
+
region: "North" | "South" | "East" | "West" | "Central" | "Northeast";
|
|
8
|
+
lat: number;
|
|
9
|
+
lng: number;
|
|
10
|
+
type: "HO" | "SO" | "BO";
|
|
11
|
+
}
|
|
12
|
+
interface NearbyOptions {
|
|
13
|
+
radiusKm?: number;
|
|
14
|
+
limit?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Lookup a single pincode.
|
|
18
|
+
* Returns null if not found or invalid.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* lookup("400001") // → { city: "Mumbai", state: "Maharashtra", ... }
|
|
22
|
+
*/
|
|
23
|
+
declare function lookup(pincode: string): PincodeResult | null;
|
|
24
|
+
/**
|
|
25
|
+
* Lookup multiple pincodes at once.
|
|
26
|
+
* Returns a Map of pincode → result (null if not found).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* lookupMany(["400001", "560001"])
|
|
30
|
+
*/
|
|
31
|
+
declare function lookupMany(pincodes: string[]): Map<string, PincodeResult | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a pincode is valid (6 digits + exists in dataset).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* isValid("400001") // → true
|
|
37
|
+
* isValid("000000") // → false
|
|
38
|
+
*/
|
|
39
|
+
declare function isValid(pincode: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Get all pincodes for a given city name (case-insensitive).
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* getByCity("Mumbai") // → [{ pincode: "400001", ... }, ...]
|
|
45
|
+
*/
|
|
46
|
+
declare function getByCity(city: string): PincodeResult[];
|
|
47
|
+
/**
|
|
48
|
+
* Get all pincodes for a given state name or state code (case-insensitive).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* getByState("Maharashtra")
|
|
52
|
+
* getByState("MH")
|
|
53
|
+
*/
|
|
54
|
+
declare function getByState(state: string): PincodeResult[];
|
|
55
|
+
/**
|
|
56
|
+
* Get all pincodes in a given district.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* getByDistrict("Patna")
|
|
60
|
+
*/
|
|
61
|
+
declare function getByDistrict(district: string): PincodeResult[];
|
|
62
|
+
/**
|
|
63
|
+
* Get all pincodes in a region.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* getByRegion("South") // → all South India pincodes
|
|
67
|
+
*/
|
|
68
|
+
declare function getByRegion(region: PincodeResult["region"]): PincodeResult[];
|
|
69
|
+
/**
|
|
70
|
+
* Find nearby pincodes within a radius from a given pincode.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* nearby("400001", { radiusKm: 10, limit: 5 })
|
|
74
|
+
*/
|
|
75
|
+
declare function nearby(pincode: string, options?: NearbyOptions): PincodeResult[];
|
|
76
|
+
/**
|
|
77
|
+
* Get distance in km between two pincodes.
|
|
78
|
+
* Returns null if either pincode is invalid.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* distanceBetween("400001", "411001") // → 148.7
|
|
82
|
+
*/
|
|
83
|
+
declare function distanceBetween(pincode1: string, pincode2: string): number | null;
|
|
84
|
+
/**
|
|
85
|
+
* Validate format only (6 digits) without checking the dataset.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* isValidFormat("400001") // → true
|
|
89
|
+
* isValidFormat("40001") // → false
|
|
90
|
+
*/
|
|
91
|
+
declare function isValidFormat(pincode: string): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Get all unique states in the dataset.
|
|
94
|
+
*/
|
|
95
|
+
declare function getAllStates(): {
|
|
96
|
+
state: string;
|
|
97
|
+
state_code: string;
|
|
98
|
+
}[];
|
|
99
|
+
/**
|
|
100
|
+
* Search pincodes by partial city, district, or state name.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* search("banga") // → matches Bengaluru
|
|
104
|
+
*/
|
|
105
|
+
declare function search(query: string): PincodeResult[];
|
|
106
|
+
declare const pincode: {
|
|
107
|
+
lookup: typeof lookup;
|
|
108
|
+
lookupMany: typeof lookupMany;
|
|
109
|
+
isValid: typeof isValid;
|
|
110
|
+
isValidFormat: typeof isValidFormat;
|
|
111
|
+
getByCity: typeof getByCity;
|
|
112
|
+
getByState: typeof getByState;
|
|
113
|
+
getByDistrict: typeof getByDistrict;
|
|
114
|
+
getByRegion: typeof getByRegion;
|
|
115
|
+
nearby: typeof nearby;
|
|
116
|
+
distanceBetween: typeof distanceBetween;
|
|
117
|
+
getAllStates: typeof getAllStates;
|
|
118
|
+
search: typeof search;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export { type NearbyOptions, type PincodeResult, pincode as default, distanceBetween, getAllStates, getByCity, getByDistrict, getByRegion, getByState, isValid, isValidFormat, lookup, lookupMany, nearby, search };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
interface PincodeResult {
|
|
2
|
+
pincode: string;
|
|
3
|
+
city: string;
|
|
4
|
+
district: string;
|
|
5
|
+
state: string;
|
|
6
|
+
state_code: string;
|
|
7
|
+
region: "North" | "South" | "East" | "West" | "Central" | "Northeast";
|
|
8
|
+
lat: number;
|
|
9
|
+
lng: number;
|
|
10
|
+
type: "HO" | "SO" | "BO";
|
|
11
|
+
}
|
|
12
|
+
interface NearbyOptions {
|
|
13
|
+
radiusKm?: number;
|
|
14
|
+
limit?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Lookup a single pincode.
|
|
18
|
+
* Returns null if not found or invalid.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* lookup("400001") // → { city: "Mumbai", state: "Maharashtra", ... }
|
|
22
|
+
*/
|
|
23
|
+
declare function lookup(pincode: string): PincodeResult | null;
|
|
24
|
+
/**
|
|
25
|
+
* Lookup multiple pincodes at once.
|
|
26
|
+
* Returns a Map of pincode → result (null if not found).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* lookupMany(["400001", "560001"])
|
|
30
|
+
*/
|
|
31
|
+
declare function lookupMany(pincodes: string[]): Map<string, PincodeResult | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a pincode is valid (6 digits + exists in dataset).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* isValid("400001") // → true
|
|
37
|
+
* isValid("000000") // → false
|
|
38
|
+
*/
|
|
39
|
+
declare function isValid(pincode: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Get all pincodes for a given city name (case-insensitive).
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* getByCity("Mumbai") // → [{ pincode: "400001", ... }, ...]
|
|
45
|
+
*/
|
|
46
|
+
declare function getByCity(city: string): PincodeResult[];
|
|
47
|
+
/**
|
|
48
|
+
* Get all pincodes for a given state name or state code (case-insensitive).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* getByState("Maharashtra")
|
|
52
|
+
* getByState("MH")
|
|
53
|
+
*/
|
|
54
|
+
declare function getByState(state: string): PincodeResult[];
|
|
55
|
+
/**
|
|
56
|
+
* Get all pincodes in a given district.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* getByDistrict("Patna")
|
|
60
|
+
*/
|
|
61
|
+
declare function getByDistrict(district: string): PincodeResult[];
|
|
62
|
+
/**
|
|
63
|
+
* Get all pincodes in a region.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* getByRegion("South") // → all South India pincodes
|
|
67
|
+
*/
|
|
68
|
+
declare function getByRegion(region: PincodeResult["region"]): PincodeResult[];
|
|
69
|
+
/**
|
|
70
|
+
* Find nearby pincodes within a radius from a given pincode.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* nearby("400001", { radiusKm: 10, limit: 5 })
|
|
74
|
+
*/
|
|
75
|
+
declare function nearby(pincode: string, options?: NearbyOptions): PincodeResult[];
|
|
76
|
+
/**
|
|
77
|
+
* Get distance in km between two pincodes.
|
|
78
|
+
* Returns null if either pincode is invalid.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* distanceBetween("400001", "411001") // → 148.7
|
|
82
|
+
*/
|
|
83
|
+
declare function distanceBetween(pincode1: string, pincode2: string): number | null;
|
|
84
|
+
/**
|
|
85
|
+
* Validate format only (6 digits) without checking the dataset.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* isValidFormat("400001") // → true
|
|
89
|
+
* isValidFormat("40001") // → false
|
|
90
|
+
*/
|
|
91
|
+
declare function isValidFormat(pincode: string): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Get all unique states in the dataset.
|
|
94
|
+
*/
|
|
95
|
+
declare function getAllStates(): {
|
|
96
|
+
state: string;
|
|
97
|
+
state_code: string;
|
|
98
|
+
}[];
|
|
99
|
+
/**
|
|
100
|
+
* Search pincodes by partial city, district, or state name.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* search("banga") // → matches Bengaluru
|
|
104
|
+
*/
|
|
105
|
+
declare function search(query: string): PincodeResult[];
|
|
106
|
+
declare const pincode: {
|
|
107
|
+
lookup: typeof lookup;
|
|
108
|
+
lookupMany: typeof lookupMany;
|
|
109
|
+
isValid: typeof isValid;
|
|
110
|
+
isValidFormat: typeof isValidFormat;
|
|
111
|
+
getByCity: typeof getByCity;
|
|
112
|
+
getByState: typeof getByState;
|
|
113
|
+
getByDistrict: typeof getByDistrict;
|
|
114
|
+
getByRegion: typeof getByRegion;
|
|
115
|
+
nearby: typeof nearby;
|
|
116
|
+
distanceBetween: typeof distanceBetween;
|
|
117
|
+
getAllStates: typeof getAllStates;
|
|
118
|
+
search: typeof search;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export { type NearbyOptions, type PincodeResult, pincode as default, distanceBetween, getAllStates, getByCity, getByDistrict, getByRegion, getByState, isValid, isValidFormat, lookup, lookupMany, nearby, search };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
default: () => index_default,
|
|
24
|
+
distanceBetween: () => distanceBetween,
|
|
25
|
+
getAllStates: () => getAllStates,
|
|
26
|
+
getByCity: () => getByCity,
|
|
27
|
+
getByDistrict: () => getByDistrict,
|
|
28
|
+
getByRegion: () => getByRegion,
|
|
29
|
+
getByState: () => getByState,
|
|
30
|
+
isValid: () => isValid,
|
|
31
|
+
isValidFormat: () => isValidFormat,
|
|
32
|
+
lookup: () => lookup,
|
|
33
|
+
lookupMany: () => lookupMany,
|
|
34
|
+
nearby: () => nearby,
|
|
35
|
+
search: () => search
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// data/pincodes.json
|
|
40
|
+
var pincodes_default = { "110001": { city: "New Delhi", district: "Central Delhi", state: "Delhi", state_code: "DL", region: "North", lat: 28.6139, lng: 77.209, type: "HO" }, "110002": { city: "Delhi", district: "Central Delhi", state: "Delhi", state_code: "DL", region: "North", lat: 28.6328, lng: 77.2197, type: "SO" }, "110011": { city: "New Delhi", district: "South Delhi", state: "Delhi", state_code: "DL", region: "North", lat: 28.5918, lng: 77.1674, type: "SO" }, "110048": { city: "New Delhi", district: "South West Delhi", state: "Delhi", state_code: "DL", region: "North", lat: 28.5245, lng: 77.1855, type: "SO" }, "110092": { city: "Delhi", district: "East Delhi", state: "Delhi", state_code: "DL", region: "North", lat: 28.6692, lng: 77.3005, type: "SO" }, "400001": { city: "Mumbai", district: "Mumbai City", state: "Maharashtra", state_code: "MH", region: "West", lat: 18.9388, lng: 72.8354, type: "HO" }, "400051": { city: "Mumbai", district: "Mumbai Suburban", state: "Maharashtra", state_code: "MH", region: "West", lat: 19.0596, lng: 72.8295, type: "SO" }, "400076": { city: "Mumbai", district: "Mumbai Suburban", state: "Maharashtra", state_code: "MH", region: "West", lat: 19.1136, lng: 72.8697, type: "SO" }, "411001": { city: "Pune", district: "Pune", state: "Maharashtra", state_code: "MH", region: "West", lat: 18.5204, lng: 73.8567, type: "HO" }, "411014": { city: "Pune", district: "Pune", state: "Maharashtra", state_code: "MH", region: "West", lat: 18.5642, lng: 73.914, type: "SO" }, "440001": { city: "Nagpur", district: "Nagpur", state: "Maharashtra", state_code: "MH", region: "West", lat: 21.1458, lng: 79.0882, type: "HO" }, "431001": { city: "Aurangabad", district: "Aurangabad", state: "Maharashtra", state_code: "MH", region: "West", lat: 19.8762, lng: 75.3433, type: "HO" }, "560001": { city: "Bengaluru", district: "Bengaluru Urban", state: "Karnataka", state_code: "KA", region: "South", lat: 12.9716, lng: 77.5946, type: "HO" }, "560029": { city: "Bengaluru", district: "Bengaluru Urban", state: "Karnataka", state_code: "KA", region: "South", lat: 12.925, lng: 77.5938, type: "SO" }, "560034": { city: "Bengaluru", district: "Bengaluru Urban", state: "Karnataka", state_code: "KA", region: "South", lat: 12.9352, lng: 77.6245, type: "SO" }, "560066": { city: "Bengaluru", district: "Bengaluru Urban", state: "Karnataka", state_code: "KA", region: "South", lat: 13.0358, lng: 77.597, type: "SO" }, "570001": { city: "Mysuru", district: "Mysuru", state: "Karnataka", state_code: "KA", region: "South", lat: 12.2958, lng: 76.6394, type: "HO" }, "580001": { city: "Hubli", district: "Dharwad", state: "Karnataka", state_code: "KA", region: "South", lat: 15.3647, lng: 75.124, type: "HO" }, "600001": { city: "Chennai", district: "Chennai", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 13.0827, lng: 80.2707, type: "HO" }, "600020": { city: "Chennai", district: "Chennai", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 13.0569, lng: 80.2425, type: "SO" }, "600042": { city: "Chennai", district: "Chennai", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 13.0067, lng: 80.2206, type: "SO" }, "641001": { city: "Coimbatore", district: "Coimbatore", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 11.0168, lng: 76.9558, type: "HO" }, "625001": { city: "Madurai", district: "Madurai", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 9.9252, lng: 78.1198, type: "HO" }, "620001": { city: "Tiruchirappalli", district: "Tiruchirappalli", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 10.7905, lng: 78.7047, type: "HO" }, "500001": { city: "Hyderabad", district: "Hyderabad", state: "Telangana", state_code: "TS", region: "South", lat: 17.385, lng: 78.4867, type: "HO" }, "500018": { city: "Hyderabad", district: "Hyderabad", state: "Telangana", state_code: "TS", region: "South", lat: 17.44, lng: 78.3489, type: "SO" }, "500081": { city: "Hyderabad", district: "Rangareddy", state: "Telangana", state_code: "TS", region: "South", lat: 17.4947, lng: 78.3996, type: "SO" }, "506001": { city: "Warangal", district: "Warangal Urban", state: "Telangana", state_code: "TS", region: "South", lat: 17.9784, lng: 79.5941, type: "HO" }, "226001": { city: "Lucknow", district: "Lucknow", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 26.8467, lng: 80.9462, type: "HO" }, "226010": { city: "Lucknow", district: "Lucknow", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 26.8631, lng: 80.9176, type: "SO" }, "208001": { city: "Kanpur", district: "Kanpur Nagar", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 26.4499, lng: 80.3319, type: "HO" }, "201301": { city: "Noida", district: "Gautam Buddha Nagar", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 28.5355, lng: 77.391, type: "HO" }, "211001": { city: "Prayagraj", district: "Prayagraj", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 25.4358, lng: 81.8463, type: "HO" }, "221001": { city: "Varanasi", district: "Varanasi", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 25.3176, lng: 82.9739, type: "HO" }, "282001": { city: "Agra", district: "Agra", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 27.1767, lng: 78.0081, type: "HO" }, "800001": { city: "Patna", district: "Patna", state: "Bihar", state_code: "BR", region: "East", lat: 25.5941, lng: 85.1376, type: "HO" }, "800020": { city: "Patna", district: "Patna", state: "Bihar", state_code: "BR", region: "East", lat: 25.6138, lng: 85.0783, type: "SO" }, "842001": { city: "Muzaffarpur", district: "Muzaffarpur", state: "Bihar", state_code: "BR", region: "East", lat: 26.1209, lng: 85.3647, type: "HO" }, "843302": { city: "Sitamarhi", district: "Sitamarhi", state: "Bihar", state_code: "BR", region: "East", lat: 26.5942, lng: 85.489, type: "HO" }, "824101": { city: "Gaya", district: "Gaya", state: "Bihar", state_code: "BR", region: "East", lat: 24.7914, lng: 85.0002, type: "HO" }, "700001": { city: "Kolkata", district: "Kolkata", state: "West Bengal", state_code: "WB", region: "East", lat: 22.5726, lng: 88.3639, type: "HO" }, "700019": { city: "Kolkata", district: "Kolkata", state: "West Bengal", state_code: "WB", region: "East", lat: 22.5093, lng: 88.3639, type: "SO" }, "700091": { city: "Kolkata", district: "North 24 Parganas", state: "West Bengal", state_code: "WB", region: "East", lat: 22.6467, lng: 88.4296, type: "SO" }, "713101": { city: "Burdwan", district: "Purba Bardhaman", state: "West Bengal", state_code: "WB", region: "East", lat: 23.2324, lng: 87.8615, type: "HO" }, "302001": { city: "Jaipur", district: "Jaipur", state: "Rajasthan", state_code: "RJ", region: "North", lat: 26.9124, lng: 75.7873, type: "HO" }, "302017": { city: "Jaipur", district: "Jaipur", state: "Rajasthan", state_code: "RJ", region: "North", lat: 26.8742, lng: 75.8074, type: "SO" }, "342001": { city: "Jodhpur", district: "Jodhpur", state: "Rajasthan", state_code: "RJ", region: "North", lat: 26.2389, lng: 73.0243, type: "HO" }, "313001": { city: "Udaipur", district: "Udaipur", state: "Rajasthan", state_code: "RJ", region: "North", lat: 24.5854, lng: 73.7125, type: "HO" }, "334001": { city: "Bikaner", district: "Bikaner", state: "Rajasthan", state_code: "RJ", region: "North", lat: 28.0229, lng: 73.3119, type: "HO" }, "380001": { city: "Ahmedabad", district: "Ahmedabad", state: "Gujarat", state_code: "GJ", region: "West", lat: 23.0225, lng: 72.5714, type: "HO" }, "380015": { city: "Ahmedabad", district: "Ahmedabad", state: "Gujarat", state_code: "GJ", region: "West", lat: 23.0376, lng: 72.5269, type: "SO" }, "395001": { city: "Surat", district: "Surat", state: "Gujarat", state_code: "GJ", region: "West", lat: 21.1702, lng: 72.8311, type: "HO" }, "390001": { city: "Vadodara", district: "Vadodara", state: "Gujarat", state_code: "GJ", region: "West", lat: 22.3072, lng: 73.1812, type: "HO" }, "360001": { city: "Rajkot", district: "Rajkot", state: "Gujarat", state_code: "GJ", region: "West", lat: 22.3039, lng: 70.8022, type: "HO" }, "462001": { city: "Bhopal", district: "Bhopal", state: "Madhya Pradesh", state_code: "MP", region: "Central", lat: 23.2599, lng: 77.4126, type: "HO" }, "452001": { city: "Indore", district: "Indore", state: "Madhya Pradesh", state_code: "MP", region: "Central", lat: 22.7196, lng: 75.8577, type: "HO" }, "474001": { city: "Gwalior", district: "Gwalior", state: "Madhya Pradesh", state_code: "MP", region: "Central", lat: 26.2183, lng: 78.1828, type: "HO" }, "492001": { city: "Raipur", district: "Raipur", state: "Chhattisgarh", state_code: "CG", region: "Central", lat: 21.2514, lng: 81.6296, type: "HO" }, "160001": { city: "Chandigarh", district: "Chandigarh", state: "Chandigarh", state_code: "CH", region: "North", lat: 30.7333, lng: 76.7794, type: "HO" }, "141001": { city: "Ludhiana", district: "Ludhiana", state: "Punjab", state_code: "PB", region: "North", lat: 30.901, lng: 75.8573, type: "HO" }, "143001": { city: "Amritsar", district: "Amritsar", state: "Punjab", state_code: "PB", region: "North", lat: 31.634, lng: 74.8723, type: "HO" }, "122001": { city: "Gurugram", district: "Gurugram", state: "Haryana", state_code: "HR", region: "North", lat: 28.4595, lng: 77.0266, type: "HO" }, "121001": { city: "Faridabad", district: "Faridabad", state: "Haryana", state_code: "HR", region: "North", lat: 28.4089, lng: 77.3178, type: "HO" }, "695001": { city: "Thiruvananthapuram", district: "Thiruvananthapuram", state: "Kerala", state_code: "KL", region: "South", lat: 8.5241, lng: 76.9366, type: "HO" }, "682001": { city: "Ernakulam", district: "Ernakulam", state: "Kerala", state_code: "KL", region: "South", lat: 9.9312, lng: 76.2673, type: "HO" }, "673001": { city: "Kozhikode", district: "Kozhikode", state: "Kerala", state_code: "KL", region: "South", lat: 11.2588, lng: 75.7804, type: "HO" }, "520001": { city: "Vijayawada", district: "Krishna", state: "Andhra Pradesh", state_code: "AP", region: "South", lat: 16.5062, lng: 80.648, type: "HO" }, "530001": { city: "Visakhapatnam", district: "Visakhapatnam", state: "Andhra Pradesh", state_code: "AP", region: "South", lat: 17.6868, lng: 83.2185, type: "HO" }, "515001": { city: "Anantapur", district: "Anantapur", state: "Andhra Pradesh", state_code: "AP", region: "South", lat: 14.6819, lng: 77.6006, type: "HO" }, "751001": { city: "Bhubaneswar", district: "Khordha", state: "Odisha", state_code: "OD", region: "East", lat: 20.2961, lng: 85.8245, type: "HO" }, "753001": { city: "Cuttack", district: "Cuttack", state: "Odisha", state_code: "OD", region: "East", lat: 20.4625, lng: 85.8828, type: "HO" }, "781001": { city: "Guwahati", district: "Kamrup Metropolitan", state: "Assam", state_code: "AS", region: "Northeast", lat: 26.1445, lng: 91.7362, type: "HO" }, "793001": { city: "Shillong", district: "East Khasi Hills", state: "Meghalaya", state_code: "ML", region: "Northeast", lat: 25.5788, lng: 91.8933, type: "HO" }, "796001": { city: "Aizawl", district: "Aizawl", state: "Mizoram", state_code: "MZ", region: "Northeast", lat: 23.7271, lng: 92.7176, type: "HO" }, "834001": { city: "Ranchi", district: "Ranchi", state: "Jharkhand", state_code: "JH", region: "East", lat: 23.3441, lng: 85.3096, type: "HO" }, "831001": { city: "Jamshedpur", district: "East Singhbhum", state: "Jharkhand", state_code: "JH", region: "East", lat: 22.8046, lng: 86.2029, type: "HO" }, "248001": { city: "Dehradun", district: "Dehradun", state: "Uttarakhand", state_code: "UK", region: "North", lat: 30.3165, lng: 78.0322, type: "HO" }, "171001": { city: "Shimla", district: "Shimla", state: "Himachal Pradesh", state_code: "HP", region: "North", lat: 31.1048, lng: 77.1734, type: "HO" }, "180001": { city: "Jammu", district: "Jammu", state: "Jammu & Kashmir", state_code: "JK", region: "North", lat: 32.7266, lng: 74.857, type: "HO" }, "190001": { city: "Srinagar", district: "Srinagar", state: "Jammu & Kashmir", state_code: "JK", region: "North", lat: 34.0837, lng: 74.7973, type: "HO" }, "403001": { city: "Panaji", district: "North Goa", state: "Goa", state_code: "GA", region: "West", lat: 15.4909, lng: 73.8278, type: "HO" } };
|
|
41
|
+
|
|
42
|
+
// src/index.ts
|
|
43
|
+
var db = pincodes_default;
|
|
44
|
+
function isValidPincode(pin) {
|
|
45
|
+
return /^\d{6}$/.test(pin.trim());
|
|
46
|
+
}
|
|
47
|
+
function haversineKm(lat1, lng1, lat2, lng2) {
|
|
48
|
+
const R = 6371;
|
|
49
|
+
const dLat = (lat2 - lat1) * Math.PI / 180;
|
|
50
|
+
const dLng = (lng2 - lng1) * Math.PI / 180;
|
|
51
|
+
const a = Math.sin(dLat / 2) ** 2 + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * Math.sin(dLng / 2) ** 2;
|
|
52
|
+
return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
53
|
+
}
|
|
54
|
+
function toResult(pin, val) {
|
|
55
|
+
return { pincode: pin, ...val };
|
|
56
|
+
}
|
|
57
|
+
function lookup(pincode2) {
|
|
58
|
+
const pin = pincode2.trim();
|
|
59
|
+
if (!isValidPincode(pin)) return null;
|
|
60
|
+
const entry = db[pin];
|
|
61
|
+
return entry ? toResult(pin, entry) : null;
|
|
62
|
+
}
|
|
63
|
+
function lookupMany(pincodes) {
|
|
64
|
+
const result = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const p of pincodes) {
|
|
66
|
+
result.set(p, lookup(p));
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
function isValid(pincode2) {
|
|
71
|
+
return lookup(pincode2) !== null;
|
|
72
|
+
}
|
|
73
|
+
function getByCity(city) {
|
|
74
|
+
const q = city.toLowerCase().trim();
|
|
75
|
+
return Object.entries(db).filter(([, v]) => v.city.toLowerCase().includes(q)).map(([pin, val]) => toResult(pin, val));
|
|
76
|
+
}
|
|
77
|
+
function getByState(state) {
|
|
78
|
+
const q = state.toLowerCase().trim();
|
|
79
|
+
return Object.entries(db).filter(
|
|
80
|
+
([, v]) => v.state.toLowerCase().includes(q) || v.state_code.toLowerCase() === q
|
|
81
|
+
).map(([pin, val]) => toResult(pin, val));
|
|
82
|
+
}
|
|
83
|
+
function getByDistrict(district) {
|
|
84
|
+
const q = district.toLowerCase().trim();
|
|
85
|
+
return Object.entries(db).filter(([, v]) => v.district.toLowerCase().includes(q)).map(([pin, val]) => toResult(pin, val));
|
|
86
|
+
}
|
|
87
|
+
function getByRegion(region) {
|
|
88
|
+
return Object.entries(db).filter(([, v]) => v.region === region).map(([pin, val]) => toResult(pin, val));
|
|
89
|
+
}
|
|
90
|
+
function nearby(pincode2, options = {}) {
|
|
91
|
+
const { radiusKm = 20, limit = 10 } = options;
|
|
92
|
+
const origin = lookup(pincode2);
|
|
93
|
+
if (!origin) return [];
|
|
94
|
+
return Object.entries(db).filter(([pin]) => pin !== pincode2).map(([pin, val]) => ({
|
|
95
|
+
result: toResult(pin, val),
|
|
96
|
+
dist: haversineKm(origin.lat, origin.lng, val.lat, val.lng)
|
|
97
|
+
})).filter(({ dist }) => dist <= radiusKm).sort((a, b) => a.dist - b.dist).slice(0, limit).map(({ result }) => result);
|
|
98
|
+
}
|
|
99
|
+
function distanceBetween(pincode1, pincode2) {
|
|
100
|
+
const a = lookup(pincode1);
|
|
101
|
+
const b = lookup(pincode2);
|
|
102
|
+
if (!a || !b) return null;
|
|
103
|
+
return parseFloat(haversineKm(a.lat, a.lng, b.lat, b.lng).toFixed(2));
|
|
104
|
+
}
|
|
105
|
+
function isValidFormat(pincode2) {
|
|
106
|
+
return isValidPincode(pincode2);
|
|
107
|
+
}
|
|
108
|
+
function getAllStates() {
|
|
109
|
+
const seen = /* @__PURE__ */ new Map();
|
|
110
|
+
for (const v of Object.values(db)) {
|
|
111
|
+
if (!seen.has(v.state_code)) seen.set(v.state_code, v.state);
|
|
112
|
+
}
|
|
113
|
+
return Array.from(seen.entries()).map(([state_code, state]) => ({ state, state_code })).sort((a, b) => a.state.localeCompare(b.state));
|
|
114
|
+
}
|
|
115
|
+
function search(query) {
|
|
116
|
+
const q = query.toLowerCase().trim();
|
|
117
|
+
if (q.length < 2) return [];
|
|
118
|
+
return Object.entries(db).filter(
|
|
119
|
+
([pin, v]) => pin.startsWith(q) || v.city.toLowerCase().includes(q) || v.district.toLowerCase().includes(q) || v.state.toLowerCase().includes(q)
|
|
120
|
+
).map(([pin, val]) => toResult(pin, val));
|
|
121
|
+
}
|
|
122
|
+
var pincode = {
|
|
123
|
+
lookup,
|
|
124
|
+
lookupMany,
|
|
125
|
+
isValid,
|
|
126
|
+
isValidFormat,
|
|
127
|
+
getByCity,
|
|
128
|
+
getByState,
|
|
129
|
+
getByDistrict,
|
|
130
|
+
getByRegion,
|
|
131
|
+
nearby,
|
|
132
|
+
distanceBetween,
|
|
133
|
+
getAllStates,
|
|
134
|
+
search
|
|
135
|
+
};
|
|
136
|
+
var index_default = pincode;
|
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
+
0 && (module.exports = {
|
|
139
|
+
distanceBetween,
|
|
140
|
+
getAllStates,
|
|
141
|
+
getByCity,
|
|
142
|
+
getByDistrict,
|
|
143
|
+
getByRegion,
|
|
144
|
+
getByState,
|
|
145
|
+
isValid,
|
|
146
|
+
isValidFormat,
|
|
147
|
+
lookup,
|
|
148
|
+
lookupMany,
|
|
149
|
+
nearby,
|
|
150
|
+
search
|
|
151
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// data/pincodes.json
|
|
2
|
+
var pincodes_default = { "110001": { city: "New Delhi", district: "Central Delhi", state: "Delhi", state_code: "DL", region: "North", lat: 28.6139, lng: 77.209, type: "HO" }, "110002": { city: "Delhi", district: "Central Delhi", state: "Delhi", state_code: "DL", region: "North", lat: 28.6328, lng: 77.2197, type: "SO" }, "110011": { city: "New Delhi", district: "South Delhi", state: "Delhi", state_code: "DL", region: "North", lat: 28.5918, lng: 77.1674, type: "SO" }, "110048": { city: "New Delhi", district: "South West Delhi", state: "Delhi", state_code: "DL", region: "North", lat: 28.5245, lng: 77.1855, type: "SO" }, "110092": { city: "Delhi", district: "East Delhi", state: "Delhi", state_code: "DL", region: "North", lat: 28.6692, lng: 77.3005, type: "SO" }, "400001": { city: "Mumbai", district: "Mumbai City", state: "Maharashtra", state_code: "MH", region: "West", lat: 18.9388, lng: 72.8354, type: "HO" }, "400051": { city: "Mumbai", district: "Mumbai Suburban", state: "Maharashtra", state_code: "MH", region: "West", lat: 19.0596, lng: 72.8295, type: "SO" }, "400076": { city: "Mumbai", district: "Mumbai Suburban", state: "Maharashtra", state_code: "MH", region: "West", lat: 19.1136, lng: 72.8697, type: "SO" }, "411001": { city: "Pune", district: "Pune", state: "Maharashtra", state_code: "MH", region: "West", lat: 18.5204, lng: 73.8567, type: "HO" }, "411014": { city: "Pune", district: "Pune", state: "Maharashtra", state_code: "MH", region: "West", lat: 18.5642, lng: 73.914, type: "SO" }, "440001": { city: "Nagpur", district: "Nagpur", state: "Maharashtra", state_code: "MH", region: "West", lat: 21.1458, lng: 79.0882, type: "HO" }, "431001": { city: "Aurangabad", district: "Aurangabad", state: "Maharashtra", state_code: "MH", region: "West", lat: 19.8762, lng: 75.3433, type: "HO" }, "560001": { city: "Bengaluru", district: "Bengaluru Urban", state: "Karnataka", state_code: "KA", region: "South", lat: 12.9716, lng: 77.5946, type: "HO" }, "560029": { city: "Bengaluru", district: "Bengaluru Urban", state: "Karnataka", state_code: "KA", region: "South", lat: 12.925, lng: 77.5938, type: "SO" }, "560034": { city: "Bengaluru", district: "Bengaluru Urban", state: "Karnataka", state_code: "KA", region: "South", lat: 12.9352, lng: 77.6245, type: "SO" }, "560066": { city: "Bengaluru", district: "Bengaluru Urban", state: "Karnataka", state_code: "KA", region: "South", lat: 13.0358, lng: 77.597, type: "SO" }, "570001": { city: "Mysuru", district: "Mysuru", state: "Karnataka", state_code: "KA", region: "South", lat: 12.2958, lng: 76.6394, type: "HO" }, "580001": { city: "Hubli", district: "Dharwad", state: "Karnataka", state_code: "KA", region: "South", lat: 15.3647, lng: 75.124, type: "HO" }, "600001": { city: "Chennai", district: "Chennai", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 13.0827, lng: 80.2707, type: "HO" }, "600020": { city: "Chennai", district: "Chennai", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 13.0569, lng: 80.2425, type: "SO" }, "600042": { city: "Chennai", district: "Chennai", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 13.0067, lng: 80.2206, type: "SO" }, "641001": { city: "Coimbatore", district: "Coimbatore", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 11.0168, lng: 76.9558, type: "HO" }, "625001": { city: "Madurai", district: "Madurai", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 9.9252, lng: 78.1198, type: "HO" }, "620001": { city: "Tiruchirappalli", district: "Tiruchirappalli", state: "Tamil Nadu", state_code: "TN", region: "South", lat: 10.7905, lng: 78.7047, type: "HO" }, "500001": { city: "Hyderabad", district: "Hyderabad", state: "Telangana", state_code: "TS", region: "South", lat: 17.385, lng: 78.4867, type: "HO" }, "500018": { city: "Hyderabad", district: "Hyderabad", state: "Telangana", state_code: "TS", region: "South", lat: 17.44, lng: 78.3489, type: "SO" }, "500081": { city: "Hyderabad", district: "Rangareddy", state: "Telangana", state_code: "TS", region: "South", lat: 17.4947, lng: 78.3996, type: "SO" }, "506001": { city: "Warangal", district: "Warangal Urban", state: "Telangana", state_code: "TS", region: "South", lat: 17.9784, lng: 79.5941, type: "HO" }, "226001": { city: "Lucknow", district: "Lucknow", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 26.8467, lng: 80.9462, type: "HO" }, "226010": { city: "Lucknow", district: "Lucknow", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 26.8631, lng: 80.9176, type: "SO" }, "208001": { city: "Kanpur", district: "Kanpur Nagar", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 26.4499, lng: 80.3319, type: "HO" }, "201301": { city: "Noida", district: "Gautam Buddha Nagar", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 28.5355, lng: 77.391, type: "HO" }, "211001": { city: "Prayagraj", district: "Prayagraj", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 25.4358, lng: 81.8463, type: "HO" }, "221001": { city: "Varanasi", district: "Varanasi", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 25.3176, lng: 82.9739, type: "HO" }, "282001": { city: "Agra", district: "Agra", state: "Uttar Pradesh", state_code: "UP", region: "North", lat: 27.1767, lng: 78.0081, type: "HO" }, "800001": { city: "Patna", district: "Patna", state: "Bihar", state_code: "BR", region: "East", lat: 25.5941, lng: 85.1376, type: "HO" }, "800020": { city: "Patna", district: "Patna", state: "Bihar", state_code: "BR", region: "East", lat: 25.6138, lng: 85.0783, type: "SO" }, "842001": { city: "Muzaffarpur", district: "Muzaffarpur", state: "Bihar", state_code: "BR", region: "East", lat: 26.1209, lng: 85.3647, type: "HO" }, "843302": { city: "Sitamarhi", district: "Sitamarhi", state: "Bihar", state_code: "BR", region: "East", lat: 26.5942, lng: 85.489, type: "HO" }, "824101": { city: "Gaya", district: "Gaya", state: "Bihar", state_code: "BR", region: "East", lat: 24.7914, lng: 85.0002, type: "HO" }, "700001": { city: "Kolkata", district: "Kolkata", state: "West Bengal", state_code: "WB", region: "East", lat: 22.5726, lng: 88.3639, type: "HO" }, "700019": { city: "Kolkata", district: "Kolkata", state: "West Bengal", state_code: "WB", region: "East", lat: 22.5093, lng: 88.3639, type: "SO" }, "700091": { city: "Kolkata", district: "North 24 Parganas", state: "West Bengal", state_code: "WB", region: "East", lat: 22.6467, lng: 88.4296, type: "SO" }, "713101": { city: "Burdwan", district: "Purba Bardhaman", state: "West Bengal", state_code: "WB", region: "East", lat: 23.2324, lng: 87.8615, type: "HO" }, "302001": { city: "Jaipur", district: "Jaipur", state: "Rajasthan", state_code: "RJ", region: "North", lat: 26.9124, lng: 75.7873, type: "HO" }, "302017": { city: "Jaipur", district: "Jaipur", state: "Rajasthan", state_code: "RJ", region: "North", lat: 26.8742, lng: 75.8074, type: "SO" }, "342001": { city: "Jodhpur", district: "Jodhpur", state: "Rajasthan", state_code: "RJ", region: "North", lat: 26.2389, lng: 73.0243, type: "HO" }, "313001": { city: "Udaipur", district: "Udaipur", state: "Rajasthan", state_code: "RJ", region: "North", lat: 24.5854, lng: 73.7125, type: "HO" }, "334001": { city: "Bikaner", district: "Bikaner", state: "Rajasthan", state_code: "RJ", region: "North", lat: 28.0229, lng: 73.3119, type: "HO" }, "380001": { city: "Ahmedabad", district: "Ahmedabad", state: "Gujarat", state_code: "GJ", region: "West", lat: 23.0225, lng: 72.5714, type: "HO" }, "380015": { city: "Ahmedabad", district: "Ahmedabad", state: "Gujarat", state_code: "GJ", region: "West", lat: 23.0376, lng: 72.5269, type: "SO" }, "395001": { city: "Surat", district: "Surat", state: "Gujarat", state_code: "GJ", region: "West", lat: 21.1702, lng: 72.8311, type: "HO" }, "390001": { city: "Vadodara", district: "Vadodara", state: "Gujarat", state_code: "GJ", region: "West", lat: 22.3072, lng: 73.1812, type: "HO" }, "360001": { city: "Rajkot", district: "Rajkot", state: "Gujarat", state_code: "GJ", region: "West", lat: 22.3039, lng: 70.8022, type: "HO" }, "462001": { city: "Bhopal", district: "Bhopal", state: "Madhya Pradesh", state_code: "MP", region: "Central", lat: 23.2599, lng: 77.4126, type: "HO" }, "452001": { city: "Indore", district: "Indore", state: "Madhya Pradesh", state_code: "MP", region: "Central", lat: 22.7196, lng: 75.8577, type: "HO" }, "474001": { city: "Gwalior", district: "Gwalior", state: "Madhya Pradesh", state_code: "MP", region: "Central", lat: 26.2183, lng: 78.1828, type: "HO" }, "492001": { city: "Raipur", district: "Raipur", state: "Chhattisgarh", state_code: "CG", region: "Central", lat: 21.2514, lng: 81.6296, type: "HO" }, "160001": { city: "Chandigarh", district: "Chandigarh", state: "Chandigarh", state_code: "CH", region: "North", lat: 30.7333, lng: 76.7794, type: "HO" }, "141001": { city: "Ludhiana", district: "Ludhiana", state: "Punjab", state_code: "PB", region: "North", lat: 30.901, lng: 75.8573, type: "HO" }, "143001": { city: "Amritsar", district: "Amritsar", state: "Punjab", state_code: "PB", region: "North", lat: 31.634, lng: 74.8723, type: "HO" }, "122001": { city: "Gurugram", district: "Gurugram", state: "Haryana", state_code: "HR", region: "North", lat: 28.4595, lng: 77.0266, type: "HO" }, "121001": { city: "Faridabad", district: "Faridabad", state: "Haryana", state_code: "HR", region: "North", lat: 28.4089, lng: 77.3178, type: "HO" }, "695001": { city: "Thiruvananthapuram", district: "Thiruvananthapuram", state: "Kerala", state_code: "KL", region: "South", lat: 8.5241, lng: 76.9366, type: "HO" }, "682001": { city: "Ernakulam", district: "Ernakulam", state: "Kerala", state_code: "KL", region: "South", lat: 9.9312, lng: 76.2673, type: "HO" }, "673001": { city: "Kozhikode", district: "Kozhikode", state: "Kerala", state_code: "KL", region: "South", lat: 11.2588, lng: 75.7804, type: "HO" }, "520001": { city: "Vijayawada", district: "Krishna", state: "Andhra Pradesh", state_code: "AP", region: "South", lat: 16.5062, lng: 80.648, type: "HO" }, "530001": { city: "Visakhapatnam", district: "Visakhapatnam", state: "Andhra Pradesh", state_code: "AP", region: "South", lat: 17.6868, lng: 83.2185, type: "HO" }, "515001": { city: "Anantapur", district: "Anantapur", state: "Andhra Pradesh", state_code: "AP", region: "South", lat: 14.6819, lng: 77.6006, type: "HO" }, "751001": { city: "Bhubaneswar", district: "Khordha", state: "Odisha", state_code: "OD", region: "East", lat: 20.2961, lng: 85.8245, type: "HO" }, "753001": { city: "Cuttack", district: "Cuttack", state: "Odisha", state_code: "OD", region: "East", lat: 20.4625, lng: 85.8828, type: "HO" }, "781001": { city: "Guwahati", district: "Kamrup Metropolitan", state: "Assam", state_code: "AS", region: "Northeast", lat: 26.1445, lng: 91.7362, type: "HO" }, "793001": { city: "Shillong", district: "East Khasi Hills", state: "Meghalaya", state_code: "ML", region: "Northeast", lat: 25.5788, lng: 91.8933, type: "HO" }, "796001": { city: "Aizawl", district: "Aizawl", state: "Mizoram", state_code: "MZ", region: "Northeast", lat: 23.7271, lng: 92.7176, type: "HO" }, "834001": { city: "Ranchi", district: "Ranchi", state: "Jharkhand", state_code: "JH", region: "East", lat: 23.3441, lng: 85.3096, type: "HO" }, "831001": { city: "Jamshedpur", district: "East Singhbhum", state: "Jharkhand", state_code: "JH", region: "East", lat: 22.8046, lng: 86.2029, type: "HO" }, "248001": { city: "Dehradun", district: "Dehradun", state: "Uttarakhand", state_code: "UK", region: "North", lat: 30.3165, lng: 78.0322, type: "HO" }, "171001": { city: "Shimla", district: "Shimla", state: "Himachal Pradesh", state_code: "HP", region: "North", lat: 31.1048, lng: 77.1734, type: "HO" }, "180001": { city: "Jammu", district: "Jammu", state: "Jammu & Kashmir", state_code: "JK", region: "North", lat: 32.7266, lng: 74.857, type: "HO" }, "190001": { city: "Srinagar", district: "Srinagar", state: "Jammu & Kashmir", state_code: "JK", region: "North", lat: 34.0837, lng: 74.7973, type: "HO" }, "403001": { city: "Panaji", district: "North Goa", state: "Goa", state_code: "GA", region: "West", lat: 15.4909, lng: 73.8278, type: "HO" } };
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
var db = pincodes_default;
|
|
6
|
+
function isValidPincode(pin) {
|
|
7
|
+
return /^\d{6}$/.test(pin.trim());
|
|
8
|
+
}
|
|
9
|
+
function haversineKm(lat1, lng1, lat2, lng2) {
|
|
10
|
+
const R = 6371;
|
|
11
|
+
const dLat = (lat2 - lat1) * Math.PI / 180;
|
|
12
|
+
const dLng = (lng2 - lng1) * Math.PI / 180;
|
|
13
|
+
const a = Math.sin(dLat / 2) ** 2 + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * Math.sin(dLng / 2) ** 2;
|
|
14
|
+
return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
15
|
+
}
|
|
16
|
+
function toResult(pin, val) {
|
|
17
|
+
return { pincode: pin, ...val };
|
|
18
|
+
}
|
|
19
|
+
function lookup(pincode2) {
|
|
20
|
+
const pin = pincode2.trim();
|
|
21
|
+
if (!isValidPincode(pin)) return null;
|
|
22
|
+
const entry = db[pin];
|
|
23
|
+
return entry ? toResult(pin, entry) : null;
|
|
24
|
+
}
|
|
25
|
+
function lookupMany(pincodes) {
|
|
26
|
+
const result = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const p of pincodes) {
|
|
28
|
+
result.set(p, lookup(p));
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
function isValid(pincode2) {
|
|
33
|
+
return lookup(pincode2) !== null;
|
|
34
|
+
}
|
|
35
|
+
function getByCity(city) {
|
|
36
|
+
const q = city.toLowerCase().trim();
|
|
37
|
+
return Object.entries(db).filter(([, v]) => v.city.toLowerCase().includes(q)).map(([pin, val]) => toResult(pin, val));
|
|
38
|
+
}
|
|
39
|
+
function getByState(state) {
|
|
40
|
+
const q = state.toLowerCase().trim();
|
|
41
|
+
return Object.entries(db).filter(
|
|
42
|
+
([, v]) => v.state.toLowerCase().includes(q) || v.state_code.toLowerCase() === q
|
|
43
|
+
).map(([pin, val]) => toResult(pin, val));
|
|
44
|
+
}
|
|
45
|
+
function getByDistrict(district) {
|
|
46
|
+
const q = district.toLowerCase().trim();
|
|
47
|
+
return Object.entries(db).filter(([, v]) => v.district.toLowerCase().includes(q)).map(([pin, val]) => toResult(pin, val));
|
|
48
|
+
}
|
|
49
|
+
function getByRegion(region) {
|
|
50
|
+
return Object.entries(db).filter(([, v]) => v.region === region).map(([pin, val]) => toResult(pin, val));
|
|
51
|
+
}
|
|
52
|
+
function nearby(pincode2, options = {}) {
|
|
53
|
+
const { radiusKm = 20, limit = 10 } = options;
|
|
54
|
+
const origin = lookup(pincode2);
|
|
55
|
+
if (!origin) return [];
|
|
56
|
+
return Object.entries(db).filter(([pin]) => pin !== pincode2).map(([pin, val]) => ({
|
|
57
|
+
result: toResult(pin, val),
|
|
58
|
+
dist: haversineKm(origin.lat, origin.lng, val.lat, val.lng)
|
|
59
|
+
})).filter(({ dist }) => dist <= radiusKm).sort((a, b) => a.dist - b.dist).slice(0, limit).map(({ result }) => result);
|
|
60
|
+
}
|
|
61
|
+
function distanceBetween(pincode1, pincode2) {
|
|
62
|
+
const a = lookup(pincode1);
|
|
63
|
+
const b = lookup(pincode2);
|
|
64
|
+
if (!a || !b) return null;
|
|
65
|
+
return parseFloat(haversineKm(a.lat, a.lng, b.lat, b.lng).toFixed(2));
|
|
66
|
+
}
|
|
67
|
+
function isValidFormat(pincode2) {
|
|
68
|
+
return isValidPincode(pincode2);
|
|
69
|
+
}
|
|
70
|
+
function getAllStates() {
|
|
71
|
+
const seen = /* @__PURE__ */ new Map();
|
|
72
|
+
for (const v of Object.values(db)) {
|
|
73
|
+
if (!seen.has(v.state_code)) seen.set(v.state_code, v.state);
|
|
74
|
+
}
|
|
75
|
+
return Array.from(seen.entries()).map(([state_code, state]) => ({ state, state_code })).sort((a, b) => a.state.localeCompare(b.state));
|
|
76
|
+
}
|
|
77
|
+
function search(query) {
|
|
78
|
+
const q = query.toLowerCase().trim();
|
|
79
|
+
if (q.length < 2) return [];
|
|
80
|
+
return Object.entries(db).filter(
|
|
81
|
+
([pin, v]) => pin.startsWith(q) || v.city.toLowerCase().includes(q) || v.district.toLowerCase().includes(q) || v.state.toLowerCase().includes(q)
|
|
82
|
+
).map(([pin, val]) => toResult(pin, val));
|
|
83
|
+
}
|
|
84
|
+
var pincode = {
|
|
85
|
+
lookup,
|
|
86
|
+
lookupMany,
|
|
87
|
+
isValid,
|
|
88
|
+
isValidFormat,
|
|
89
|
+
getByCity,
|
|
90
|
+
getByState,
|
|
91
|
+
getByDistrict,
|
|
92
|
+
getByRegion,
|
|
93
|
+
nearby,
|
|
94
|
+
distanceBetween,
|
|
95
|
+
getAllStates,
|
|
96
|
+
search
|
|
97
|
+
};
|
|
98
|
+
var index_default = pincode;
|
|
99
|
+
export {
|
|
100
|
+
index_default as default,
|
|
101
|
+
distanceBetween,
|
|
102
|
+
getAllStates,
|
|
103
|
+
getByCity,
|
|
104
|
+
getByDistrict,
|
|
105
|
+
getByRegion,
|
|
106
|
+
getByState,
|
|
107
|
+
isValid,
|
|
108
|
+
isValidFormat,
|
|
109
|
+
lookup,
|
|
110
|
+
lookupMany,
|
|
111
|
+
nearby,
|
|
112
|
+
search
|
|
113
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bharat-pincode",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Offline-first Indian pincode lookup — city, state, district, nearby, distance & more. Zero dependencies.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"data/pincodes.json",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
23
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
24
|
+
"test": "node --experimental-vm-modules node_modules/.bin/jest",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"india",
|
|
29
|
+
"pincode",
|
|
30
|
+
"postal-code",
|
|
31
|
+
"zip-code",
|
|
32
|
+
"city",
|
|
33
|
+
"state",
|
|
34
|
+
"district",
|
|
35
|
+
"geolocation",
|
|
36
|
+
"indian-cities",
|
|
37
|
+
"offline",
|
|
38
|
+
"address",
|
|
39
|
+
"lookup"
|
|
40
|
+
],
|
|
41
|
+
"author": "Ashutosh Kumar Tripathi <ashutosh_2312res192@iitp.ac.in>",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/AshutoshIITP1234/india-pincode"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/AshutoshIITP1234/india-pincode#readme",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/AshutoshIITP1234/india-pincode/issues"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^20.19.41",
|
|
53
|
+
"tsup": "^8.5.1",
|
|
54
|
+
"typescript": "^5.9.3"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=16"
|
|
58
|
+
},
|
|
59
|
+
"sideEffects": false
|
|
60
|
+
}
|