🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@orama/highlight

Package Overview
Dependencies
Maintainers
8
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@orama/highlight

Highlight any text in any JavaScript lib (browser, server, React, Vue, you name it!)

latest
npmnpm
Version
0.1.9
Version published
Maintainers
8
Created
Source

Highlight

Test CI

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)
// [
//    {
//      start: 10,
//      end: 14
//    }, {
//      start: 16,
//      end: 18
//    }, {
//      start: 20,
//      end: 23
//    }
//  ]

console.log(highlighted.HTML)
// "The quick <mark class="orama-highlight">brown</mark> <mark class="orama-highlight">fox</mark> <mark class="orama-highlight">jump</mark>s over the lazy dog"

console.log(highlighted.trim(10))
// "...uick <mark class="orama-highlight">brown</mark>..."

You can always customize the library behavior by passing some options to the class constructor:

const highlighted = new Highlight({
  caseSensitive: true,        // Only highlight words that respect the second parameter's casing. Default is false
  wholeWords: true,           // Only highlight entire words, no prefixes
  HTMLTag: 'div',             // Default is "mark"
  CSSClass: 'my-custom-class' // default is 'orama-highlight'
})

License

Apache 2.0

Keywords

full-text search

FAQs

Package last updated on 05 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts