Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/davebitter/highlight_word
- Owner: DaveBitter
- License: mit
- Created: 2018-04-14T17:37:59.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-14T17:48:38.000Z (over 6 years ago)
- Last Synced: 2024-10-08T15:04:06.300Z (about 1 month ago)
- Language: JavaScript
- Size: 18.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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`.