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

ontyper

v1.0.0

Published

A directive-based typewriter for interactive web experiences.

Readme

OnTyper

A directive-based typewriter for interactive web experiences.

Overview

OnTyper lets you create dynamic typewriter effects with embedded commands (directives) that control behavior in real time.

  • Control typing behavior using inline directives
  • Define custom variables and functions
  • Execute synchronous and asynchronous functions during typing
  • Supports HTML tags

Installation & Usage

Installation

Browser

Include the script tag:

<script src="https://cdn.jsdelivr.net/gh/rezzvy/ontyper@1023a49/dist/ontyper.min.js"></script>
const typer = new OnTyper({ target: null });
// change null to node element

Node

Install via npm:

npm install ontyper
import OnTyper from "ontyper";

const typer = new OnTyper({ target: null });
// change null to node element

Usage

typer.setFn("askName", () => {
  typer.setVar("name", prompt("What is your name?"));
});

typer.write("Hello there![@delay:500] What is your name? [@run:askName] I see...[@delay:1000], so your name is [@speed:1000][@var:name]");

Examples

Running an async function

<p class="text"></p>
const typer = new OnTyper({ target: document.querySelector(".text") });

typer.setFn("fetchData", async () => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, 2000);
  });
});

typer.write("Fetching data... [@async:fetchData] Data has been fetched!");

Evaluated a function value

<p class="text"></p>
const typer = new OnTyper({ target: document.querySelector(".text") });

typer.setFn("sayHi", (name) => {
  return `Hello ${name}`;
});

typer.write("[@eval:sayHi(Rezzvy)]");

Create function alias

<p class="text"></p>
const typer = new OnTyper({ target: document.querySelector(".text") });

typer.setFn("alert", (msg) => {
  alert(msg);
});

typer.setFnAlias("print", "alert");

typer.write("Hold up! [@print:Stop there!]");

Documentation

new OnTyper(options)

Initializes a new OnTyper instance. It accepts a single configuration object.

| Property | Type | Default | Description | | :--------- | :------------ | :----------- | :-------------------------------------------------------------------- | | target | HTMLElement | Required | The DOM element where the typing effect will be rendered. | | speed | Number | 25 | The default typing speed in milliseconds per character. | | onStart | Function | undefined | Callback executed when the typing effect begins. | | onTyping | Function | undefined | Callback executed immediately after a token or character is rendered. | | onFinish | Function | undefined | Callback executed when the entire text sequence completes. |

API Reference

write(text)

Starts the typing effect with the provided string. | Parameter | Type | Description | | :--- | :--- | :--- | | text | String | The text containing characters, HTML tags, and directives to type out. |

setVar(key, val)

Registers a variable that can be injected into the text. | Parameter | Type | Description | | :--- | :--- | :--- | | key | String | The unique identifier for the variable. | | val | Any | The value to substitute when [@var:key] is called. |

setFn(key, fn)

Registers a function that can be executed via directives. | Parameter | Type | Description | | :--- | :--- | :--- | | key | String | The unique identifier for the function. | | fn | Function| The function to execute. |

setFnAlias(key, functionName, type)

Creates an alias for a registered function, allowing you to use a custom directive name. | Parameter | Type | Default | Description | | :--- | :--- | :--- | :--- | | key | String | - | The custom directive name (cannot be a reserved directive). | | functionName| String | - | The name of the previously registered function. | | type | String | "run" | The execution type. Must be "run", "async", or "eval". |

pause()

Pauses the current typing execution.

resume()

Resumes a paused typing execution.

skip()

Skips the typing effect, immediately evaluating all remaining directives and injecting the rest of the text into the DOM.

destroy(clearDom)

Destroys the current instance and clears internal timers. | Parameter | Type | Default | Description | | :--- | :--- | :--- | :--- | | clearDom | Boolean | true | If true, clears the innerHTML of the target element. |

isOnlyDirectives(text)

Utility method to check if a provided string consists exclusively of directives. | Parameter | Type | Description | | :--- | :--- | :--- | | text | String | The text to check. Returns true or false. |

Directive Commands

Directives are embedded inside the text using the [@directive:value] syntax.

| Directive | Syntax | Description | | :---------- | :------------------- | :--------------------------------------------------------------------------- | | speed | [@speed:ms] | Changes the typing speed to the specified milliseconds per character. | | delay | [@delay:ms] | Pauses the typewriter for the specified milliseconds. | | var | [@var:key] | Injects the value of a registered variable into the text. | | run | [@run:fn(param)] | Synchronously executes a registered function. Accepts an optional parameter. | | async | [@async:fn(param)] | Pauses typing until the registered asynchronous function resolves. | | eval | [@eval:fn(param)] | Executes a function and injects its return value directly into the text. |

The api Object

The api object provides read-only state information about the current typewriter instance. It is passed into lifecycle events (onStart, onTyping, onFinish) and can be accessed externally via typer.api.

| Property | Type | Description | | :--------------- | :------- | :--------------------------------------------------------------------------------- | | tokens | Array | The array of parsed characters, HTML tags, and directives. | | tokenIndex | Number | The current index being processed within the tokens array. | | progress | Object | Returns an object containing the current progress: { raw: 0.5, percent: "50%" }. |

Behavior

Variable Value

You can't put another variable directive inside the variable parameter like this:

typer.setVar("name", "[@var:name]");

Any directive inside the var string will be unwrapped to avoid an infinite loop.

Reserved Alias

You can't set a function alias that is similar to any built-in directive syntax. It will throw an error:

// This will throw an error
typer.setFnAlias("speed", "mySpeedFunc");

Contributing

There's always room for improvement. Feel free to contribute!

Licensing

The project is licensed under MIT License. Check the license file for more details.