From f2f4c03d69d0eb9721c74a89ec573f239967b467 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Fri, 30 Jul 2021 12:12:00 +0200 Subject: [PATCH] Make name filtering exclusive to HTML nodes --- skooma.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/skooma.js b/skooma.js index ed5aeb9..df0363b 100644 --- a/skooma.js +++ b/skooma.js @@ -38,17 +38,18 @@ const parseArgs = (element, ...args) => { element.setAttribute(key, parseAttribute(arg[key])) } -const node = (name, args, xmlns) => { +const node = (name, args, options) => { let element - if (xmlns) - element = document.createElementNS(xmlns, name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()) + if (options.nameFilter) name = options.nameFilter(name) + if (options.xmlns) + element = document.createElementNS(options.xmlns, name) else - element = document.createElement(name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()) + element = document.createElement(name) parseArgs(element, args) 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 svg = nameSpacedProxy("http://www.w3.org/2000/svg") +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"})