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

@clinth/repl-pad

v0.1.2

Published

Javascript REPL

Readme

repl-pad

repl-pad takes some Javascript and presents it in an editable REPL-like environment. It is meant for easily making example snippets runnable and editable.

Demos:

Results appear as an inline overlay directly to the right of each line of code:

Screenshot

Repl-pad gives the illusion that each line of code is executed independently, with the result shown to the side. In reality each block executes along with every block that precedes it.

Statements that generate an error are skipped over optimistically, so the REPL experience can be more 'sketchy':

Screenshot

URL-based imports can be used as well:

Screenshot

Caveats

for await ... of and async functions are handled by wrapping the whole snippet in an immediately-invoked async function expression. This allows await to work, but code runs in a single async context rather than as true top-level await.

Because the same code is re-evaluated repeatedly, initiating timers can be problematic. Use the complete mode to avoid this.

Usage

npm install --save @clinth/repl-pad

Repl-pad is a vanilla web component. It can be used programmatically, but it was designed to be hosted in a stand-alone simple HTML page. Code source comes in base64-encoded via a URI anchor:

pad.html#ugly-base-64-string

A small helper function allows you to generate this URL automatically from a HTML element's innerText. This is meant to convert a static code example into something runnable.

In your HTML:

<pre id="eg1">
const x = 1;
</pre>

In your JS:

import {fromInnerText} from '@clinth/repl-pad';
const el = document.getElementById(`eg1`);

// Yields: pad.html#...
const uri = fromInnerText(el, `pad.html`);

// Create an edit link and add after example
const link = document.createElement(`a`);
link.href = uri;
link.innerText = `Edit`;
el.parentNode.insertBefore(link, el.nextSibling);

One can add edit links for all elements that match a CSS selector:

<pre>
  const x = 1;
</pre>

<pre>
  const x = Math.random();
</pre>
import {fromQuery} from '@clinth/repl-pad/link.js';
const r = fromQuery(`pre`, `pad.html`);

for (const {el, uri} of r) {
  const link = document.createElement(`a`);
  link.href = uri;
  link.innerText = `Edit`;
  el.parentNode.insertBefore(link, el.nextSibling);
}

See this in action in docs/index.html.

Programmatic usage

It's also possible to send JS code programmatically:

import {ReplPadElement} from '@clinth/repl-pad';
const r = new ReplPadElement(`
  const x = 1;
  x;
`);
document.body.appendChild(r);

Or use the custom element directly in HTML (after importing the module):

<repl-pad></repl-pad>

Result display

Results appear as an overlay to the right of each line. They are colour-coded:

  • Default (grey) — normal value
  • Red — error
  • Italic grey — informational (e.g. pending timer ⏱)

For loops

For for and for...of loops, the index variable's values are shown comma-separated on the opening for line. Expressions inside the loop body also accumulate their values per line:

for (let i = 0; i < 5; i++) {
  i * 2;
}

The for line shows: 0, 1, 2, 3, 4
The body expression line shows: 0, 2, 4, 6, 8

Timers (setTimeout / setInterval)

setTimeout callbacks show the elapsed time with a ⏱ prefix when they fire. Expressions inside the callback are captured and displayed on their own lines.

setInterval callbacks accumulate values comma-separated, like a loop.

setTimeout(() => {
  Math.random();
}, 2000);

The setTimeout line shows: ⏱ 2s
The inner expression line shows the return value when it fires.

Refresh button

Hover over any result label to reveal a ↻ button. Clicking it re-executes just that block against the same context from the last full run, without re-running the entire script.

Re-evaluation

Repl-pad evaluates each block along with its preceding blocks. The consequence is that some statements are executed several times.

For example, with three console.log lines, the first line runs three times (once per block that follows). Repl-pad does not re-evaluate console.* statements by default to avoid duplicate output. For this reason, avoid side-effects inside console.*:

// Bad: data is changed within the console statement
console.log(i++);

// Good: side-effect is separate
i++;
console.log(i);

Options

Options can be specified as URL parameters:

pad.html?reevalUndef=false&maxResultLength=20#base-64

Or as attributes on the web component:

<repl-pad reevalUndef="false" maxResultLength="20"></repl-pad>

Or as JS properties before the component runs:

const pad = new ReplPadElement();
pad.maxResultLength = 20;
pad.maxLoopLength = 10;

reevalUndef (true/false, default true)

If true, statements that return undefined are re-evaluated when building the cumulative context for later blocks. If false, they are skipped, which prevents some duplicate side-effects.


reevalConsole (true/false, default false)

If true, console.* statements are re-evaluated as part of the cumulative context.


maxResultLength (integer, default 10)

Maximum characters shown per result label before truncating with .... Hover over a truncated result to see the full value. Error messages are never truncated.


maxLoopLength (integer, default 5)

Maximum number of iterations to capture and display for for loops and setInterval firings.


mode (string, default "")

Set to "complete" to run the entire script in a Web Worker (experimental). This avoids timer accumulation across re-runs.

Styling

See docs/pad.html for an example.

repl-pad {
  display: flex;
  flex: 1;
}

CSS custom properties:

| Property | Purpose | |---|---| | --mono-font | Monospace font family for the editor and result labels | | --ui-font | Sans-serif font for any UI chrome | | --font-size | Base font size | | --padding | Editor padding | | --line-height | Line height (must match for overlay alignment) | | --output | Result label colour | | --console-error | Error label colour | | --console-warn | Warning colour | | --ui-bg | UI background | | --ui-fg | UI foreground | | --ui-pinstripe | Subtle background accent | | --ui-highlight-bg | Text selection background | | --ui-highlight-fg | Text selection foreground | | --console-bg | Console panel background | | --console-fg | Console panel foreground | | --comment-font | Font family for // comments (falls back to --mono-font) | | --comment-style | font-style for // comments, e.g. italic or normal (falls back to italic) | | --comment-color | Colour for // comments (falls back to --ui-fg) |

Only // line comments are styled; /* */ block comments are not detected.

Developing

npm run dev

Continually rebuilds and serves the demo pages with HMR.

npm run build

Builds the library to ./dist.