10.0.0 • Published 1 year ago

my-humble-tests v10.0.0

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

Tiny util to highlight given string in text.

API

This package contains only one function exported as getChunks. This method searches a string of text for a set of search terms and returns an array of chunks that describe 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

8.0.0

1 year ago

6.0.1

1 year ago

10.0.0

1 year ago

3.0.0

1 year ago

2.2.0

1 year ago

4.0.0

1 year ago

9.0.2

1 year ago

7.0.0

1 year ago

9.0.1

1 year ago

9.0.0

1 year ago

2.1.0

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

2.0.0

1 year ago

1.6.0

1 year ago