-
Notifications
You must be signed in to change notification settings - Fork 3
/
namespaces.js
34 lines (29 loc) · 1015 Bytes
/
namespaces.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const namespaces = {
xml: 'http://www.w3.org/XML/1998/namespace',
html: 'http://www.w3.org/1999/xhtml',
svg: 'http://www.w3.org/2000/svg',
math: 'http://www.w3.org/1998/Math/MathML',
xlink: 'http://www.w3.org/1999/xlink'
}
/**
* Get declared namespaceURI using it's prefix
* @param {string} prefix - Perfix for the namespaceURI
* @returns {string} NamespaceURI defined by the prefix
*/
const getNamespace = (prefix) => {
if (namespaces[prefix]) return namespaces[prefix]
throw new Error(`[EF] Namespace "${prefix}" has not been declared.`)
}
/**
* Declare namespaceURI with a prefix
* @param {string} prefix - Perfix for the namespaceURI
* @param {string} namespaceURI - NamespaceURI associated with the prefix
* @returns {void}
*/
const declareNamespace = (prefix, namespaceURI) => {
if (namespaces[prefix]) {
throw new Error(`[EF] Namespace "${prefix}" has already been declared as "${namespaces[prefix]}".`)
}
namespaces[prefix] = namespaceURI
}
export {getNamespace, declareNamespace}