forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurls.js
More file actions
18 lines (17 loc) · 683 Bytes
/
urls.js
File metadata and controls
18 lines (17 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* DO NOT add the urls here directly. Edit the urls.json file instead.
* The urls are automatically precompiled into the variable below at build time.
*/
const urls = { /* __COMPILED_URLS__ */ }
/**
* Get an URL and replace tokens with provided values.
*
* @param {string} key The key of the URL template to use.
* @param {Object} [tokens] An object of tokens to replace in the URL template.
* @returns {string} URL with tokens replaced with the provided values.
*/
export const getUrl = (key, tokens = {}) => {
if (!key) { throw new Error('Must provide a key for getUrl()') }
if (!urls[key]) { throw new Error('Invalid getUrl() key') }
return urls[key](tokens)
}