GithubHelp home page GithubHelp logo

text-typing's Introduction

npm version

text-typing

A tool for creating typewriter effect, with a simple, promise based api.

text-typing gif

Installation

Install npm package

npm

npm install text-typing

yarn

yarn add text-typing

And then import the package

import {textTyping} from "text-typing";

Usage

All you need to do is to initialize the tool, passing a reference to an existing DOM element, and start typing!

HTML

<h1 id="myHeading"></h1>

JS

(async () => {      
  const txt = textTyping(document.getElementById("myHeading"));
  await txt.typeText("Hello");
})();    

Chaining methods

You can call multiple methods on the same instance, either by using await (inside an async function), or by using then after a method call

await
(async () => {      
  const txt = textTyping(elem);
  await txt.typeText("Hello");
  await txt.backspace(2);
})();
then
(() => {
  const txt = textTyping(elem);
  txt.typeText("Hello").then(resp => {
    resp.backspace(2);
  });
})();

Options

speed

The typing speed that is going to be used by called methods, if no specific speed is provided to the specific method.

If provided with a single number, the speed is going to be constant. An array of two numbers can be provided as the minimum (first number) and the maximum (second number) speed. In case of an array provided, the speed is going to be random in the specified range.

  • type <number> | <number[]>

  • optional true

  • default [100, 500]

cursor

The cursor that is going to be displayed.

  • type <string>

  • optional true

  • default |

Methods

typeText()

Start typing the specified text in the given speed (if speed is not provided, the options speed will be used)

Syntax
txt.typeText(text[, className][, speed])
Parameters
  • text <string>: The text to be typed
  • className <string>: An optional class or set of classes to be applied (If you want to add multiple classes, separate them with space)
  • speed optional <number> | <number[]>: The typing speed
Return value
  • Promise

lineBreak()

Insert a line break

Syntax
txt.lineBreak()
Parameters

none

Return value
  • Promise

injectHTML()

Insert HTML element

Syntax
txt.injectHTML(htmlElement[, speed])
Parameters
  • htmlElement <HTMLElement>: The HTML element to be injected
  • speed optional <number> | <number[]>: The delay of the element injection
Return value
  • Promise

delete()

Delete the specified amount of letters from the begining of the text

Syntax
txt.delete(iterations[, speed])
Parameters
  • iterations <number>: The amount of letters to be deleted
  • speed optional <number> | <number[]>: The deletion speed
Return value
  • Promise

backspace()

Remove the specified amount of letters, starting from the end of the text

Syntax
txt.backspace(iterations[, speed])
Parameters
  • iterations <number>: The amount of letters to be removed
  • speed optional <number> | <number[]>: The deletion speed
Return value
  • Promise

moveCursor()

Place the cursor either at the begining or at the end of the text

Syntax
txt.moveCursor(point)
Parameters
  • point <string>: The point at which the cursor will be placed. Possible values: start / end (If any value other than start is provided, the cursor will be moved at the end of the text)
Return value
  • Promise

sleep()

Stop the execution for the given time

Syntax
txt.sleep(speed)
Parameters
  • speed optional <number> | <number[]>: The time of pause in milliseconds
Return value
  • Promise

Changelog

Checkout the CHANGELOG file

text-typing's People

Contributors

kapantzak avatar

Watchers

 avatar  avatar

text-typing's Issues

Update README

Add note about babel-polyfill
If imported more than once it conflicts

README

Fix intro

A tool for creating typwriter effect, with a simple, promise based api

Add sleep method

function sleep(time) {
    return new Promise(resolve => {
        setTimeout(() => {
            resolve();
        }, time);
    })
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.