Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

highlight-words-core

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

highlight-words-core

Utility functions shared by react-highlight-words and react-native-highlight-words

  • 1.0.3
  • npm
  • Socket score

Version published
Weekly downloads
454K
decreased by-28.34%
Maintainers
2
Weekly downloads
 
Created

What is highlight-words-core?

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.

What are highlight-words-core's main functionalities?

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);

Other packages similar to highlight-words-core

Keywords

FAQs

Package last updated on 22 Sep 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc