Make name filtering exclusive to HTML nodes
This commit is contained in:
parent
f8db2ca876
commit
cb7ad57874
1 changed files with 8 additions and 7 deletions
15
skooma.js
15
skooma.js
|
@ -38,17 +38,18 @@ const parseArgs = (element, ...args) => {
|
||||||
element.setAttribute(key, parseAttribute(arg[key]))
|
element.setAttribute(key, parseAttribute(arg[key]))
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = (name, args, xmlns) => {
|
const node = (name, args, options) => {
|
||||||
let element
|
let element
|
||||||
if (xmlns)
|
if (options.nameFilter) name = options.nameFilter(name)
|
||||||
element = document.createElementNS(xmlns, name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase())
|
if (options.xmlns)
|
||||||
|
element = document.createElementNS(options.xmlns, name)
|
||||||
else
|
else
|
||||||
element = document.createElement(name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase())
|
element = document.createElement(name)
|
||||||
parseArgs(element, args)
|
parseArgs(element, args)
|
||||||
return element
|
return element
|
||||||
}
|
}
|
||||||
|
|
||||||
const nameSpacedProxy = (xmlns) => new Proxy(Window, { get: (target, prop, receiver) => { return (...args) => node(prop, args, xmlns) }})
|
const nameSpacedProxy = (options={}) => new Proxy(Window, { get: (target, prop, receiver) => { return (...args) => node(prop, args, options) }})
|
||||||
|
|
||||||
export const html = nameSpacedProxy()
|
export const html = nameSpacedProxy({nameFilter: name => name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()})
|
||||||
export const svg = nameSpacedProxy("http://www.w3.org/2000/svg")
|
export const svg = nameSpacedProxy({xmlns: "http://www.w3.org/2000/svg"})
|
||||||
|
|
Loading…
Reference in a new issue