@theholocron/location-utils 1.7.1 → 1.8.1

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 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
- declare function getCurrentLocation(): Promise<IGeolocationCoordinates>;
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
23
  export declare const location: {
15
24
  getCurrent: typeof getCurrentLocation;
16
25
  };
17
26
  //#endregion
18
- export type { IGeolocationCoordinates };
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
- console.warn("Location permission denied, using fallback");
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
- console.warn("Error fetching fresh location:", error);
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.7.1",
3
+ "version": "1.8.1",
4
4
  "description": "Location utilities.",
5
5
  "keywords": [
6
6
  "location",
@@ -30,8 +30,8 @@
30
30
  "dist"
31
31
  ],
32
32
  "devDependencies": {
33
- "@theholocron/tsdown-config": "^7.33.0",
34
- "@theholocron/vitest-config": "^7.33.0",
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",