
Security News
Critical Security Vulnerability in React Server Components
React disclosed a CVSS 10.0 RCE in React Server Components and is advising users to upgrade affected packages and frameworks to patched versions now.
highlight-words-core
Advanced tools
Utility functions shared by react-highlight-words and react-native-highlight-words
Utility functions shared by react-highlight-words and react-native-highlight-words.
The primary API for this package is a function exported as findAll. This method searches a string of text for a set of search terms and returns an array of "chunks" that describe the matches found.
Each "chunk" is an object consisting of a pair of indices (chunk.start and chunk.end) and a boolean specfifying whether the chunk is a match (chunk.highlight). For example:
import { findAll } from "highlight-words-core";
const textToHighlight = "This is some text to highlight.";
const searchWords = ["This", "i"];
const chunks = findAll({
searchWords,
textToHighlight
});
const highlightedText = chunks
.map(chunk => {
const { end, highlight, start } = chunk;
const text = textToHighlight.substr(start, end - start);
if (highlight) {
return `<mark>${text}</mark>`;
} else {
return text;
}
})
.join("");
Run this example on Code Sandbox.
findAllThe findAll function accepts several parameters, although only the searchWords array and textToHighlight string are required.
| Parameter | Required? | Type | Description |
|---|---|---|---|
| autoEscape | boolean | Escape special regular expression characters | |
| caseSensitive | boolean | Search should be case sensitive | |
| findChunks | Function | Custom find function (advanced) | |
| sanitize | Function | Custom sanitize function (advanced) | |
| searchWords | ✅ | Array<string> | Array of words to search for |
| textToHighlight | ✅ | string | Text to search and highlight |
MIT License - fork, modify and use however you want.
The react-highlight-words package provides similar functionality but is specifically designed for React applications. It allows you to highlight words within a React component, making it more suitable for front-end development compared to highlight-words-core, which is a more general utility.
The highlight.js package is a syntax highlighter for code, which can also be used to highlight words within a text. However, it is more focused on code syntax highlighting rather than general text highlighting, making it a bit different in scope compared to highlight-words-core.
The mark.js package is a versatile library for highlighting text. It offers more advanced features like custom element creation, regular expression support, and more. It is more feature-rich compared to highlight-words-core, which is simpler and more focused on basic word highlighting.
FAQs
Utility functions shared by react-highlight-words and react-native-highlight-words
The npm package highlight-words-core receives a total of 786,904 weekly downloads. As such, highlight-words-core popularity was classified as popular.
We found that highlight-words-core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
React disclosed a CVSS 10.0 RCE in React Server Components and is advising users to upgrade affected packages and frameworks to patched versions now.

Research
/Security News
We spotted a wave of auto-generated “elf-*” npm packages published every two minutes from new accounts, with simple malware variants and early takedowns underway.

Security News
TypeScript 6.0 will be the last JavaScript-based major release, as the project shifts to the TypeScript 7 native toolchain with major build speedups.