Socket
Socket
Sign inDemoInstall

split-html-to-chars

Package Overview
Dependencies
83
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    split-html-to-chars

Splits text inside valid HTML into chars, wrapping them in a given template. Common usage: animating letters of text.


Version published
Maintainers
1
Created

Readme

Source

Split html to letters for animation

Takes this:

<h2>Some <strong>bold</strong> text<br> with<i>Tags</i></h2>

Returns this:

<h2>
	<span class="letter">S</span>
	<span class="letter">o</span>
	<span class="letter">m</span>
	<span class="letter">e</span>
	<span class="letter"> </span>
	<strong>
		<span class="letter">b</span>
		<span class="letter">o</span>
		<span class="letter">l</span>
		<span class="letter">d</span>
	</strong>
	<span class="letter"> </span>
	<span class="letter">t</span>
	<span class="letter">e</span>
	<span class="letter">x</span>
	<span class="letter">t</span>
    <br>
	<span class="letter">w</span>
	<span class="letter">i</span>
	<span class="letter">t</span>
	<span class="letter">h</span>
	<i>
		<span class="letter">T</span>
		<span class="letter">a</span>
		<span class="letter">g</span>
		<span class="letter">s</span>
	</i>
</h2>

If invoked like this:

import Splitter from 'split-html-to-chars';

Splitter(html,'<span class="letter">$</span>');

Why i did that

For animations like this one:

Letters animation

Common use case might be replacing HTML on load:

import Splitter from 'split-html-to-chars';
// iterating each replaced element
let els = document.querySelectorAll(".js-splitme");
[].forEach.call(els, function(el) {
	// outerHTML, thats *important*, no direct text nodes should be in parsed HTML
	el.outerHTML = Splitter(el.outerHTML, '<span class="letter">$</span>');
});

Yuri akella Artiukh

Keywords

FAQs

Last updated on 10 Jul 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc