Skip to content

Commit 18b8f00

Browse files
committed
fix: add isValidLatLngTuple function to validate latitude and longitude tuples
1 parent 6652f40 commit 18b8f00

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/types/isValidMarker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ export const isValidLongitude = (value: unknown): value is number => {
1414
return typeof value === "number" && value >= -180 && value <= 180;
1515
};
1616

17+
/**
18+
* Checks if value is a valid [latitude, longitude] tuple.
19+
*/
20+
export const isValidLatLngTuple = (value: unknown): value is [number, number] => {
21+
return Array.isArray(value) && value.length === 2 && isValidLatitude(value[0]) && isValidLongitude(value[1]);
22+
};
23+
1724
/**
1825
* Type guard that validates a MarkerProps object at runtime
1926
* and narrows lat/lng from unknown to number.

0 commit comments

Comments
 (0)