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

markupwriter

v1.0.4

Published

markupwriter is a javascript library that lets you animate your html code snippet as raw text and render it at the same time, just as if you were writing it live. It's super lightweight, written in pure JS, using ES6 promises and native asynchronous funct

Downloads

3

Readme

markupwriter · npm version

markupwriter is a javascript library that lets you animate your html code snippet as raw text and render it at the same time, just as if you were writing it live. It's super lightweight, written in pure JS, using ES6 promises and native asynchronous functions to get the animation effect.

Example

Before anything, please check out this example page I put together to better understand what effect can you achieve by using this library.

Installation and usage with npm

Note: basic webpack configuration is required when using npm with this library.

Instalation

npm install markupwriter

Usage

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>markupwriter - basic usage</title>
  </head>
  <body>
    <div class="rendered-html"></div>
    <div class="raw-html"></div>
	
	<!-- Path to your bundled script -->
	<script src="./build/bundle.js" type="text/javascript"></script>
  </body>
</html>

index.js

import MarkupWriter from 'markupwriter';

const renderedHtmlContainer = document.querySelector('.rendered-html');
const rawHtmlContainer = document.querySelector('.raw-html');
const htmlString = `
<div class="container">
	<h1>Hey there</h1>
	<p>This is some cool stuff going on here</p>
</div>
`;

const markupWriter = new MarkupWriter(
  renderedHtmlContainer,
  rawHtmlContainer,
  htmlString
);

markupWriter.start();

Open index.html file in the browser enviroment to see the result.

Usage with CDN

This approach doesn't require webpack or even an npm project.

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>markupwriter - basic usage</title>
  </head>
  <body>
    <div class="rendered-html"></div>
    <div class="raw-html"></div>
	
	<!-- markupwriter lib -->
    <script
      src="https://cdn.jsdelivr.net/npm/markupwriter"
      type="text/javascript"
    ></script>
	
    <script src="index.js" type="text/javascript"></script>
  </body>
</html>

index.js

const renderedHtmlContainer = document.querySelector('.rendered-html');
const rawHtmlContainer = document.querySelector('.raw-html');
const htmlString = `
<div class="container">
	<h1>Hey there</h1>
	<p>This is some cool stuff going on here</p>
</div>
`;

/* MarkupWriter is a global object existing in the browser */

const markupWriter = new MarkupWriter(
  renderedHtmlContainer,
  rawHtmlContainer,
  htmlString
);

markupWriter.start();

Open index.html file in the browser enviroment to see the result.

Configuration

As a fourth argument to the MarkupWriter constructor you can optionally pass a configuration object.

Possible config options

| Property | Type | Description | Default value | | --------------------------------- | -------- | ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- | | charInterval | number | Interval in miliseconds between each character rendered | 90 | | charactersPerLine | number | Number of characters per line after which script will look to make a break to new line | 50 | | displayCursor | boolean | Whether to display cursor in raw html animation or not | true | | cursorOptions | object | More configuration around cursor | - | | cursorOptions.cursorString | string | String which will be rendered as cursor, can contain html | <span class="markupwriter-cursor">|</span> | | cursorOptions.color | string | Valid css color string for the cursor | rgb(252, 186, 3) | | cursorOptions.animationSpeed | number | Blinking animation duration in seconds | 1 | | cursorOptions.isStatic | boolean | Whether or not cursor should render just once or rerender with every character animated | false | | pauseBeforeTagOpen | number | Pause in miliseconds before opening new html tag | 500 | | pauseAfterTagClose | number | Pause in miliseconds after closing html tag | 180 | | increasingPace | object | Configuration of increasing animation speed with every new character in the same node | - | | increasingPace.use | boolean | Whether or not to use this effect at all | true | | increasingPace.multiplier | number | Multiplier of charInterval, less = faster increase with every new character rendered in the same node | 0.99 | | increasingPace.maximumTimesChange | number | Times speed increase cap | 2.2 | | onFinish | function | Callback when animation finishes | () => {} |

Example usage with configuration object

index.js

import MarkupWriter from 'markupwriter';

const renderedHtmlContainer = document.querySelector('.rendered-html');
const rawHtmlContainer = document.querySelector('.raw-html');
const htmlString = `
<div class="container">
	<h1>Hey there</h1>
	<p>This is some cool stuff going on here</p>
</div>
`;

const config = {
  charInterval: 150,
  cursorOptions: {
    cursorString: '<h1>!</h1>',
    color: 'red'
  },
  onFinish: () => {
    alert('End of story');
  }
};

const markupWriter = new MarkupWriter(
  renderedHtmlContainer,
  rawHtmlContainer,
  htmlString,
  config
);

markupWriter.start();