stentor-address 1.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ ## stentor-address
2
+
3
+ A set of shared utilities for address parsing.
4
+
5
+ Also includes zip to timezone functions and haversine distance calculations.
@@ -0,0 +1,53 @@
1
+ /*! Copyright (c) 2025, XAPP AI */
2
+ import { AddressIntentRequestSlotMap } from "stentor-models";
3
+ import * as addresser from "addresser";
4
+ export interface ParsedAddress extends Omit<addresser.IParsedAddress, "id" | "zipCode"> {
5
+ formattedAddress?: string;
6
+ /**
7
+ * Direction such as NW, SE, etc.
8
+ */
9
+ streetDirection?: string;
10
+ /**
11
+ * Zip/Postal Code
12
+ */
13
+ zipCode?: string;
14
+ /**
15
+ * Place name, typically the city or town.
16
+ */
17
+ placeName: string;
18
+ /**
19
+ * An ID for the address.
20
+ *
21
+ * @note It is not recommended to use this.
22
+ */
23
+ id?: string;
24
+ }
25
+ /**
26
+ * Attempts to parse an address from a string.
27
+ *
28
+ * @param address
29
+ * @returns Parsed address in ParsedAddress format
30
+ */
31
+ export declare function parseAddress(address: string): ParsedAddress | undefined;
32
+ /**
33
+ * Forms an address string from from the slots.
34
+ *
35
+ * @param slots
36
+ * @returns
37
+ */
38
+ export declare function formAddressFromSlots(slots: AddressIntentRequestSlotMap): string;
39
+ /**
40
+ * Attempts to parse an address from a string.
41
+ *
42
+ * @param address
43
+ * @returns
44
+ */
45
+ export declare function parseAddressAsSlots(address: string): AddressIntentRequestSlotMap;
46
+ /**
47
+ * Takes an input and attempts to parse out all the components
48
+ *
49
+ * It can be passed a partial address object and will attempt to fill in the missing components if a fullAddress is provided
50
+ *
51
+ * @param input
52
+ */
53
+ export declare function getAddressComponents(input: string | Partial<ParsedAddress>): ParsedAddress;
package/lib/address.js ADDED
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parseAddress = parseAddress;
37
+ exports.formAddressFromSlots = formAddressFromSlots;
38
+ exports.parseAddressAsSlots = parseAddressAsSlots;
39
+ exports.getAddressComponents = getAddressComponents;
40
+ const stentor_utils_1 = require("stentor-utils");
41
+ const addresser = __importStar(require("addresser"));
42
+ /**
43
+ * Custom fallback parser for address strings.
44
+ *
45
+ * @param formattedAddress
46
+ * @returns Parsed address in the format of IParsedAddress
47
+ */
48
+ function customParseAddress(formattedAddress) {
49
+ const parsedAddress = {
50
+ zipCode: "",
51
+ stateAbbreviation: "",
52
+ stateName: "",
53
+ placeName: "",
54
+ addressLine1: "",
55
+ streetNumber: "",
56
+ streetSuffix: "",
57
+ streetName: "",
58
+ id: "",
59
+ };
60
+ const parts = formattedAddress.split(",").map((part) => part.trim());
61
+ if (parts.length === 4) {
62
+ // Format: "Street, City, State/Province PostalCode, Country"
63
+ parsedAddress.addressLine1 = parts[0];
64
+ parsedAddress.placeName = parts[1];
65
+ const statePostal = parts[2].split(" ");
66
+ if (statePostal.length > 1 && /^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/.test(statePostal.slice(-2).join(" "))) {
67
+ parsedAddress.stateAbbreviation = statePostal.slice(0, -2).join(" ");
68
+ parsedAddress.zipCode = statePostal.slice(-2).join(" ");
69
+ }
70
+ else {
71
+ parsedAddress.stateAbbreviation = statePostal.slice(0, -1).join(" ");
72
+ parsedAddress.zipCode = statePostal[statePostal.length - 1];
73
+ }
74
+ parsedAddress.stateName = parsedAddress.stateAbbreviation; // Fallback since the full name isn't provided
75
+ }
76
+ else if (parts.length === 3) {
77
+ // Format: "City, State/Province PostalCode, Country"
78
+ parsedAddress.placeName = parts[0];
79
+ const statePostal = parts[1].split(" ");
80
+ if (statePostal.length > 1 && /^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/.test(statePostal.slice(-2).join(" "))) {
81
+ parsedAddress.stateAbbreviation = statePostal.slice(0, -2).join(" ");
82
+ parsedAddress.zipCode = statePostal.slice(-2).join(" ");
83
+ }
84
+ else {
85
+ parsedAddress.stateAbbreviation = statePostal.slice(0, -1).join(" ");
86
+ parsedAddress.zipCode = statePostal[statePostal.length - 1];
87
+ }
88
+ parsedAddress.stateName = parsedAddress.stateAbbreviation; // Fallback since the full name isn't provided
89
+ }
90
+ else {
91
+ console.warn("Unexpected address format:", formattedAddress);
92
+ }
93
+ parsedAddress.id = `${parsedAddress.placeName}-${parsedAddress.zipCode}-${parsedAddress.addressLine1}`
94
+ .replace(/\s+/g, "-")
95
+ .toLowerCase();
96
+ return parsedAddress;
97
+ }
98
+ /**
99
+ * Attempts to parse an address from a string.
100
+ *
101
+ * @param address
102
+ * @returns Parsed address in ParsedAddress format
103
+ */
104
+ function parseAddress(address) {
105
+ let addressed;
106
+ try {
107
+ addressed = addresser.parseAddress(address);
108
+ }
109
+ catch (e) {
110
+ // Not a valid address
111
+ // Fallback to custom parser
112
+ addressed = customParseAddress(address);
113
+ }
114
+ return addressed;
115
+ }
116
+ /**
117
+ * Forms an address string from from the slots.
118
+ *
119
+ * @param slots
120
+ * @returns
121
+ */
122
+ function formAddressFromSlots(slots) {
123
+ const hasCity = slots.city && slots.city.value;
124
+ const hasState = slots.state && slots.state.value;
125
+ let address = "";
126
+ if (slots.street_number && slots.street_number.value) {
127
+ address += slots.street_number.value + " ";
128
+ }
129
+ if (slots.street && slots.street.value) {
130
+ // make sure we aren't adding the street number twice
131
+ // see if street starts with street number, if it does don't add it
132
+ if (slots.street.value.trim().startsWith(address.trim())) {
133
+ // just replace it since it is a dupe
134
+ address = slots.street.value + " ";
135
+ }
136
+ else {
137
+ address += slots.street.value + " ";
138
+ }
139
+ }
140
+ else if (slots.street_name && slots.street_name.value) {
141
+ address += slots.street_name.value + " ";
142
+ }
143
+ // if we have quadrant and it isn't already in the street name
144
+ if (slots.quadrant &&
145
+ slots.quadrant.value &&
146
+ !address.trim().toLowerCase().endsWith(slots.quadrant.value.toLowerCase())) {
147
+ address += slots.quadrant.value + " ";
148
+ }
149
+ if (hasCity || hasState) {
150
+ address = address.trim();
151
+ address += ", ";
152
+ }
153
+ if (slots.city && slots.city.value) {
154
+ if (hasState) {
155
+ address += slots.city.value + ", ";
156
+ }
157
+ else {
158
+ address += slots.city.value + " ";
159
+ }
160
+ }
161
+ if (slots.state && slots.state.value) {
162
+ address += slots.state.value + " ";
163
+ }
164
+ if (slots.zip && slots.zip.value) {
165
+ address += slots.zip.value;
166
+ }
167
+ return address.trim();
168
+ }
169
+ /**
170
+ * Attempts to parse an address from a string.
171
+ *
172
+ * @param address
173
+ * @returns
174
+ */
175
+ function parseAddressAsSlots(address) {
176
+ const slots = {};
177
+ let addressed;
178
+ try {
179
+ addressed = addresser.parseAddress(address);
180
+ }
181
+ catch (e) {
182
+ // not a valid address
183
+ console.warn(`Unable to parse address string "${address}"`);
184
+ }
185
+ if (addressed) {
186
+ // Pull out the zipCode
187
+ slots.zip = {
188
+ name: "zip",
189
+ value: addressed.zipCode,
190
+ };
191
+ slots.city = {
192
+ name: "city",
193
+ value: addressed.placeName,
194
+ };
195
+ slots.state = {
196
+ name: "state",
197
+ value: addressed.stateName,
198
+ };
199
+ slots.street_number = {
200
+ name: "street_number",
201
+ value: addressed.streetNumber,
202
+ };
203
+ slots.street = {
204
+ name: "street",
205
+ value: addressed.addressLine1,
206
+ };
207
+ slots.street_name = {
208
+ name: "street_name",
209
+ value: addressed.addressLine1.replace(addressed.streetNumber, "").trim(),
210
+ };
211
+ const fullAddress = formAddressFromSlots(slots);
212
+ if (fullAddress) {
213
+ slots.address = {
214
+ name: "address",
215
+ value: fullAddress,
216
+ };
217
+ }
218
+ }
219
+ return slots;
220
+ }
221
+ /**
222
+ * Takes an input and attempts to parse out all the components
223
+ *
224
+ * It can be passed a partial address object and will attempt to fill in the missing components if a fullAddress is provided
225
+ *
226
+ * @param input
227
+ */
228
+ function getAddressComponents(input) {
229
+ let parsedAddress;
230
+ if (typeof input === "string") {
231
+ parsedAddress = parseAddress(input);
232
+ }
233
+ else {
234
+ parsedAddress = input;
235
+ }
236
+ // do some tests to make sure we have all the components
237
+ if (!parsedAddress.stateAbbreviation || !parsedAddress.stateName) {
238
+ // attempt to parse the address section and merge it in
239
+ const parsedFormattedAddress = parseAddress(parsedAddress.formattedAddress || parsedAddress.addressLine1);
240
+ // clean off the parsedFormattedAddress to remove any empty strings & values
241
+ const pruned = (0, stentor_utils_1.pruneEmpty)(parsedFormattedAddress);
242
+ parsedAddress = Object.assign(Object.assign({}, parsedAddress), pruned);
243
+ }
244
+ if (!parsedAddress.id) {
245
+ // id is just concatenation of the address
246
+ let id = "";
247
+ if (parsedAddress.addressLine1) {
248
+ id += `${parsedAddress.addressLine1},`;
249
+ }
250
+ if (parsedAddress.placeName) {
251
+ id += `-${parsedAddress.placeName},`;
252
+ }
253
+ if (parsedAddress.stateName) {
254
+ id += `-${parsedAddress.stateName}`;
255
+ }
256
+ if (parsedAddress.zipCode) {
257
+ id += `-${parsedAddress.zipCode}`;
258
+ }
259
+ parsedAddress.id = id.replace(/\s+/g, "-");
260
+ }
261
+ return parsedAddress;
262
+ }
263
+ //# sourceMappingURL=address.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.js","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,oCAYC;AAQD,oDAsDC;AAQD,kDAsDC;AASD,oDAsCC;AArRD,iDAA2C;AAE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CAAC,OAAO,EAAE,CAAC;YAC1B,EAAE,IAAI,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC;QACpC,CAAC;QAED,aAAa,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /*! Copyright (c) 2025, XAPP AI */
2
+ /**
3
+ * Calculate the Haversine distance between two points on the Earth.
4
+ * @param one The first point with latitude and longitude.
5
+ * @param two The second point with latitude and longitude.
6
+ * @returns The distance between the two points in kilometers.
7
+ */
8
+ export declare function haversineDistanceKm(one: {
9
+ lat: number;
10
+ lon: number;
11
+ }, two: {
12
+ lat: number;
13
+ lon: number;
14
+ }): number;
15
+ /**
16
+ * Calculate the Haversine distance between two points on the Earth in miles.
17
+ *
18
+ * Calls first haversineDistanceKm and uses a conversion rate of 1 km = 0.621371 miles.
19
+ *
20
+ * @param one The first point with latitude and longitude.
21
+ * @param two The second point with latitude and longitude.
22
+ * @returns The distance between the two points in miles.
23
+ */
24
+ export declare function haversineDistanceMiles(one: {
25
+ lat: number;
26
+ lon: number;
27
+ }, two: {
28
+ lat: number;
29
+ lon: number;
30
+ }): number;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2025, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.haversineDistanceKm = haversineDistanceKm;
5
+ exports.haversineDistanceMiles = haversineDistanceMiles;
6
+ /**
7
+ * Calculate the Haversine distance between two points on the Earth.
8
+ * @param one The first point with latitude and longitude.
9
+ * @param two The second point with latitude and longitude.
10
+ * @returns The distance between the two points in kilometers.
11
+ */
12
+ function haversineDistanceKm(one, two) {
13
+ const { lat: lat1, lon: lon1 } = one;
14
+ const { lat: lat2, lon: lon2 } = two;
15
+ const R = 6371; // Radius of Earth in km
16
+ const toRad = (x) => (x * Math.PI) / 180;
17
+ const dLat = toRad(lat2 - lat1);
18
+ const dLon = toRad(lon2 - lon1);
19
+ const a = Math.pow(Math.sin(dLat / 2), 2) + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.pow(Math.sin(dLon / 2), 2);
20
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
21
+ return R * c;
22
+ }
23
+ /**
24
+ * Calculate the Haversine distance between two points on the Earth in miles.
25
+ *
26
+ * Calls first haversineDistanceKm and uses a conversion rate of 1 km = 0.621371 miles.
27
+ *
28
+ * @param one The first point with latitude and longitude.
29
+ * @param two The second point with latitude and longitude.
30
+ * @returns The distance between the two points in miles.
31
+ */
32
+ function haversineDistanceMiles(one, two) {
33
+ const km = haversineDistanceKm(one, two);
34
+ return km * 0.621371; // convert km to miles
35
+ }
36
+ //# sourceMappingURL=haversine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"haversine.js","sourceRoot":"","sources":["../src/haversine.ts"],"names":[],"mappings":";AAAA,kCAAkC;;AAQlC,kDAWC;AAWD,wDAGC;AA/BD;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,GAAiC,EAAE,GAAiC;IACtG,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IACrC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAErC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,wBAAwB;IACxC,MAAM,KAAK,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;IACzD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,SAAA,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,EAAI,CAAC,CAAA,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,SAAA,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,EAAI,CAAC,CAAA,CAAC;IAC5G,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzD,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CAAC,GAAiC,EAAE,GAAiC;IACzG,MAAM,EAAE,GAAG,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzC,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC,sBAAsB;AAC9C,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /*! Copyright (c) 2025, XAPP AI */
2
+ export * from "./address";
3
+ export * from "./haversine";
4
+ export * from "./zipToTZ";
package/lib/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*! Copyright (c) 2025, XAPP AI */
18
+ __exportStar(require("./address"), exports);
19
+ __exportStar(require("./haversine"), exports);
20
+ __exportStar(require("./zipToTZ"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kCAAkC;AAClC,4CAA0B;AAC1B,8CAA4B;AAC5B,4CAA0B"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converts a ZIP code that is in the 5-digit format to a timezone string, such as "America/New_York".
3
+ *
4
+ * @param zip
5
+ * @throws Error if the ZIP code is not in the correct format or if the timezone is not found.
6
+ * @returns
7
+ */
8
+ export declare function zipToTz(zip: string): string;
package/lib/zipToTZ.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zipToTz = zipToTz;
4
+ /*! Copyright (c) 2025, XAPP AI */
5
+ const zipToTZData_1 = require("./zipToTZData"); // adjust path as needed
6
+ /**
7
+ * Converts a ZIP code that is in the 5-digit format to a timezone string, such as "America/New_York".
8
+ *
9
+ * @param zip
10
+ * @throws Error if the ZIP code is not in the correct format or if the timezone is not found.
11
+ * @returns
12
+ */
13
+ function zipToTz(zip) {
14
+ const cleanZip = zip.replace(/\s/g, "");
15
+ if (!/^\d{5}$/.test(cleanZip)) {
16
+ console.warn(`Invalid ZIP code format: ${zip}`);
17
+ }
18
+ return zipToTZData_1.zipToTimezone[cleanZip];
19
+ }
20
+ //# sourceMappingURL=zipToTZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zipToTZ.js","sourceRoot":"","sources":["../src/zipToTZ.ts"],"names":[],"mappings":";;AAUA,0BAQC;AAlBD,kCAAkC;AAClC,+CAA8C,CAAC,wBAAwB;AAEvE;;;;;;GAMG;AACH,SAAgB,OAAO,CAAC,GAAW;IACjC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAExC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,OAAO,CAAC,IAAI,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,2BAAa,CAAC,QAAQ,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,2 @@
1
+ /*! Copyright (c) 2025, XAPP AI */
2
+ export declare const zipToTimezone: Record<string, string>;