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

lightweight-typewriter

v2.0.8

Published

Lightweight typewriter

Downloads

343

Readme

Lightweight custom typewriter

size gzip size gzip size

Demo is available here

Usage

Add it to your html:

<script src="https://unpkg.com/[email protected]/build/typewriter.min.js"></script>

or install as a dependency:

npm i lightweight-typewriter
yarn add lightweight-typewriter

Import:

const TypeWriter = require('lightweight-typewriter');
import TypeWriter from 'lightweight-typewriter';

Create an element with the desired class name and create a class instance:

<h1 class="myCoolTypeWriter"></h1>

<script>
  new TypeWriter('myCoolTypeWriter', {
    text: ['I am typable', 'Me too']
  }).start();
  // Don't forget to chain start()
</script>

Done! Refresh the page and see the result :)

Customize

If you would pass text to the element, it will be displayed in front of the typewriter and margin-left: 6px will be applied:

<p class="type-write">Front Text</p>

<script>
  new TypeWriter('type-write').start();
</script>

<!-- Above results in: -->
<p class="type-write">
  Front Text<span style="margin-left: 6px">Typing text</span>
</p>

<!-- To control margin-left use indent property -->
<script>
  new TypeWriter('type-write', {
    indent: '0px'
  }).start();
</script>

You can dynamically change all the properties with applyChanges() method:

const typeWriter = new TypeWriter('myCoolTypeWriter', {
  text: ['outside', 'inside'],
  speed: 500,
  pause: 1000,
  indent: '2px',
  cursorStyle: {
    width: '3px',
    color: 'dodgerblue'
  }
}).start();

// change speed and cursor after 1 second
setTimeout(() => {
  typeWriter.applyChanges({
    speed: 1500,
    cursorStyle: {
      color: 'red'
    }
    // ... other props
  })
}, 1000);

There are also available start() and stop() methods:

// create an instance
const typeWriter = new TypeWriter('elemClass', {
  text: ['sometext']
});

// start typing when it's needed
setTimeout(() => {
  typeWriter.start()
}, 1000);

// completely pause typing; can be resumed with start()
typeWriter.stop()

// stop typing and continue after 2 seconds
typeWriter.stop(2000)

Options

| option | type | required / default | example | | -------------- | ----------- | ------------------------------------ | --------------------------------------- | | elementClass | string | yes | 'myCoolTypeWriter' | | text | array | yes | ['out', 'in'] | | speed | number (ms) | no / 1000 | 2000 | | pause | number (ms) | no / 1500 | 2000 | | indent | string | no / '0px' or '6px' | '4px' | | cursorStyle | object | no / { color: '#000', width: '2px' } | { color: 'dodgerblue', width: '5px' } |

elementClass is the class name of target element
text is an array of typing strings
speed specifies the time needed to write a word
pause specifies the delay before the word starts deleting
cursorStyle is an optional object for styling typing cursor