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

kensington-express

v1.0.5

Published

Express middleware for function-based view rendering with kensington

Readme

kensington-express

Express middleware that attaches res.renderView() to each response, for use with function-based (no template engine) view rendering.

Installation

npm install kensington-express

Usage

// views/layout.js
import t from 'kensington';

export default function layout(locals, page) {
  return t.htmlWithDocType({ lang: 'en' },
    t.head(
      t.title(locals.title),
    ),
    t.body(
      page(locals),
    ),
  );
}
// views/home.js
import t from 'kensington';

export default function homePage({ title, items }) {
  return t.main(
    t.h1(title),
    t.ul(items.map(item => t.li(item))),
  );
}
// app.js
import kensingtonView from 'kensington-express';
import layout from './views/layout.js';
import homePage from './views/home.js';

app.use(kensingtonView(layout));

app.get('/', (req, res) => {
  res.renderView(homePage, { title: 'Home', items: ['foo', 'bar'] });
});

API

kensingtonView(defaultLayout, htmlValidator?)

Returns an Express middleware. Call once during app setup.

| Parameter | Type | Description | |---|---|---| | defaultLayout | LayoutRenderer \| null | Wraps every page renderer. Pass null to render pages without a layout. | | htmlValidator | (html: string) => void \| Promise<void> | Called after the response is sent. Useful for dev-time HTML linting. |

res.renderView(pageRenderer, options?)

Renders and sends an HTML response.

| Parameter | Type | Description | |---|---|---| | pageRenderer | (locals) => string | Renders the page content. | | options | object | Merged into locals. Pass layout to override the default layout for this response. |

Locals available to both renderers are merged in this order (later values win):

  1. req.route
  2. app.locals
  3. res.locals
  4. options passed to renderView

Layouts

To use an alternate layout for a route, pass it as layout:

// views/admin-layout.js
import t from 'kensington';

export default function adminLayout(locals, page) {
  return t.htmlWithDocType({ lang: 'en' },
    t.head(
      t.title(locals.title),
    ),
    t.body(
      t.nav('Admin'),
      page(locals),
    ),
  );
}
// app.js
import adminLayout from './views/admin-layout.js';

app.get('/admin', (req, res) => {
  res.renderView(adminPage, { layout: adminLayout, title: 'Admin' });
});

To skip the layout entirely for a route, pass layout: null:

res.renderView(myPageRenderer, { layout: null });

HTML validation

Pass a htmlValidator function to report markup issues during development. It runs after the response is sent so it never blocks the client:

import { HtmlValidate } from 'html-validate';

const htmlvalidate = new HtmlValidate();

async function htmlValidator(html) {
  const report = await htmlvalidate.validateString(html);
  if (!report.valid) console.warn(report.results);
}

app.use(kensingtonView(layout, process.env.NODE_ENV !== 'production' ? htmlValidator : undefined));