
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
hit-highlighter
Advanced tools
Small and simple hit highlighter for search engines running in the browser and Node.js
A small and versatile hit highlighter for search engines running in the browser and Node.js. Language agnostic, meaning it supports all languages that can be split into words with code.
Takes a query array and where the values matches within the search result array, it adds hightight code. Goes well with words'n'numbers for extracting words (and numbers) from a string of text.
Also part of daq-proc, which is meant as a hassle free document and query processor for search engines running in the browser.
API is changed, both how to import for CJS and ESM and how to reference when using <script>
tag.
Check out the demo to better understand how the hit-highlighter works.
<script src="https://cdn.jsdelivr.net/npm/hit-highlighter/dist/hit-highlighter.umd.min.js"></script>
<script>
//hh.highlight() available
</script>
const { highlight } = require ('hit-highlight')
// highlight() available
import { highlight } from 'hit-highlight'
// highlight() available
hightlight([query array], [item array], {prpoerties})
query
and item
are arrays of words. properties
is optional to define, since you have defaultProperties:
defaultProperties = {
itemMaxWords: 0,
truncateStart: '<span class="truncated">',
truncateEnd: '</span>',
hitPaddingMin: 5,
highlightStart: '<span class="hitHighlight">',
highlightEnd: '</span>',
divider: ' '
}
If you want to overwrite anything, i.e. maximum words to show in an item, you can do:
hightlight([query array], [item array], {itemMaxWords: 100})
const query = ['interesting', 'words']
const item = ['some', 'interesting', 'words', 'to', 'remember']
highlight(query, item)
// returns:
// 'some <span class="hitHighlight">interesting words</span> to remember '
const query = ['interesting', 'words']
const item = ['some', 'interesting', 'words', 'to', 'remember']
const properties = { highlightStart: '**', highlightEnd: '**' }
highlight(query, item, properties)
// returns:
// 'some **interesting words** to remember '
const query = ['no', 'hits']
const item = ['some', 'interesting', 'words', 'to', 'remember']
highlight(query, item)
// returns:
// 'some interesting words to remember '
FAQs
Small and simple hit highlighter for search engines running in the browser and Node.js
The npm package hit-highlighter receives a total of 17 weekly downloads. As such, hit-highlighter popularity was classified as not popular.
We found that hit-highlighter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.