summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@dfupdate.se>2022-10-27 23:17:24 +0200
committerMarcus Lundblad <ml@dfupdate.se>2022-11-15 23:34:27 +0100
commit748e2a6a0a13bf18f80456b3d422b25fd85556b4 (patch)
treebe372384e1667c3d3cc1a260a5b6b26e77b451bf
parentdcf63e70f7768770ccf0435ec750a181048bce9a (diff)
downloadgnome-maps-748e2a6a0a13bf18f80456b3d422b25fd85556b4.tar.gz
osmUtils: Add function to get a Wikidata tag from a URL
Adds a function to get the Wikidata tag from a URL of the forms: http(s)://www.wikidata.org/wiki/Qnnnn or http(s)://www.wikidata.org/wiki/Special:EntityPage/Qnnnn.
-rw-r--r--src/osmUtils.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/osmUtils.js b/src/osmUtils.js
index fd245a76..23a2bff2 100644
--- a/src/osmUtils.js
+++ b/src/osmUtils.js
@@ -43,6 +43,23 @@ export function getWikipediaOSMArticleFormatFromUrl(url) {
}
}
+/*
+ * Gets a Wikidata tag from from a URL of the forms
+ * https://www.wikidata.org/wiki/Qnnnn, or
+ * https://www.wikidata.org/wiki/Special:EntityPage/Qnnnn
+ * or null if input doesn't match these formats
+ */
+export function getWikidataFromUrl(url) {
+ let regex =
+ /https?:\/\/www.\wikidata\.org\/wiki\/(?:Special:EntityPage\/)?(Q\d+)/;
+ let match = url.match(regex);
+
+ if (match?.length === 3 || match?.length === 2)
+ return match.last();
+ else
+ return null;
+}
+
/**
* Updates a Place object according to an OSMObject.
* Will also update place in the place store.