9.6.0 • Published 2 years ago

textsplitter v9.6.0

Weekly downloads
12
License
MIT
Repository
github
Last release
2 years ago

TextSplitter 🔪

npm version gzip size license dependencies

Description

TextSplitter is a lightweight library designed to split text into individual characters, words, or lines. It also includes a new feature to preserve HTML tags when using the splitLines function.

Installation

You can install TextSplitter using npm or yarn:

npm install textsplitter --save

or

yarn add textsplitter

Usage

Import the required functions from 'textsplitter':

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

Use the following functions according to your requirements:

  • splitLetters(container, openingtag, closingtag): Splits individual characters.
  • splitWords(container, openingtag, closingtag): Splits words.
  • splitLines(container, openingtag, closingtag): Splits lines while preserving HTML tags.

React usage example:

useEffect(() => {
  const lines = splitLines(ref.current, openingtag, closingtag);

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

  return () => {
    // Destroy lines (return to its initial state)
    lines.destroy();
  };
}, []);

Example

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

Output

example.gif

License

MIT © Niels Reijnders


If you're looking for a lightweight library to split text into characters, words, or lines while preserving HTML tags, TextSplitter is the right choice! Easily integrate it into your projects using npm or yarn.

9.6.0

2 years ago

9.4.2

2 years ago

9.4.1

2 years ago

9.4.0

2 years ago

9.5.1

2 years ago

9.5.0

2 years ago

9.3.0

2 years ago

9.2.3

2 years ago

9.2.1

2 years ago

9.2.0

2 years ago

9.1.0

3 years ago

7.0.0

3 years ago

7.0.2

3 years ago

7.0.1

3 years ago

8.0.0

3 years ago

9.0.0

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

6.1.0

3 years ago

6.0.0

3 years ago

6.1.1

3 years ago

6.1.4

3 years ago

6.1.3

3 years ago

6.1.5

3 years ago

4.1.0

3 years ago

4.0.0

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.5.9

3 years ago

1.5.8

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.4.0

5 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago