textsplitter
TypeScript icon, indicating that this package has built-in type declarations

9.2.3 • Public • Published

TextSplitter 🔪

npm version gzip size license dependencies

Tiny library to split each characters, words or lines! New feature for splitlines function to preserve HTML tags.

Install

npm install textsplitter --save

Usage

import { splitLetters, splitWords, splitLines } from 'textsplitter';

// HTML ELEMENT, STRING, STRING
splitLetters(container, openingtag, closingtag);

// HTML ELEMENT, STRING, STRING
splitWords(container, openingtag, closingtag);

// HTML ELEMENT, STRING, STRING
splitLines(container, openingtag, closingtag);

// React usage
useEffect(() => {
  // It is not specific made for React but it works fine
  splitLines(ref.current, openingtag, closingtag);

  // If not calulating correctly this might be an issue with the fonts which are not ready yet 
  document.fonts.ready.then(() => {
    splitLines(ref.current, openingtag, closingtag);
  });

  // When running React in strict mode you might want to add an if statement to check if the function already fired
  if (!ref.current.querySelector('.lines')) {
    splitLines(ref.current, '<span class="lines">', '</span>');
  }
}, [])

Example

splitLines(document.getElementById("container"), "<span><thisiscoolhuh>", "</thisiscoolhuh></span>");

Output

example.gif

MIT © Niels Reijnders

Install

npm i textsplitter

DownloadsWeekly Downloads

144

Version

9.2.3

License

MIT

Unpacked Size

36.4 kB

Total Files

12

Last publish

Collaborators

  • nielsreijnders