• Stars
    star
    239
  • Rank 168,763 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⌨️ Simulate a typewriter effect in vanilla JavaScript.

malarkey npm Version Build Status Coverage Status

Simulate a typewriter effect in vanilla JavaScript.

  • Flexible API allowing granular control
  • Option to repeat the sequence indefinitely
  • Allows stopping and resuming the sequence on-the-fly
  • 524 bytes gzipped

Usage

Editable demo (CodePen)

<div class="typewriter"></div>
const malarkey = require('malarkey')

const element = document.querySelector('.typewriter')
function callback (text) {
  element.textContent = text
}
const options = {
  typeSpeed: 50,
  deleteSpeed: 50,
  pauseDuration: 2000,
  repeat: true
}
malarkey(callback, options)
  .type('Say hello')
  .pause()
  .delete()
  .type('Wave goodbye')
  .pause()
  .delete()

API

const malarkey = require('malarkey')

const m = malarkey(callback [, options])

Initialise the typewriter effect with the given optional options settings.

  • callback is a function that is invoked for every type and delete event in the sequence. The function signature is (text), where text is the string of characters that have been typed so far.

  • options is an object literal:

    Key Description Default
    typeSpeed Duration in milliseconds to type a single character 50
    deleteSpeed Duration in milliseconds to delete a single character 50
    pauseDuration Duration in milliseconds to pause 2000
    repeat Whether to repeat the entire sequence indefinitely false

m.type(string [, options])

Type the given string, one character at a time.

  • Set options.speed to override the default typeSpeed.

m.delete([characterCount, options])

Delete the specified number of characters, one character at a time.

  • characterCount is a positive integer. If not specified, all characters previously typed will be deleted, one character at a time.
  • Set options.speed to override the default deleteSpeed.

m.pause([options])

Do nothing for some duration.

  • Set options.duration to override the default pauseDuration.

m.clear()

Immediately clear all characters that were typed.

m.call(fn)

Call the given fn function.

  • The function signature of fn is (callback, text). Invoke callback to signal that fn has finished execution and that we can move on to the next event in the sequence.

m.triggerStop([fn])

Stops the sequence. Calls the given fn function when the sequence has been stopped.

  • The function signature of fn is (text).

m.triggerResume()

Resume the sequence. Has no effect if the sequence is already running.

m.isStopped()

Returns true if the sequence is currently stopped, else returns false.

Installation

Install via yarn:

$ yarn add malarkey

Or npm:

$ npm install --save malarkey

License

MIT

More Repositories

1

vdx

🎞️ An intuitive CLI for processing video, powered by FFmpeg
TypeScript
1,665
star
2

charming

🎩 Lettering.js in vanilla JavaScript
JavaScript
1,005
star
3

create-figma-plugin

🔋 The comprehensive toolkit for developing plugins and widgets for Figma and FigJam
TypeScript
943
star
4

figma-plugins

🔥 Monorepo for my Figma plugins
TypeScript
238
star
5

ffmpeg-cheatsheet

📼 A cheatsheet for common video processing operations in FFmpeg
185
star
6

load-google-maps-api

🌏 A lightweight Promise-returning helper for loading the Google Maps JavaScript API
JavaScript
170
star
7

vim-basics

✌️ Just the basics to get you up and running with Vim
Vim Script
136
star
8

stable-diffusion-rest-api

🤗 Run Stable Diffusion locally via a REST API on an M1/M2 MacBook
TypeScript
129
star
9

line-clamp

🗜️ Line clamp a DOM element in vanilla JavaScript
JavaScript
75
star
10

autosize-input

🎈 Effortless, dynamic-width text boxes in vanilla JavaScript
JavaScript
68
star
11

figma-plugins-stats

📈 A CLI to get live and historical stats for your Figma plugins
TypeScript
61
star
12

cuba

🇨🇺 Google Sheets + SQL = JSON
JavaScript
55
star
13

single-page-markdown-website

🌶️ Create a nice single-page documentation website from one or more Markdown files
TypeScript
47
star
14

menu-aim

🎯 Instant mega menus in vanilla JavaScript.
JavaScript
40
star
15

fastmatter

👀 A fast frontmatter parser. Supports both string and stream inputs.
JavaScript
28
star
16

awesome-create-figma-plugin

26
star
17

regular-expressions-cheatsheet

🅰️ A concise cheatsheet for using Regular Expressions in JavaScript
JavaScript
16
star
18

generate-css

💥 Dynamically generate functional CSS classes from HTML and JavaScript source files
TypeScript
16
star
19

stoke

🌲 Generate the Abstract Syntax Tree (AST) of a Bash command
JavaScript
15
star
20

gulp-tape

👻 Run Tape tests in Gulp.
JavaScript
14
star
21

generate-ts-docs

📘 Utilities to parse type information and JSDoc annotations from TypeScript source files, and render Markdown documentation
TypeScript
12
star
22

shell-basics

🐚 A quick overview of the Unix shell
12
star
23

macos-keyboard-shortcuts

⌨️ A CLI to set application-specific keyboard shortcuts for macOS
TypeScript
12
star
24

rdd

📝 Preview your Markdown locally as it would appear on GitHub, with live updating
JavaScript
11
star
25

code-problems

