Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/davebitter/highlight_word

wrap strings in text with a mark
https://github.com/davebitter/highlight_word

Last synced: about 1 month ago
JSON representation

wrap strings in text with a mark

Awesome Lists containing this project

README

        

# 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

```js
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:

`example`.