Highlight

Orama Highlight allows you to easily highlight substrings in a given input.
Installation
npm i @orama/highlight
bun i @orama/highlight
Usage
import { Highlight } from '@orama/highlight'
const inputString = 'The quick brown fox jumps over the lazy dog'
const toHighlight = 'brown fox jump'
const highlighter = new Highlight()
const highlighted = highlighter.highlight(inputString, toHighlight)
console.log(highlighted.positions)
console.log(highlighted.HTML)
console.log(highlighted.trim(10))
You can always customize the library behavior by passing some options to the class constructor:
const highlighted = new Highlight({
caseSensitive: true,
wholeWords: true,
HTMLTag: 'div',
CSSClass: 'my-custom-class'
})
License
Apache 2.0