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

typerio

v2.1.1

Published

A simple npm package that writes text character by character.

Downloads

22

Readme

Typerio ⌨️

Typerio gif

Typerio is a simple, lightweight and easy-to-use npm package that writes text character by character, much like a terminal.

It supports multi-style phrases and allows you to customize the appearance and speed of text display.

Getting started

How to install 📩

$ npm install typerio

How to use 🤷‍♂️

Important message!

Version ^2.0.0 is not compatible with previous versions. Looking for docs for 1.5.0? Documentation for version 1.5.0 · pasiastazebra/typerio Wiki · GitHub

To get started, you have to import typerioRender() function to your project.

import { typerioRender } from 'typerio'

Now you can use typerioRender() function to - as it stands - render a text.

typerioRender(
  input,
  {
    frames,
    prefix,
    speed,
    target,
    clearingPolicy,
  },
  callback
);

JavaScript💛

As you can see, function takes a lot of arguments. But don't panic, let's take a look at them really quick:

  • input is an array of objects with the following properties:
{
    text: string, //Text which will be rendered.
    style: string, //Custom CSS class.
    HTMLelement: HTMLElement //HTML element inside of which text will be
}                            //rendered. Usually p or span
  • Configuration object:
    • frames - Array of 2 string which will be used as an animation.
    • prefix - String placed at the beggining of the rendered text.
    • speed - Typing animation speed in ms.
    • target - HTML element inside of which animation will be rendered.
    • clearingPolicy - Boolean value, if true all content inside of the target will be deleted.
  • callback - Optional function that will be launched after the animation.

Note that every arguments besides input and callback need to be parsed as one object.

typerioRender() is an asynchronic function. If you want to call it on the same target more than once in a row, you can use await to wait untill previous animation is completed.


CSS💙

Typerio uses typerio as default class for every element, typerioPrefix as class for its prefix and classes provided as style via input array. To style it, simply declare them inside of your CSS.


Customize default configuration🪄

Providing the same data as an configuration object in typerioRender() function would be a nuisance. That's why version 2.0.0 introduced configuration object which allows you to set the default values which will be used, if you won't provide them via typerioRender() function. To change them you can simply use

typerioConfig.setDefaultConfig({
  newFrames,
  newPrefix,
  newSpeed,
  newTarget,
  newClearingPolicy,
});

As you can see, there are the same arguments as in configuration object. You can also get the default config object using:

typerioConfig.getDefaultConfig();

Please note, that the default target value is set to {}, which means that you have to declare this value in typerioConfig or pass it everytime via typerioRender() function.

Example code 👀

//JavaScript

import { typerioRender, typerioConfig } from 'typerio'

const outputWindow = document.querySelector(".window-console");
const button = document.querySelector("button");

typerioConfig.setDefaultConfig({
  newFrames: [".", ".."],
  newPrefix: "x",
  newSpeed: 20,
  newTarget: outputWindow,
  newClearingPolicy: false,
});

button.addEventListener("click", async () => {
  const textInput = document.querySelector("input").value;
  const styleInput = document.querySelector("select").value;

  if (textInput !== "") {
    const inputObject = [
      { text: textInput, style: styleInput, HTMLelement: "span" },
    ];
    await typerioRender(inputObject, { prefix: "$", speed: "25" });
  }
});
//SCSS

.typerio {
  &.typerioPrefix {
    color: #6495ed;
    font-style: italic;
  }
  &.red {
    color: #cd5c5c;
  }

  &.green {
    color: #86af80;
  }

  &.blue {
    color: #6495ed;
  }
  &.white {
    color: #ddccbb;
  }
  &.italic {
    color: #ddccbb;
    font-style: italic;
  }
}

Live demo 🎞️