tools/fixturesCleanup.js   A
last analyzed

Complexity

Total Complexity 13
Complexity/F 1.18

Size

Lines of Code 52
Function Count 11

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 36
mnd 2
bc 2
fnc 11
dl 0
loc 52
rs 10
bpm 0.1818
cpm 1.1818
noi 2
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
B fixturesCleanup.js ➔ dropColumns 0 18 6
B fixturesCleanup.js ➔ dust 0 30 7
1
import * as csv from 'fast-csv';
2
3
export async function dust(input, output, threshold) {
4
    const result = { total: 0 };
5
    const merged = {};
6
7
    return new Promise((res, rej) => {
8
        input
9
            .pipe(csv.parse({
10
                headers   : false,
11
                delimiter : ','
12
            }))
13
            .pipe(csv.format({ headers: false }))
14
            .on('error', error => rej(error))
15
            .transform((row, next) => {
16
                const [ word, weight ] = row;
17
                const sanitized = word.trim().toLowerCase();
18
19
                if (!sanitized) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
                result.total++;
21
                const num = weight && Number.parseFloat(weight);
22
                const isGood = num && (num > threshold);
23
24
                if (!isGood) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
25
                merged[sanitized] = num;
26
27
                next(null, row);
28
            })
29
            .pipe(output)
30
            .on('end', (rowCount) => res({ total: rowCount }));
31
    });
32
}
33
34
35
export async function dropColumns(input, output, columns) {
36
    return new Promise((res, rej) => {
37
        input
38
            .pipe(csv.parse({
39
                headers   : false,
40
                delimiter : ','
41
            }))
42
            .pipe(csv.format({ headers: false }))
43
            .on('error', error => rej(error))
44
            .transform((row, next) => {
45
                const cols = row.filter((e, index) => columns.includes(index));
46
47
                next(null, cols);
48
            })
49
            .pipe(output)
50
            .on('end', (rowCount) => res({ total: rowCount }));
51
    });
52
}
53