Vdo
🏷 Minimal JSX compatible html focused templating engine.
Install / Use
/learn @DylanPiercey/VdoREADME
VDO
The lightweight JSX compatible templating engine. Perfect for creating html strings server side or in browser.
Check out set-dom, diffhtml or morphdom for React style diffing.
Why
JSX is powerful compared to other templating engines but it has some warts. It has some abstractions that simply don't make sense for creating html (ala className). "VDO" provides a JSX interface that is specifically designed for rendering html, not DOM.
Features
- Minimal API.
- ~1kb min/gzip.
- No extra "data-react-id".
- No random span's.
- Allows any custom attribute (react only allows data-).
- Render nested arrays.
- Optimized for rendering html.
- Escaped values by default.
- JSX compatible.
Installation
Npm
npm install vdo
Example
/** @jsx vdo */
const vdo = require('vdo');
function MyPartial (attrs, children) {
return <span class="custom" data-value={attrs.value}/>;
}
const html = (
<div class="root">
<MyPartial value="1"/>
</div>
);
document.body.innerHTML = html;
API
- isElement(element) : Tests if given
elementis a vdo virtual element.
vdo.isElement(<div/>); // true
- markSafe(html) : Marks html as safe as a VDO child node.
// Use #markSafe instead of "innerHTML" when coming from react.
// This allows for mixes of safe and unsafe html in the same node.
const myHTMLStr = "<br/>";
const vNode = <div>{ vdo.markSafe(myHTMLStr) }</div>;
String(vNode); //-> <div><br/></div>
- with(context, renderer) : Gives all components inside a render function some external
context.
// renderer must be a function that returns a virtual node.
function MyComponent (props, children, context) {
return (
<div>External data: { context }</div>
);
}
String(vdo.with(1, ()=> <MyComponent/>));
//-> "<div>External Data: 1</div>"
- createElement(type, props, children...) : Create a virtual node/component.
// Automatically called when using JSX.
let vNode = vdo.createElement("div", { editable: true }, "Hello World");
// Or call vdo directly
let vNode = vdo("div", { editable: true }, "Hello World");
// Render to string on the server.
vNode.toString(); // '<div editable="true">Hello World</div>';
/**
* @params type can also be a function (shown in example above).
*/
Contributions
- Use
npm testto run tests.
Please feel free to create a PR!
Related Skills
node-connect
349.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
