MCPcopy Index your code
hub / github.com/tkirda/jQuery-Autocomplete / formatResult

Function formatResult

src/format.ts:16–34  ·  view source on GitHub ↗
(suggestion: Suggestion, currentValue: string)

Source from the content-addressed store, hash-verified

14}
15
16export function formatResult(suggestion: Suggestion, currentValue: string): string {
17 if (!currentValue) {
18 // Same escaping channel as formatGroup — let the browser handle entities
19 // so an HTML-bearing suggestion.value can't break out of the text node.
20 const span = document.createElement("span");
21 span.textContent = suggestion.value;
22 return span.innerHTML;
23 }
24
25 const pattern = "(" + utils.escapeRegExChars(currentValue) + ")";
26
27 return suggestion.value
28 .replace(new RegExp(pattern, "gi"), "<strong>$1</strong>")
29 .replace(/&/g, "&amp;")
30 .replace(/</g, "&lt;")
31 .replace(/>/g, "&gt;")
32 .replace(/"/g, "&quot;")
33 .replace(/&lt;(\/?strong)&gt;/g, "<$1>");
34}
35
36export function formatGroup(_suggestion: Suggestion, category: string): string {
37 const div = document.createElement("div");

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected