@theholocron/location-utils 1.7.0 → 1.8.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/README.md +1 -0
- package/dist/index.d.mts +12 -3
- package/dist/index.mjs +4 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -31,6 +31,7 @@ Requests the device's current position via the [Geolocation API](https://develop
|
|
|
31
31
|
|
|
32
32
|
- If geolocation permission is denied, returns fallback coordinates `{ latitude: 0, longitude: 0, accuracy: 0 }` with a console warning.
|
|
33
33
|
- Uses `enableHighAccuracy: true` and a 27-second timeout.
|
|
34
|
+
- Pass a `LocationLogger` (`{ warn(message, meta?) }`) as the first argument to route warnings elsewhere instead of `console.warn`: `location.getCurrent(myLogger)`.
|
|
34
35
|
|
|
35
36
|
> **Note:** Requires a browser environment — does not work in Node.js.
|
|
36
37
|
|
package/dist/index.d.mts
CHANGED
|
@@ -8,11 +8,20 @@ interface IGeolocationCoordinates {
|
|
|
8
8
|
longitude: number;
|
|
9
9
|
speed?: number | null;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Minimal structural logger seam — accept any object shaped like this
|
|
13
|
+
* (including a real `@theholocron/observability` `Logger` via a thin
|
|
14
|
+
* adapter) without this package taking a dependency on it. Defaults to
|
|
15
|
+
* `console.warn` so behavior is unchanged when nothing is injected.
|
|
16
|
+
*/
|
|
17
|
+
interface LocationLogger {
|
|
18
|
+
warn(message: string, meta?: unknown): void;
|
|
19
|
+
}
|
|
20
|
+
declare function getCurrentLocation(logger?: LocationLogger): Promise<IGeolocationCoordinates>;
|
|
12
21
|
//#endregion
|
|
13
22
|
//#region src/index.d.ts
|
|
14
|
-
declare const location: {
|
|
23
|
+
export declare const location: {
|
|
15
24
|
getCurrent: typeof getCurrentLocation;
|
|
16
25
|
};
|
|
17
26
|
//#endregion
|
|
18
|
-
export {
|
|
27
|
+
export type { IGeolocationCoordinates, LocationLogger };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//#region src/location.ts
|
|
2
|
+
const consoleLogger = { warn: (message, meta) => meta === void 0 ? console.warn(message) : console.warn(message, meta) };
|
|
2
3
|
const fallbackCoordinates = {
|
|
3
4
|
accuracy: 0,
|
|
4
5
|
latitude: 0,
|
|
@@ -8,9 +9,9 @@ const fallbackCoordinates = {
|
|
|
8
9
|
heading: null,
|
|
9
10
|
speed: null
|
|
10
11
|
};
|
|
11
|
-
async function getCurrentLocation() {
|
|
12
|
+
async function getCurrentLocation(logger = consoleLogger) {
|
|
12
13
|
if ((await navigator.permissions.query({ name: "geolocation" })).state === "denied") {
|
|
13
|
-
|
|
14
|
+
logger.warn("Location permission denied, using fallback");
|
|
14
15
|
return fallbackCoordinates;
|
|
15
16
|
}
|
|
16
17
|
try {
|
|
@@ -30,7 +31,7 @@ async function getCurrentLocation() {
|
|
|
30
31
|
speed: position.coords.speed
|
|
31
32
|
};
|
|
32
33
|
} catch (error) {
|
|
33
|
-
|
|
34
|
+
logger.warn("Error fetching fresh location:", error);
|
|
34
35
|
return fallbackCoordinates;
|
|
35
36
|
}
|
|
36
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/location-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Location utilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"location",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@theholocron/tsdown-config": "^
|
|
34
|
-
"@theholocron/vitest-config": "^
|
|
33
|
+
"@theholocron/tsdown-config": "^8.2.0",
|
|
34
|
+
"@theholocron/vitest-config": "^8.2.0",
|
|
35
35
|
"@tsconfig/node-lts": "^24.0.1",
|
|
36
36
|
"@types/node": "^26.2.0",
|
|
37
37
|
"@vitest/coverage-v8": "^4.1.10",
|
|
38
|
-
"happy-dom": "^20.
|
|
39
|
-
"tsdown": "^0.
|
|
38
|
+
"happy-dom": "^20.14.0",
|
|
39
|
+
"tsdown": "^0.23.0",
|
|
40
40
|
"vitest": "^4.1.10"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|