Skip to content

Commit 610fabd

Browse files
committed
Extract constants out of for-loops
1 parent bb44d78 commit 610fabd

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

website/src/queries-logic.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
const { Octokit } = require("@octokit/rest");
22
const { throttling } = require("@octokit/plugin-throttling");
33

4+
5+
/* Filtering constants. */
6+
const attributeRgx = '([a-z]+)';
7+
const operatorRgx = '(<=|>=|[<=>])';
8+
const valueRgx = '([0-9]{4}-[0-9]{2}-[0-9]{2}|[0-9]+)';
9+
const regex = new RegExp(attributeRgx + operatorRgx + valueRgx);
10+
const mapTable = {
11+
'ahead': 'ahead_by',
12+
'behind': 'behind_by',
13+
'pushed': 'pushed_at',
14+
'date': 'pushed_at',
15+
'd': 'pushed_at',
16+
'a': 'ahead_by',
17+
'b': 'behind_by',
18+
'p': 'pushed_at',
19+
's': 'stars',
20+
'f': 'forks',
21+
};
22+
423
/* Variables that should be cleared for every new query (defaults are set in "clear_old_data"). */
524
let TABLE_DATA = [];
625
let REPO_DATE;
@@ -310,28 +329,10 @@ function updateFilterFunction() {
310329
return;
311330
}
312331

313-
const mapTable = {
314-
'ahead': 'ahead_by',
315-
'behind': 'behind_by',
316-
'pushed': 'pushed_at',
317-
'date': 'pushed_at',
318-
'd': 'pushed_at',
319-
'a': 'ahead_by',
320-
'b': 'behind_by',
321-
'p': 'pushed_at',
322-
's': 'stars',
323-
'f': 'forks',
324-
};
325-
326332
// parse filter string into condition object
327333
const conditionStrList = filter.split(' ');
328334
let conditionObj = {};
329335
for (const condition of conditionStrList) {
330-
const attributeRgx = '([a-z]+)';
331-
const operatorRgx = '(<=|>=|[<=>])';
332-
const valueRgx = '([0-9]{4}-[0-9]{2}-[0-9]{2}|[0-9]+)';
333-
const regex = new RegExp(attributeRgx + operatorRgx + valueRgx);
334-
335336
const matchResult = condition.match(regex);
336337
let [attribute, operator, value] = matchResult ? matchResult.slice(1) : [];
337338
if (!attribute || !operator || !value) {

0 commit comments

Comments
 (0)