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 // Match functions
// //
@ -158,62 +145,47 @@ function scoreFuzzyMatch() {
// Searchers // Searchers
// //
(function () { app.Searcher = class Searcher extends Events {
let CHUNK_SIZE = undefined; static CHUNK_SIZE = 20000;
let DEFAULTS = undefined;
let SEPARATORS_REGEXP = undefined; static DEFAULTS = {
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;
DEFAULTS = {
max_results: app.config.max_results, max_results: app.config.max_results,
fuzzy_min_length: 3, fuzzy_min_length: 3,
}; };
SEPARATORS_REGEXP = static SEPARATORS_REGEXP =
/#|::|:-|->|\$(?=\w)|\-(?=\w)|\:(?=\w)|\ [\/\-&]\ |:\ |\ /g; /#|::|:-|->|\$(?=\w)|\-(?=\w)|\:(?=\w)|\ [\/\-&]\ |:\ |\ /g;
EOS_SEPARATORS_REGEXP = /(\w)[\-:]$/; static EOS_SEPARATORS_REGEXP = /(\w)[\-:]$/;
INFO_PARANTHESES_REGEXP = /\ \(\w+?\)$/; static INFO_PARANTHESES_REGEXP = /\ \(\w+?\)$/;
EMPTY_PARANTHESES_REGEXP = /\(\)/; static EMPTY_PARANTHESES_REGEXP = /\(\)/;
EVENT_REGEXP = /\ event$/; static EVENT_REGEXP = /\ event$/;
DOT_REGEXP = /\.+/g; static DOT_REGEXP = /\.+/g;
WHITESPACE_REGEXP = /\s/g; static WHITESPACE_REGEXP = /\s/g;
EMPTY_STRING = ""; static EMPTY_STRING = "";
ELLIPSIS = "..."; static ELLIPSIS = "...";
STRING = "string"; static STRING = "string";
}
static normalizeString(string) { static normalizeString(string) {
return string return string
.toLowerCase() .toLowerCase()
.replace(ELLIPSIS, EMPTY_STRING) .replace(Searcher.ELLIPSIS, Searcher.EMPTY_STRING)
.replace(EVENT_REGEXP, EMPTY_STRING) .replace(Searcher.EVENT_REGEXP, Searcher.EMPTY_STRING)
.replace(INFO_PARANTHESES_REGEXP, EMPTY_STRING) .replace(Searcher.INFO_PARANTHESES_REGEXP, Searcher.EMPTY_STRING)
.replace(SEPARATORS_REGEXP, SEPARATOR) .replace(Searcher.SEPARATORS_REGEXP, SEPARATOR)
.replace(DOT_REGEXP, SEPARATOR) .replace(Searcher.DOT_REGEXP, SEPARATOR)
.replace(EMPTY_PARANTHESES_REGEXP, EMPTY_STRING) .replace(Searcher.EMPTY_PARANTHESES_REGEXP, Searcher.EMPTY_STRING)
.replace(WHITESPACE_REGEXP, EMPTY_STRING); .replace(Searcher.WHITESPACE_REGEXP, Searcher.EMPTY_STRING);
} }
static normalizeQuery(string) { static normalizeQuery(string) {
string = this.normalizeString(string); string = this.normalizeString(string);
return string.replace(EOS_SEPARATORS_REGEXP, "$1."); return string.replace(Searcher.EOS_SEPARATORS_REGEXP, "$1.");
} }
constructor(options) { constructor(options) {
super(); super();
this.options = $.extend({}, DEFAULTS, options || {}); this.options = $.extend({}, Searcher.DEFAULTS, options || {});
} }
find(data, attr, q) { find(data, attr, q) {
@ -269,17 +241,16 @@ function scoreFuzzyMatch() {
} }
free() { free() {
this.data = this.data = null;
this.attr = this.attr = null;
this.dataLength = this.dataLength = null;
this.matchers = this.matchers = null;
this.matcher = this.matcher = null;
this.query = this.query = null;
this.totalResults = this.totalResults = null;
this.scoreMap = this.scoreMap = null;
this.cursor = this.cursor = null;
this.timeout = this.timeout = null;
null;
} }
match() { match() {
@ -309,11 +280,7 @@ function scoreFuzzyMatch() {
matchChunk() { matchChunk() {
({ matcher } = this); ({ matcher } = this);
for ( for (let j = 0, end = this.chunkSize(); j < end; j++) {
let j = 0, end = this.chunkSize(), asc = 0 <= end;
asc ? j < end : j > end;
asc ? j++ : j--
) {
value = this.data[this.cursor][this.attr]; value = this.data[this.cursor][this.attr];
if (value.split) { if (value.split) {
// string // string
@ -337,10 +304,10 @@ function scoreFuzzyMatch() {
} }
chunkSize() { chunkSize() {
if (this.cursor + CHUNK_SIZE > this.dataLength) { if (this.cursor + Searcher.CHUNK_SIZE > this.dataLength) {
return this.dataLength % CHUNK_SIZE; return this.dataLength % Searcher.CHUNK_SIZE;
} else { } else {
return CHUNK_SIZE; return Searcher.CHUNK_SIZE;
} }
} }
@ -397,10 +364,7 @@ function scoreFuzzyMatch() {
} }
return new RegExp(chars.join(".*?")); // abc -> /a.*?b.*?c.*?/ return new RegExp(chars.join(".*?")); // abc -> /a.*?b.*?c.*?/
} }
}; };
app.Searcher.initClass();
return app.Searcher;
})();
app.SynchronousSearcher = class SynchronousSearcher extends app.Searcher { app.SynchronousSearcher = class SynchronousSearcher extends app.Searcher {
match() { match() {

Loading…
Cancel
Save