🐫 Working through code problems in OCaml
OCaml
7
star
26

git-cheatsheet

🌳 A handy list of commonly used Git commands
6
star
27

interpolate

Simple string interpolation in PHP.
PHP
5
star
28

sketch-plugins

Monorepo for my Sketch plugins
JavaScript
5
star
29

quine

✍️ Programs that write themselves.
Shell
5
star
30

sketch-plugin-helper

Utilities to help you make Sketch plugins
JavaScript
5
star
31

grouper

Assign objects to groups by one or more properties, by object value, or by using a comparator function.
JavaScript
4
star
32

modal

Super-simple modals in vanilla JavaScript.
JavaScript
4
star
33

react-redux-modal

🔮 A React modal bound to the Redux store.
JavaScript
4
star
34

widget

TypeScript
3
star
35

yuanqing.sg

⚪ My personal website
HTML
3
star
36

figmake

🍦 A tiny CLI for making Figma plugins in HTML, CSS, and vanilla JavaScript
TypeScript
3
star
37

sketch-handbook

📙 A concise handbook on working precisely and effectively in Sketch
Shell
3
star
38

figma-plugins-monetization-stats

JavaScript
3
star
39

figma-add-auto-layout-item

TypeScript
2
star
40

versus

Compare two variables with the comparison operator specified as a string.
JavaScript
2
star
41

google-sheets-rest-api

JavaScript
2
star
42

q

🍦 An opinionated CLI for creating lightweight, vanilla HTML/CSS websites
JavaScript
2
star
43

jockey

Modelling a playlist that supports shuffle, repeat, and reordering.
JavaScript
2
star
44

xoxo

🎧 A YouTube mixtape maker thing.
JavaScript
2
star
45

asset-versioning

🗃️ Version your assets by appending a hash to the filename.
JavaScript
2
star
46

shared-event-listeners

A utility for minimising the number of event listeners bound on a given DOM element.
JavaScript
2
star
47

Q.js

A micro JavaScript library.
JavaScript
2
star
48

create-figma-plugin-react-example

JavaScript
2
star
49

sketch-add-artboard-borders-and-titles

JavaScript
2
star
50

extract

Sugar for getting data out of strings in PHP.
PHP
2
star
51

fi

Query a collection of text files like a document database in PHP.
PHP
2
star
52

string-extractor

Regular expression sugar for getting data out of strings.
JavaScript
1
star
53

cli

TypeScript
1
star
54

cors

JavaScript
1
star
55

savoy

Higher-order functions (synchronous and asynchronous each/eachSeries/map/filter/fold) and functions for flow control (parallel/series/waterfall) in under 1 KB.
JavaScript
1
star
56

kontact

An extensible contact form in PHP and vanilla JavaScript/AJAX.
JavaScript
1
star
57

abstract-backup

💾 Download a local backup of the Sketch files from all your Abstract projects
JavaScript
1
star
58

sketch-sort-layer-list

JavaScript
1
star
59

npm-boilerplate

Barebones boilerplate using `npm run-script`.
JavaScript
1
star
60

clinical

💊 A minimum-viable arguments parser in ~90 LOC with zero dependencies
TypeScript
1
star
61

google-sheets

🍃 An easier interface to read from and write to Google Sheets
JavaScript
1
star
62

sketch-clean-document

JavaScript
1
star
63

gulp-boilerplate

A Gulp-powered boilerplate for Node and JavaScript projects.
JavaScript
1
star
64

segue

Enqueue functions, and call them in series.
JavaScript
1
star
65

unfurl

Extract the query string and hash of a URL.
JavaScript
1
star
66

sketch-extract-text

JavaScript
1
star
67

bbqr

JavaScript
1
star
68

sketch-move-layers

JavaScript
1
star
69

pppath

Join strings to form a valid file path.
JavaScript
1
star
70

simple-code-editor

TypeScript
1
star
71

resizable

TypeScript
1
star
72

svg-inserter

TypeScript
1
star
73

build-website

TypeScript
1
star
74

.github

1
star
75

eslint-config-yuanqing

⚙️ An opinionated ESLint configuration for TypeScript and Preact projects
JavaScript
1
star
76

append-js-extension-to-local-imports

JavaScript
1
star
77

screen-recorder

JavaScript
1
star
78

sketch-select-layers

JavaScript
1
star
79

sketch-draw-slice-over-selection

JavaScript
1
star
80

sketch-align-to-grid

JavaScript
1
star
81

frontend-boilerplate

🌱 Super basic web boilerplate with Sass and vanilla JavaScript.
HTML
1
star
82

isomorphic

JavaScript
1
star
83

tsu

Utilities and functional wrappers over `through2`.
JavaScript
1
star
84

sketch-rename-layers

🖋️ [WIP] A Sketch plugin to automate layer renaming
JavaScript
1
star
85

johnson-trotter

An implementation of the Johnson-Trotter permutation algorithm.
JavaScript
1
star
86

rectify

Unsmarten your quotes, dashes, and ellipses.
JavaScript
1
star
87

stylelint-config-yuanqing

🕴️ An opinionated stylelint configuration
JavaScript
1
star
88

react-autocomplete

[UNMAINTAINED] React autocomplete component with an opinionated UX.
JavaScript
1
star