Add has metamethod to proxies

This change allows proxies to be used with `with` for easier HTML/SVG
generation.
This commit is contained in:
Talia 2021-08-04 17:00:00 +02:00
parent 736f850dd7
commit 0d547a3ceb
No known key found for this signature in database
GPG key ID: AD727AD22802D0D6

View file

@ -49,7 +49,10 @@ const node = (name, args, options) => {
return element return element
} }
const nameSpacedProxy = (options={}) => new Proxy(Window, { get: (target, prop, receiver) => { return (...args) => node(prop, args, options) }}) const nameSpacedProxy = (options={}) => new Proxy(Window, {
get: (target, prop, receiver) => { return (...args) => node(prop, args, options) },
has: (target, prop) => true,
})
export const html = nameSpacedProxy({nameFilter: name => name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()}) export const html = nameSpacedProxy({nameFilter: name => name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()})
export const svg = nameSpacedProxy({xmlns: "http://www.w3.org/2000/svg"}) export const svg = nameSpacedProxy({xmlns: "http://www.w3.org/2000/svg"})