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

selftype

v1.0.0

Published

Easily add animated text to your projects.

Downloads

2

Readme

SelfType.js

JavaScript class that animates text similarly to the style that can be found at Google Docs' or Slack's homepage.

Instructions

To use this library in your project, perform the following steps.

  1. Copy the class SelfType into your project.

  2. Link the HTML elements to SelfType.js. This is done simply by setting an appropriate id attribute on the HTML tags. To activate the element whose contents should be animated, add the id="st-text" attribute. To activate the cursor, add the id = "st-cursor" attribute. If not set up properly, you will get a console warning.

  3. Add your own stylesheets (optional).

  4. Start the animation by constructing a var selftype = new SelfType() class. You can optionally pass the constructor a configuration object. Below is an example of such object.

    
    {
        appendPeriod: false,
        backspace: false,
        backspaceHighlight: true,
        highlightColor: '#289BCC',
        highlightHideCursor: true,
        ignoreDiacriticalSigns: true,
        keepWord: true,
        newLine: true,
    	pause: 1500,
        pauseStart: 0,
        pauseEnd: 0,
        repeat: false,
        randomize: false,
        searchDOM: true,
    	speed: 'slow',
        words: ['hello', 'this', 'is', 'SelfType'], 
    }

    Configuration object properties:

    • appendText - string - Any text that should be appended after each word. [default: empty string]
    • backspace - boolean - Should the text be removed one letter at a time? [default: false]
    • backspaceHighlight - boolean - Should the text be highlighted before being deleted? (only if backspace is set to false) [default: true]
    • color - string - The default text colour. [default: #212121]
    • colors - object - Object containing colour definitions and values. [default: empty]
    • diacriticalSigns - array - Which symbols should be treated as diacritical signs? This has effect only if ignoreDiacriticalSigns is set to false. [default: [',', '.', '?', '!']]
    • highlightColor - string - Hexadecimal value of the colour to use for the highlight. [default: #289BCC]
    • highlightHideCursor - boolean - Should the cursor be hidden while the text is highlighted? [default: true]
    • ignoreDiacriticalSigns - boolean - Should the animation continue at the same speed when reaching a diacritical sign in the word? [default: false]
    • keepWords - boolean - Should we delete the text after finishing the current word? [default: false]
    • lightColor - string - If we are highlighting the text and it is too dark, this colour will be used to create the contrast. [default: #efefef]
    • newLine - boolean - Should every word start on a new line? [default: true]
    • pause - integer - Time in milliseconds to wait on the end of the animation cycle. [default: 1000]
    • pauseStart - integer - Time in mmilliseconds to wait before the word is animated. (optional) If skipped, pause value is used.
    • pauseEnd - integer - Time in milliseconds to wait after the word is animated. (optional) If skipped, pause value is used.
    • plainText - boolean - By default, every character is wrapped into a separate HTML element. Set plainText to true to disable this behaviour. [default: false]
    • repeat - boolean - Should the words be repeated over? [default: false]
    • randomize - boolean - Should the words be displayed in random order? [default: false]
    • randomizeAllowRepeat - boolean - If the randomize flag is set to true and the randomly picked word matches the last printed word, should we print it anyway? [default: false]
    • searchDOM - boolean - If set to true, SelfType will use all 'data-' attributes from the node with id = 'st-text' to construct the options object. In addition, SelfType will process all children nodes and use their contents to construct the word phrases. Turn off if unused to improve the performance. [default: true]
    • speed - integer | string - Speed of the animation. [default: 5]
    • words - array - Array of strings that will be animated on screen.

    You can also create the configuration object directly from HTML. Simply prepend any of the properties above with data- (except for the words) and insert this attribute into the HTML code on the element you chose in step 2, like so: <span id="st-text" data-words="Hello, SelfType"></span>. If you want to optimise for SEO or need to insert longer phrases, you can also insert words directly into the HTML instead of constructing them with Javascript, like so.

    
    <i class="st-text" id="st-text">
        <span>Hi!</span>
        <span>My name is Jeff</span>
        <span>I do web development and funky stuff.</span>
    </i><i class="st-cursor" id="st-cursor">|</i>
  5. SelfType also supports basic commands inside of each phrase. Their pattern is $<command>-<value>;. Currently, these commands are available:

    • $wait-<integer>; - Pauses the animation temporarily within the given word. This is useful for longer phrases, for example He looked below and saw there a ...$wait-3000; magic potion. The time to wait should be entered in milliseconds.
    • $color-<name>; - You can create your own colour definitions! If you need to make your text more lively, it is very easy to do so. When creating the configuration object, set the colors property to an object whose keys are the colour names to be used, such as
    
    colors: {
        red: 'red',
        blue: '#00f',
        magicColor: '#346123',
    }

    Then you can use these variables anywhere in your text to apply the new colour to the text following the command. Consider this example: <span>This text will have default colour,$color-red; and this one will be red.</span>

  6. The library uses an interval to animate the text. This means that you might need to remove it to prevent memory leaks, depending on your project requirements. You can do so with selftype.pause().

  7. The object constructed with new SelfType() provides you with the following methods and properties that can be used or modified at any time during the runtime.

    
    options - complete configuration object that can be changed on the fly
    pause() - pauses the animation
    play() - resumes the animation

That's it! Enjoy SelfType!

Demo

You can view the (older) demo on CodePen.