@mailwoman/spatial 11.1.0 → 11.2.0

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,294 +0,0 @@
1
- // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
- // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
-
4
- /**
5
- * @file The shapes a typed query takes when it is a point rather than an address, and the one parser for them.
6
- *
7
- * A search field receives coordinates in a dozen spellings, a plus code, an H3 cell, a geohash or a
8
- * Who's On First id beside ordinary addresses. {@link parsePointQuery} reads the whole text as one of those shapes or
9
- * answers `null`, so a caller sends only an address to the classifier. It reads text and decodes no cell: decoding a cell
10
- * to a coordinate belongs to the module that owns the format, and the H3 reader loads a WebAssembly binary
11
- * that a text test mustn't pay for.
12
- */
13
-
14
- import { isValidLatitude, isValidLongitude } from "#coordinate/bounds"
15
- import { isFullPlusCode, isShortPlusCode } from "#open-location-code"
16
-
17
- /**
18
- * The axis order a coordinate pair was read in.
19
- *
20
- * `lat_lon` is the order people write and the order inside a Google Maps link.
21
- * `lon_lat` is reported when the first number is out of latitude range, so it can only be a longitude.
22
- */
23
- export type CoordinateOrder = "lat_lon" | "lon_lat"
24
-
25
- export type PointQuery =
26
- | {
27
- kind: "coordinates"
28
- lat: number
29
- lon: number
30
- order: CoordinateOrder
31
- }
32
- | {
33
- /**
34
- * An Open Location Code, upper-cased.
35
- *
36
- * A short code (`VFQ6+92P`) decodes only beside a reference position.
37
- * The caller supplies that position.
38
- */
39
- kind: "plus_code"
40
- code: string
41
- full: boolean
42
- }
43
- | {
44
- /**
45
- * An H3 cell index in its hexadecimal form, lower-cased.
46
- *
47
- * Only the shape is checked here: the H3 library decides validity when it decodes the cell.
48
- */
49
- kind: "h3"
50
- cell: string
51
- }
52
- | {
53
- /**
54
- * A geohash, lower-cased.
55
- *
56
- * It is accepted only behind a `geohash:` or `gh:` prefix, because a bare hash is also a word.
57
- */
58
- kind: "geohash"
59
- hash: string
60
- }
61
- | {
62
- /**
63
- * A Who's On First id, from `wof:85633793`, `wof 85633793` or a Spelunker link.
64
- */
65
- kind: "wof"
66
- id: number
67
- }
68
-
69
- /**
70
- * `wof:85633793`, `wof 85633793`, `whosonfirst:85633793`.
71
- */
72
- const WOF_REFERENCE = /^(?:wof|whosonfirst)[\s:]+(\d{1,16})$/iu
73
-
74
- /**
75
- * A Spelunker place page, with or without the trailing slash.
76
- */
77
- const SPELUNKER_URL = /^https?:\/\/spelunker\.whosonfirst\.org\/id\/(\d{1,16})\/?$/iu
78
-
79
- /**
80
- * The hexadecimal form of an H3 cell: mode 1 in the high nibble, then fourteen more digits.
81
- */
82
- const H3_CELL = /^(?:h3:)?(8[0-9a-f]{14})$/iu
83
-
84
- /**
85
- * A geohash behind its prefix, in the base-32 alphabet that omits `a`, `i`, `l` and `o`.
86
- */
87
- const GEOHASH_REFERENCE = /^(?:geohash|gh):\s*([0-9b-hjkmnp-z]{1,12})$/iu
88
-
89
- /**
90
- * A `geo:` URI, `geo:48.8584,2.2945` with an optional altitude and parameters.
91
- */
92
- const GEO_URI = /^geo:(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)(?:,-?\d+(?:\.\d+)?)?(?:;.*)?$/iu
93
-
94
- /**
95
- * Google Maps' path segment, `@48.8584,2.2945,17z`, with the zoom optional.
96
- */
97
- const MAPS_SEGMENT = /^@(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)(?:,[\d.]+z)?$/iu
98
-
99
- /**
100
- * A labeled pair in either order: `lat 48.85 lon 2.29`, `lng=2.29, lat=48.85`.
101
- */
102
- const LABELED_PAIR =
103
- /^(lat(?:itude)?|lon(?:gitude)?|lng)\s*[:=]?\s*(-?\d+(?:\.\d+)?)\s*[,;\s]\s*(lat(?:itude)?|lon(?:gitude)?|lng)\s*[:=]?\s*(-?\d+(?:\.\d+)?)$/iu
104
-
105
- /**
106
- * One angle: a signed decimal, or degrees with optional minutes and seconds,
107
- * each with its mark, and an optional hemisphere letter after it.
108
- */
109
- const ANGLE =
110
- /^([+-])?\s*(\d+(?:\.\d+)?)\s*(?:°|º|d\b)?\s*(?:(\d+(?:\.\d+)?)\s*(?:'|′|’|m\b)\s*)?(?:(\d+(?:\.\d+)?)\s*(?:"|″|”|''|s\b)\s*)?([NSEW])?$/iu
111
-
112
- /**
113
- * A pair of angles is split at the comma or semicolon, or after the first hemisphere letter,
114
- * or between two decimal numbers at the whitespace between them.
115
- */
116
- const PAIR_AT_HEMISPHERE = /^(.+?[NSEW])\s+(.+)$/iu
117
- const PAIR_AT_SPACE = /^(\S+)\s+(\S+)$/u
118
-
119
- interface Angle {
120
- degrees: number
121
- hemisphere: "N" | "S" | "E" | "W" | null
122
- }
123
-
124
- function parseAngle(text: string): Angle | null {
125
- const match = ANGLE.exec(text.trim())
126
-
127
- if (!match) return null
128
-
129
- const [, sign, degrees, minutes = "0", seconds = "0", letter] = match
130
- const magnitude = Number(degrees) + Number(minutes) / 60 + Number(seconds) / 3600
131
-
132
- if (!Number.isFinite(magnitude)) return null
133
-
134
- const hemisphere = letter ? (letter.toUpperCase() as Angle["hemisphere"]) : null
135
- const negative = sign === "-" || hemisphere === "S" || hemisphere === "W"
136
-
137
- return { degrees: negative ? -magnitude : magnitude, hemisphere }
138
- }
139
-
140
- /**
141
- * A pair of angles as the point they name, or `null` when the pair is out of range in both orders.
142
- *
143
- * Hemisphere letters decide the axis.
144
- * Without them the first number is the latitude, as in a Google Maps link,
145
- * unless only the other order is in range.
146
- */
147
- function pairToPoint(first: Angle, second: Angle): PointQuery | null {
148
- const latLetters = new Set(["N", "S"])
149
- const lonLetters = new Set(["E", "W"])
150
-
151
- if (first.hemisphere && second.hemisphere) {
152
- if (latLetters.has(first.hemisphere) && lonLetters.has(second.hemisphere)) {
153
- return coordinates(first.degrees, second.degrees, "lat_lon")
154
- }
155
-
156
- if (lonLetters.has(first.hemisphere) && latLetters.has(second.hemisphere)) {
157
- return coordinates(second.degrees, first.degrees, "lon_lat")
158
- }
159
-
160
- return null
161
- }
162
-
163
- if (first.hemisphere) {
164
- return latLetters.has(first.hemisphere)
165
- ? coordinates(first.degrees, second.degrees, "lat_lon")
166
- : coordinates(second.degrees, first.degrees, "lon_lat")
167
- }
168
-
169
- if (second.hemisphere) {
170
- return lonLetters.has(second.hemisphere)
171
- ? coordinates(first.degrees, second.degrees, "lat_lon")
172
- : coordinates(second.degrees, first.degrees, "lon_lat")
173
- }
174
-
175
- return coordinates(first.degrees, second.degrees, "lat_lon") ?? coordinates(second.degrees, first.degrees, "lon_lat")
176
- }
177
-
178
- function coordinates(lat: number, lon: number, order: CoordinateOrder): PointQuery | null {
179
- if (!isValidLatitude(lat) || !isValidLongitude(lon)) return null
180
-
181
- return { kind: "coordinates", lat, lon, order }
182
- }
183
-
184
- /**
185
- * Whether a bare pair of numbers reads as a coordinate rather than two counts.
186
- *
187
- * `12 34` reads as a house number beside a postcode and as a position, so a bare pair
188
- * needs a comma, a decimal point, a degree mark or a hemisphere letter.
189
- */
190
- const COORDINATE_MARK = /[,;.°º'′"″NSEW]/iu
191
-
192
- function parseCoordinatePair(text: string): PointQuery | null {
193
- if (!COORDINATE_MARK.test(text)) return null
194
-
195
- const halves =
196
- (/[,;]/u.test(text) ? text.split(/[,;]/u, 2) : null) ??
197
- PAIR_AT_HEMISPHERE.exec(text)?.slice(1, 3) ??
198
- PAIR_AT_SPACE.exec(text)?.slice(1, 3)
199
-
200
- if (!halves || halves.length !== 2) return null
201
-
202
- const first = parseAngle(halves[0]!)
203
- const second = parseAngle(halves[1]!)
204
-
205
- if (!first || !second) return null
206
-
207
- return pairToPoint(first, second)
208
- }
209
-
210
- /**
211
- * Reads a whole query as the point it names: a coordinate pair in decimal,
212
- * degrees-minutes-seconds, `geo:` or Google Maps form, a full or short plus code,
213
- * an H3 cell, a prefixed geohash, or a Who's On First id.
214
- *
215
- * Returns `null` for text that's none of these.
216
- * Every address is such a text.
217
- *
218
- * A coordinate outside the valid range in both axis orders is also `null`, never clamped.
219
- */
220
- export function parsePointQuery(text: string): PointQuery | null {
221
- const trimmed = text.trim()
222
-
223
- if (!trimmed) return null
224
-
225
- const wof = WOF_REFERENCE.exec(trimmed) ?? SPELUNKER_URL.exec(trimmed)
226
-
227
- if (wof) {
228
- const id = Number(wof[1])
229
-
230
- return Number.isSafeInteger(id) && id > 0 ? { kind: "wof", id } : null
231
- }
232
-
233
- const h3 = H3_CELL.exec(trimmed)
234
-
235
- if (h3) return { kind: "h3", cell: h3[1]!.toLowerCase() }
236
-
237
- const geohash = GEOHASH_REFERENCE.exec(trimmed)
238
-
239
- if (geohash) return { kind: "geohash", hash: geohash[1]!.toLowerCase() }
240
-
241
- if (isFullPlusCode(trimmed)) return { kind: "plus_code", code: trimmed.toUpperCase(), full: true }
242
-
243
- if (isShortPlusCode(trimmed)) return { kind: "plus_code", code: trimmed.toUpperCase(), full: false }
244
-
245
- const uri = GEO_URI.exec(trimmed) ?? MAPS_SEGMENT.exec(trimmed)
246
-
247
- if (uri) return coordinates(Number(uri[1]), Number(uri[2]), "lat_lon")
248
-
249
- const labeled = LABELED_PAIR.exec(trimmed)
250
-
251
- if (labeled) {
252
- const [, firstLabel, firstValue, secondLabel, secondValue] = labeled
253
- const firstIsLat = /^lat/iu.test(firstLabel!)
254
-
255
- if (firstIsLat === /^lat/iu.test(secondLabel!)) return null
256
-
257
- return firstIsLat
258
- ? coordinates(Number(firstValue), Number(secondValue), "lat_lon")
259
- : coordinates(Number(secondValue), Number(firstValue), "lon_lat")
260
- }
261
-
262
- return parseCoordinatePair(trimmed)
263
- }
264
-
265
- /**
266
- * A coordinate pair as text, latitude first, in the form {@link parsePointQuery} reads back.
267
- *
268
- * Six decimals place a point within about 11 cm.
269
- */
270
- export function coordinatePairText(lat: number, lon: number, decimals = 6): string {
271
- return `${lat.toFixed(decimals)}, ${lon.toFixed(decimals)}`
272
- }
273
-
274
- /**
275
- * The label a point query is shown under, such as the tag column of a parse.
276
- */
277
- export const POINT_QUERY_LABEL: Record<PointQuery["kind"], string> = {
278
- coordinates: "coordinates",
279
- plus_code: "plus code",
280
- h3: "H3 cell",
281
- geohash: "geohash",
282
- wof: "Who's On First id",
283
- }
284
-
285
- /**
286
- * The same shapes as a noun phrase with its article, for a sentence: "this is a plus code".
287
- */
288
- export const POINT_QUERY_PHRASE: Record<PointQuery["kind"], string> = {
289
- coordinates: "a coordinate pair",
290
- plus_code: "a plus code",
291
- h3: "an H3 cell",
292
- geohash: "a geohash",
293
- wof: "a Who's On First id",
294
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * The axis order a coordinate pair was read in.
3
- *
4
- * `lat_lon` is the order people write and the order inside a Google Maps link.
5
- * `lon_lat` is reported when the first number is out of latitude range, so it can only be a longitude.
6
- */
7
- export type CoordinateOrder = "lat_lon" | "lon_lat";
8
- export type PointQuery = {
9
- kind: "coordinates";
10
- lat: number;
11
- lon: number;
12
- order: CoordinateOrder;
13
- } | {
14
- /**
15
- * An Open Location Code, upper-cased.
16
- *
17
- * A short code (`VFQ6+92P`) decodes only beside a reference position.
18
- * The caller supplies that position.
19
- */
20
- kind: "plus_code";
21
- code: string;
22
- full: boolean;
23
- } | {
24
- /**
25
- * An H3 cell index in its hexadecimal form, lower-cased.
26
- *
27
- * Only the shape is checked here: the H3 library decides validity when it decodes the cell.
28
- */
29
- kind: "h3";
30
- cell: string;
31
- } | {
32
- /**
33
- * A geohash, lower-cased.
34
- *
35
- * It is accepted only behind a `geohash:` or `gh:` prefix, because a bare hash is also a word.
36
- */
37
- kind: "geohash";
38
- hash: string;
39
- } | {
40
- /**
41
- * A Who's On First id, from `wof:85633793`, `wof 85633793` or a Spelunker link.
42
- */
43
- kind: "wof";
44
- id: number;
45
- };
46
- /**
47
- * Reads a whole query as the point it names: a coordinate pair in decimal,
48
- * degrees-minutes-seconds, `geo:` or Google Maps form, a full or short plus code,
49
- * an H3 cell, a prefixed geohash, or a Who's On First id.
50
- *
51
- * Returns `null` for text that's none of these.
52
- * Every address is such a text.
53
- *
54
- * A coordinate outside the valid range in both axis orders is also `null`, never clamped.
55
- */
56
- export declare function parsePointQuery(text: string): PointQuery | null;
57
- /**
58
- * A coordinate pair as text, latitude first, in the form {@link parsePointQuery} reads back.
59
- *
60
- * Six decimals place a point within about 11 cm.
61
- */
62
- export declare function coordinatePairText(lat: number, lon: number, decimals?: number): string;
63
- /**
64
- * The label a point query is shown under, such as the tag column of a parse.
65
- */
66
- export declare const POINT_QUERY_LABEL: Record<PointQuery["kind"], string>;
67
- /**
68
- * The same shapes as a noun phrase with its article, for a sentence: "this is a plus code".
69
- */
70
- export declare const POINT_QUERY_PHRASE: Record<PointQuery["kind"], string>;
71
- //# sourceMappingURL=point-query.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"point-query.d.ts","sourceRoot":"","sources":["../lib/point-query.ts"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,CAAA;AAEnD,MAAM,MAAM,UAAU,GACnB;IACA,IAAI,EAAE,aAAa,CAAA;IACnB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,eAAe,CAAA;CACrB,GACD;IACA;;;;;OAKG;IACH,IAAI,EAAE,WAAW,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,OAAO,CAAA;CACZ,GACD;IACA;;;;OAIG;IACH,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACX,GACD;IACA;;;;OAIG;IACH,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACX,GACD;IACA;;OAEG;IACH,IAAI,EAAE,KAAK,CAAA;IACX,EAAE,EAAE,MAAM,CAAA;CACT,CAAA;AA+IJ;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CA2C/D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAI,GAAG,MAAM,CAEjF;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAMhE,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAMjE,CAAA"}
@@ -1,194 +0,0 @@
1
- // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
- // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
- /**
4
- * @file The shapes a typed query takes when it is a point rather than an address, and the one parser for them.
5
- *
6
- * A search field receives coordinates in a dozen spellings, a plus code, an H3 cell, a geohash or a
7
- * Who's On First id beside ordinary addresses. {@link parsePointQuery} reads the whole text as one of those shapes or
8
- * answers `null`, so a caller sends only an address to the classifier. It reads text and decodes no cell: decoding a cell
9
- * to a coordinate belongs to the module that owns the format, and the H3 reader loads a WebAssembly binary
10
- * that a text test mustn't pay for.
11
- */
12
- import { isValidLatitude, isValidLongitude } from "#coordinate/bounds";
13
- import { isFullPlusCode, isShortPlusCode } from "#open-location-code";
14
- /**
15
- * `wof:85633793`, `wof 85633793`, `whosonfirst:85633793`.
16
- */
17
- const WOF_REFERENCE = /^(?:wof|whosonfirst)[\s:]+(\d{1,16})$/iu;
18
- /**
19
- * A Spelunker place page, with or without the trailing slash.
20
- */
21
- const SPELUNKER_URL = /^https?:\/\/spelunker\.whosonfirst\.org\/id\/(\d{1,16})\/?$/iu;
22
- /**
23
- * The hexadecimal form of an H3 cell: mode 1 in the high nibble, then fourteen more digits.
24
- */
25
- const H3_CELL = /^(?:h3:)?(8[0-9a-f]{14})$/iu;
26
- /**
27
- * A geohash behind its prefix, in the base-32 alphabet that omits `a`, `i`, `l` and `o`.
28
- */
29
- const GEOHASH_REFERENCE = /^(?:geohash|gh):\s*([0-9b-hjkmnp-z]{1,12})$/iu;
30
- /**
31
- * A `geo:` URI, `geo:48.8584,2.2945` with an optional altitude and parameters.
32
- */
33
- const GEO_URI = /^geo:(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)(?:,-?\d+(?:\.\d+)?)?(?:;.*)?$/iu;
34
- /**
35
- * Google Maps' path segment, `@48.8584,2.2945,17z`, with the zoom optional.
36
- */
37
- const MAPS_SEGMENT = /^@(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)(?:,[\d.]+z)?$/iu;
38
- /**
39
- * A labeled pair in either order: `lat 48.85 lon 2.29`, `lng=2.29, lat=48.85`.
40
- */
41
- const LABELED_PAIR = /^(lat(?:itude)?|lon(?:gitude)?|lng)\s*[:=]?\s*(-?\d+(?:\.\d+)?)\s*[,;\s]\s*(lat(?:itude)?|lon(?:gitude)?|lng)\s*[:=]?\s*(-?\d+(?:\.\d+)?)$/iu;
42
- /**
43
- * One angle: a signed decimal, or degrees with optional minutes and seconds,
44
- * each with its mark, and an optional hemisphere letter after it.
45
- */
46
- const ANGLE = /^([+-])?\s*(\d+(?:\.\d+)?)\s*(?:°|º|d\b)?\s*(?:(\d+(?:\.\d+)?)\s*(?:'|′|’|m\b)\s*)?(?:(\d+(?:\.\d+)?)\s*(?:"|″|”|''|s\b)\s*)?([NSEW])?$/iu;
47
- /**
48
- * A pair of angles is split at the comma or semicolon, or after the first hemisphere letter,
49
- * or between two decimal numbers at the whitespace between them.
50
- */
51
- const PAIR_AT_HEMISPHERE = /^(.+?[NSEW])\s+(.+)$/iu;
52
- const PAIR_AT_SPACE = /^(\S+)\s+(\S+)$/u;
53
- function parseAngle(text) {
54
- const match = ANGLE.exec(text.trim());
55
- if (!match)
56
- return null;
57
- const [, sign, degrees, minutes = "0", seconds = "0", letter] = match;
58
- const magnitude = Number(degrees) + Number(minutes) / 60 + Number(seconds) / 3600;
59
- if (!Number.isFinite(magnitude))
60
- return null;
61
- const hemisphere = letter ? letter.toUpperCase() : null;
62
- const negative = sign === "-" || hemisphere === "S" || hemisphere === "W";
63
- return { degrees: negative ? -magnitude : magnitude, hemisphere };
64
- }
65
- /**
66
- * A pair of angles as the point they name, or `null` when the pair is out of range in both orders.
67
- *
68
- * Hemisphere letters decide the axis.
69
- * Without them the first number is the latitude, as in a Google Maps link,
70
- * unless only the other order is in range.
71
- */
72
- function pairToPoint(first, second) {
73
- const latLetters = new Set(["N", "S"]);
74
- const lonLetters = new Set(["E", "W"]);
75
- if (first.hemisphere && second.hemisphere) {
76
- if (latLetters.has(first.hemisphere) && lonLetters.has(second.hemisphere)) {
77
- return coordinates(first.degrees, second.degrees, "lat_lon");
78
- }
79
- if (lonLetters.has(first.hemisphere) && latLetters.has(second.hemisphere)) {
80
- return coordinates(second.degrees, first.degrees, "lon_lat");
81
- }
82
- return null;
83
- }
84
- if (first.hemisphere) {
85
- return latLetters.has(first.hemisphere)
86
- ? coordinates(first.degrees, second.degrees, "lat_lon")
87
- : coordinates(second.degrees, first.degrees, "lon_lat");
88
- }
89
- if (second.hemisphere) {
90
- return lonLetters.has(second.hemisphere)
91
- ? coordinates(first.degrees, second.degrees, "lat_lon")
92
- : coordinates(second.degrees, first.degrees, "lon_lat");
93
- }
94
- return coordinates(first.degrees, second.degrees, "lat_lon") ?? coordinates(second.degrees, first.degrees, "lon_lat");
95
- }
96
- function coordinates(lat, lon, order) {
97
- if (!isValidLatitude(lat) || !isValidLongitude(lon))
98
- return null;
99
- return { kind: "coordinates", lat, lon, order };
100
- }
101
- /**
102
- * Whether a bare pair of numbers reads as a coordinate rather than two counts.
103
- *
104
- * `12 34` reads as a house number beside a postcode and as a position, so a bare pair
105
- * needs a comma, a decimal point, a degree mark or a hemisphere letter.
106
- */
107
- const COORDINATE_MARK = /[,;.°º'′"″NSEW]/iu;
108
- function parseCoordinatePair(text) {
109
- if (!COORDINATE_MARK.test(text))
110
- return null;
111
- const halves = (/[,;]/u.test(text) ? text.split(/[,;]/u, 2) : null) ??
112
- PAIR_AT_HEMISPHERE.exec(text)?.slice(1, 3) ??
113
- PAIR_AT_SPACE.exec(text)?.slice(1, 3);
114
- if (!halves || halves.length !== 2)
115
- return null;
116
- const first = parseAngle(halves[0]);
117
- const second = parseAngle(halves[1]);
118
- if (!first || !second)
119
- return null;
120
- return pairToPoint(first, second);
121
- }
122
- /**
123
- * Reads a whole query as the point it names: a coordinate pair in decimal,
124
- * degrees-minutes-seconds, `geo:` or Google Maps form, a full or short plus code,
125
- * an H3 cell, a prefixed geohash, or a Who's On First id.
126
- *
127
- * Returns `null` for text that's none of these.
128
- * Every address is such a text.
129
- *
130
- * A coordinate outside the valid range in both axis orders is also `null`, never clamped.
131
- */
132
- export function parsePointQuery(text) {
133
- const trimmed = text.trim();
134
- if (!trimmed)
135
- return null;
136
- const wof = WOF_REFERENCE.exec(trimmed) ?? SPELUNKER_URL.exec(trimmed);
137
- if (wof) {
138
- const id = Number(wof[1]);
139
- return Number.isSafeInteger(id) && id > 0 ? { kind: "wof", id } : null;
140
- }
141
- const h3 = H3_CELL.exec(trimmed);
142
- if (h3)
143
- return { kind: "h3", cell: h3[1].toLowerCase() };
144
- const geohash = GEOHASH_REFERENCE.exec(trimmed);
145
- if (geohash)
146
- return { kind: "geohash", hash: geohash[1].toLowerCase() };
147
- if (isFullPlusCode(trimmed))
148
- return { kind: "plus_code", code: trimmed.toUpperCase(), full: true };
149
- if (isShortPlusCode(trimmed))
150
- return { kind: "plus_code", code: trimmed.toUpperCase(), full: false };
151
- const uri = GEO_URI.exec(trimmed) ?? MAPS_SEGMENT.exec(trimmed);
152
- if (uri)
153
- return coordinates(Number(uri[1]), Number(uri[2]), "lat_lon");
154
- const labeled = LABELED_PAIR.exec(trimmed);
155
- if (labeled) {
156
- const [, firstLabel, firstValue, secondLabel, secondValue] = labeled;
157
- const firstIsLat = /^lat/iu.test(firstLabel);
158
- if (firstIsLat === /^lat/iu.test(secondLabel))
159
- return null;
160
- return firstIsLat
161
- ? coordinates(Number(firstValue), Number(secondValue), "lat_lon")
162
- : coordinates(Number(secondValue), Number(firstValue), "lon_lat");
163
- }
164
- return parseCoordinatePair(trimmed);
165
- }
166
- /**
167
- * A coordinate pair as text, latitude first, in the form {@link parsePointQuery} reads back.
168
- *
169
- * Six decimals place a point within about 11 cm.
170
- */
171
- export function coordinatePairText(lat, lon, decimals = 6) {
172
- return `${lat.toFixed(decimals)}, ${lon.toFixed(decimals)}`;
173
- }
174
- /**
175
- * The label a point query is shown under, such as the tag column of a parse.
176
- */
177
- export const POINT_QUERY_LABEL = {
178
- coordinates: "coordinates",
179
- plus_code: "plus code",
180
- h3: "H3 cell",
181
- geohash: "geohash",
182
- wof: "Who's On First id",
183
- };
184
- /**
185
- * The same shapes as a noun phrase with its article, for a sentence: "this is a plus code".
186
- */
187
- export const POINT_QUERY_PHRASE = {
188
- coordinates: "a coordinate pair",
189
- plus_code: "a plus code",
190
- h3: "an H3 cell",
191
- geohash: "a geohash",
192
- wof: "a Who's On First id",
193
- };
194
- //# sourceMappingURL=point-query.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"point-query.js","sourceRoot":"","sources":["../lib/point-query.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAsDrE;;GAEG;AACH,MAAM,aAAa,GAAG,yCAAyC,CAAA;AAE/D;;GAEG;AACH,MAAM,aAAa,GAAG,+DAA+D,CAAA;AAErF;;GAEG;AACH,MAAM,OAAO,GAAG,6BAA6B,CAAA;AAE7C;;GAEG;AACH,MAAM,iBAAiB,GAAG,+CAA+C,CAAA;AAEzE;;GAEG;AACH,MAAM,OAAO,GAAG,0EAA0E,CAAA;AAE1F;;GAEG;AACH,MAAM,YAAY,GAAG,uDAAuD,CAAA;AAE5E;;GA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