UNPKG

@gowiz/searchbar

Version:

Different search bars powered by Gowiz search engine technology

28 lines 949 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getHighlightParts = void 0; const string_util_1 = require("./string_util"); function getHighlightParts(text, query) { const textLength = text === null || text === undefined ? 0 : text.length; const queryLength = query === null || query === undefined ? 0 : query.length; if (queryLength < 1) { if (textLength > 0) { return [text]; } return []; } if (textLength < 0) { return []; } text = string_util_1.reformatQueryForSearch(text); query = string_util_1.reformatQueryForSearch(query); if (text.toLocaleLowerCase() === query.toLocaleLowerCase()) { return []; } const parts = text.split(new RegExp(`(${query})`, 'gi')); return parts.filter(function (e) { return e; }); } exports.getHighlightParts = getHighlightParts; //# sourceMappingURL=highlight.js.map