@tmlmobilidade/utils 20250822.1813.23 → 20250822.1829.15
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.
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given latitude value is valid.
|
|
3
|
+
* @param value The latitude value to check.
|
|
4
|
+
* @returns True if the latitude is valid, false otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isValidLatitude(value: number): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if the given longitude value is valid.
|
|
9
|
+
* @param value The longitude value to check.
|
|
10
|
+
* @returns True if the longitude is valid, false otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isValidLongitude(value: number): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if the given latitude and longitude values form a valid coordinate pair.
|
|
15
|
+
* @param lat The latitude value to check.
|
|
16
|
+
* @param lng The longitude value to check.
|
|
17
|
+
* @returns True if the coordinate pair is valid, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isValidCoordinatePair(lat: number, lng: number): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Parses a coordinate string in the following formats:
|
|
22
|
+
* - `lat, lng`
|
|
23
|
+
* - `lat lng` (with a space or a tab)
|
|
24
|
+
* @param input The coordinate string to parse.
|
|
25
|
+
* @returns The parsed coordinates as an object, or null if the input is invalid.
|
|
26
|
+
*/
|
|
27
|
+
export declare const parseCoordinateString: (input: string) => null | {
|
|
28
|
+
lat: number;
|
|
29
|
+
lng: number;
|
|
30
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given latitude value is valid.
|
|
4
|
+
* @param value The latitude value to check.
|
|
5
|
+
* @returns True if the latitude is valid, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export function isValidLatitude(value) {
|
|
8
|
+
return value >= -90 && value <= 90;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the given longitude value is valid.
|
|
12
|
+
* @param value The longitude value to check.
|
|
13
|
+
* @returns True if the longitude is valid, false otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export function isValidLongitude(value) {
|
|
16
|
+
return value >= -180 && value <= 180;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the given latitude and longitude values form a valid coordinate pair.
|
|
20
|
+
* @param lat The latitude value to check.
|
|
21
|
+
* @param lng The longitude value to check.
|
|
22
|
+
* @returns True if the coordinate pair is valid, false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
export function isValidCoordinatePair(lat, lng) {
|
|
25
|
+
return isValidLatitude(lat) && isValidLongitude(lng);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parses a coordinate string in the following formats:
|
|
29
|
+
* - `lat, lng`
|
|
30
|
+
* - `lat lng` (with a space or a tab)
|
|
31
|
+
* @param input The coordinate string to parse.
|
|
32
|
+
* @returns The parsed coordinates as an object, or null if the input is invalid.
|
|
33
|
+
*/
|
|
34
|
+
export const parseCoordinateString = (input) => {
|
|
35
|
+
const regex = /^\s*([+-]?\d+(?:\.\d+)?)\s*(?:,|\s)\s*([+-]?\d+(?:\.\d+)?)\s*$/;
|
|
36
|
+
const match = input.match(regex);
|
|
37
|
+
if (!match)
|
|
38
|
+
return null;
|
|
39
|
+
const lat = parseFloat(match[1]);
|
|
40
|
+
const lng = parseFloat(match[2]);
|
|
41
|
+
return isValidCoordinatePair(lat, lng) ? { lat, lng } : null;
|
|
42
|
+
};
|
package/dist/src/geo/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './chunk-line.js';
|
|
2
2
|
export * from './constants.js';
|
|
3
3
|
export * from './conversions.js';
|
|
4
|
+
export * from './coordinates.js';
|
|
4
5
|
export * from './cut-line-at-length.js';
|
|
5
6
|
export * from './geojson-collections.js';
|
|
6
7
|
export * from './get-geofence-on-point.js';
|
package/dist/src/geo/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './chunk-line.js';
|
|
2
2
|
export * from './constants.js';
|
|
3
3
|
export * from './conversions.js';
|
|
4
|
+
export * from './coordinates.js';
|
|
4
5
|
export * from './cut-line-at-length.js';
|
|
5
6
|
export * from './geojson-collections.js';
|
|
6
7
|
export * from './get-geofence-on-point.js';
|
package/package.json
CHANGED