Skip to content

Commit 70e58b3

Browse files
committed
fix: vite compilation
1 parent 1b0c3c6 commit 70e58b3

File tree

4 files changed

+106
-50
lines changed

4 files changed

+106
-50
lines changed
File renamed without changes.

package-lock.json

Lines changed: 82 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
22
"name": "browser-geo-tz",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"author": "Kevin Wang <[email protected]>",
55
"license": "MIT",
66
"unpkg": "dist/geotz.js",
7-
"types": "index.d.ts",
7+
"types": "index.ts",
8+
"module": "index.ts",
89
"scripts": {
910
"prepublishOnly": "npm run build",
1011
"build": "mkdir -p dist && browserify src/find.ts -p [ tsify ] -d -s GeoTZ > dist/geotz.js",
1112
"test": "vitest"
1213
},
1314
"dependencies": {
14-
"@turf/boolean-point-in-polygon": "^6.5.0",
15-
"@turf/helpers": "^6.5.0",
15+
"@turf/boolean-point-in-polygon": "^7.1.0",
16+
"@turf/helpers": "^7.1.0",
1617
"geobuf": "^3.0.2",
1718
"pbf": "^3.2.1"
1819
},

src/find.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@ export function init(
2424
const geoData =
2525
typeof geoDataSource === "string"
2626
? async (start: number, end: number) => {
27-
const response = await fetch(geoDataSource, {
28-
headers: { Range: `bytes=${start}-${end}` },
29-
});
30-
return await response.arrayBuffer();
31-
}
27+
const response = await fetch(geoDataSource, {
28+
headers: { Range: `bytes=${start}-${end}` },
29+
});
30+
return await response.arrayBuffer();
31+
}
3232
: geoDataSource;
3333

3434
let tzDataPromise: Promise<any> | null = null;
3535

3636
const tzData =
3737
typeof tzDataSource === "string"
3838
? async () => {
39-
if (tzDataPromise) {
40-
return await tzDataPromise;
41-
}
42-
const promise = fetch(tzDataSource).then((response) =>
43-
response.json(),
44-
);
45-
tzDataPromise = promise;
46-
return await promise;
39+
if (tzDataPromise) {
40+
return await tzDataPromise;
4741
}
42+
const promise = fetch(tzDataSource).then((response) =>
43+
response.json(),
44+
);
45+
tzDataPromise = promise;
46+
return await promise;
47+
}
4848
: tzDataSource;
4949

5050
return {
@@ -173,11 +173,14 @@ async function findImpl(
173173
if (geoJson.type === "FeatureCollection") {
174174
for (let i = 0; i < geoJson.features.length; i++) {
175175
if (inside(pt, geoJson.features[i] as any)) {
176-
timezonesContainingPoint.push(geoJson.features[i].properties.tzid);
176+
const properties = geoJson.features[i].properties;
177+
if (properties) {
178+
timezonesContainingPoint.push(properties.tzid);
179+
}
177180
}
178181
}
179182
} else if (geoJson.type === "Feature") {
180-
if (inside(pt, geoJson as any)) {
183+
if (inside(pt, geoJson as any) && geoJson.properties) {
181184
timezonesContainingPoint.push(geoJson.properties.tzid);
182185
}
183186
}
@@ -190,7 +193,7 @@ async function findImpl(
190193
} else if (curTzData.length > 0) {
191194
// exact match found
192195
const timezones = tzDataResponse.timezones;
193-
return curTzData.map((idx) => timezones[idx]);
196+
return curTzData.map((idx: number) => timezones[idx]);
194197
} else if (typeof curTzData !== "object") {
195198
// not another nested quad index, throw error
196199
err = new Error("Unexpected data type");

0 commit comments

Comments
 (0)