@tmlmobilidade/utils 20250825.2309.5 → 20250825.2311.31

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.
@@ -1,15 +1,15 @@
1
1
  /**
2
2
  * Checks if the given latitude value is valid given Portugal limits.
3
3
  * @param value The latitude value to check.
4
- * @returns True if the latitude is valid, false otherwise.
4
+ * @returns The clamped latitude value if valid, false otherwise.
5
5
  */
6
- export declare function isValidLatitude(value: number): boolean;
6
+ export declare function isValidLatitude(value: number): false | number;
7
7
  /**
8
8
  * Checks if the given longitude value is valid given Portugal limits.
9
9
  * @param value The longitude value to check.
10
- * @returns True if the longitude is valid, false otherwise.
10
+ * @returns The clamped longitude value if valid, false otherwise.
11
11
  */
12
- export declare function isValidLongitude(value: number): boolean;
12
+ export declare function isValidLongitude(value: number): false | number;
13
13
  /**
14
14
  * Checks if the given latitude and longitude values form a valid coordinate pair.
15
15
  * @param lat The latitude value to check.
@@ -2,22 +2,26 @@
2
2
  /**
3
3
  * Checks if the given latitude value is valid given Portugal limits.
4
4
  * @param value The latitude value to check.
5
- * @returns True if the latitude is valid, false otherwise.
5
+ * @returns The clamped latitude value if valid, false otherwise.
6
6
  */
7
7
  export function isValidLatitude(value) {
8
8
  const hasValue = value !== undefined && value !== null;
9
9
  const isWithinPortugal = value >= 36.9 && value <= 42.0;
10
- return hasValue && isWithinPortugal;
10
+ if (!hasValue || !isWithinPortugal)
11
+ return false;
12
+ return clampCoordinate(value);
11
13
  }
12
14
  /**
13
15
  * Checks if the given longitude value is valid given Portugal limits.
14
16
  * @param value The longitude value to check.
15
- * @returns True if the longitude is valid, false otherwise.
17
+ * @returns The clamped longitude value if valid, false otherwise.
16
18
  */
17
19
  export function isValidLongitude(value) {
18
20
  const hasValue = value !== undefined && value !== null;
19
21
  const isWithinPortugal = value >= -9.5 && value <= -6.0;
20
- return hasValue && isWithinPortugal;
22
+ if (!hasValue || !isWithinPortugal)
23
+ return false;
24
+ return clampCoordinate(value);
21
25
  }
22
26
  /**
23
27
  * Checks if the given latitude and longitude values form a valid coordinate pair.
@@ -26,7 +30,9 @@ export function isValidLongitude(value) {
26
30
  * @returns True if the coordinate pair is valid, false otherwise.
27
31
  */
28
32
  export function isValidCoordinatePair(lat, lng) {
29
- return isValidLatitude(lat) && isValidLongitude(lng);
33
+ const isValidLat = isValidLatitude(lat);
34
+ const isValidLng = isValidLongitude(lng);
35
+ return !!isValidLat && !!isValidLng;
30
36
  }
31
37
  /**
32
38
  * Clamps a coordinate value to 6 decimal places.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/utils",
3
- "version": "20250825.2309.5",
3
+ "version": "20250825.2311.31",
4
4
  "author": "João de Vasconcelos & Jusi Monteiro",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "homepage": "https://github.com/tmlmobilidade/services#readme",