From e1313ee7abb93a8a20f978ac152b462c9ef74a43 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 16 Oct 2026 10:29:49 +0200 Subject: feat(user): location suggestions from OpenStreetMap There is no place database on this machine, and the user chose Nominatim over a tz city list for coverage. It is asked 1s after typing stops (its policy: one request a second, an identifying User-Agent, nothing personal sent), from three characters, in the desktop's language, and a reply to an older query is dropped. places() turns its JSON into 'place, region, country' labels and treats an error page as no suggestions; test_user.js covers it. Co-Authored-By: Claude Opus 5.5 --- desktop/modules/user/test_user.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'desktop/modules/user/test_user.js') diff --git a/desktop/modules/user/test_user.js b/desktop/modules/user/test_user.js index 3ab22a1..3f1a73d 100644 --- a/desktop/modules/user/test_user.js +++ b/desktop/modules/user/test_user.js @@ -18,7 +18,7 @@ const assert = require("assert"); const src = fs.readFileSync(__dirname + "/User.js", "utf8") .replace(/^\.pragma library$/m, ""); -const U = new Function(src + "\nreturn { parse, keys, locales, gitName };")(); +const U = new Function(src + "\nreturn { parse, keys, locales, gitName, places };")(); // parse: key=value lines; a value may itself hold "=". assert.deepStrictEqual(U.parse("name=Jane Doèr\nlocation=a=b\n\n"), @@ -44,4 +44,24 @@ assert.strictEqual(U.gitName("Ève Àlba"), "Ève À."); assert.strictEqual(U.gitName(" Jane Doèr "), "Jane D."); assert.strictEqual(U.gitName(""), ""); +// places: Nominatim jsonv2 results as "place, region, country", the most +// specific settlement name first, duplicates and repeated parts dropped. +const nominatim = JSON.stringify([ + { name: "Roma", address: { city: "Roma", state: "Lazio", country: "Italia" } }, + { name: "Rome", address: { town: "Rome", county: "Floyd County", state: "Georgia", country: "United States" } }, + { name: "Roma", address: { city: "Roma", state: "Lazio", country: "Italia" } }, + { name: "Monaco", address: { city: "Monaco", country: "Monaco" } }, + { name: "Piazza", address: { village: "Piazza", country: "Italia" } }, + { name: "Somewhere" }, +]); +assert.deepStrictEqual(U.places(nominatim), [ + "Roma, Lazio, Italia", + "Rome, Georgia, United States", + "Monaco", + "Piazza, Italia", + "Somewhere", +]); +assert.deepStrictEqual(U.places(""), []); +assert.deepStrictEqual(U.places("rate limited"), []); + console.log("test_user: ok"); -- cgit v1.2.3