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

ejs-builder

v0.0.1

Published

A builder for the EJS templating engine

Readme

EJS Renderer

A wrapper around the EJS library to render templates with middleware.

Installation

npm install ejs-builder

Usage

The following example demonstrates how to create a renderer with a template string and use middleware to modify the view before rendering.

import { createRenderer } from "ejs-builder";

// Define a view interface
interface View {
  name: string;
}

// Get a template string from somewhere
const templateStr = "<h1>Hello, <%= name %>!</h1>";

// Create a renderer with a template string
const render = createRenderer<View>(templateStr);

// Use a middleware to modify the view
render.use(async (ctx, next) => {
  ctx.view.name = ctx.view.name.toUpperCase();
  await next();
});

render.use(async (ctx, next) => {
  ctx.view.name = ctx.view.name.replace("!", "!!");
  await next();
});

// Render the template with a view
const html = await render({ name: "world" });
console.log(html); // <h1>Hello, WORLD!!</h1>

API

Renderer

The renderer class is used to render templates with middleware.

createRenderer<T>(template: string, options?: Options): Render<T>

Creates a new renderer with the given template string.

Arguments:

  • template - The template string to render
  • options - The options to pass to the EJS compiler

Example:

import { createRenderer } from "ejs-builder";

const templateString = "<h1>Hello, <%= name %>!</h1>";
const renderer = createRenderer(templateString, { delimiter: "?" });

render(view: T): Promise<string>

Renders the template with the given view.

Arguments:

  • view - The view to render the template with

render.use(...middlewares: Middleware<T>[]): void

Adds a middleware to the renderer.

Arguments:

  • middlewares - The middleware functions to add

Middleware

composeMiddleware<T>(fn: ComposeFn<T>, ...middlewares: Middleware<T>[]): ComposedFn<T>

Composes a middleware function with the given compile function and middleware.

Arguments:

  • fn - The compose function
  • middlewares - The middleware functions

Example:

import { composeMiddleware } from "ejs-builder";

const middleware = composeMiddleware(
  (ctx, next) => {
    ctx.view.name = ctx.view.name.toUpperCase();
    return next();
  },
  (ctx, next) => {
    ctx.view.name = ctx.view.name.replace("!", "!!");
    return next();
  },
);

// Execute the middleware
await middleware({ view: { name: "world" } });

License

This project is licensed under the MIT License - see the LICENSE file for details.