picocrank 1.22.0 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -362,11 +362,35 @@ function selectItem(item) {
|
|
|
362
362
|
close()
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
+
function escapeHtml(value) {
|
|
366
|
+
return String(value)
|
|
367
|
+
.replace(/&/g, '&')
|
|
368
|
+
.replace(/</g, '<')
|
|
369
|
+
.replace(/>/g, '>')
|
|
370
|
+
.replace(/"/g, '"')
|
|
371
|
+
.replace(/'/g, ''')
|
|
372
|
+
}
|
|
373
|
+
|
|
365
374
|
function highlightText(text, query) {
|
|
366
|
-
if (
|
|
375
|
+
if (text == null || text === '') return ''
|
|
376
|
+
|
|
377
|
+
const source = String(text)
|
|
378
|
+
if (!query) return escapeHtml(source)
|
|
379
|
+
|
|
380
|
+
const regex = new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi')
|
|
381
|
+
let result = ''
|
|
382
|
+
let lastIndex = 0
|
|
383
|
+
|
|
384
|
+
for (const match of source.matchAll(regex)) {
|
|
385
|
+
const start = match.index
|
|
386
|
+
const matched = match[0]
|
|
387
|
+
result += escapeHtml(source.slice(lastIndex, start))
|
|
388
|
+
result += `<mark>${escapeHtml(matched)}</mark>`
|
|
389
|
+
lastIndex = start + matched.length
|
|
390
|
+
}
|
|
367
391
|
|
|
368
|
-
|
|
369
|
-
return
|
|
392
|
+
result += escapeHtml(source.slice(lastIndex))
|
|
393
|
+
return result
|
|
370
394
|
}
|
|
371
395
|
|
|
372
396
|
function addItem(item) {
|