aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/user/User.js
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/modules/user/User.js')
-rw-r--r--desktop/modules/user/User.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/desktop/modules/user/User.js b/desktop/modules/user/User.js
index 8160b7f..5c3d5a2 100644
--- a/desktop/modules/user/User.js
+++ b/desktop/modules/user/User.js
@@ -44,3 +44,21 @@ function gitName(name) {
if (w.length < 2) return w.join(" ");
return w.slice(0, -1).join(" ") + " " + Array.from(w[w.length - 1])[0] + ".";
}
+
+// Nominatim jsonv2 search results as location labels, "place, region,
+// country", deduplicated. Anything that is not a JSON array (an error page,
+// a rate-limit notice) is no suggestions rather than an error.
+function places(text) {
+ let rows;
+ try { rows = JSON.parse(text); } catch (e) { return []; }
+ if (!Array.isArray(rows)) return [];
+ const out = [];
+ for (const r of rows) {
+ const a = r.address || {};
+ const parts = [a.city || a.town || a.village || a.hamlet || a.municipality || r.name,
+ a.state, a.country].filter(p => p);
+ const label = parts.filter((p, i) => parts.indexOf(p) === i).join(", ");
+ if (label && !out.includes(label)) out.push(label);
+ }
+ return out;
+}