1.0.0 • Published 6 years ago

highlight-word v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Highlight Word

This tiny package wraps strings in a text you pass it in a mark. You can then style the mark to your liking.

Example usage

const highlightWord = require('highlight-word');

const el = document.getElementById('example');
const text = el.textContent;
const word = 'example';

el.innerText = highlightWord(text, word);

Highlight Word accepts two parameters. The first parameter is the source text where you want to highlight the word. The second parameter is the word you want to highlight. The function returns your original text with found words wrapped like this:

<mark class='wh-highlight'>example</mark>.