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

@bandf/code-image

v1.2.0

Published

Browser-only code image rendering powered by Highlight.js and Canvas.

Downloads

97

Readme

@bandf/code-image

Browser-only code image rendering powered by Highlight.js and the Canvas API. The package takes source code and optional metadata, lays out a styled code card, and returns a PNG Blob. It does not use a server or send source code over the network.

Install

npm install @bandf/code-image

Use

import {renderCodeImage} from '@bandf/code-image';

const png = await renderCodeImage({
    code: 'const answer = 42;',
    language: 'javascript',
    title: 'answer.js'
});

png is a browser Blob with type image/png. Applications can write it to the clipboard, download it with an object URL, upload it, or display it.

React and bundlers

The package has no React dependency. Call it from a client-side event handler and keep presentation, loading state, and delivery of the resulting Blob in the application:

'use client';

import {renderCodeImage} from '@bandf/code-image';

export function CodeImageButton({code, language, onImage}) {
    const createImage = async () => {
        const png = await renderCodeImage({code, language});
        onImage(png);
    };

    return <button onClick={createImage}>Create image</button>;
}

The package is native ESM and uses a dynamic import for Highlight.js, allowing modern bundlers to keep the full language build in an on-demand chunk. It is verified with Vite's production bundler. Importing the module during server-side rendering is safe, but calling renderCodeImage requires DOM and Canvas browser APIs. React Server Components and other SSR applications must invoke it from a client boundary.

Highlighting

Highlight.js is a direct dependency and implementation detail of this package. Callers provide a language when they know it. If the language is missing or not recognized, the package uses Highlight.js automatic detection. If highlighting fails, rendering falls back to uncolored source text.

The full Highlight.js language build is used so the default package works without language registration or application-level highlighter configuration.

Themes

The default theme is light. A built-in dark theme is also available:

await renderCodeImage(input, {theme: 'dark'});

A custom theme can extend either built-in theme:

await renderCodeImage(input, {
    theme: {
        base: 'dark',
        codeBackground: '#101418',
        syntax: {
            keyword: '#7dd3fc'
        }
    }
});

Theme input is explicit. The renderer does not inspect the consuming page's CSS or global custom properties, so the same input and theme produce a consistent design across applications.

Exports

  • renderCodeImage(input, options) returns a Promise for a PNG Blob.
  • codeImageFilename(input) creates a filesystem-safe PNG filename.
  • validateCodeImageSelection(input) validates and normalizes input.
  • codeImageThemes exposes the built-in theme values.
  • resolveCodeImageTheme(input) resolves names and partial custom themes.

Browser requirements

Rendering requires HTMLCanvasElement, a 2D Canvas context, and HTMLCanvasElement.toBlob(). Clipboard and download behavior deliberately remain the responsibility of the consuming application.

License

MIT