@ministryofjustice/probation-search-frontend
Version:
A shared UI component to search for probation cases from within your Express/Nunjucks application
22 lines • 858 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = highlighter;
const highlight_words_core_1 = require("highlight-words-core");
function highlighter(query) {
return function highlight(textToHighlight, shouldHighlight = true) {
if (!shouldHighlight || !textToHighlight || !query) {
return textToHighlight;
}
return (0, highlight_words_core_1.findAll)({
textToHighlight,
searchWords: query?.split(' ') ?? [],
autoEscape: true,
})
.map(({ start, end, highlight: hasHighlight }) => {
const text = textToHighlight.substring(start, end);
return hasHighlight ? `<span class="govuk-tag--yellow">${text}</span>` : text;
})
.join('');
};
}
//# sourceMappingURL=highlighting.js.map