UNPKG

@jsonhero/fuzzy-json-search

Version:
1,016 lines (1,003 loc) 69.2 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var LRUCache = require('lru-cache'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var LRUCache__default = /*#__PURE__*/_interopDefaultLegacy(LRUCache); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __spreadArray(to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); } function startsWithIgnoreCase(str, candidate) { var candidateLength = candidate.length; if (candidate.length > str.length) { return false; } return compareSubstringIgnoreCase(str, candidate, 0, candidateLength) === 0; } function compareSubstringIgnoreCase(a, b, aStart, aEnd, bStart, bEnd) { if (aStart === void 0) { aStart = 0; } if (aEnd === void 0) { aEnd = a.length; } if (bStart === void 0) { bStart = 0; } if (bEnd === void 0) { bEnd = b.length; } for (; aStart < aEnd && bStart < bEnd; aStart++, bStart++) { var codeA = a.charCodeAt(aStart); var codeB = b.charCodeAt(bStart); if (codeA === codeB) { // equal continue; } if (codeA >= 128 || codeB >= 128) { // not ASCII letters -> fallback to lower-casing strings return compareSubstring(a.toLowerCase(), b.toLowerCase(), aStart, aEnd, bStart, bEnd); } // mapper lower-case ascii letter onto upper-case varinats // [97-122] (lower ascii) --> [65-90] (upper ascii) if (isLowerAsciiLetter(codeA)) { codeA -= 32; } if (isLowerAsciiLetter(codeB)) { codeB -= 32; } // compare both code points var diff = codeA - codeB; if (diff === 0) { continue; } return diff; } var aLen = aEnd - aStart; var bLen = bEnd - bStart; if (aLen < bLen) { return -1; } else if (aLen > bLen) { return 1; } return 0; } function isLowerAsciiLetter(code) { return code >= 97 /* a */ && code <= 122 /* z */; } function compareSubstring(a, b, aStart, aEnd, bStart, bEnd) { if (aStart === void 0) { aStart = 0; } if (aEnd === void 0) { aEnd = a.length; } if (bStart === void 0) { bStart = 0; } if (bEnd === void 0) { bEnd = b.length; } for (; aStart < aEnd && bStart < bEnd; aStart++, bStart++) { var codeA = a.charCodeAt(aStart); var codeB = b.charCodeAt(bStart); if (codeA < codeB) { return -1; } else if (codeA > codeB) { return 1; } } var aLen = aEnd - aStart; var bLen = bEnd - bStart; if (aLen < bLen) { return -1; } else if (aLen > bLen) { return 1; } return 0; } var CharCode; (function (CharCode) { CharCode[CharCode["Null"] = 0] = "Null"; /** * The `\b` character. */ CharCode[CharCode["Backspace"] = 8] = "Backspace"; /** * The `\t` character. */ CharCode[CharCode["Tab"] = 9] = "Tab"; /** * The `\n` character. */ CharCode[CharCode["LineFeed"] = 10] = "LineFeed"; /** * The `\r` character. */ CharCode[CharCode["CarriageReturn"] = 13] = "CarriageReturn"; CharCode[CharCode["Space"] = 32] = "Space"; /** * The `!` character. */ CharCode[CharCode["ExclamationMark"] = 33] = "ExclamationMark"; /** * The `"` character. */ CharCode[CharCode["DoubleQuote"] = 34] = "DoubleQuote"; /** * The `#` character. */ CharCode[CharCode["Hash"] = 35] = "Hash"; /** * The `$` character. */ CharCode[CharCode["DollarSign"] = 36] = "DollarSign"; /** * The `%` character. */ CharCode[CharCode["PercentSign"] = 37] = "PercentSign"; /** * The `&` character. */ CharCode[CharCode["Ampersand"] = 38] = "Ampersand"; /** * The `'` character. */ CharCode[CharCode["SingleQuote"] = 39] = "SingleQuote"; /** * The `(` character. */ CharCode[CharCode["OpenParen"] = 40] = "OpenParen"; /** * The `)` character. */ CharCode[CharCode["CloseParen"] = 41] = "CloseParen"; /** * The `*` character. */ CharCode[CharCode["Asterisk"] = 42] = "Asterisk"; /** * The `+` character. */ CharCode[CharCode["Plus"] = 43] = "Plus"; /** * The `,` character. */ CharCode[CharCode["Comma"] = 44] = "Comma"; /** * The `-` character. */ CharCode[CharCode["Dash"] = 45] = "Dash"; /** * The `.` character. */ CharCode[CharCode["Period"] = 46] = "Period"; /** * The `/` character. */ CharCode[CharCode["Slash"] = 47] = "Slash"; CharCode[CharCode["Digit0"] = 48] = "Digit0"; CharCode[CharCode["Digit1"] = 49] = "Digit1"; CharCode[CharCode["Digit2"] = 50] = "Digit2"; CharCode[CharCode["Digit3"] = 51] = "Digit3"; CharCode[CharCode["Digit4"] = 52] = "Digit4"; CharCode[CharCode["Digit5"] = 53] = "Digit5"; CharCode[CharCode["Digit6"] = 54] = "Digit6"; CharCode[CharCode["Digit7"] = 55] = "Digit7"; CharCode[CharCode["Digit8"] = 56] = "Digit8"; CharCode[CharCode["Digit9"] = 57] = "Digit9"; /** * The `:` character. */ CharCode[CharCode["Colon"] = 58] = "Colon"; /** * The `;` character. */ CharCode[CharCode["Semicolon"] = 59] = "Semicolon"; /** * The `<` character. */ CharCode[CharCode["LessThan"] = 60] = "LessThan"; /** * The `=` character. */ CharCode[CharCode["Equals"] = 61] = "Equals"; /** * The `>` character. */ CharCode[CharCode["GreaterThan"] = 62] = "GreaterThan"; /** * The `?` character. */ CharCode[CharCode["QuestionMark"] = 63] = "QuestionMark"; /** * The `@` character. */ CharCode[CharCode["AtSign"] = 64] = "AtSign"; CharCode[CharCode["A"] = 65] = "A"; CharCode[CharCode["B"] = 66] = "B"; CharCode[CharCode["C"] = 67] = "C"; CharCode[CharCode["D"] = 68] = "D"; CharCode[CharCode["E"] = 69] = "E"; CharCode[CharCode["F"] = 70] = "F"; CharCode[CharCode["G"] = 71] = "G"; CharCode[CharCode["H"] = 72] = "H"; CharCode[CharCode["I"] = 73] = "I"; CharCode[CharCode["J"] = 74] = "J"; CharCode[CharCode["K"] = 75] = "K"; CharCode[CharCode["L"] = 76] = "L"; CharCode[CharCode["M"] = 77] = "M"; CharCode[CharCode["N"] = 78] = "N"; CharCode[CharCode["O"] = 79] = "O"; CharCode[CharCode["P"] = 80] = "P"; CharCode[CharCode["Q"] = 81] = "Q"; CharCode[CharCode["R"] = 82] = "R"; CharCode[CharCode["S"] = 83] = "S"; CharCode[CharCode["T"] = 84] = "T"; CharCode[CharCode["U"] = 85] = "U"; CharCode[CharCode["V"] = 86] = "V"; CharCode[CharCode["W"] = 87] = "W"; CharCode[CharCode["X"] = 88] = "X"; CharCode[CharCode["Y"] = 89] = "Y"; CharCode[CharCode["Z"] = 90] = "Z"; /** * The `[` character. */ CharCode[CharCode["OpenSquareBracket"] = 91] = "OpenSquareBracket"; /** * The `\` character. */ CharCode[CharCode["Backslash"] = 92] = "Backslash"; /** * The `]` character. */ CharCode[CharCode["CloseSquareBracket"] = 93] = "CloseSquareBracket"; /** * The `^` character. */ CharCode[CharCode["Caret"] = 94] = "Caret"; /** * The `_` character. */ CharCode[CharCode["Underline"] = 95] = "Underline"; /** * The ``(`)`` character. */ CharCode[CharCode["BackTick"] = 96] = "BackTick"; CharCode[CharCode["a"] = 97] = "a"; CharCode[CharCode["b"] = 98] = "b"; CharCode[CharCode["c"] = 99] = "c"; CharCode[CharCode["d"] = 100] = "d"; CharCode[CharCode["e"] = 101] = "e"; CharCode[CharCode["f"] = 102] = "f"; CharCode[CharCode["g"] = 103] = "g"; CharCode[CharCode["h"] = 104] = "h"; CharCode[CharCode["i"] = 105] = "i"; CharCode[CharCode["j"] = 106] = "j"; CharCode[CharCode["k"] = 107] = "k"; CharCode[CharCode["l"] = 108] = "l"; CharCode[CharCode["m"] = 109] = "m"; CharCode[CharCode["n"] = 110] = "n"; CharCode[CharCode["o"] = 111] = "o"; CharCode[CharCode["p"] = 112] = "p"; CharCode[CharCode["q"] = 113] = "q"; CharCode[CharCode["r"] = 114] = "r"; CharCode[CharCode["s"] = 115] = "s"; CharCode[CharCode["t"] = 116] = "t"; CharCode[CharCode["u"] = 117] = "u"; CharCode[CharCode["v"] = 118] = "v"; CharCode[CharCode["w"] = 119] = "w"; CharCode[CharCode["x"] = 120] = "x"; CharCode[CharCode["y"] = 121] = "y"; CharCode[CharCode["z"] = 122] = "z"; /** * The `{` character. */ CharCode[CharCode["OpenCurlyBrace"] = 123] = "OpenCurlyBrace"; /** * The `|` character. */ CharCode[CharCode["Pipe"] = 124] = "Pipe"; /** * The `}` character. */ CharCode[CharCode["CloseCurlyBrace"] = 125] = "CloseCurlyBrace"; /** * The `~` character. */ CharCode[CharCode["Tilde"] = 126] = "Tilde"; CharCode[CharCode["U_Combining_Grave_Accent"] = 768] = "U_Combining_Grave_Accent"; CharCode[CharCode["U_Combining_Acute_Accent"] = 769] = "U_Combining_Acute_Accent"; CharCode[CharCode["U_Combining_Circumflex_Accent"] = 770] = "U_Combining_Circumflex_Accent"; CharCode[CharCode["U_Combining_Tilde"] = 771] = "U_Combining_Tilde"; CharCode[CharCode["U_Combining_Macron"] = 772] = "U_Combining_Macron"; CharCode[CharCode["U_Combining_Overline"] = 773] = "U_Combining_Overline"; CharCode[CharCode["U_Combining_Breve"] = 774] = "U_Combining_Breve"; CharCode[CharCode["U_Combining_Dot_Above"] = 775] = "U_Combining_Dot_Above"; CharCode[CharCode["U_Combining_Diaeresis"] = 776] = "U_Combining_Diaeresis"; CharCode[CharCode["U_Combining_Hook_Above"] = 777] = "U_Combining_Hook_Above"; CharCode[CharCode["U_Combining_Ring_Above"] = 778] = "U_Combining_Ring_Above"; CharCode[CharCode["U_Combining_Double_Acute_Accent"] = 779] = "U_Combining_Double_Acute_Accent"; CharCode[CharCode["U_Combining_Caron"] = 780] = "U_Combining_Caron"; CharCode[CharCode["U_Combining_Vertical_Line_Above"] = 781] = "U_Combining_Vertical_Line_Above"; CharCode[CharCode["U_Combining_Double_Vertical_Line_Above"] = 782] = "U_Combining_Double_Vertical_Line_Above"; CharCode[CharCode["U_Combining_Double_Grave_Accent"] = 783] = "U_Combining_Double_Grave_Accent"; CharCode[CharCode["U_Combining_Candrabindu"] = 784] = "U_Combining_Candrabindu"; CharCode[CharCode["U_Combining_Inverted_Breve"] = 785] = "U_Combining_Inverted_Breve"; CharCode[CharCode["U_Combining_Turned_Comma_Above"] = 786] = "U_Combining_Turned_Comma_Above"; CharCode[CharCode["U_Combining_Comma_Above"] = 787] = "U_Combining_Comma_Above"; CharCode[CharCode["U_Combining_Reversed_Comma_Above"] = 788] = "U_Combining_Reversed_Comma_Above"; CharCode[CharCode["U_Combining_Comma_Above_Right"] = 789] = "U_Combining_Comma_Above_Right"; CharCode[CharCode["U_Combining_Grave_Accent_Below"] = 790] = "U_Combining_Grave_Accent_Below"; CharCode[CharCode["U_Combining_Acute_Accent_Below"] = 791] = "U_Combining_Acute_Accent_Below"; CharCode[CharCode["U_Combining_Left_Tack_Below"] = 792] = "U_Combining_Left_Tack_Below"; CharCode[CharCode["U_Combining_Right_Tack_Below"] = 793] = "U_Combining_Right_Tack_Below"; CharCode[CharCode["U_Combining_Left_Angle_Above"] = 794] = "U_Combining_Left_Angle_Above"; CharCode[CharCode["U_Combining_Horn"] = 795] = "U_Combining_Horn"; CharCode[CharCode["U_Combining_Left_Half_Ring_Below"] = 796] = "U_Combining_Left_Half_Ring_Below"; CharCode[CharCode["U_Combining_Up_Tack_Below"] = 797] = "U_Combining_Up_Tack_Below"; CharCode[CharCode["U_Combining_Down_Tack_Below"] = 798] = "U_Combining_Down_Tack_Below"; CharCode[CharCode["U_Combining_Plus_Sign_Below"] = 799] = "U_Combining_Plus_Sign_Below"; CharCode[CharCode["U_Combining_Minus_Sign_Below"] = 800] = "U_Combining_Minus_Sign_Below"; CharCode[CharCode["U_Combining_Palatalized_Hook_Below"] = 801] = "U_Combining_Palatalized_Hook_Below"; CharCode[CharCode["U_Combining_Retroflex_Hook_Below"] = 802] = "U_Combining_Retroflex_Hook_Below"; CharCode[CharCode["U_Combining_Dot_Below"] = 803] = "U_Combining_Dot_Below"; CharCode[CharCode["U_Combining_Diaeresis_Below"] = 804] = "U_Combining_Diaeresis_Below"; CharCode[CharCode["U_Combining_Ring_Below"] = 805] = "U_Combining_Ring_Below"; CharCode[CharCode["U_Combining_Comma_Below"] = 806] = "U_Combining_Comma_Below"; CharCode[CharCode["U_Combining_Cedilla"] = 807] = "U_Combining_Cedilla"; CharCode[CharCode["U_Combining_Ogonek"] = 808] = "U_Combining_Ogonek"; CharCode[CharCode["U_Combining_Vertical_Line_Below"] = 809] = "U_Combining_Vertical_Line_Below"; CharCode[CharCode["U_Combining_Bridge_Below"] = 810] = "U_Combining_Bridge_Below"; CharCode[CharCode["U_Combining_Inverted_Double_Arch_Below"] = 811] = "U_Combining_Inverted_Double_Arch_Below"; CharCode[CharCode["U_Combining_Caron_Below"] = 812] = "U_Combining_Caron_Below"; CharCode[CharCode["U_Combining_Circumflex_Accent_Below"] = 813] = "U_Combining_Circumflex_Accent_Below"; CharCode[CharCode["U_Combining_Breve_Below"] = 814] = "U_Combining_Breve_Below"; CharCode[CharCode["U_Combining_Inverted_Breve_Below"] = 815] = "U_Combining_Inverted_Breve_Below"; CharCode[CharCode["U_Combining_Tilde_Below"] = 816] = "U_Combining_Tilde_Below"; CharCode[CharCode["U_Combining_Macron_Below"] = 817] = "U_Combining_Macron_Below"; CharCode[CharCode["U_Combining_Low_Line"] = 818] = "U_Combining_Low_Line"; CharCode[CharCode["U_Combining_Double_Low_Line"] = 819] = "U_Combining_Double_Low_Line"; CharCode[CharCode["U_Combining_Tilde_Overlay"] = 820] = "U_Combining_Tilde_Overlay"; CharCode[CharCode["U_Combining_Short_Stroke_Overlay"] = 821] = "U_Combining_Short_Stroke_Overlay"; CharCode[CharCode["U_Combining_Long_Stroke_Overlay"] = 822] = "U_Combining_Long_Stroke_Overlay"; CharCode[CharCode["U_Combining_Short_Solidus_Overlay"] = 823] = "U_Combining_Short_Solidus_Overlay"; CharCode[CharCode["U_Combining_Long_Solidus_Overlay"] = 824] = "U_Combining_Long_Solidus_Overlay"; CharCode[CharCode["U_Combining_Right_Half_Ring_Below"] = 825] = "U_Combining_Right_Half_Ring_Below"; CharCode[CharCode["U_Combining_Inverted_Bridge_Below"] = 826] = "U_Combining_Inverted_Bridge_Below"; CharCode[CharCode["U_Combining_Square_Below"] = 827] = "U_Combining_Square_Below"; CharCode[CharCode["U_Combining_Seagull_Below"] = 828] = "U_Combining_Seagull_Below"; CharCode[CharCode["U_Combining_X_Above"] = 829] = "U_Combining_X_Above"; CharCode[CharCode["U_Combining_Vertical_Tilde"] = 830] = "U_Combining_Vertical_Tilde"; CharCode[CharCode["U_Combining_Double_Overline"] = 831] = "U_Combining_Double_Overline"; CharCode[CharCode["U_Combining_Grave_Tone_Mark"] = 832] = "U_Combining_Grave_Tone_Mark"; CharCode[CharCode["U_Combining_Acute_Tone_Mark"] = 833] = "U_Combining_Acute_Tone_Mark"; CharCode[CharCode["U_Combining_Greek_Perispomeni"] = 834] = "U_Combining_Greek_Perispomeni"; CharCode[CharCode["U_Combining_Greek_Koronis"] = 835] = "U_Combining_Greek_Koronis"; CharCode[CharCode["U_Combining_Greek_Dialytika_Tonos"] = 836] = "U_Combining_Greek_Dialytika_Tonos"; CharCode[CharCode["U_Combining_Greek_Ypogegrammeni"] = 837] = "U_Combining_Greek_Ypogegrammeni"; CharCode[CharCode["U_Combining_Bridge_Above"] = 838] = "U_Combining_Bridge_Above"; CharCode[CharCode["U_Combining_Equals_Sign_Below"] = 839] = "U_Combining_Equals_Sign_Below"; CharCode[CharCode["U_Combining_Double_Vertical_Line_Below"] = 840] = "U_Combining_Double_Vertical_Line_Below"; CharCode[CharCode["U_Combining_Left_Angle_Below"] = 841] = "U_Combining_Left_Angle_Below"; CharCode[CharCode["U_Combining_Not_Tilde_Above"] = 842] = "U_Combining_Not_Tilde_Above"; CharCode[CharCode["U_Combining_Homothetic_Above"] = 843] = "U_Combining_Homothetic_Above"; CharCode[CharCode["U_Combining_Almost_Equal_To_Above"] = 844] = "U_Combining_Almost_Equal_To_Above"; CharCode[CharCode["U_Combining_Left_Right_Arrow_Below"] = 845] = "U_Combining_Left_Right_Arrow_Below"; CharCode[CharCode["U_Combining_Upwards_Arrow_Below"] = 846] = "U_Combining_Upwards_Arrow_Below"; CharCode[CharCode["U_Combining_Grapheme_Joiner"] = 847] = "U_Combining_Grapheme_Joiner"; CharCode[CharCode["U_Combining_Right_Arrowhead_Above"] = 848] = "U_Combining_Right_Arrowhead_Above"; CharCode[CharCode["U_Combining_Left_Half_Ring_Above"] = 849] = "U_Combining_Left_Half_Ring_Above"; CharCode[CharCode["U_Combining_Fermata"] = 850] = "U_Combining_Fermata"; CharCode[CharCode["U_Combining_X_Below"] = 851] = "U_Combining_X_Below"; CharCode[CharCode["U_Combining_Left_Arrowhead_Below"] = 852] = "U_Combining_Left_Arrowhead_Below"; CharCode[CharCode["U_Combining_Right_Arrowhead_Below"] = 853] = "U_Combining_Right_Arrowhead_Below"; CharCode[CharCode["U_Combining_Right_Arrowhead_And_Up_Arrowhead_Below"] = 854] = "U_Combining_Right_Arrowhead_And_Up_Arrowhead_Below"; CharCode[CharCode["U_Combining_Right_Half_Ring_Above"] = 855] = "U_Combining_Right_Half_Ring_Above"; CharCode[CharCode["U_Combining_Dot_Above_Right"] = 856] = "U_Combining_Dot_Above_Right"; CharCode[CharCode["U_Combining_Asterisk_Below"] = 857] = "U_Combining_Asterisk_Below"; CharCode[CharCode["U_Combining_Double_Ring_Below"] = 858] = "U_Combining_Double_Ring_Below"; CharCode[CharCode["U_Combining_Zigzag_Above"] = 859] = "U_Combining_Zigzag_Above"; CharCode[CharCode["U_Combining_Double_Breve_Below"] = 860] = "U_Combining_Double_Breve_Below"; CharCode[CharCode["U_Combining_Double_Breve"] = 861] = "U_Combining_Double_Breve"; CharCode[CharCode["U_Combining_Double_Macron"] = 862] = "U_Combining_Double_Macron"; CharCode[CharCode["U_Combining_Double_Macron_Below"] = 863] = "U_Combining_Double_Macron_Below"; CharCode[CharCode["U_Combining_Double_Tilde"] = 864] = "U_Combining_Double_Tilde"; CharCode[CharCode["U_Combining_Double_Inverted_Breve"] = 865] = "U_Combining_Double_Inverted_Breve"; CharCode[CharCode["U_Combining_Double_Rightwards_Arrow_Below"] = 866] = "U_Combining_Double_Rightwards_Arrow_Below"; CharCode[CharCode["U_Combining_Latin_Small_Letter_A"] = 867] = "U_Combining_Latin_Small_Letter_A"; CharCode[CharCode["U_Combining_Latin_Small_Letter_E"] = 868] = "U_Combining_Latin_Small_Letter_E"; CharCode[CharCode["U_Combining_Latin_Small_Letter_I"] = 869] = "U_Combining_Latin_Small_Letter_I"; CharCode[CharCode["U_Combining_Latin_Small_Letter_O"] = 870] = "U_Combining_Latin_Small_Letter_O"; CharCode[CharCode["U_Combining_Latin_Small_Letter_U"] = 871] = "U_Combining_Latin_Small_Letter_U"; CharCode[CharCode["U_Combining_Latin_Small_Letter_C"] = 872] = "U_Combining_Latin_Small_Letter_C"; CharCode[CharCode["U_Combining_Latin_Small_Letter_D"] = 873] = "U_Combining_Latin_Small_Letter_D"; CharCode[CharCode["U_Combining_Latin_Small_Letter_H"] = 874] = "U_Combining_Latin_Small_Letter_H"; CharCode[CharCode["U_Combining_Latin_Small_Letter_M"] = 875] = "U_Combining_Latin_Small_Letter_M"; CharCode[CharCode["U_Combining_Latin_Small_Letter_R"] = 876] = "U_Combining_Latin_Small_Letter_R"; CharCode[CharCode["U_Combining_Latin_Small_Letter_T"] = 877] = "U_Combining_Latin_Small_Letter_T"; CharCode[CharCode["U_Combining_Latin_Small_Letter_V"] = 878] = "U_Combining_Latin_Small_Letter_V"; CharCode[CharCode["U_Combining_Latin_Small_Letter_X"] = 879] = "U_Combining_Latin_Small_Letter_X"; /** * Unicode Character 'LINE SEPARATOR' (U+2028) * http://www.fileformat.info/info/unicode/char/2028/index.htm */ CharCode[CharCode["LINE_SEPARATOR"] = 8232] = "LINE_SEPARATOR"; /** * Unicode Character 'PARAGRAPH SEPARATOR' (U+2029) * http://www.fileformat.info/info/unicode/char/2029/index.htm */ CharCode[CharCode["PARAGRAPH_SEPARATOR"] = 8233] = "PARAGRAPH_SEPARATOR"; /** * Unicode Character 'NEXT LINE' (U+0085) * http://www.fileformat.info/info/unicode/char/0085/index.htm */ CharCode[CharCode["NEXT_LINE"] = 133] = "NEXT_LINE"; // http://www.fileformat.info/info/unicode/category/Sk/list.htm CharCode[CharCode["U_CIRCUMFLEX"] = 94] = "U_CIRCUMFLEX"; CharCode[CharCode["U_GRAVE_ACCENT"] = 96] = "U_GRAVE_ACCENT"; CharCode[CharCode["U_DIAERESIS"] = 168] = "U_DIAERESIS"; CharCode[CharCode["U_MACRON"] = 175] = "U_MACRON"; CharCode[CharCode["U_ACUTE_ACCENT"] = 180] = "U_ACUTE_ACCENT"; CharCode[CharCode["U_CEDILLA"] = 184] = "U_CEDILLA"; CharCode[CharCode["U_MODIFIER_LETTER_LEFT_ARROWHEAD"] = 706] = "U_MODIFIER_LETTER_LEFT_ARROWHEAD"; CharCode[CharCode["U_MODIFIER_LETTER_RIGHT_ARROWHEAD"] = 707] = "U_MODIFIER_LETTER_RIGHT_ARROWHEAD"; CharCode[CharCode["U_MODIFIER_LETTER_UP_ARROWHEAD"] = 708] = "U_MODIFIER_LETTER_UP_ARROWHEAD"; CharCode[CharCode["U_MODIFIER_LETTER_DOWN_ARROWHEAD"] = 709] = "U_MODIFIER_LETTER_DOWN_ARROWHEAD"; CharCode[CharCode["U_MODIFIER_LETTER_CENTRED_RIGHT_HALF_RING"] = 722] = "U_MODIFIER_LETTER_CENTRED_RIGHT_HALF_RING"; CharCode[CharCode["U_MODIFIER_LETTER_CENTRED_LEFT_HALF_RING"] = 723] = "U_MODIFIER_LETTER_CENTRED_LEFT_HALF_RING"; CharCode[CharCode["U_MODIFIER_LETTER_UP_TACK"] = 724] = "U_MODIFIER_LETTER_UP_TACK"; CharCode[CharCode["U_MODIFIER_LETTER_DOWN_TACK"] = 725] = "U_MODIFIER_LETTER_DOWN_TACK"; CharCode[CharCode["U_MODIFIER_LETTER_PLUS_SIGN"] = 726] = "U_MODIFIER_LETTER_PLUS_SIGN"; CharCode[CharCode["U_MODIFIER_LETTER_MINUS_SIGN"] = 727] = "U_MODIFIER_LETTER_MINUS_SIGN"; CharCode[CharCode["U_BREVE"] = 728] = "U_BREVE"; CharCode[CharCode["U_DOT_ABOVE"] = 729] = "U_DOT_ABOVE"; CharCode[CharCode["U_RING_ABOVE"] = 730] = "U_RING_ABOVE"; CharCode[CharCode["U_OGONEK"] = 731] = "U_OGONEK"; CharCode[CharCode["U_SMALL_TILDE"] = 732] = "U_SMALL_TILDE"; CharCode[CharCode["U_DOUBLE_ACUTE_ACCENT"] = 733] = "U_DOUBLE_ACUTE_ACCENT"; CharCode[CharCode["U_MODIFIER_LETTER_RHOTIC_HOOK"] = 734] = "U_MODIFIER_LETTER_RHOTIC_HOOK"; CharCode[CharCode["U_MODIFIER_LETTER_CROSS_ACCENT"] = 735] = "U_MODIFIER_LETTER_CROSS_ACCENT"; CharCode[CharCode["U_MODIFIER_LETTER_EXTRA_HIGH_TONE_BAR"] = 741] = "U_MODIFIER_LETTER_EXTRA_HIGH_TONE_BAR"; CharCode[CharCode["U_MODIFIER_LETTER_HIGH_TONE_BAR"] = 742] = "U_MODIFIER_LETTER_HIGH_TONE_BAR"; CharCode[CharCode["U_MODIFIER_LETTER_MID_TONE_BAR"] = 743] = "U_MODIFIER_LETTER_MID_TONE_BAR"; CharCode[CharCode["U_MODIFIER_LETTER_LOW_TONE_BAR"] = 744] = "U_MODIFIER_LETTER_LOW_TONE_BAR"; CharCode[CharCode["U_MODIFIER_LETTER_EXTRA_LOW_TONE_BAR"] = 745] = "U_MODIFIER_LETTER_EXTRA_LOW_TONE_BAR"; CharCode[CharCode["U_MODIFIER_LETTER_YIN_DEPARTING_TONE_MARK"] = 746] = "U_MODIFIER_LETTER_YIN_DEPARTING_TONE_MARK"; CharCode[CharCode["U_MODIFIER_LETTER_YANG_DEPARTING_TONE_MARK"] = 747] = "U_MODIFIER_LETTER_YANG_DEPARTING_TONE_MARK"; CharCode[CharCode["U_MODIFIER_LETTER_UNASPIRATED"] = 749] = "U_MODIFIER_LETTER_UNASPIRATED"; CharCode[CharCode["U_MODIFIER_LETTER_LOW_DOWN_ARROWHEAD"] = 751] = "U_MODIFIER_LETTER_LOW_DOWN_ARROWHEAD"; CharCode[CharCode["U_MODIFIER_LETTER_LOW_UP_ARROWHEAD"] = 752] = "U_MODIFIER_LETTER_LOW_UP_ARROWHEAD"; CharCode[CharCode["U_MODIFIER_LETTER_LOW_LEFT_ARROWHEAD"] = 753] = "U_MODIFIER_LETTER_LOW_LEFT_ARROWHEAD"; CharCode[CharCode["U_MODIFIER_LETTER_LOW_RIGHT_ARROWHEAD"] = 754] = "U_MODIFIER_LETTER_LOW_RIGHT_ARROWHEAD"; CharCode[CharCode["U_MODIFIER_LETTER_LOW_RING"] = 755] = "U_MODIFIER_LETTER_LOW_RING"; CharCode[CharCode["U_MODIFIER_LETTER_MIDDLE_GRAVE_ACCENT"] = 756] = "U_MODIFIER_LETTER_MIDDLE_GRAVE_ACCENT"; CharCode[CharCode["U_MODIFIER_LETTER_MIDDLE_DOUBLE_GRAVE_ACCENT"] = 757] = "U_MODIFIER_LETTER_MIDDLE_DOUBLE_GRAVE_ACCENT"; CharCode[CharCode["U_MODIFIER_LETTER_MIDDLE_DOUBLE_ACUTE_ACCENT"] = 758] = "U_MODIFIER_LETTER_MIDDLE_DOUBLE_ACUTE_ACCENT"; CharCode[CharCode["U_MODIFIER_LETTER_LOW_TILDE"] = 759] = "U_MODIFIER_LETTER_LOW_TILDE"; CharCode[CharCode["U_MODIFIER_LETTER_RAISED_COLON"] = 760] = "U_MODIFIER_LETTER_RAISED_COLON"; CharCode[CharCode["U_MODIFIER_LETTER_BEGIN_HIGH_TONE"] = 761] = "U_MODIFIER_LETTER_BEGIN_HIGH_TONE"; CharCode[CharCode["U_MODIFIER_LETTER_END_HIGH_TONE"] = 762] = "U_MODIFIER_LETTER_END_HIGH_TONE"; CharCode[CharCode["U_MODIFIER_LETTER_BEGIN_LOW_TONE"] = 763] = "U_MODIFIER_LETTER_BEGIN_LOW_TONE"; CharCode[CharCode["U_MODIFIER_LETTER_END_LOW_TONE"] = 764] = "U_MODIFIER_LETTER_END_LOW_TONE"; CharCode[CharCode["U_MODIFIER_LETTER_SHELF"] = 765] = "U_MODIFIER_LETTER_SHELF"; CharCode[CharCode["U_MODIFIER_LETTER_OPEN_SHELF"] = 766] = "U_MODIFIER_LETTER_OPEN_SHELF"; CharCode[CharCode["U_MODIFIER_LETTER_LOW_LEFT_ARROW"] = 767] = "U_MODIFIER_LETTER_LOW_LEFT_ARROW"; CharCode[CharCode["U_GREEK_LOWER_NUMERAL_SIGN"] = 885] = "U_GREEK_LOWER_NUMERAL_SIGN"; CharCode[CharCode["U_GREEK_TONOS"] = 900] = "U_GREEK_TONOS"; CharCode[CharCode["U_GREEK_DIALYTIKA_TONOS"] = 901] = "U_GREEK_DIALYTIKA_TONOS"; CharCode[CharCode["U_GREEK_KORONIS"] = 8125] = "U_GREEK_KORONIS"; CharCode[CharCode["U_GREEK_PSILI"] = 8127] = "U_GREEK_PSILI"; CharCode[CharCode["U_GREEK_PERISPOMENI"] = 8128] = "U_GREEK_PERISPOMENI"; CharCode[CharCode["U_GREEK_DIALYTIKA_AND_PERISPOMENI"] = 8129] = "U_GREEK_DIALYTIKA_AND_PERISPOMENI"; CharCode[CharCode["U_GREEK_PSILI_AND_VARIA"] = 8141] = "U_GREEK_PSILI_AND_VARIA"; CharCode[CharCode["U_GREEK_PSILI_AND_OXIA"] = 8142] = "U_GREEK_PSILI_AND_OXIA"; CharCode[CharCode["U_GREEK_PSILI_AND_PERISPOMENI"] = 8143] = "U_GREEK_PSILI_AND_PERISPOMENI"; CharCode[CharCode["U_GREEK_DASIA_AND_VARIA"] = 8157] = "U_GREEK_DASIA_AND_VARIA"; CharCode[CharCode["U_GREEK_DASIA_AND_OXIA"] = 8158] = "U_GREEK_DASIA_AND_OXIA"; CharCode[CharCode["U_GREEK_DASIA_AND_PERISPOMENI"] = 8159] = "U_GREEK_DASIA_AND_PERISPOMENI"; CharCode[CharCode["U_GREEK_DIALYTIKA_AND_VARIA"] = 8173] = "U_GREEK_DIALYTIKA_AND_VARIA"; CharCode[CharCode["U_GREEK_DIALYTIKA_AND_OXIA"] = 8174] = "U_GREEK_DIALYTIKA_AND_OXIA"; CharCode[CharCode["U_GREEK_VARIA"] = 8175] = "U_GREEK_VARIA"; CharCode[CharCode["U_GREEK_OXIA"] = 8189] = "U_GREEK_OXIA"; CharCode[CharCode["U_GREEK_DASIA"] = 8190] = "U_GREEK_DASIA"; CharCode[CharCode["U_IDEOGRAPHIC_FULL_STOP"] = 12290] = "U_IDEOGRAPHIC_FULL_STOP"; CharCode[CharCode["U_LEFT_CORNER_BRACKET"] = 12300] = "U_LEFT_CORNER_BRACKET"; CharCode[CharCode["U_RIGHT_CORNER_BRACKET"] = 12301] = "U_RIGHT_CORNER_BRACKET"; CharCode[CharCode["U_LEFT_BLACK_LENTICULAR_BRACKET"] = 12304] = "U_LEFT_BLACK_LENTICULAR_BRACKET"; CharCode[CharCode["U_RIGHT_BLACK_LENTICULAR_BRACKET"] = 12305] = "U_RIGHT_BLACK_LENTICULAR_BRACKET"; CharCode[CharCode["U_OVERLINE"] = 8254] = "U_OVERLINE"; /** * UTF-8 BOM * Unicode Character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF) * http://www.fileformat.info/info/unicode/char/feff/index.htm */ CharCode[CharCode["UTF8_BOM"] = 65279] = "UTF8_BOM"; CharCode[CharCode["U_FULLWIDTH_SEMICOLON"] = 65307] = "U_FULLWIDTH_SEMICOLON"; CharCode[CharCode["U_FULLWIDTH_COMMA"] = 65292] = "U_FULLWIDTH_COMMA"; })(CharCode || (CharCode = {})); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Return a hash value for an object. */ function hash(obj) { return doHash(obj, 0); } function doHash(obj, hashVal) { switch (typeof obj) { case "object": if (obj === null) { return numberHash(349, hashVal); } else if (Array.isArray(obj)) { return arrayHash(obj, hashVal); } return objectHash(obj, hashVal); case "string": return stringHash(obj, hashVal); case "boolean": return booleanHash(obj, hashVal); case "number": return numberHash(obj, hashVal); case "undefined": return numberHash(937, hashVal); default: return numberHash(617, hashVal); } } function numberHash(val, initialHashVal) { return ((initialHashVal << 5) - initialHashVal + val) | 0; // hashVal * 31 + ch, keep as int32 } function booleanHash(b, initialHashVal) { return numberHash(b ? 433 : 863, initialHashVal); } function stringHash(s, hashVal) { hashVal = numberHash(149417, hashVal); for (var i = 0, length_1 = s.length; i < length_1; i++) { hashVal = numberHash(s.charCodeAt(i), hashVal); } return hashVal; } function arrayHash(arr, initialHashVal) { initialHashVal = numberHash(104579, initialHashVal); return arr.reduce(function (hashVal, item) { return doHash(item, hashVal); }, initialHashVal); } function objectHash(obj, initialHashVal) { initialHashVal = numberHash(181387, initialHashVal); return Object.keys(obj) .sort() .reduce(function (hashVal, key) { hashVal = stringHash(key, hashVal); return doHash(obj[key], hashVal); }, initialHashVal); } /** @class */ ((function () { function Hasher() { this._value = 0; } Object.defineProperty(Hasher.prototype, "value", { get: function () { return this._value; }, enumerable: false, configurable: true }); Hasher.prototype.hash = function (obj) { this._value = doHash(obj, this._value); return this._value; }; return Hasher; })()); var SHA1Constant; (function (SHA1Constant) { SHA1Constant[SHA1Constant["BLOCK_SIZE"] = 64] = "BLOCK_SIZE"; SHA1Constant[SHA1Constant["UNICODE_REPLACEMENT"] = 65533] = "UNICODE_REPLACEMENT"; })(SHA1Constant || (SHA1Constant = {})); var NO_MATCH = 0; var NO_SCORE = [NO_MATCH, []]; function scoreFuzzy(target, query, queryLower, allowNonContiguousMatches, optimizeForPaths) { if (optimizeForPaths === void 0) { optimizeForPaths = true; } if (!target || !query) { return NO_SCORE; // return early if target or query are undefined } var targetLength = target.length; var queryLength = query.length; if (targetLength < queryLength) { return NO_SCORE; // impossible for query to be contained in target } // if (DEBUG) { // console.group(`Target: ${target}, Query: ${query}`); // } var targetLower = target.toLowerCase(); var res = doScoreFuzzy(query, queryLower, queryLength, target, targetLower, targetLength, allowNonContiguousMatches, optimizeForPaths); // if (DEBUG) { // console.log(`%cFinal Score: ${res[0]}`, 'font-weight: bold'); // console.groupEnd(); // } return res; } function doScoreFuzzy(query, queryLower, queryLength, target, targetLower, targetLength, allowNonContiguousMatches, optimizeForPaths) { var scores = []; var matches = []; // // Build Scorer Matrix: // // The matrix is composed of query q and target t. For each index we score // q[i] with t[i] and compare that with the previous score. If the score is // equal or larger, we keep the match. In addition to the score, we also keep // the length of the consecutive matches to use as boost for the score. // // t a r g e t // q // u // e // r // y // for (var queryIndex_1 = 0; queryIndex_1 < queryLength; queryIndex_1++) { var queryIndexOffset = queryIndex_1 * targetLength; var queryIndexPreviousOffset = queryIndexOffset - targetLength; var queryIndexGtNull = queryIndex_1 > 0; var queryCharAtIndex = query[queryIndex_1]; var queryLowerCharAtIndex = queryLower[queryIndex_1]; for (var targetIndex_1 = 0; targetIndex_1 < targetLength; targetIndex_1++) { var targetIndexGtNull = targetIndex_1 > 0; var currentIndex = queryIndexOffset + targetIndex_1; var leftIndex = currentIndex - 1; var diagIndex = queryIndexPreviousOffset + targetIndex_1 - 1; var leftScore = targetIndexGtNull ? scores[leftIndex] : 0; var diagScore = queryIndexGtNull && targetIndexGtNull ? scores[diagIndex] : 0; var matchesSequenceLength = queryIndexGtNull && targetIndexGtNull ? matches[diagIndex] : 0; // If we are not matching on the first query character any more, we only produce a // score if we had a score previously for the last query index (by looking at the diagScore). // This makes sure that the query always matches in sequence on the target. For example // given a target of "ede" and a query of "de", we would otherwise produce a wrong high score // for query[1] ("e") matching on target[0] ("e") because of the "beginning of word" boost. var score = void 0; if (!diagScore && queryIndexGtNull) { score = 0; } else { score = computeCharScore(queryCharAtIndex, queryLowerCharAtIndex, target, targetLower, targetIndex_1, matchesSequenceLength, optimizeForPaths); } // We have a score and its equal or larger than the left score // Match: sequence continues growing from previous diag value // Score: increases by diag score value var isValidScore = score && diagScore + score >= leftScore; if (isValidScore && // We don't need to check if it's contiguous if we allow non-contiguous matches (allowNonContiguousMatches || // We must be looking for a contiguous match. // Looking at an index higher than 0 in the query means we must have already // found out this is contiguous otherwise there wouldn't have been a score queryIndexGtNull || // lastly check if the query is completely contiguous at this index in the target targetLower.startsWith(queryLower, targetIndex_1))) { matches[currentIndex] = matchesSequenceLength + 1; scores[currentIndex] = diagScore + score; } // We either have no score or the score is lower than the left score // Match: reset to 0 // Score: pick up from left hand side else { matches[currentIndex] = NO_MATCH; scores[currentIndex] = leftScore; } } } // Restore Positions (starting from bottom right of matrix) var positions = []; var queryIndex = queryLength - 1; var targetIndex = targetLength - 1; while (queryIndex >= 0 && targetIndex >= 0) { var currentIndex = queryIndex * targetLength + targetIndex; var match = matches[currentIndex]; if (match === NO_MATCH) { targetIndex--; // go left } else { positions.push(targetIndex); // go up and left queryIndex--; targetIndex--; } } // Print matrix // if (DEBUG_MATRIX) { // printMatrix(query, target, matches, scores); // } return [scores[queryLength * targetLength - 1], positions.reverse()]; } function computeCharScore(queryCharAtIndex, queryLowerCharAtIndex, target, targetLower, targetIndex, matchesSequenceLength, optimizeForPaths) { var score = 0; if (!considerAsEqual(queryLowerCharAtIndex, targetLower[targetIndex])) { return score; // no match of characters } // Character match bonus score += 1; // if (DEBUG) { // console.groupCollapsed(`%cCharacter match bonus: +1 (char: ${queryLowerCharAtIndex} at index ${targetIndex}, total score: ${score})`, 'font-weight: normal'); // } // Consecutive match bonus if (matchesSequenceLength > 0) { score += matchesSequenceLength * 5; // if (DEBUG) { // console.log(`Consecutive match bonus: +${matchesSequenceLength * 5}`); // } } // Same case bonus if (queryCharAtIndex === target[targetIndex]) { score += 1; // if (DEBUG) { // console.log('Same case bonus: +1'); // } } // Start of word bonus if (targetIndex === 0) { score += 8; // if (DEBUG) { // console.log('Start of word bonus: +8'); // } } else { // After separator bonus var separatorBonus = scoreSeparatorAtPos(target.charCodeAt(targetIndex - 1)); if (separatorBonus && optimizeForPaths) { score += separatorBonus; // if (DEBUG) { // console.log(`After separator bonus: +${separatorBonus}`); // } } // Inside word upper case bonus (camel case). We only give this bonus if we're not in a contiguous sequence. // For example: // NPE => NullPointerException = boost // HTTP => HTTP = not boost else if (isUpper(target.charCodeAt(targetIndex)) && matchesSequenceLength === 0) { score += 2; // if (DEBUG) { // console.log('Inside word upper case bonus: +2'); // } } } // if (DEBUG) { // console.groupEnd(); // } return score; } function considerAsEqual(a, b) { if (a === b) { return true; } // Special case path separators: ignore platform differences if (a === ".") { return b === "."; } return false; } function scoreSeparatorAtPos(charCode) { switch (charCode) { // prefer path separators... case 46 /* Period */: return 5; case 47 /* Slash */: case 92 /* Backslash */: case 95 /* Underline */: case 45 /* Dash */: case 32 /* Space */: case 39 /* SingleQuote */: case 34 /* DoubleQuote */: case 58 /* Colon */: return 4; // ...over other separators default: return 0; } } function isUpper(code) { return 65 /* A */ <= code && code <= 90 /* Z */; } var MULTIPLE_QUERY_VALUES_SEPARATOR = " "; function prepareQuery(original) { if (typeof original !== "string") { original = ""; } var originalLowercase = original.toLowerCase(); var _a = normalizeQuery(original), pathNormalized = _a.pathNormalized, normalized = _a.normalized, normalizedLowercase = _a.normalizedLowercase; var containsPathSeparator = pathNormalized.indexOf(".") >= 0; var expectExactMatch = queryExpectsExactMatch(original); var values = undefined; var originalSplit = original.split(MULTIPLE_QUERY_VALUES_SEPARATOR); if (originalSplit.length > 1) { for (var _i = 0, originalSplit_1 = originalSplit; _i < originalSplit_1.length; _i++) { var originalPiece = originalSplit_1[_i]; var expectExactMatchPiece = queryExpectsExactMatch(originalPiece); var _b = normalizeQuery(originalPiece), pathNormalizedPiece = _b.pathNormalized, normalizedPiece = _b.normalized, normalizedLowercasePiece = _b.normalizedLowercase; if (normalizedPiece) { if (!values) { values = []; } values.push({ original: originalPiece, originalLowercase: originalPiece.toLowerCase(), pathNormalized: pathNormalizedPiece, normalized: normalizedPiece, normalizedLowercase: normalizedLowercasePiece, expectContiguousMatch: expectExactMatchPiece, }); } } } return { original: original, originalLowercase: originalLowercase, pathNormalized: pathNormalized, normalized: normalized, normalizedLowercase: normalizedLowercase, values: values, containsPathSeparator: containsPathSeparator, expectContiguousMatch: expectExactMatch, }; } function normalizeQuery(original) { var pathNormalized = original.replace(/\//g, "."); // Help Windows users to search for paths when using slash // we remove quotes here because quotes are used for exact match search var normalized = stripWildcards(pathNormalized).replace(/\s|"/g, ""); return { pathNormalized: pathNormalized, normalized: normalized, normalizedLowercase: normalized.toLowerCase(), }; } function stripWildcards(pattern) { return pattern.replace(/\*/g, ""); } function queryExpectsExactMatch(query) { return query.startsWith('"') && query.endsWith('"'); } var NO_ITEM_SCORE = Object.freeze({ score: 0 }); function scoreItemFuzzy(item, query, allowNonContiguousMatches, accessor, cache) { if (cache === void 0) { cache = new Map(); } if (!item || !query.normalized) { return NO_ITEM_SCORE; // we need an item and query to score on at least } var label = accessor.getItemLabel(item); if (!label) { return NO_ITEM_SCORE; // we need a label at least } var description = accessor.getItemDescription(item); var path = accessor.getItemPath(item); var rawValue = accessor.getRawValue(item); var formattedValue = accessor.getFormattedValue(item); var cacheHash = getCacheHash(label, description, path, rawValue, formattedValue, allowNonContiguousMatches, query); var cached = cache.get(cacheHash); if (cached) { return cached; } var itemScore = doScoreItemFuzzy(label, description, path, rawValue, formattedValue, query, allowNonContiguousMatches); cache.set(cacheHash, itemScore); return itemScore; } var PATH_IDENTITY_SCORE = 1 << 18; var LABEL_PREFIX_SCORE_THRESHOLD = 1 << 17; var LABEL_SCORE_THRESHOLD = 1 << 16; function doScoreItemFuzzy(label, description, path, rawValue, formattedValue, query, allowNonContiguousMatches) { var preferLabelMatches = !path || !query.containsPathSeparator; // Treat identity matches on full path highest if (path && query.pathNormalized === path) { return { score: PATH_IDENTITY_SCORE, labelMatch: [{ start: 0, end: label.length }], descriptionMatch: description ? [{ start: 0, end: description.length }] : undefined, label: label, description: description, rawValue: rawValue, formattedValue: formattedValue, }; } // Score: multiple inputs if (query.values && query.values.length > 1) { return doScoreItemFuzzyMultiple(label, description, path, rawValue, formattedValue, query.values, preferLabelMatches, allowNonContiguousMatches); } // Score: single input return doScoreItemFuzzySingle(label, description, path, rawValue, formattedValue, query, preferLabelMatches, allowNonContiguousMatches); } function doScoreItemFuzzyMultiple(label, description, path, rawValue, formattedValue, query, preferLabelMatches, allowNonContiguousMatches) { var totalScore = 0; var totalLabelMatches = []; var totalDescriptionMatches = []; var totalRawValueMatches = []; var totalFormattedValueMatches = []; for (var _i = 0, query_1 = query; _i < query_1.length; _i++) { var queryPiece = query_1[_i]; var _a = doScoreItemFuzzySingle(label, description, path, rawValue, formattedValue, queryPiece, preferLabelMatches, allowNonContiguousMatches), score = _a.score, labelMatch = _a.labelMatch, descriptionMatch = _a.descriptionMatch, rawValueMatch = _a.rawValueMatch, formattedValueMatch = _a.formattedValueMatch; if (score === 0) { // if a single query value does not match, return with // no score entirely, we require all queries to match return NO_ITEM_SCORE; } totalScore += score; if (labelMatch) { totalLabelMatches.push.apply(totalLabelMatches, labelMatch); } if (descriptionMatch) { totalDescriptionMatches.push.apply(totalDescriptionMatches, descriptionMatch); } if (rawValueMatch) { totalRawValueMatches.push.apply(totalRawValueMatches, rawValueMatch); } if (formattedValueMatch) { totalFormattedValueMatches.push.apply(totalFormattedValueMatches, formattedValueMatch); } } // if we have a score, ensure that the positions are // sorted in ascending order and distinct return { score: totalScore, labelMatch: totalLabelMatches.length > 0 ? normalizeMatches(totalLabelMatches) : undefined, descriptionMatch: totalDescriptionMatches.length > 0 ? normalizeMatches(totalDescriptionMatches) : undefined, rawValueMatch: totalRawValueMatches.length > 0 ? normalizeMatches(totalRawValueMatches) : undefined, formattedValueMatch: totalFormattedValueMatches.length > 0 ? normalizeMatches(totalFormattedValueMatches) : undefined, label: label, description: description, rawValue: rawValue, formattedValue: formattedValue, }; } function doScoreItemFuzzySingle(label, description, path, rawValue, formattedValue, query, preferLabelMatches, allowNonContiguousMatches) { // Prefer label matches if told so or we have no description if (preferLabelMatches || !description) { var _a = scoreFuzzy(label, query.normalized, query.normalizedLowercase, allowNonContiguousMatches && !query.expectContiguousMatch), labelScore = _a[0], labelPositions = _a[1]; if (labelScore) { // If we have a prefix match on the label, we give a much // higher baseScore to elevate these matches over others // This ensures that typing a file name wins over results // that are present somewhere in the label, but not the // beginning. var labelPrefixMatch = matchesPrefix(true, query.normalized, label); var baseScore = void 0; if (labelPrefixMatch) { baseScore = LABEL_PREFIX_SCORE_THRESHOLD; // We give another boost to labels that are short, e.g. given // files "window.ts" and "windowActions.ts" and a query of // "window", we want "window.ts" to receive a higher score. // As such we compute the percentage the query has within the // label and add that to the baseScore. var prefixLengthBoost = Math.round((query.normalized.length / label.length) * 100); baseScore += prefixLengthBoost; } else { baseScore = LABEL_SCORE_THRESHOLD; } return integrateValueScores({ score: baseScore + labelScore, labelMatch: labelPrefixMatch || createMatches(labelPositions), label: label, description: description, rawValue: rawValue, formattedValue: formattedValue, }, rawValue, formattedValue, query, allowNonContiguousMatches); } } // Finally compute description + label scores if we have a description if (description) { var descriptionPrefix = description; if (path) { descriptionPrefix = "".concat(description, "."); // assume this is a fi