{"id":42059,"library":"tag2link","title":"tag2link","description":"tag2link provides formatter URLs for OpenStreetMap keys, enabling conversion of OSM tags into hyperlinks. Version 2026.5.21 is current, updated periodically from Wikidata and OSM Wiki via automated scripts (Python + npm). It replaces `$1` in URL templates with the tag value. Ships TypeScript types. Key differentiator: centralized, community-maintained mapping from OSM keys to authoritative external resources (e.g., Wikidata, OSM Wiki).","status":"active","version":"2026.5.21","language":"javascript","source_language":"en","source_url":"https://github.com/JOSM/tag2link","tags":["javascript","openstreetmap","tagging","tag2link","hyperlink","url-template","typescript"],"install":[{"cmd":"npm install tag2link","lang":"bash","label":"npm"},{"cmd":"yarn add tag2link","lang":"bash","label":"yarn"},{"cmd":"pnpm add tag2link","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only; default export is the main JSON object mapping keys to URL templates.","wrong":"const tag2link = require('tag2link')","symbol":"tag2link","correct":"import tag2link from 'tag2link'"},{"note":"TypeScript type for the exported JSON structure; no runtime value.","wrong":"","symbol":"Tag2LinkData","correct":"import type { Tag2LinkData } from 'tag2link'"},{"note":"Named export for an array of {key, url} objects, available since v2026.5.0.","wrong":"","symbol":"entries","correct":"import { entries } from 'tag2link'"}],"quickstart":{"code":"import tag2link from 'tag2link';\n\n// Get the formatter URL for a given OSM key\nconst key = 'highway';\nconst urlTemplate = tag2link[key];\nif (urlTemplate) {\n  // Replace $1 with the tag value to get a concrete URL\n  const tagValue = 'primary';\n  const fullUrl = urlTemplate.replace('$1', tagValue);\n  console.log(fullUrl);\n  // e.g., \"https://wiki.openstreetmap.org/wiki/Key:highway\"\n} else {\n  console.log('No formatter URL found for key:', key);\n}","lang":"typescript","description":"Demonstrates importing the default export, looking up a formatter URL by OSM key, and substituting the tag value."},"warnings":[{"fix":"Access directly with the key string as it appears in OSM (e.g., 'highway', 'amenity').","message":"The exported object keys are OSM keys (e.g., 'highway'), not prefixed with 'key:' or 'tag:'.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always check for existence before accessing or use optional chaining.","message":"Not all OSM keys have formatter URLs; missing keys yield undefined.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use encodeURIComponent($1) in replacement if the template does not expect raw values.","message":"URL templates contain $1 placeholder; some URLs may require URL-encoding of the tag value.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use dynamic import() or switch to ESM-compatible environment. For older versions, pin to <2026.5.0.","message":"Package migrated to ESM-only starting v2026.5.0; CommonJS require() fails.","severity":"breaking","affected_versions":">=2026.5.0"},{"fix":"Import directly from 'tag2link' (default export) or from 'tag2link/entries' for array format.","message":"Index.json removed in favor of package exports; paths like 'tag2link/index.json' no longer work.","severity":"breaking","affected_versions":">=2026.5.0"}],"env_vars":null,"search_vec":"'1':34 '2026.5.21':17 'authorit':56 'autom':28 'central':47 'communiti':49 'community-maintain':48 'convers':10 'current':19 'differenti':46 'e.g':59 'enabl':9 'extern':57 'formatt':4 'hyperlink':15,67 'javascript':63 'key':8,45,54 'maintain':50 'map':51 'npm':31 'openstreetmap':7,64 'osm':12,25,53,61 'period':21 'provid':3 'python':30 'replac':33 'resourc':58 'script':29 'ship':42 'tag':13,40,65 'tag2link':1,2,66 'templat':37,70 'type':44 'typescript':43,71 'updat':20 'url':5,36,69 'url-templ':68 'valu':41 'version':16 'via':27 'wiki':26,62 'wikidata':23,60","created_at":"2026-06-04T18:55:25.335615+00:00","updated_at":"2026-06-04T18:55:25.335615+00:00","problems":[{"fix":"Use `import tag2link from 'tag2link'` instead.","cause":"Package restructured; index.json is no longer a direct file path.","error":"Cannot find module 'tag2link/index.json'"},{"fix":"Switch to ESM environment or use dynamic import: `const tag2link = await import('tag2link');`","cause":"Package is ESM-only since v2026.5.0.","error":"require() of ES Module tag2link not supported"},{"fix":"Check the exact OSM key and that a formatter URL exists (e.g., 'highway' works, 'highwayy' does not).","cause":"Key not present in the mapping or typo.","error":"TypeError: tag2link[key] is undefined"},{"fix":"Run `npm install tag2link` and ensure import path is exactly 'tag2link'.","cause":"Package not installed or incorrect import path.","error":"Error: Cannot find module 'tag2link'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/JOSM/tag2link","github":"https://github.com/JOSM/tag2link","docs":null,"changelog":null,"pypi":null,"npm":"tag2link","openapi_spec":null,"status_page":null,"smithery":null,"categories":["maps"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}