split-text-js

1.0.3 • Public • Published

SplitTextJS

NPM package

Light weight Javascript text splitter

This Javascript text splitter has been created to allow easy and seo friendly text splitting (for animations) in two lines of code, it's including words, letters, spaces and special characters splitting.

ExampleRepositoryQuestions

Usage

Download the file and include it in your HTML

<p class="text">This is my cool text!</p>
 
<script src="js/SplitTextJS.js"></script>

Or install and import it as a module

$ npm install split-text-js

First, import SplitTextJS :

import SplitTextJS from 'split-text-js';

Then, use SplitTextJS :

<p class="text">This is my cool text!</p>
// Select the DOM element wich contains the target text
const text = document.querySelector('.text');
 
// Split the text and store the result
const splittedText = new SplitTextJS(text);
 
// Now you can access your splitted text in the returned object
 
// Acces words :
const textWords = splittedText.words;
 
// Acces letters :
const textChars = splittedText.chars;
 
// Acces spaces :
const textSpaces = splittedText.spaces;
 
// Acces original text :
const textOriginal = splittedText.originalText;

If everything went well you should see this.

Change log

Releases

Package Sidebar

Install

npm i split-text-js

Weekly Downloads

213

Version

1.0.3

License

MIT

Unpacked Size

4.37 kB

Total Files

3

Last publish

Collaborators

  • saucy_