diff options
author | Marcus Lundblad <ml@dfupdate.se> | 2022-10-27 23:17:24 +0200 |
---|---|---|
committer | Marcus Lundblad <ml@dfupdate.se> | 2022-11-15 23:34:27 +0100 |
commit | 748e2a6a0a13bf18f80456b3d422b25fd85556b4 (patch) | |
tree | be372384e1667c3d3cc1a260a5b6b26e77b451bf | |
parent | dcf63e70f7768770ccf0435ec750a181048bce9a (diff) | |
download | gnome-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.js | 17 |
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. |