Passed
Push — master ( a3cf99...dec494 )
by Dmytro
02:02
created

utils.js ➔ resolve   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
1
import { URL } from 'url';
2
import path from 'path';
3
import jsonQuery from 'json-query';
4
import factory from './Test';
5
import { entry } from './constants';
6
7
8
export function extractUrls(text) {
9
    const pattern = /(?:(?:https?|ftp):\/\/|\b(?:[a-z\d]+\.))(?:(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))?\))+(?:\((?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))?\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))?/; // eslint-disable-line
10
11
    return text.match(new RegExp(pattern, 'ig')).map(u => new URL(u));
12
}
13
14
export async function findTrackLog(query) {
15
    const tracks = await factory.getTracks();
16
    const res = jsonQuery(query, {
17
        data         : tracks,
18
        enableRegexp : true
19
    });
20
21
    return res.value;
22
}
23
24
export function load(relPath, clearCache) {
25
    const absPath = path.resolve(entry, relPath);
26
27
    if (clearCache) delete require.cache[require.resolve(absPath)];
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...
28
    // eslint-disable-next-line security/detect-non-literal-require
29
    const result =  require(absPath);
30
31
    if (clearCache) delete require.cache[require.resolve(absPath)];
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...
32
33
    return result;
34
}
35
36
export function resolve(relPath) {
37
    return require.resolve(path.join(entry, relPath));
38
}
39