Skip to content

Vizel API / core/src / splitVizelTextByMatches

Function: splitVizelTextByMatches()

ts
function splitVizelTextByMatches(text, matches?): VizelTextSegment[];

Defined in: packages/core/src/utils/textHighlight.ts:37

Split text into segments based on match indices from fuzzy search.

Parameters

ParameterTypeDescription
textstringThe original text to split
matches?[number, number][]Array of [start, end] index pairs indicating matched regions

Returns

VizelTextSegment[]

Array of text segments with highlight flags

Example

ts
// "Hello World" with "llo Wo" matched (indices [2,7])
const segments = splitVizelTextByMatches("Hello World", [[2, 7]]);
// Returns:
// [
//   { text: "He", highlight: false },
//   { text: "llo Wo", highlight: true },
//   { text: "rld", highlight: false },
// ]

Released under the MIT License.