string-typer
A tiny, environment-agnostic, string typing simulator.
There are a bunch of these things, but they tend to be tied to the DOM or full of opinions. This is just a simple function that takes a string and a callback, and calls that callback for each character, at a random interval, until the string is reproduced. Sound complex? That’s just me being a poor writer. But check out the usage examples.
Install
$ npm install string-typer
Usage
Basic
On the command line
var type =
In the browser
var type = var field = document
Stopping prematurely
Works in both environments.
var type = var field = document var stop = fieldoninput = stop
Advanced
Set the range of possibly keystroke delays:
var type = var delay = min: 350 max: 1000
Overwrite an initial string:
var type = var opts = initial: 'type this somewhat fast' min: 350 max: 1000
Looping
var type = var text = 'type this really slow' 'type this somewhat fast' var opts = initial: 'type this somewhat fast' min: 350 max: 1000 var stop = documentdocumentElementonclick = stop
Page weight
compression | size |
---|---|
string-typer.js | 4.28 kB |
string-typer.min.js | 2.56 kB |
string-typer.min.js.gz | 1.05 kB |