npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

koa-ve

v1.0.1

Published

Vé: asynchronous server side rendering of JSX using Koa

Readme

Asynchronous server side rendering of JSX using Koa

React's JSX is a pleasant enough way to write HTML, but when rendering server side, the whole shebang with states and JS-style attributes is needlessly complicated. Vé, named after the norse god who gave the original stick-figure-humans shapes and senses, is a small project to give simple JSX-support through Koa without distraction.

npm install --save koa-ve

Configured for Koa

The renderer is written with Koa's ctx and next in mind. While technically not a requirement, the alternative is to write your own middleware using Ve.engine, which takes a writable stream and the component to render as its first two arguments. All later arguments will be available to the component-functions.

npm install --save koa

Better with Babel and its React/JSX transformation plugin

npm install --save-dev babel-cli babel-plugin-transform-react-jsx

The difference between

<div class="my-div">hello world</div>

and

Ve.component("div", {class: "my-div"}, "hello world");

is quite noticable, after all.

Configure .babelrc

{
  "plugins": [
    ["transform-react-jsx",
      {
        "pragma": "Ve.component"
      }
    ]
  ],
}

Use as middleware

app.use(require('koa-ve').render)

Write HTML components with JSX

All attribute names are written in the usual HTML-way, using double quotes, with the value's double-quotes escaped. There is white-list of valid attribute names in Ve.config taken from MDN which determines what will be visible, also allowing /^data-[\w-]*$/ and /^on\w+$/.

The configuration object also includes lists of tag-names for empty elements (br, input, etc) which do not display its children, and preformatted elements (textarea, pre) which filters away non-string children.

const Ve = require('koa-ve');
async function MyDiv (ctx) {
  return <div {...this.attr} class={"my-div " + this.attr.class}>
    {this.children}
  </div>
}

All together

The following example can be found as small-demo/demo.jsx.

const Koa = require('koa');
const Ve = require('koa-ve');
 
async function Component (ctx) {
  ctx.state.title = "Component - " + ctx.state.title;
  await new Promise((ok) => setTimeout(ok, 100))
  return (
    <div class="component">
      <header>
        <h1>
          Hello World
        </h1>
      </header>
      <main data-name={'"you"'} custom-attributes="will be hidden by default">
        <Child name={"you"}> 
          Hello
        </Child>
      </main>
      <footer>
          &copy; 2018
      </footer>
    </div>
  )
}
 
function Child () {
  return <h3>
    {this.children}
    to
    <i>
      {this.attr.name}
    </i>
    as well
  </h3>
}
 
const app = new Koa();
app.use(Ve.render);
app.use(async (ctx, next) => {
  ctx.state.title = "Vé"
  let children = await next();
  return (
    <html>
      <head>
        <meta charset="utf-8"/>
        <title>
          {ctx.state.title}
        </title>
        <style>
{`
.component {
  width: 250px;
  margin: 50px;
}
h1 {
  color: steelblue;
  font-weight: normal;
}
`}
        </style>
      </head>
      <body>
        {children}
      </body>
    </html>
  )
})
 
app.use(Component);
app.listen(3000);

And finally the source, as available to the browser:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8"/>
    <title>
      Component - Vé
    </title>
    <style>
      
.component {
  width: 250px;
  margin: 50px;
}
h1 {
  color: steelblue;
  font-weight: normal;
}

    </style>
  </head>
  <body>
    <div class="component">
      <header>
        <h1>
          Hello World
        </h1>
      </header>
      <main data-name="&quot;you&quot;">
        <h3>
          Hello
          to
          <i>
            you
          </i>
          as well
        </h3>
      </main>
      <footer>
        © 2018
      </footer>
    </div>
  </body>
</html>