Sanity-check decaffeinate app.Searcher

pull/1441/head
Simon Legner 1 year ago
parent 978d4a9f64
commit efb3697622

@ -1,16 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS104: Avoid inline assignments
* DS202: Simplify dynamic range loops
* DS206: Consider reworking classes to avoid initClass
* DS207: Consider shorter variations of null checks
* DS209: Avoid top-level return
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
//
// Match functions
//
@ -158,62 +145,47 @@ function scoreFuzzyMatch() {
// Searchers
//
(function () {
let CHUNK_SIZE = undefined;
let DEFAULTS = undefined;
let SEPARATORS_REGEXP = undefined;
let EOS_SEPARATORS_REGEXP = undefined;
let INFO_PARANTHESES_REGEXP = undefined;
let EMPTY_PARANTHESES_REGEXP = undefined;
let EVENT_REGEXP = undefined;
let DOT_REGEXP = undefined;
let WHITESPACE_REGEXP = undefined;
let EMPTY_STRING = undefined;
let ELLIPSIS = undefined;
let STRING = undefined;
app.Searcher = class Searcher extends Events {
static initClass() {
CHUNK_SIZE = 20000;
static CHUNK_SIZE = 20000;
DEFAULTS = {
static DEFAULTS = {
max_results: app.config.max_results,
fuzzy_min_length: 3,
};
SEPARATORS_REGEXP =
static SEPARATORS_REGEXP =
/#|::|:-|->|\$(?=\w)|\-(?=\w)|\:(?=\w)|\ [\/\-&]\ |:\ |\ /g;
EOS_SEPARATORS_REGEXP = /(\w)[\-:]$/;
INFO_PARANTHESES_REGEXP = /\ \(\w+?\)$/;
EMPTY_PARANTHESES_REGEXP = /\(\)/;
EVENT_REGEXP = /\ event$/;
DOT_REGEXP = /\.+/g;
WHITESPACE_REGEXP = /\s/g;
static EOS_SEPARATORS_REGEXP = /(\w)[\-:]$/;
static INFO_PARANTHESES_REGEXP = /\ \(\w+?\)$/;
static EMPTY_PARANTHESES_REGEXP = /\(\)/;
static EVENT_REGEXP = /\ event$/;
static DOT_REGEXP = /\.+/g;
static WHITESPACE_REGEXP = /\s/g;
EMPTY_STRING = "";
ELLIPSIS = "...";
STRING = "string";
}
static EMPTY_STRING = "";
static ELLIPSIS = "...";
static STRING = "string";
static normalizeString(string) {
return string
.toLowerCase()
.replace(ELLIPSIS, EMPTY_STRING)
.replace(EVENT_REGEXP, EMPTY_STRING)
.replace(INFO_PARANTHESES_REGEXP, EMPTY_STRING)
.replace(SEPARATORS_REGEXP, SEPARATOR)
.replace(DOT_REGEXP, SEPARATOR)
.replace(EMPTY_PARANTHESES_REGEXP, EMPTY_STRING)
.replace(WHITESPACE_REGEXP, EMPTY_STRING);
.replace(Searcher.ELLIPSIS, Searcher.EMPTY_STRING)
.replace(Searcher.EVENT_REGEXP, Searcher.EMPTY_STRING)
.replace(Searcher.INFO_PARANTHESES_REGEXP, Searcher.EMPTY_STRING)
.replace(Searcher.SEPARATORS_REGEXP, SEPARATOR)
.replace(Searcher.DOT_REGEXP, SEPARATOR)
.replace(Searcher.EMPTY_PARANTHESES_REGEXP, Searcher.EMPTY_STRING)
.replace(Searcher.WHITESPACE_REGEXP, Searcher.EMPTY_STRING);
}
static normalizeQuery(string) {
string = this.normalizeString(string);
return string.replace(EOS_SEPARATORS_REGEXP, "$1.");
return string.replace(Searcher.EOS_SEPARATORS_REGEXP, "$1.");
}
constructor(options) {
super();
this.options = $.extend({}, DEFAULTS, options || {});
this.options = $.extend({}, Searcher.DEFAULTS, options || {});
}
find(data, attr, q) {
@ -269,17 +241,16 @@ function scoreFuzzyMatch() {
}
free() {
this.data =
this.attr =
this.dataLength =
this.matchers =
this.matcher =
this.query =
this.totalResults =
this.scoreMap =
this.cursor =
this.timeout =
null;
this.data = null;
this.attr = null;
this.dataLength = null;
this.matchers = null;
this.matcher = null;
this.query = null;
this.totalResults = null;
this.scoreMap = null;
this.cursor = null;
this.timeout = null;
}
match() {
@ -309,11 +280,7 @@ function scoreFuzzyMatch() {
matchChunk() {
({ matcher } = this);
for (
let j = 0, end = this.chunkSize(), asc = 0 <= end;
asc ? j < end : j > end;
asc ? j++ : j--
) {
for (let j = 0, end = this.chunkSize(); j < end; j++) {
value = this.data[this.cursor][this.attr];
if (value.split) {
// string
@ -337,10 +304,10 @@ function scoreFuzzyMatch() {
}
chunkSize() {
if (this.cursor + CHUNK_SIZE > this.dataLength) {
return this.dataLength % CHUNK_SIZE;
if (this.cursor + Searcher.CHUNK_SIZE > this.dataLength) {
return this.dataLength % Searcher.CHUNK_SIZE;
} else {
return CHUNK_SIZE;
return Searcher.CHUNK_SIZE;
}
}
@ -398,9 +365,6 @@ function scoreFuzzyMatch() {
return new RegExp(chars.join(".*?")); // abc -> /a.*?b.*?c.*?/
}
};
app.Searcher.initClass();
return app.Searcher;
})();
app.SynchronousSearcher = class SynchronousSearcher extends app.Searcher {
match() {

Loading…
Cancel
Save