3 ms·
A bit off topic but I wrote a very small JS library that uses this exact format 6-7 years ago. It transforms such an object to a DOM tree. This is nice to see s
by jraph 9y ago
A bit off topic but I wrote a very small JS library that uses this exact format 6-7 years ago. It transforms such an object to a DOM tree. This is nice to see somebody mention this format, this kind of validates it. So, thank you!
It also accepts things like ["div#123.class-name-1 class-name-2", ["span", "Hello world"]].
You can keep a reference of a node in a Javascript object if needed:
let refs = {};
let div = jso2dom(
["div",
["span", {"#":"sp"}, "Hello world"]
],
refs
);
console.log(refs.sp); // <span> Hello World </span>
I've found it very convenient so far and still use it today. This is simple, prodigiously stupid and works in vanilla JS, so this works for me for the time being.
Parsing may be complex but in my case, this is done by the Javascript engine, so I'm not affected by this complexity.