ink-framework-location 0.1.0-alpha.1 → 0.1.0-alpha.10
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/package.json +2 -2
- package/src/index.ts +15 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ink-framework-location",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": "./src/index.ts"
|
|
6
6
|
},
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"ink": "npm:ink-framework@0.1.0-alpha.
|
|
8
|
+
"ink": "npm:ink-framework@0.1.0-alpha.10"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"repository": {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { callNative, NativeError } from "ink/native";
|
|
2
2
|
|
|
3
3
|
export type LocationAccuracy = "balanced" | "high";
|
|
4
|
+
export interface DefaultLocation {
|
|
5
|
+
latitude: number;
|
|
6
|
+
longitude: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export interface LocationFix {
|
|
5
10
|
latitude: number;
|
|
6
11
|
longitude: number;
|
|
@@ -59,6 +64,16 @@ function parseTracking(value: unknown): LocationTrackingState {
|
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
export const location = {
|
|
67
|
+
async default(): Promise<DefaultLocation | null> {
|
|
68
|
+
const value: unknown = JSON.parse(await callNative("light-sdk", "default-location", ""));
|
|
69
|
+
if (value === null) return null;
|
|
70
|
+
if (typeof value !== "object"
|
|
71
|
+
|| !("latitude" in value) || typeof value.latitude !== "number" || !Number.isFinite(value.latitude) || Math.abs(value.latitude) > 90
|
|
72
|
+
|| !("longitude" in value) || typeof value.longitude !== "number" || !Number.isFinite(value.longitude) || Math.abs(value.longitude) > 180) {
|
|
73
|
+
throw new NativeError("protocol", "Invalid default location");
|
|
74
|
+
}
|
|
75
|
+
return { latitude: value.latitude, longitude: value.longitude };
|
|
76
|
+
},
|
|
62
77
|
async *watch(options: LocationWatchOptions = {}): AsyncGenerator<LocationFix> {
|
|
63
78
|
const watch = Number(await callNative("location", "watch-start", updateOptions(options), { signal: options.signal }));
|
|
64
79
|
if (!Number.isSafeInteger(watch) || watch <= 0) throw new NativeError("protocol", "Invalid location watch");
|