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 🙏

© 2024 – Pkg Stats / Ryan Hefner

prompteur

v1.0.9

Published

A sleek library for easily animating text on your HTML pages, bringing dynamic and engaging content to life with minimal effort.

Downloads

7

Readme

Prompteur

Version

A sleek library for easily animating text on your HTML pages, bringing dynamic and engaging content to life with minimal effort.

If you want more info you can:

Installation

npm

npm i prompteur

bun

bun add prompteur

Usage

Import

ESM

import { Prompteur } from "prompteur"

CommonJS

const { Prompteur } = require("prompteur")

Instanciate

const prompteur = new Prompteur({
  elt: document.getElementById("elementId"),
  text: "Hello Mom!",
  speed: 3,
  loop: true,
  render: "default",
})

prompteur.start()

Documentation

elt

The DOM Element that will contain the animated text.

text

The text to animate.

[!WARNING]
The text injected via innerHTML is not sanitized. If your text is somehow user defined, it is strongly recommended to use a HTML sanitizer (like dompurify) before defining the text attribute.

speed

The speed at wich the animation should run. This speed is defined in characters per second. The default speed is defined at 10 characters per second.

loop

Whether the animation should loop. It is defined as false by default.

render

The function used to generated the animated text. You can use a predefined Generators name string default,reverse,line or html.

const prompteur = new Prompteur({
  elt: document.getElementById("elementId"),
  text: 'Ipsum Lorem <span style="color:red">dolor</span> sit amet',
  speed: 4,
  render: "html",
})

You can also define a custom render function. The fucntion takes two argument:

  • f A factor representing the current animation progress. Its value goes from 0 to 1.
  • p A reference to the prompteur instance

The render function should return the animated text.

Here is the example of the implementations of the line render, as matter of example.

const prompteur = new Prompteur({
  elt: document.getElementById("elementId"),
  text: "Line1\nLine2\nLine3\nLine4",
  speed: 12,
  render: (f, opt) => {
    const { text } = opt
    const lines = text.split("\n")
    const n = f / (1 / lines.length)
    return lines.slice(0, n).join("\n")
  },
})

You can always retrieve predefined renderers functions by importing 'renderers' from prompteur package.

import { Prompteur, renderers } from "prompteur"

const prompteur = new Prompteur({
  elt: document.getElementById("elementId"),
  text: 'Ipsum Lorem <span style="color:red">dolor</span> sit amet',
  speed: 4,
  render: (f, opt) => {
    return `<pre>${renderers.html(f, opt)}</pre>`
  },
})

Methods

Once instanciated, you can start, pause or stop the animation at any time by using prompteur's method of the same name. You can check a prompteur state at any time by checking its state attribute. The state attribute could be running, paused or stopped.

import { Prompteur } from "prompteur"

const prompteur = new Prompteur({
  elt: document.getElementById("elementId"),
  text: "Hello Mom!",
  speed: 2,
})

prompteur.start()

setTimeout(() => {
  prompteur.pause()
  console.log(prompteur.state) // paused
}, 2500)

Events

You can define event listeners for every Prompteur event. The following events are available:

  • start triggered when the animation start
  • pause triggered when the animation is paused
  • play triggered when the animation was paused and start again
  • stop triggered when the animation is stopped
import { Prompteur } from "prompteur"

const prompteur = new Prompteur({
  elt: document.getElementById("elementId"),
  text: "Hello Mom!",
  speed: 2,
})

prompteur.on("pause", () => console.log("Prompteur has been paused"))

prompteur.start()

setTimeout(() => {
  prompteur.pause()
  // Prompteur has been paused
}, 2500)