@wordpress/components
Version:
UI components for WordPress.
34 lines (33 loc) • 1.26 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let highlight_words_core = require("highlight-words-core");
let _wordpress_element = require("@wordpress/element");
// packages/components/src/text/utils.ts
/**
* Creates the highlighted text rendered by Text.
*
* @param options Highlighter options.
* @param options.autoEscape Whether to escape regular-expression characters.
* @param options.caseSensitive Whether matching is case-sensitive.
* @param options.children Text to highlight.
* @param options.sanitize Text normalization function used for matching.
* @param options.searchWords Search terms to highlight.
*/
function createHighlighterText({ autoEscape, caseSensitive = false, children, sanitize, searchWords = [] }) {
if (!children) return null;
return (0, highlight_words_core.findAll)({
autoEscape,
caseSensitive,
sanitize,
searchWords,
textToHighlight: children
}).map((chunk, index) => (0, _wordpress_element.createElement)(chunk.highlight ? "mark" : "span", {
children: children.slice(chunk.start, chunk.end),
key: index
}));
}
exports.createHighlighterText = createHighlighterText;
//# sourceMappingURL=utils.cjs.map