fuse.basic.common.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  1. /**
  2. * Fuse.js v6.4.3 - Lightweight fuzzy-search (http://fusejs.io)
  3. *
  4. * Copyright (c) 2020 Kiro Risk (http://kiro.me)
  5. * All Rights Reserved. Apache Software License 2.0
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. */
  9. 'use strict';
  10. function _typeof(obj) {
  11. "@babel/helpers - typeof";
  12. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  13. _typeof = function (obj) {
  14. return typeof obj;
  15. };
  16. } else {
  17. _typeof = function (obj) {
  18. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  19. };
  20. }
  21. return _typeof(obj);
  22. }
  23. function _classCallCheck(instance, Constructor) {
  24. if (!(instance instanceof Constructor)) {
  25. throw new TypeError("Cannot call a class as a function");
  26. }
  27. }
  28. function _defineProperties(target, props) {
  29. for (var i = 0; i < props.length; i++) {
  30. var descriptor = props[i];
  31. descriptor.enumerable = descriptor.enumerable || false;
  32. descriptor.configurable = true;
  33. if ("value" in descriptor) descriptor.writable = true;
  34. Object.defineProperty(target, descriptor.key, descriptor);
  35. }
  36. }
  37. function _createClass(Constructor, protoProps, staticProps) {
  38. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  39. if (staticProps) _defineProperties(Constructor, staticProps);
  40. return Constructor;
  41. }
  42. function _defineProperty(obj, key, value) {
  43. if (key in obj) {
  44. Object.defineProperty(obj, key, {
  45. value: value,
  46. enumerable: true,
  47. configurable: true,
  48. writable: true
  49. });
  50. } else {
  51. obj[key] = value;
  52. }
  53. return obj;
  54. }
  55. function ownKeys(object, enumerableOnly) {
  56. var keys = Object.keys(object);
  57. if (Object.getOwnPropertySymbols) {
  58. var symbols = Object.getOwnPropertySymbols(object);
  59. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  60. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  61. });
  62. keys.push.apply(keys, symbols);
  63. }
  64. return keys;
  65. }
  66. function _objectSpread2(target) {
  67. for (var i = 1; i < arguments.length; i++) {
  68. var source = arguments[i] != null ? arguments[i] : {};
  69. if (i % 2) {
  70. ownKeys(Object(source), true).forEach(function (key) {
  71. _defineProperty(target, key, source[key]);
  72. });
  73. } else if (Object.getOwnPropertyDescriptors) {
  74. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  75. } else {
  76. ownKeys(Object(source)).forEach(function (key) {
  77. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  78. });
  79. }
  80. }
  81. return target;
  82. }
  83. function _toConsumableArray(arr) {
  84. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  85. }
  86. function _arrayWithoutHoles(arr) {
  87. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  88. }
  89. function _iterableToArray(iter) {
  90. if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
  91. }
  92. function _unsupportedIterableToArray(o, minLen) {
  93. if (!o) return;
  94. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  95. var n = Object.prototype.toString.call(o).slice(8, -1);
  96. if (n === "Object" && o.constructor) n = o.constructor.name;
  97. if (n === "Map" || n === "Set") return Array.from(o);
  98. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  99. }
  100. function _arrayLikeToArray(arr, len) {
  101. if (len == null || len > arr.length) len = arr.length;
  102. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  103. return arr2;
  104. }
  105. function _nonIterableSpread() {
  106. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  107. }
  108. function isArray(value) {
  109. return !Array.isArray ? getTag(value) === '[object Array]' : Array.isArray(value);
  110. } // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js
  111. var INFINITY = 1 / 0;
  112. function baseToString(value) {
  113. // Exit early for strings to avoid a performance hit in some environments.
  114. if (typeof value == 'string') {
  115. return value;
  116. }
  117. var result = value + '';
  118. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  119. }
  120. function toString(value) {
  121. return value == null ? '' : baseToString(value);
  122. }
  123. function isString(value) {
  124. return typeof value === 'string';
  125. }
  126. function isNumber(value) {
  127. return typeof value === 'number';
  128. } // Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js
  129. function isBoolean(value) {
  130. return value === true || value === false || isObjectLike(value) && getTag(value) == '[object Boolean]';
  131. }
  132. function isObject(value) {
  133. return _typeof(value) === 'object';
  134. } // Checks if `value` is object-like.
  135. function isObjectLike(value) {
  136. return isObject(value) && value !== null;
  137. }
  138. function isDefined(value) {
  139. return value !== undefined && value !== null;
  140. }
  141. function isBlank(value) {
  142. return !value.trim().length;
  143. } // Gets the `toStringTag` of `value`.
  144. // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js
  145. function getTag(value) {
  146. return value == null ? value === undefined ? '[object Undefined]' : '[object Null]' : Object.prototype.toString.call(value);
  147. }
  148. var EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available';
  149. var LOGICAL_SEARCH_UNAVAILABLE = 'Logical search is not available';
  150. var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
  151. var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = function LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key) {
  152. return "Invalid value for key ".concat(key);
  153. };
  154. var PATTERN_LENGTH_TOO_LARGE = function PATTERN_LENGTH_TOO_LARGE(max) {
  155. return "Pattern length exceeds max of ".concat(max, ".");
  156. };
  157. var MISSING_KEY_PROPERTY = function MISSING_KEY_PROPERTY(name) {
  158. return "Missing ".concat(name, " property in key");
  159. };
  160. var INVALID_KEY_WEIGHT_VALUE = function INVALID_KEY_WEIGHT_VALUE(key) {
  161. return "Property 'weight' in key '".concat(key, "' must be a positive integer");
  162. };
  163. var hasOwn = Object.prototype.hasOwnProperty;
  164. var KeyStore = /*#__PURE__*/function () {
  165. function KeyStore(keys) {
  166. var _this = this;
  167. _classCallCheck(this, KeyStore);
  168. this._keys = [];
  169. this._keyMap = {};
  170. var totalWeight = 0;
  171. keys.forEach(function (key) {
  172. var obj = createKey(key);
  173. totalWeight += obj.weight;
  174. _this._keys.push(obj);
  175. _this._keyMap[obj.id] = obj;
  176. totalWeight += obj.weight;
  177. }); // Normalize weights so that their sum is equal to 1
  178. this._keys.forEach(function (key) {
  179. key.weight /= totalWeight;
  180. });
  181. }
  182. _createClass(KeyStore, [{
  183. key: "get",
  184. value: function get(keyId) {
  185. return this._keyMap[keyId];
  186. }
  187. }, {
  188. key: "keys",
  189. value: function keys() {
  190. return this._keys;
  191. }
  192. }, {
  193. key: "toJSON",
  194. value: function toJSON() {
  195. return JSON.stringify(this._keys);
  196. }
  197. }]);
  198. return KeyStore;
  199. }();
  200. function createKey(key) {
  201. var path = null;
  202. var id = null;
  203. var src = null;
  204. var weight = 1;
  205. if (isString(key) || isArray(key)) {
  206. src = key;
  207. path = createKeyPath(key);
  208. id = createKeyId(key);
  209. } else {
  210. if (!hasOwn.call(key, 'name')) {
  211. throw new Error(MISSING_KEY_PROPERTY('name'));
  212. }
  213. var name = key.name;
  214. src = name;
  215. if (hasOwn.call(key, 'weight')) {
  216. weight = key.weight;
  217. if (weight <= 0) {
  218. throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
  219. }
  220. }
  221. path = createKeyPath(name);
  222. id = createKeyId(name);
  223. }
  224. return {
  225. path: path,
  226. id: id,
  227. weight: weight,
  228. src: src
  229. };
  230. }
  231. function createKeyPath(key) {
  232. return isArray(key) ? key : key.split('.');
  233. }
  234. function createKeyId(key) {
  235. return isArray(key) ? key.join('.') : key;
  236. }
  237. function get(obj, path) {
  238. var list = [];
  239. var arr = false;
  240. var deepGet = function deepGet(obj, path, index) {
  241. if (!isDefined(obj)) {
  242. return;
  243. }
  244. if (!path[index]) {
  245. // If there's no path left, we've arrived at the object we care about.
  246. list.push(obj);
  247. } else {
  248. var key = path[index];
  249. var value = obj[key];
  250. if (!isDefined(value)) {
  251. return;
  252. } // If we're at the last value in the path, and if it's a string/number/bool,
  253. // add it to the list
  254. if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
  255. list.push(toString(value));
  256. } else if (isArray(value)) {
  257. arr = true; // Search each item in the array.
  258. for (var i = 0, len = value.length; i < len; i += 1) {
  259. deepGet(value[i], path, index + 1);
  260. }
  261. } else if (path.length) {
  262. // An object. Recurse further.
  263. deepGet(value, path, index + 1);
  264. }
  265. }
  266. }; // Backwards compatibility (since path used to be a string)
  267. deepGet(obj, isString(path) ? path.split('.') : path, 0);
  268. return arr ? list : list[0];
  269. }
  270. var MatchOptions = {
  271. // Whether the matches should be included in the result set. When `true`, each record in the result
  272. // set will include the indices of the matched characters.
  273. // These can consequently be used for highlighting purposes.
  274. includeMatches: false,
  275. // When `true`, the matching function will continue to the end of a search pattern even if
  276. // a perfect match has already been located in the string.
  277. findAllMatches: false,
  278. // Minimum number of characters that must be matched before a result is considered a match
  279. minMatchCharLength: 1
  280. };
  281. var BasicOptions = {
  282. // When `true`, the algorithm continues searching to the end of the input even if a perfect
  283. // match is found before the end of the same input.
  284. isCaseSensitive: false,
  285. // When true, the matching function will continue to the end of a search pattern even if
  286. includeScore: false,
  287. // List of properties that will be searched. This also supports nested properties.
  288. keys: [],
  289. // Whether to sort the result list, by score
  290. shouldSort: true,
  291. // Default sort function: sort by ascending score, ascending index
  292. sortFn: function sortFn(a, b) {
  293. return a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1;
  294. }
  295. };
  296. var FuzzyOptions = {
  297. // Approximately where in the text is the pattern expected to be found?
  298. location: 0,
  299. // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
  300. // (of both letters and location), a threshold of '1.0' would match anything.
  301. threshold: 0.6,
  302. // Determines how close the match must be to the fuzzy location (specified above).
  303. // An exact letter match which is 'distance' characters away from the fuzzy location
  304. // would score as a complete mismatch. A distance of '0' requires the match be at
  305. // the exact location specified, a threshold of '1000' would require a perfect match
  306. // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
  307. distance: 100
  308. };
  309. var AdvancedOptions = {
  310. // When `true`, it enables the use of unix-like search commands
  311. useExtendedSearch: false,
  312. // The get function to use when fetching an object's properties.
  313. // The default will search nested paths *ie foo.bar.baz*
  314. getFn: get,
  315. // When `true`, search will ignore `location` and `distance`, so it won't matter
  316. // where in the string the pattern appears.
  317. // More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
  318. ignoreLocation: false,
  319. // When `true`, the calculation for the relevance score (used for sorting) will
  320. // ignore the field-length norm.
  321. // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
  322. ignoreFieldNorm: false
  323. };
  324. var Config = _objectSpread2({}, BasicOptions, {}, MatchOptions, {}, FuzzyOptions, {}, AdvancedOptions);
  325. var SPACE = /[^ ]+/g; // Field-length norm: the shorter the field, the higher the weight.
  326. // Set to 3 decimals to reduce index size.
  327. function norm() {
  328. var mantissa = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3;
  329. var cache = new Map();
  330. return {
  331. get: function get(value) {
  332. var numTokens = value.match(SPACE).length;
  333. if (cache.has(numTokens)) {
  334. return cache.get(numTokens);
  335. }
  336. var n = parseFloat((1 / Math.sqrt(numTokens)).toFixed(mantissa));
  337. cache.set(numTokens, n);
  338. return n;
  339. },
  340. clear: function clear() {
  341. cache.clear();
  342. }
  343. };
  344. }
  345. var FuseIndex = /*#__PURE__*/function () {
  346. function FuseIndex() {
  347. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  348. _ref$getFn = _ref.getFn,
  349. getFn = _ref$getFn === void 0 ? Config.getFn : _ref$getFn;
  350. _classCallCheck(this, FuseIndex);
  351. this.norm = norm(3);
  352. this.getFn = getFn;
  353. this.isCreated = false;
  354. this.setIndexRecords();
  355. }
  356. _createClass(FuseIndex, [{
  357. key: "setSources",
  358. value: function setSources() {
  359. var docs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  360. this.docs = docs;
  361. }
  362. }, {
  363. key: "setIndexRecords",
  364. value: function setIndexRecords() {
  365. var records = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  366. this.records = records;
  367. }
  368. }, {
  369. key: "setKeys",
  370. value: function setKeys() {
  371. var _this = this;
  372. var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  373. this.keys = keys;
  374. this._keysMap = {};
  375. keys.forEach(function (key, idx) {
  376. _this._keysMap[key.id] = idx;
  377. });
  378. }
  379. }, {
  380. key: "create",
  381. value: function create() {
  382. var _this2 = this;
  383. if (this.isCreated || !this.docs.length) {
  384. return;
  385. }
  386. this.isCreated = true; // List is Array<String>
  387. if (isString(this.docs[0])) {
  388. this.docs.forEach(function (doc, docIndex) {
  389. _this2._addString(doc, docIndex);
  390. });
  391. } else {
  392. // List is Array<Object>
  393. this.docs.forEach(function (doc, docIndex) {
  394. _this2._addObject(doc, docIndex);
  395. });
  396. }
  397. this.norm.clear();
  398. } // Adds a doc to the end of the index
  399. }, {
  400. key: "add",
  401. value: function add(doc) {
  402. var idx = this.size();
  403. if (isString(doc)) {
  404. this._addString(doc, idx);
  405. } else {
  406. this._addObject(doc, idx);
  407. }
  408. } // Removes the doc at the specified index of the index
  409. }, {
  410. key: "removeAt",
  411. value: function removeAt(idx) {
  412. this.records.splice(idx, 1); // Change ref index of every subsquent doc
  413. for (var i = idx, len = this.size(); i < len; i += 1) {
  414. this.records[i].i -= 1;
  415. }
  416. }
  417. }, {
  418. key: "getValueForItemAtKeyId",
  419. value: function getValueForItemAtKeyId(item, keyId) {
  420. return item[this._keysMap[keyId]];
  421. }
  422. }, {
  423. key: "size",
  424. value: function size() {
  425. return this.records.length;
  426. }
  427. }, {
  428. key: "_addString",
  429. value: function _addString(doc, docIndex) {
  430. if (!isDefined(doc) || isBlank(doc)) {
  431. return;
  432. }
  433. var record = {
  434. v: doc,
  435. i: docIndex,
  436. n: this.norm.get(doc)
  437. };
  438. this.records.push(record);
  439. }
  440. }, {
  441. key: "_addObject",
  442. value: function _addObject(doc, docIndex) {
  443. var _this3 = this;
  444. var record = {
  445. i: docIndex,
  446. $: {}
  447. }; // Iterate over every key (i.e, path), and fetch the value at that key
  448. this.keys.forEach(function (key, keyIndex) {
  449. // console.log(key)
  450. var value = _this3.getFn(doc, key.path);
  451. if (!isDefined(value)) {
  452. return;
  453. }
  454. if (isArray(value)) {
  455. (function () {
  456. var subRecords = [];
  457. var stack = [{
  458. nestedArrIndex: -1,
  459. value: value
  460. }];
  461. while (stack.length) {
  462. var _stack$pop = stack.pop(),
  463. nestedArrIndex = _stack$pop.nestedArrIndex,
  464. _value = _stack$pop.value;
  465. if (!isDefined(_value)) {
  466. continue;
  467. }
  468. if (isString(_value) && !isBlank(_value)) {
  469. var subRecord = {
  470. v: _value,
  471. i: nestedArrIndex,
  472. n: _this3.norm.get(_value)
  473. };
  474. subRecords.push(subRecord);
  475. } else if (isArray(_value)) {
  476. _value.forEach(function (item, k) {
  477. stack.push({
  478. nestedArrIndex: k,
  479. value: item
  480. });
  481. });
  482. }
  483. }
  484. record.$[keyIndex] = subRecords;
  485. })();
  486. } else if (!isBlank(value)) {
  487. var subRecord = {
  488. v: value,
  489. n: _this3.norm.get(value)
  490. };
  491. record.$[keyIndex] = subRecord;
  492. }
  493. });
  494. this.records.push(record);
  495. }
  496. }, {
  497. key: "toJSON",
  498. value: function toJSON() {
  499. return {
  500. keys: this.keys,
  501. records: this.records
  502. };
  503. }
  504. }]);
  505. return FuseIndex;
  506. }();
  507. function createIndex(keys, docs) {
  508. var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
  509. _ref2$getFn = _ref2.getFn,
  510. getFn = _ref2$getFn === void 0 ? Config.getFn : _ref2$getFn;
  511. var myIndex = new FuseIndex({
  512. getFn: getFn
  513. });
  514. myIndex.setKeys(keys.map(createKey));
  515. myIndex.setSources(docs);
  516. myIndex.create();
  517. return myIndex;
  518. }
  519. function parseIndex(data) {
  520. var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  521. _ref3$getFn = _ref3.getFn,
  522. getFn = _ref3$getFn === void 0 ? Config.getFn : _ref3$getFn;
  523. var keys = data.keys,
  524. records = data.records;
  525. var myIndex = new FuseIndex({
  526. getFn: getFn
  527. });
  528. myIndex.setKeys(keys);
  529. myIndex.setIndexRecords(records);
  530. return myIndex;
  531. }
  532. function transformMatches(result, data) {
  533. var matches = result.matches;
  534. data.matches = [];
  535. if (!isDefined(matches)) {
  536. return;
  537. }
  538. matches.forEach(function (match) {
  539. if (!isDefined(match.indices) || !match.indices.length) {
  540. return;
  541. }
  542. var indices = match.indices,
  543. value = match.value;
  544. var obj = {
  545. indices: indices,
  546. value: value
  547. };
  548. if (match.key) {
  549. obj.key = match.key.src;
  550. }
  551. if (match.idx > -1) {
  552. obj.refIndex = match.idx;
  553. }
  554. data.matches.push(obj);
  555. });
  556. }
  557. function transformScore(result, data) {
  558. data.score = result.score;
  559. }
  560. function computeScore(pattern) {
  561. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  562. _ref$errors = _ref.errors,
  563. errors = _ref$errors === void 0 ? 0 : _ref$errors,
  564. _ref$currentLocation = _ref.currentLocation,
  565. currentLocation = _ref$currentLocation === void 0 ? 0 : _ref$currentLocation,
  566. _ref$expectedLocation = _ref.expectedLocation,
  567. expectedLocation = _ref$expectedLocation === void 0 ? 0 : _ref$expectedLocation,
  568. _ref$distance = _ref.distance,
  569. distance = _ref$distance === void 0 ? Config.distance : _ref$distance,
  570. _ref$ignoreLocation = _ref.ignoreLocation,
  571. ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation;
  572. var accuracy = errors / pattern.length;
  573. if (ignoreLocation) {
  574. return accuracy;
  575. }
  576. var proximity = Math.abs(expectedLocation - currentLocation);
  577. if (!distance) {
  578. // Dodge divide by zero error.
  579. return proximity ? 1.0 : accuracy;
  580. }
  581. return accuracy + proximity / distance;
  582. }
  583. function convertMaskToIndices() {
  584. var matchmask = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  585. var minMatchCharLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Config.minMatchCharLength;
  586. var indices = [];
  587. var start = -1;
  588. var end = -1;
  589. var i = 0;
  590. for (var len = matchmask.length; i < len; i += 1) {
  591. var match = matchmask[i];
  592. if (match && start === -1) {
  593. start = i;
  594. } else if (!match && start !== -1) {
  595. end = i - 1;
  596. if (end - start + 1 >= minMatchCharLength) {
  597. indices.push([start, end]);
  598. }
  599. start = -1;
  600. }
  601. } // (i-1 - start) + 1 => i - start
  602. if (matchmask[i - 1] && i - start >= minMatchCharLength) {
  603. indices.push([start, i - 1]);
  604. }
  605. return indices;
  606. }
  607. // Machine word size
  608. var MAX_BITS = 32;
  609. function search(text, pattern, patternAlphabet) {
  610. var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
  611. _ref$location = _ref.location,
  612. location = _ref$location === void 0 ? Config.location : _ref$location,
  613. _ref$distance = _ref.distance,
  614. distance = _ref$distance === void 0 ? Config.distance : _ref$distance,
  615. _ref$threshold = _ref.threshold,
  616. threshold = _ref$threshold === void 0 ? Config.threshold : _ref$threshold,
  617. _ref$findAllMatches = _ref.findAllMatches,
  618. findAllMatches = _ref$findAllMatches === void 0 ? Config.findAllMatches : _ref$findAllMatches,
  619. _ref$minMatchCharLeng = _ref.minMatchCharLength,
  620. minMatchCharLength = _ref$minMatchCharLeng === void 0 ? Config.minMatchCharLength : _ref$minMatchCharLeng,
  621. _ref$includeMatches = _ref.includeMatches,
  622. includeMatches = _ref$includeMatches === void 0 ? Config.includeMatches : _ref$includeMatches,
  623. _ref$ignoreLocation = _ref.ignoreLocation,
  624. ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation;
  625. if (pattern.length > MAX_BITS) {
  626. throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
  627. }
  628. var patternLen = pattern.length; // Set starting location at beginning text and initialize the alphabet.
  629. var textLen = text.length; // Handle the case when location > text.length
  630. var expectedLocation = Math.max(0, Math.min(location, textLen)); // Highest score beyond which we give up.
  631. var currentThreshold = threshold; // Is there a nearby exact match? (speedup)
  632. var bestLocation = expectedLocation; // Performance: only computer matches when the minMatchCharLength > 1
  633. // OR if `includeMatches` is true.
  634. var computeMatches = minMatchCharLength > 1 || includeMatches; // A mask of the matches, used for building the indices
  635. var matchMask = computeMatches ? Array(textLen) : [];
  636. var index; // Get all exact matches, here for speed up
  637. while ((index = text.indexOf(pattern, bestLocation)) > -1) {
  638. var score = computeScore(pattern, {
  639. currentLocation: index,
  640. expectedLocation: expectedLocation,
  641. distance: distance,
  642. ignoreLocation: ignoreLocation
  643. });
  644. currentThreshold = Math.min(score, currentThreshold);
  645. bestLocation = index + patternLen;
  646. if (computeMatches) {
  647. var i = 0;
  648. while (i < patternLen) {
  649. matchMask[index + i] = 1;
  650. i += 1;
  651. }
  652. }
  653. } // Reset the best location
  654. bestLocation = -1;
  655. var lastBitArr = [];
  656. var finalScore = 1;
  657. var binMax = patternLen + textLen;
  658. var mask = 1 << patternLen - 1;
  659. for (var _i = 0; _i < patternLen; _i += 1) {
  660. // Scan for the best match; each iteration allows for one more error.
  661. // Run a binary search to determine how far from the match location we can stray
  662. // at this error level.
  663. var binMin = 0;
  664. var binMid = binMax;
  665. while (binMin < binMid) {
  666. var _score2 = computeScore(pattern, {
  667. errors: _i,
  668. currentLocation: expectedLocation + binMid,
  669. expectedLocation: expectedLocation,
  670. distance: distance,
  671. ignoreLocation: ignoreLocation
  672. });
  673. if (_score2 <= currentThreshold) {
  674. binMin = binMid;
  675. } else {
  676. binMax = binMid;
  677. }
  678. binMid = Math.floor((binMax - binMin) / 2 + binMin);
  679. } // Use the result from this iteration as the maximum for the next.
  680. binMax = binMid;
  681. var start = Math.max(1, expectedLocation - binMid + 1);
  682. var finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen; // Initialize the bit array
  683. var bitArr = Array(finish + 2);
  684. bitArr[finish + 1] = (1 << _i) - 1;
  685. for (var j = finish; j >= start; j -= 1) {
  686. var currentLocation = j - 1;
  687. var charMatch = patternAlphabet[text.charAt(currentLocation)];
  688. if (computeMatches) {
  689. // Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`)
  690. matchMask[currentLocation] = +!!charMatch;
  691. } // First pass: exact match
  692. bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch; // Subsequent passes: fuzzy match
  693. if (_i) {
  694. bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
  695. }
  696. if (bitArr[j] & mask) {
  697. finalScore = computeScore(pattern, {
  698. errors: _i,
  699. currentLocation: currentLocation,
  700. expectedLocation: expectedLocation,
  701. distance: distance,
  702. ignoreLocation: ignoreLocation
  703. }); // This match will almost certainly be better than any existing match.
  704. // But check anyway.
  705. if (finalScore <= currentThreshold) {
  706. // Indeed it is
  707. currentThreshold = finalScore;
  708. bestLocation = currentLocation; // Already passed `loc`, downhill from here on in.
  709. if (bestLocation <= expectedLocation) {
  710. break;
  711. } // When passing `bestLocation`, don't exceed our current distance from `expectedLocation`.
  712. start = Math.max(1, 2 * expectedLocation - bestLocation);
  713. }
  714. }
  715. } // No hope for a (better) match at greater error levels.
  716. var _score = computeScore(pattern, {
  717. errors: _i + 1,
  718. currentLocation: expectedLocation,
  719. expectedLocation: expectedLocation,
  720. distance: distance,
  721. ignoreLocation: ignoreLocation
  722. });
  723. if (_score > currentThreshold) {
  724. break;
  725. }
  726. lastBitArr = bitArr;
  727. }
  728. var result = {
  729. isMatch: bestLocation >= 0,
  730. // Count exact matches (those with a score of 0) to be "almost" exact
  731. score: Math.max(0.001, finalScore)
  732. };
  733. if (computeMatches) {
  734. var indices = convertMaskToIndices(matchMask, minMatchCharLength);
  735. if (!indices.length) {
  736. result.isMatch = false;
  737. } else if (includeMatches) {
  738. result.indices = indices;
  739. }
  740. }
  741. return result;
  742. }
  743. function createPatternAlphabet(pattern) {
  744. var mask = {};
  745. for (var i = 0, len = pattern.length; i < len; i += 1) {
  746. var char = pattern.charAt(i);
  747. mask[char] = (mask[char] || 0) | 1 << len - i - 1;
  748. }
  749. return mask;
  750. }
  751. var BitapSearch = /*#__PURE__*/function () {
  752. function BitapSearch(pattern) {
  753. var _this = this;
  754. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  755. _ref$location = _ref.location,
  756. location = _ref$location === void 0 ? Config.location : _ref$location,
  757. _ref$threshold = _ref.threshold,
  758. threshold = _ref$threshold === void 0 ? Config.threshold : _ref$threshold,
  759. _ref$distance = _ref.distance,
  760. distance = _ref$distance === void 0 ? Config.distance : _ref$distance,
  761. _ref$includeMatches = _ref.includeMatches,
  762. includeMatches = _ref$includeMatches === void 0 ? Config.includeMatches : _ref$includeMatches,
  763. _ref$findAllMatches = _ref.findAllMatches,
  764. findAllMatches = _ref$findAllMatches === void 0 ? Config.findAllMatches : _ref$findAllMatches,
  765. _ref$minMatchCharLeng = _ref.minMatchCharLength,
  766. minMatchCharLength = _ref$minMatchCharLeng === void 0 ? Config.minMatchCharLength : _ref$minMatchCharLeng,
  767. _ref$isCaseSensitive = _ref.isCaseSensitive,
  768. isCaseSensitive = _ref$isCaseSensitive === void 0 ? Config.isCaseSensitive : _ref$isCaseSensitive,
  769. _ref$ignoreLocation = _ref.ignoreLocation,
  770. ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation;
  771. _classCallCheck(this, BitapSearch);
  772. this.options = {
  773. location: location,
  774. threshold: threshold,
  775. distance: distance,
  776. includeMatches: includeMatches,
  777. findAllMatches: findAllMatches,
  778. minMatchCharLength: minMatchCharLength,
  779. isCaseSensitive: isCaseSensitive,
  780. ignoreLocation: ignoreLocation
  781. };
  782. this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
  783. this.chunks = [];
  784. if (!this.pattern.length) {
  785. return;
  786. }
  787. var addChunk = function addChunk(pattern, startIndex) {
  788. _this.chunks.push({
  789. pattern: pattern,
  790. alphabet: createPatternAlphabet(pattern),
  791. startIndex: startIndex
  792. });
  793. };
  794. var len = this.pattern.length;
  795. if (len > MAX_BITS) {
  796. var i = 0;
  797. var remainder = len % MAX_BITS;
  798. var end = len - remainder;
  799. while (i < end) {
  800. addChunk(this.pattern.substr(i, MAX_BITS), i);
  801. i += MAX_BITS;
  802. }
  803. if (remainder) {
  804. var startIndex = len - MAX_BITS;
  805. addChunk(this.pattern.substr(startIndex), startIndex);
  806. }
  807. } else {
  808. addChunk(this.pattern, 0);
  809. }
  810. }
  811. _createClass(BitapSearch, [{
  812. key: "searchIn",
  813. value: function searchIn(text) {
  814. var _this$options = this.options,
  815. isCaseSensitive = _this$options.isCaseSensitive,
  816. includeMatches = _this$options.includeMatches;
  817. if (!isCaseSensitive) {
  818. text = text.toLowerCase();
  819. } // Exact match
  820. if (this.pattern === text) {
  821. var _result = {
  822. isMatch: true,
  823. score: 0
  824. };
  825. if (includeMatches) {
  826. _result.indices = [[0, text.length - 1]];
  827. }
  828. return _result;
  829. } // Otherwise, use Bitap algorithm
  830. var _this$options2 = this.options,
  831. location = _this$options2.location,
  832. distance = _this$options2.distance,
  833. threshold = _this$options2.threshold,
  834. findAllMatches = _this$options2.findAllMatches,
  835. minMatchCharLength = _this$options2.minMatchCharLength,
  836. ignoreLocation = _this$options2.ignoreLocation;
  837. var allIndices = [];
  838. var totalScore = 0;
  839. var hasMatches = false;
  840. this.chunks.forEach(function (_ref2) {
  841. var pattern = _ref2.pattern,
  842. alphabet = _ref2.alphabet,
  843. startIndex = _ref2.startIndex;
  844. var _search = search(text, pattern, alphabet, {
  845. location: location + startIndex,
  846. distance: distance,
  847. threshold: threshold,
  848. findAllMatches: findAllMatches,
  849. minMatchCharLength: minMatchCharLength,
  850. includeMatches: includeMatches,
  851. ignoreLocation: ignoreLocation
  852. }),
  853. isMatch = _search.isMatch,
  854. score = _search.score,
  855. indices = _search.indices;
  856. if (isMatch) {
  857. hasMatches = true;
  858. }
  859. totalScore += score;
  860. if (isMatch && indices) {
  861. allIndices = [].concat(_toConsumableArray(allIndices), _toConsumableArray(indices));
  862. }
  863. });
  864. var result = {
  865. isMatch: hasMatches,
  866. score: hasMatches ? totalScore / this.chunks.length : 1
  867. };
  868. if (hasMatches && includeMatches) {
  869. result.indices = allIndices;
  870. }
  871. return result;
  872. }
  873. }]);
  874. return BitapSearch;
  875. }();
  876. var registeredSearchers = [];
  877. function createSearcher(pattern, options) {
  878. for (var i = 0, len = registeredSearchers.length; i < len; i += 1) {
  879. var searcherClass = registeredSearchers[i];
  880. if (searcherClass.condition(pattern, options)) {
  881. return new searcherClass(pattern, options);
  882. }
  883. }
  884. return new BitapSearch(pattern, options);
  885. }
  886. var LogicalOperator = {
  887. AND: '$and',
  888. OR: '$or'
  889. };
  890. var KeyType = {
  891. PATH: '$path',
  892. PATTERN: '$val'
  893. };
  894. var isExpression = function isExpression(query) {
  895. return !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
  896. };
  897. var isPath = function isPath(query) {
  898. return !!query[KeyType.PATH];
  899. };
  900. var isLeaf = function isLeaf(query) {
  901. return !isArray(query) && isObject(query) && !isExpression(query);
  902. };
  903. var convertToExplicit = function convertToExplicit(query) {
  904. return _defineProperty({}, LogicalOperator.AND, Object.keys(query).map(function (key) {
  905. return _defineProperty({}, key, query[key]);
  906. }));
  907. }; // When `auto` is `true`, the parse function will infer and initialize and add
  908. // the appropriate `Searcher` instance
  909. function parse(query, options) {
  910. var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
  911. _ref3$auto = _ref3.auto,
  912. auto = _ref3$auto === void 0 ? true : _ref3$auto;
  913. var next = function next(query) {
  914. var keys = Object.keys(query);
  915. var isQueryPath = isPath(query);
  916. if (!isQueryPath && keys.length > 1 && !isExpression(query)) {
  917. return next(convertToExplicit(query));
  918. }
  919. if (isLeaf(query)) {
  920. var key = isQueryPath ? query[KeyType.PATH] : keys[0];
  921. var pattern = isQueryPath ? query[KeyType.PATTERN] : query[key];
  922. if (!isString(pattern)) {
  923. throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
  924. }
  925. var obj = {
  926. keyId: createKeyId(key),
  927. pattern: pattern
  928. };
  929. if (auto) {
  930. obj.searcher = createSearcher(pattern, options);
  931. }
  932. return obj;
  933. }
  934. var node = {
  935. children: [],
  936. operator: keys[0]
  937. };
  938. keys.forEach(function (key) {
  939. var value = query[key];
  940. if (isArray(value)) {
  941. value.forEach(function (item) {
  942. node.children.push(next(item));
  943. });
  944. }
  945. });
  946. return node;
  947. };
  948. if (!isExpression(query)) {
  949. query = convertToExplicit(query);
  950. }
  951. return next(query);
  952. }
  953. var Fuse = /*#__PURE__*/function () {
  954. function Fuse(docs) {
  955. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  956. var index = arguments.length > 2 ? arguments[2] : undefined;
  957. _classCallCheck(this, Fuse);
  958. this.options = _objectSpread2({}, Config, {}, options);
  959. if (this.options.useExtendedSearch && !false) {
  960. throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
  961. }
  962. this._keyStore = new KeyStore(this.options.keys);
  963. this.setCollection(docs, index);
  964. }
  965. _createClass(Fuse, [{
  966. key: "setCollection",
  967. value: function setCollection(docs, index) {
  968. this._docs = docs;
  969. if (index && !(index instanceof FuseIndex)) {
  970. throw new Error(INCORRECT_INDEX_TYPE);
  971. }
  972. this._myIndex = index || createIndex(this.options.keys, this._docs, {
  973. getFn: this.options.getFn
  974. });
  975. }
  976. }, {
  977. key: "add",
  978. value: function add(doc) {
  979. if (!isDefined(doc)) {
  980. return;
  981. }
  982. this._docs.push(doc);
  983. this._myIndex.add(doc);
  984. }
  985. }, {
  986. key: "remove",
  987. value: function remove() {
  988. var predicate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
  989. return (
  990. /* doc, idx */
  991. false
  992. );
  993. };
  994. var results = [];
  995. for (var i = 0, len = this._docs.length; i < len; i += 1) {
  996. var doc = this._docs[i];
  997. if (predicate(doc, i)) {
  998. this.removeAt(i);
  999. i -= 1;
  1000. len -= 1;
  1001. results.push(doc);
  1002. }
  1003. }
  1004. return results;
  1005. }
  1006. }, {
  1007. key: "removeAt",
  1008. value: function removeAt(idx) {
  1009. this._docs.splice(idx, 1);
  1010. this._myIndex.removeAt(idx);
  1011. }
  1012. }, {
  1013. key: "getIndex",
  1014. value: function getIndex() {
  1015. return this._myIndex;
  1016. }
  1017. }, {
  1018. key: "search",
  1019. value: function search(query) {
  1020. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  1021. _ref$limit = _ref.limit,
  1022. limit = _ref$limit === void 0 ? -1 : _ref$limit;
  1023. var _this$options = this.options,
  1024. includeMatches = _this$options.includeMatches,
  1025. includeScore = _this$options.includeScore,
  1026. shouldSort = _this$options.shouldSort,
  1027. sortFn = _this$options.sortFn,
  1028. ignoreFieldNorm = _this$options.ignoreFieldNorm;
  1029. var results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
  1030. computeScore$1(results, {
  1031. ignoreFieldNorm: ignoreFieldNorm
  1032. });
  1033. if (shouldSort) {
  1034. results.sort(sortFn);
  1035. }
  1036. if (isNumber(limit) && limit > -1) {
  1037. results = results.slice(0, limit);
  1038. }
  1039. return format(results, this._docs, {
  1040. includeMatches: includeMatches,
  1041. includeScore: includeScore
  1042. });
  1043. }
  1044. }, {
  1045. key: "_searchStringList",
  1046. value: function _searchStringList(query) {
  1047. var searcher = createSearcher(query, this.options);
  1048. var records = this._myIndex.records;
  1049. var results = []; // Iterate over every string in the index
  1050. records.forEach(function (_ref2) {
  1051. var text = _ref2.v,
  1052. idx = _ref2.i,
  1053. norm = _ref2.n;
  1054. if (!isDefined(text)) {
  1055. return;
  1056. }
  1057. var _searcher$searchIn = searcher.searchIn(text),
  1058. isMatch = _searcher$searchIn.isMatch,
  1059. score = _searcher$searchIn.score,
  1060. indices = _searcher$searchIn.indices;
  1061. if (isMatch) {
  1062. results.push({
  1063. item: text,
  1064. idx: idx,
  1065. matches: [{
  1066. score: score,
  1067. value: text,
  1068. norm: norm,
  1069. indices: indices
  1070. }]
  1071. });
  1072. }
  1073. });
  1074. return results;
  1075. }
  1076. }, {
  1077. key: "_searchLogical",
  1078. value: function _searchLogical(query) {
  1079. {
  1080. throw new Error(LOGICAL_SEARCH_UNAVAILABLE);
  1081. }
  1082. }
  1083. }, {
  1084. key: "_searchObjectList",
  1085. value: function _searchObjectList(query) {
  1086. var _this2 = this;
  1087. var searcher = createSearcher(query, this.options);
  1088. var _this$_myIndex = this._myIndex,
  1089. keys = _this$_myIndex.keys,
  1090. records = _this$_myIndex.records;
  1091. var results = []; // List is Array<Object>
  1092. records.forEach(function (_ref5) {
  1093. var item = _ref5.$,
  1094. idx = _ref5.i;
  1095. if (!isDefined(item)) {
  1096. return;
  1097. }
  1098. var matches = []; // Iterate over every key (i.e, path), and fetch the value at that key
  1099. keys.forEach(function (key, keyIndex) {
  1100. matches.push.apply(matches, _toConsumableArray(_this2._findMatches({
  1101. key: key,
  1102. value: item[keyIndex],
  1103. searcher: searcher
  1104. })));
  1105. });
  1106. if (matches.length) {
  1107. results.push({
  1108. idx: idx,
  1109. item: item,
  1110. matches: matches
  1111. });
  1112. }
  1113. });
  1114. return results;
  1115. }
  1116. }, {
  1117. key: "_findMatches",
  1118. value: function _findMatches(_ref6) {
  1119. var key = _ref6.key,
  1120. value = _ref6.value,
  1121. searcher = _ref6.searcher;
  1122. if (!isDefined(value)) {
  1123. return [];
  1124. }
  1125. var matches = [];
  1126. if (isArray(value)) {
  1127. value.forEach(function (_ref7) {
  1128. var text = _ref7.v,
  1129. idx = _ref7.i,
  1130. norm = _ref7.n;
  1131. if (!isDefined(text)) {
  1132. return;
  1133. }
  1134. var _searcher$searchIn2 = searcher.searchIn(text),
  1135. isMatch = _searcher$searchIn2.isMatch,
  1136. score = _searcher$searchIn2.score,
  1137. indices = _searcher$searchIn2.indices;
  1138. if (isMatch) {
  1139. matches.push({
  1140. score: score,
  1141. key: key,
  1142. value: text,
  1143. idx: idx,
  1144. norm: norm,
  1145. indices: indices
  1146. });
  1147. }
  1148. });
  1149. } else {
  1150. var text = value.v,
  1151. norm = value.n;
  1152. var _searcher$searchIn3 = searcher.searchIn(text),
  1153. isMatch = _searcher$searchIn3.isMatch,
  1154. score = _searcher$searchIn3.score,
  1155. indices = _searcher$searchIn3.indices;
  1156. if (isMatch) {
  1157. matches.push({
  1158. score: score,
  1159. key: key,
  1160. value: text,
  1161. norm: norm,
  1162. indices: indices
  1163. });
  1164. }
  1165. }
  1166. return matches;
  1167. }
  1168. }]);
  1169. return Fuse;
  1170. }(); // Practical scoring function
  1171. function computeScore$1(results, _ref8) {
  1172. var _ref8$ignoreFieldNorm = _ref8.ignoreFieldNorm,
  1173. ignoreFieldNorm = _ref8$ignoreFieldNorm === void 0 ? Config.ignoreFieldNorm : _ref8$ignoreFieldNorm;
  1174. results.forEach(function (result) {
  1175. var totalScore = 1;
  1176. result.matches.forEach(function (_ref9) {
  1177. var key = _ref9.key,
  1178. norm = _ref9.norm,
  1179. score = _ref9.score;
  1180. var weight = key ? key.weight : null;
  1181. totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm));
  1182. });
  1183. result.score = totalScore;
  1184. });
  1185. }
  1186. function format(results, docs) {
  1187. var _ref10 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
  1188. _ref10$includeMatches = _ref10.includeMatches,
  1189. includeMatches = _ref10$includeMatches === void 0 ? Config.includeMatches : _ref10$includeMatches,
  1190. _ref10$includeScore = _ref10.includeScore,
  1191. includeScore = _ref10$includeScore === void 0 ? Config.includeScore : _ref10$includeScore;
  1192. var transformers = [];
  1193. if (includeMatches) transformers.push(transformMatches);
  1194. if (includeScore) transformers.push(transformScore);
  1195. return results.map(function (result) {
  1196. var idx = result.idx;
  1197. var data = {
  1198. item: docs[idx],
  1199. refIndex: idx
  1200. };
  1201. if (transformers.length) {
  1202. transformers.forEach(function (transformer) {
  1203. transformer(result, data);
  1204. });
  1205. }
  1206. return data;
  1207. });
  1208. }
  1209. Fuse.version = '6.4.3';
  1210. Fuse.createIndex = createIndex;
  1211. Fuse.parseIndex = parseIndex;
  1212. Fuse.config = Config;
  1213. {
  1214. Fuse.parseQuery = parse;
  1215. }
  1216. module.exports = Fuse;