Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
highlight-words-core
Advanced tools
Utility functions shared by react-highlight-words and react-native-highlight-words
The highlight-words-core npm package is a utility for finding and highlighting words within a string. It is particularly useful for search functionalities where you need to emphasize the search terms within the results.
Highlight Words
This feature allows you to find and highlight specific words within a given text. The `findAll` function takes an object with `searchWords` and `textToHighlight` properties and returns an array of chunks indicating the positions of the highlighted words.
const { findAll } = require('highlight-words-core');
const textToHighlight = 'This is a sample text to highlight certain words.';
const searchWords = ['sample', 'highlight'];
const chunks = findAll({
searchWords,
textToHighlight
});
console.log(chunks);
Case Insensitive Search
This feature allows you to perform a case-insensitive search. By setting the `caseSensitive` option to `false`, the search will ignore case differences between the search words and the text.
const { findAll } = require('highlight-words-core');
const textToHighlight = 'This is a Sample text to Highlight certain words.';
const searchWords = ['sample', 'highlight'];
const chunks = findAll({
searchWords,
textToHighlight,
autoEscape: true,
caseSensitive: false
});
console.log(chunks);
Escape Special Characters
This feature allows you to escape special characters in the search words. By setting the `autoEscape` option to `true`, special characters in the search words will be escaped, preventing them from being interpreted as regular expressions.
const { findAll } = require('highlight-words-core');
const textToHighlight = 'This is a sample text with special characters like * and ?.';
const searchWords = ['*', '?'];
const chunks = findAll({
searchWords,
textToHighlight,
autoEscape: true
});
console.log(chunks);
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.
Utility functions shared by react-highlight-words
and react-native-highlight-words
.
MIT License - fork, modify and use however you want.
FAQs
Utility functions shared by react-highlight-words and react-native-highlight-words
The npm package highlight-words-core receives a total of 347,214 weekly downloads. As such, highlight-words-core popularity was classified as popular.
We found that highlight-words-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.