@sesamecare-oss/us-postal-codes 2.0.0 → 2.0.2
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/build/index.js +4 -2
- package/build/index.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +4 -2
package/build/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
3
4
|
const EARTH_RADIUS_MILES = 3958.8;
|
|
5
|
+
const CURRENT_DIRECTORY = dirname(fileURLToPath(import.meta.url));
|
|
4
6
|
function haversineDistance(lat1, lng1, lat2, lng2) {
|
|
5
7
|
const toRad = (deg) => (deg * Math.PI) / 180;
|
|
6
8
|
const dLat = toRad(lat2 - lat1);
|
|
@@ -12,7 +14,7 @@ function haversineDistance(lat1, lng1, lat2, lng2) {
|
|
|
12
14
|
export class USPostalCodes {
|
|
13
15
|
db;
|
|
14
16
|
async open() {
|
|
15
|
-
this.db = new DatabaseSync(
|
|
17
|
+
this.db = new DatabaseSync(join(CURRENT_DIRECTORY, '../assets/uspostalcodes.db'));
|
|
16
18
|
}
|
|
17
19
|
async lookup(zipCode) {
|
|
18
20
|
if (!this.db) {
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAczC,MAAM,kBAAkB,GAAG,MAAM,CAA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OAAO,CAAC,mEAAmE,CAAC;aAC5E,GAAG,CAAC,OAAO,CAKX,CAAC;IACN,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,GAAW,EAAE,KAAK,GAAG,EAAE;QAC/C,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,CAAC;QAED,iEAAiE;QACjE,+CAA+C;QAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE;aACjB,OAAO,CACN;;iBAES,CACV;aACA,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,CAM7B,CAAC;QAEJ,OAAO,IAAI;aACR,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACb,UAAU,EAAE,GAAG,CAAC,WAAW;YAC3B,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;SACrF,CAAC,CAAC;aACF,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC;IACvD,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sesamecare-oss/us-postal-codes",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Lookup city, state and geolocation by US postal codes. Includes infra for fetching the latest values.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
7
|
"author": "Developers <developers@sesamecare.com>",
|
|
8
8
|
"license": "UNLICENSED",
|
|
9
9
|
"packageManager": "yarn@3.6.0",
|
|
10
|
+
"type": "module",
|
|
10
11
|
"scripts": {
|
|
11
12
|
"build": "tsc -p tsconfig.build.json",
|
|
12
13
|
"clean": "yarn dlx rimraf ./dist",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
3
4
|
|
|
4
5
|
export interface PostalCodeLocation {
|
|
5
6
|
postalCode: string;
|
|
@@ -14,6 +15,7 @@ export interface NearbyResult extends PostalCodeLocation {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
const EARTH_RADIUS_MILES = 3958.8;
|
|
18
|
+
const CURRENT_DIRECTORY = dirname(fileURLToPath(import.meta.url));
|
|
17
19
|
|
|
18
20
|
function haversineDistance(lat1: number, lng1: number, lat2: number, lng2: number): number {
|
|
19
21
|
const toRad = (deg: number) => (deg * Math.PI) / 180;
|
|
@@ -29,7 +31,7 @@ export class USPostalCodes {
|
|
|
29
31
|
db: DatabaseSync | undefined;
|
|
30
32
|
|
|
31
33
|
async open() {
|
|
32
|
-
this.db = new DatabaseSync(
|
|
34
|
+
this.db = new DatabaseSync(join(CURRENT_DIRECTORY, '../assets/uspostalcodes.db'));
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
async lookup(zipCode: string): Promise<
|