datatracker/client/shared/urls.js
Nicolas Giard 0c920b0a29
fix: precompile template urls at build time + bs5 btn on agenda loading screen (#4679)
* fix: precompile template urls at build time + bs5 btn on agenda loading screen

* fix: add back url store changes
2022-11-01 11:51:33 -05:00

19 lines
683 B
JavaScript

/**
* 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)
}