1.1.2 • Published 1 year ago

highlight-string v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Tiny util to highlight given string in text. Written in TypeScript. Better alternative for highlight-words-core.

API

This package contains only one function exported as getChunks. This method searches for a given string in text and returns an array of chunks that describes the matches found. For example:

import { getChunks } from 'highlight-string';

const text = 'Have a nice day!';
const substrings = ['a', 'day'];

const chunks = getChunks({
  text,
  substrings,
});

const highlightedText = chunks
  .map(({ highlighted, text }) => (highlighted ? `<mark>${text}</mark>` : text))
  .join('');

getChunks

ParameterRequired?Default valueTypeDescription
text-stringText to search and highlight
substrings-Array<string>Array of strings to search for
caseSensitivefalsebooleanPass true if search should be case sensitive
sanitize-(text: string) => stringSanitize function

License

MIT

1.1.1

1 year ago

1.1.0

1 year ago

1.1.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.1.3

1 year ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago