npm / highlight-words-core
highlight-words-core
What changed in highlight-words-core 2, from its official release notes, upgrade guides and advisories. Also covers @types/highlight-words-core. Sources checked 2026-10-19.
10 breaking4 new APIs and options2 behavior and defaults6 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli inithighlight-words-core 222 changes
Breaking changes 10
String search words are matched literally by default. Use RegExp search words to match patterns, or set autoEscape to false for trusted input.
Chunk is a union of highlighted and non-highlighted chunks; check chunk.highlight before reading searchIndex, and use literal highlight values when constructing chunks.
combineChunks no longer sorts its input array in place and always returns new chunk objects.
Published code uses modern JavaScript syntax instead of ES5 output; older environments and bundlers that cannot parse it need to transpile the package.
findChunks and combineChunks no longer include a highlight property in returned chunks; final chunks from findAll and fillInChunks still do.
Custom findChunks functions must include searchIndex in each returned chunk, identifying the matching word's index within searchWords.
Custom findChunks functions receive searchWords as a ReadonlyArray; mutable-array parameter declarations must be updated.
The package ships CommonJS and ES module builds and defines exports, so only the package root can be imported; deep imports and previously published src/*.js files are unavailable.
Non-string search words from untyped callers are matched as strings instead of being skipped when falsy.
The package is written in TypeScript and ships TypeScript declarations; Flow types are no longer included.
New APIs and options 4
HighlightedChunk is an exported type for highlighted chunks.
NonHighlightedChunk is an exported type for non-highlighted chunks.
Highlighted chunks include searchIndex, the index within searchWords of the matching search word.
searchWords can include RegExp objects, which are used as-is with their own flags.
Behavior and default changes 2
With autoEscape false, invalid regular-expression string search words are matched literally instead of throwing an error.
When sanitize changes text, it is applied character by character so matches can map back to the original text; context-dependent sanitizers can produce different results.
Fixes and other changes 6
Custom findChunks results extending outside the text or ending before they start no longer produce invalid or overlapping chunks.
Matches map back to the original text when sanitize changes its length.
searchWords can be a readonly array, such as an array declared with as const.
Missing searchWords values no longer throw an error; nothing is highlighted.
Surrogate pairs, such as emoji, are no longer split between chunks.
Missing textToHighlight values are no longer searched as strings such as "undefined".