
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A lightweight, customizable text highlighting library that illuminates matches in a content.
A tiny but powerful text highlighting library that handles diacritics, punctations, multiple word patterns, and smart text matching. Perfect for search interfaces and text analysis.
To install Spotmark, use npm:
npm install spotmark
or
yarn add spotmark
// ES6 import
import { createHighlighter } from 'spotmark';
// or CommonJS require
const { createHighlighter } = require('spotmark');
const text = 'This is a simple but an amazing tool for text highlight 😎.';
const pattern = 'amazing';
const highlight = createHighlighter();
highlight(text, pattern);
→ 'This is a simple but an <span class="text-highlight">amazing</span> tool for text highlight 😎.'
const text = 'This is a simple but an amazing tool for text highlight 😎.';
const pattern = 'e';
const highlight = createHighlighter();
highlight(text, pattern);
→ 'This is a simpl<span class="text-highlight">e</span> but an amazing tool for t<span class="text-highlight">e</span>xt highlight 😎.'
const text = 'This is a simple but an amazing tool for text highlight 😎.';
const pattern = 'amazing';
const config = { tag: 'mark' };
const highlight = createHighlighter(config);
highlight(text, pattern);
→ 'This is a simple but an <mark class="text-highlight">amazing</mark> tool for text highlight 😎.'
const text = 'This is a simple but an amazing tool for text highlight 😎.';
const pattern = 'amazing';
const config = { className: 'custom-highlight' };
const highlight = createHighlighter(config);
highlight(text, pattern);
→ 'This is a simple but an <span class="custom-highlight">amazing</span> tool for text highlight 😎.'
const text = 'This is a simple but an amazing tool for text highlight 😎.';
const pattern = 'a';
const config = { matchAll: false };
const highlight = createHighlighter(config);
highlight(text, pattern);
→ 'This is <span class="text-highlight">a</span> simple but an amazing tool for text highlight 😎.'
const text = 'This is a simple but an amazing tool for text highlight 😎.';
const pattern = 'AMAZING';
const config = { caseSensitive: true };
const highlight = createHighlighter(config);
highlight(text, pattern);
→ 'This is a simple but an amazing tool for text highlight 😎.'
const text = 'This is a simple but an amazing tool for text highlight 😎.';
const pattern = 'simple amazing';
const config = { separateWordSearch: true };
const highlight = createHighlighter(config);
highlight(text, pattern);
→ 'This is a <span class="text-highlight">simple</span> but an <span class="text-highlight">amazing</span> tool for text highlight 😎.'
const text = 'Je suis allé à la café.';
const pattern = 'alle';
const highlight = createHighlighter({ diacritics: true });
highlight(text, pattern);
→ 'Je suis <span class="text-highlight">allé</span> à la café.'
const text = "Let's go!";
const pattern = 'Lets';
const highlight = createHighlighter({ ignorePunctuation: true });
highlight(text, pattern);
→ "<span class="text-highlight">Let's</span> go!"
createHighlighter(config?: HighlightOptions)Creates a configured highlighter function. This is the main entry point of the library.
Parameters:
config: Optional configuration object (see HighlightOptions)Returns:
(text: string, query: string) => string;
Example:
const highlight = createHighlighter({ caseSensitive: true });
highlight(text: string, query: string)The function returned by createHighlighter. It performs the actual text highlighting.
Parameters:
text: The source text where highlighting will be performedquery: The search pattern(s) to highlightReturns:
Example:
const highlighted = highlight('Hello world', 'world'); // Returns: "Hello <span class="text-highlight">world</span>"
HighlightOptionsConfiguration options for the highlighter.
| Property | Type | Default | Description |
|---|---|---|---|
caseSensitive | boolean | false | Enables case-sensitive matching |
className | string | 'text-highlight' | CSS class applied to highlight wrapper elements |
diacritics | boolean | true | Enables matching of text with diacritical marks |
ignorePunctuation | boolean | false | Removes punctuation from search consideration |
matchAll | boolean | true | Highlights all matches instead of just the first |
separateWordSearch | boolean | true | Treats space-separated query words as individual patterns |
tag | string | 'span' | HTML tag used for wrapping highlighted matches |
Example:
const options: HighlightOptions = {
caseSensitive: true,
className: 'custom-highlight',
tag: 'mark',
};
To style the wrapped text, you need to add CSS for the default class name text-highlight (or your custom class name if configured).
.text-highlight {
background-color: yellow;
color: black;
}
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License.
FAQs
A lightweight, customizable text highlighting library that illuminates matches in a content.
We found that spotmark 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.