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

smart-typer-js

v1.0.0

Published

A smart typer object that makes it easy to queue messages and groups of messages for a precise user experience.

Readme

typer.js

A smart typer object that makes it easy to queue messages and groups of messages for a precise user experience.

Using typer.js

Import and instantiate

import Typer from './typer.js';

displayArea = document.getElementById('typer-element');

const typerObj = new Typer(displayArea, { speed: 40 });

Basic usage

typerObj.render();

textScreens = [
  {
    messages: [
      { data: "Hello, world", pauseMs: 750 },
      { data: "\n", pauseMs: 1000 },
      { data: "\n\nThis is another line" },
    ],
  }
];

setTimeout(() => typerObj.type(textScreens), 1800);

Advanced usage

This was originally built for loading (typing) content sent from an API. The API sent content based on outside factors beyond client-side logic. This is a barebones example of how that can be achieved using typer.js.

Example payload from apiClient.getScreenContents:

[
  {
    "messages": [
      { "data": "Hello world." },
      { "data": "\n" },
      { "data": "Let's change the color to red" }
    ],
    "pauseMs": 50,
    "onDoneCallback": "changeColorToRed"
  }
]
const onDoneCallbackFunctions = {
  changeColorToRed: (unlockCallback) => {
    document.body.style.color = "#FF0000";

    unlockCallback();
  },
  // ...
};


try {
  textScreens = await apiClient.getScreenContents()
  textScreens.forEach((screen) => {
    // if the screen has a callback, find and apply it
    if (screen.onDoneCallbackFnName) {
      screen.onDoneCallback = onDoneCallbackFunctions[screen.onDoneCallbackFnName];
    }
  });
}
catch(err) {
  textScreens = [
    {
      messages: [
        { data: "an error occurred loading content.", pauseMs: 750 },
        { data: "\n\nerror details:", pauseMs: 650 },
        { data: "\n", pauseMs: 200 },
        { data: err.message },
      ]
    }
  ];
}

typerObj.render();
typerObj.type(textScreens);

Typer Overview

Functions

| Method | Description | |--------------------------:|-----------------------------------------------------------------------------------------------| | Typer(HTMLElement, options) | Constructor, requires an HTMLElement | | render() | Render the typer container on the page (cursor will appear even before type() isn't called) | | type(content) | Adds content to the queue (will be typed when ready) | | flush() | Flush screen | | hide() | Hide the typer's container Element | | show() | Show the typer's container Element |

Typer(HTMLElement, options)

A simplified Typer object that can write screens of text to a given container element.

Parameters
  • HTMLElement A valid HTMLElement (i.e., a p)
  • options An optional JSON including options. See the default options object below.
    {
      "cursorChar": "|",
      "speed": 60,
      "refreshTimeMs": 250,
      "defaultPauseTimeMs": 200,
      "defaultScreenPauseTimeMs": 1000
    }

render()

Render the typer container on the page

type(content)

Adds content (a list of screen objects) to the queue that will be typed when ready.
Also starts an interval that watches the queue

flush()

Flush (clear) the screen

hide()

Hide the typer (typing area) element

show()

Show the typer (typing area) element

Data Structures

message

A message is a JSON object representing text. The properties for a message object are described below.

| property | required | description | | -------: | --- | ----------- | | data | ✅| The text to be written | | pauseMs | | The duration (in milliseconds) to pause after data is written (before the typer will continue onto its next task) |

Example
{
  "data": "Hello, world",
  "pauseMs": 2500
}

screen

A screen is a JSON object that includes the following properties

| property | required | description | | -------: | --- | ----------- | | messages | ✅ | An array of message objects | | pauseMs | | The duration (in milliseconds) to pause (lock) the screen after all content is written | | onDoneCallback | | A callback function that will be invoked after the screen is unlocked (after all content is typed and pauseMs has passed). More info |

Example
{
  "messages": [
    {
      "data": "Hello, world",
      "pauseMs": 2500
    }
  ],
  "pauseMs": 5000,
  "onDoneCallback": "changeColorToRed"
}
Using the screen onDoneCallback

Providing an onDoneCallback function is simple. The function will be passed an unlockCallback function parameter which must be called. If the unlockCallback is not called, the typer will never unlock the screen and be stuck indefinitely.

const changeColorToRed = (unlockCallback) => {
  document.body.style.color = "#FF0000";

  unlockCallback(); // This must be called within the callback
}


const screen = {
  "messages": [ { "data": "Hello, world" } ],
  "onDoneCallback": changeColorToRed
}