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

typish

v0.2.3

Published

Typewriter simulator

Downloads

17

Readme

typish

Yet another typewriter simulator. Demo →

Unlike others like it, typish supports inserting HTML elements. This means you'll be able to do pseudo-syntax highlighting or insert buttons, like below.

var typish = require('typish');

function repeat() {
  typish('#container')
    .type('hello stranger')
    .del(8)
    .type('you. ')
    .type('continue', '<a href="next.html">')
    .wait(50)
    .then(repeat)
}

repeat();

Status npm version

API cheatsheet

typish(element)
  .speed(50)         // sets base speed in milliseconds
  .type("hi")        // types something letter by letter
  .type("hi", "red") // types, with classname set to 'red'
  .type("hi", "<b>") // types, uses a custom tag
  .type("hi", 0)     // types immediately
  .del()             // delete 1 character
  .del(4)            // delete 4 characters
  .wait()            // pauses for a while
  .wait(10)          // pauses (10x longer)
  .clear()           // clears everything
  .clear(0)          // clears everything immediately (speed is 0)
  .then(function)    // executes something asynchronously

typish()

typish(element)

Starts typish. element may be a DOM element, selector, or a jQuery object. This returns a typish object that you can run methods on.

typish('#container')
typish($("#box"))
typish(el)

A typish instance also has the following variables:

  • this.el: the element
  • this.length: how many characters are present at the moment
  • this.last: the last <span> in the box

type()

type(text, [element, speed])

Types some text. If element is given, it'll start a new span. You can also give a different speed to make it faster or slower.

typish(el)
  .type('hello')
  .type('hello', 'keyword')
  .type('hello', 10)
  .type('hello', 'keyword', 10)

When a name is passed to the element parameter, it'll be used as a class name for a <span>.

typish(el)
  .type('Jack', 'name')

<div id='box'><span class='name'>Jack</span></div>

Each .type() call creates a new span element.

typish(el)
  .type('Jack ', 'name')
  .type('Sparrow', 'last')

<div id='box'>
  <span class='name'>Jack </span>
  <span class='last'>Sparrow</span>
</div>

The parameter element can also be an HTML tag.

typish('#box')
  .type('download me', '<a href="download.html">')

<div id='box'>
  <a href="download.html">download me</a>
</div>

The speed argument is multiplied by whatever you set on speed(). Doing .type('hello', 1/2) will type a message 2x as fast as normal.

typish('#box')
  .type('download me', '<b>', 1/2)

del()

del([count, speed])

Deletes characters. if count is given, it'll delete that many characters. If speed is given, that's the speed it'll run on.

typish('.box')
  .type('hello John')
  .del(4)
  .type('Sherlock')

The speed argument is multiplied by the time it takes to type one character (ie, whatever you set on speed()). Doing .del(10, 1/2) will delete 10 characters 2x as fast as it types.

wait()

wait([speed])

Waits a while. This waits the equivalent of whatever you set in .speed(), that is, it waits exactly the time it takes to type 1 character.

The speed argument is multiplied by the time it takes to type one character (ie, whatever you set on speed()). Doing .wait(10) pauses for the time it takes to type 10 characters.

typish(el)
  .type('hello')
  .wait(10)
  .type('there')

clear()

clear([speed])

Clears the entire thing one letter at a time. To clear everything instantly, use .clear(0).

typish('.box')
  .type('hello.')
  .clear()

Also see type() for an explanation on the speed parameter.

then()

then(function)

Executes a function asynchronously.

typish('#box')
  .type('hello')
  .then(popupSomething)
  .wait()
  .type('there')
  .then(popupSomethingAgain)

speed()

speed(ms)

Sets the base speed. All speed arguments will be multiplied by this number.

typish('.box')
  .speed(50)
  .type('hello')

You can call speed() in the middle of an animation to slow it down or speed it up.

typish('.box')
  .speed(50)
  .type('hello ')
  .speed(100)
  .type('world')

queue()

queue(fn(next))

Queues a command for execution. The function fn will be invoked, where the next parameter should be ran to move onto the next thing on queue.

typish(el)
  .queue(function (next) {
    this.el.className += ' -fade-in'
    setTimeout(next, 100)
  })

This is used for asynchronous functions. See then() if you would like to execute something synchronously.

defer()

defer(next, [speed])

Waits then runs next. Useful inside queue().

typish(el)
  .queue(function (next) {
    //dosomething
    this.defer(next)
  })

See type() for an explanation of the speed parameter.

Blinking cursor

This is optional, and it's done via CSS. Check out typish.scss for some helpers on getting this to work.

@import 'typish';
.box {
  @include typish-cursor($color: #a83);
}

@include typish-keyframes;

Similar projects

  • jquery.typer.js
    • pro: easier to configure
    • con: jQuery dependency
    • con: can't configure speed while it types
    • con: doesn't support spans
  • malarkey
    • pro: smaller footprint in bytes
    • con: doesn't support spans
  • typed.js
    • pro: easier to setup, just an array of sentences
    • con: can't delete parts of a message
    • con: doesn't support spans

Thanks

typish © 2015+, Rico Sta. Cruz. Released under the MIT License. Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz