india-pincode 2.4.0 → 2.5.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.
@@ -0,0 +1,150 @@
1
+ declare enum ErrorCode {
2
+ INVALID_PINCODE = "INVALID_PINCODE",
3
+ PINCODE_NOT_FOUND = "PINCODE_NOT_FOUND",
4
+ STATE_NOT_FOUND = "STATE_NOT_FOUND",
5
+ DISTRICT_NOT_FOUND = "DISTRICT_NOT_FOUND",
6
+ INVALID_COORDINATES = "INVALID_COORDINATES",
7
+ INVALID_INPUT = "INVALID_INPUT",
8
+ NO_RESULTS = "NO_RESULTS"
9
+ }
10
+ interface ApiError {
11
+ code: ErrorCode;
12
+ message: string;
13
+ suggestions?: string[];
14
+ }
15
+ interface ApiResponse<T> {
16
+ success: boolean;
17
+ data: T | null;
18
+ error?: ApiError;
19
+ }
20
+ interface PostOffice {
21
+ pincode: string;
22
+ area: string;
23
+ officeType: OfficeType;
24
+ delivery: boolean;
25
+ district: string;
26
+ state: string;
27
+ country: string;
28
+ circle: string;
29
+ region: string;
30
+ division: string;
31
+ latitude: number | null;
32
+ longitude: number | null;
33
+ }
34
+ type OfficeType = 'BO' | 'SO' | 'HO' | 'PO' | 'GPO';
35
+ interface QueryOptions {
36
+ /** Max results to return (default: 100) */
37
+ limit?: number;
38
+ /** Page number, 1-based (default: 1) */
39
+ page?: number;
40
+ /** Filter by office type */
41
+ officeType?: OfficeType;
42
+ /** Filter only delivery offices */
43
+ deliveryOnly?: boolean;
44
+ }
45
+ interface PaginatedResult<T> {
46
+ data: T[];
47
+ total: number;
48
+ page: number;
49
+ limit: number;
50
+ totalPages: number;
51
+ }
52
+ interface NearbyResult extends PostOffice {
53
+ distanceKm: number;
54
+ }
55
+ interface AreaInfo {
56
+ pincode: string;
57
+ area: string;
58
+ latitude: number | null;
59
+ longitude: number | null;
60
+ }
61
+ interface PincodeSummary {
62
+ pincode: string;
63
+ district: string;
64
+ state: string;
65
+ country: string;
66
+ areas: AreaInfo[];
67
+ deliveryAreas: number;
68
+ hasCoordinates: boolean;
69
+ }
70
+ interface DistrictSummary {
71
+ district: string;
72
+ state: string;
73
+ country: string;
74
+ totalAreas: number;
75
+ totalPincodes: number;
76
+ pincodes: string[];
77
+ }
78
+ interface StateSummary {
79
+ state: string;
80
+ country: string;
81
+ totalDistricts: number;
82
+ totalAreas: number;
83
+ totalPincodes: number;
84
+ districts: string[];
85
+ }
86
+
87
+ /**
88
+ * - Geo-nearby → Haversine with early bounding-box pruning.
89
+ * - All responses wrapped in ApiResponse with proper error codes.
90
+ */
91
+ declare class IndiaPincode {
92
+ private _data;
93
+ private _byPincode;
94
+ private _byState;
95
+ private _byDistrict;
96
+ private _byArea;
97
+ constructor(data: PostOffice[]);
98
+ private isValidPincode;
99
+ private loadRuntimeData;
100
+ private indexByPincode;
101
+ private indexByState;
102
+ private indexByDistrict;
103
+ private indexByArea;
104
+ private buildIndex;
105
+ private paginate;
106
+ /** Get all post offices for a pincode. Returns error for invalid/missing pincodes. */
107
+ getByPincode(pincode: string, options?: QueryOptions): ApiResponse<PaginatedResult<PostOffice>>;
108
+ /** Get a complete summary for a pincode. */
109
+ getPincodeSummary(pincode: string): ApiResponse<PincodeSummary>;
110
+ /** Get all post offices in a state. */
111
+ getByState(state: string, options?: QueryOptions): ApiResponse<PaginatedResult<PostOffice>>;
112
+ /** Get a summary for a state — districts, pincode count, etc. */
113
+ getStateSummary(state: string): ApiResponse<StateSummary>;
114
+ /** Get all unique state names. */
115
+ getAllStates(): string[];
116
+ /** Get all post offices in a district. */
117
+ getByDistrict(district: string, options?: QueryOptions): ApiResponse<PaginatedResult<PostOffice>>;
118
+ /** Get a summary for a district. */
119
+ getDistrictSummary(district: string): ApiResponse<DistrictSummary>;
120
+ /** Get all districts for a state. */
121
+ getDistrictsByState(state: string): ApiResponse<string[]>;
122
+ /** Get all unique district names. */
123
+ getAllDistricts(): string[];
124
+ /** Get post offices by exact area name (case-insensitive). */
125
+ getByArea(name: string, options?: QueryOptions): ApiResponse<PaginatedResult<PostOffice>>;
126
+ /** Get all pincodes in a state. */
127
+ getPincodesByState(state: string): ApiResponse<string[]>;
128
+ /** Get all pincodes in a district. */
129
+ getPincodesByDistrict(district: string): ApiResponse<string[]>;
130
+ /**
131
+ * Search across pincode, area name, district, state.
132
+ * Returns early once limit is reached — no wasted iteration.
133
+ */
134
+ search(query: string, options?: QueryOptions): ApiResponse<PaginatedResult<PostOffice>>;
135
+ /**
136
+ * Find post offices near a given coordinate.
137
+ * Uses bounding-box pre-filter + Haversine for accuracy.
138
+ * Returns sorted by distance ascending.
139
+ */
140
+ findNearby(lat: number, lng: number, radiusKm?: number, limit?: number): ApiResponse<NearbyResult[]>;
141
+ /** Total number of post office records loaded. */
142
+ getTotalRecords(): number;
143
+ /** Total number of unique pincodes. */
144
+ getTotalPincodes(): number;
145
+ /** Clear all cached data and indexes — reloads fresh on next call. */
146
+ /** Clear all cached indexes — rebuilds on next call. */
147
+ clearCache(): void;
148
+ }
149
+
150
+ export { type ApiError as A, type DistrictSummary as D, ErrorCode as E, IndiaPincode as I, type NearbyResult as N, type OfficeType as O, type PaginatedResult as P, type QueryOptions as Q, type StateSummary as S, type ApiResponse as a, type AreaInfo as b, type PincodeSummary as c, type PostOffice as d };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "india-pincode",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Ultra-fast lookup for Indian pincode data — state, city, district, latitude, longitude. Works standalone or as a NestJS module.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -8,8 +8,14 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
+ "browser": "./dist/browser.mjs",
11
12
  "import": "./dist/index.mjs",
12
13
  "require": "./dist/index.js"
14
+ },
15
+ "./browser": {
16
+ "types": "./dist/browser.d.ts",
17
+ "import": "./dist/browser.mjs",
18
+ "require": "./dist/browser.js"
13
19
  }
14
20
  },
15
21
  "files": [
@@ -47,7 +53,9 @@
47
53
  "tsup": "^8.5.1",
48
54
  "typescript": "^5.9.3"
49
55
  },
50
- "dependencies": {},
56
+ "dependencies": {
57
+ "pako": "^2.1.0"
58
+ },
51
59
  "peerDependencies": {
52
60
  "@nestjs/common": ">=9.0.0",
53
61
  "reflect-metadata": ">=0.1.0",