src/utils.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 3

Size

Lines of Code 36
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 24
mnd 4
bc 4
fnc 2
dl 0
loc 36
rs 10
bpm 2
cpm 3
noi 1
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A utils.js ➔ _axiosError 0 13 1
A utils.js ➔ resolveUrl 0 18 5
1
// import { URL } from 'url';
2
import { last } from 'myrmidon';
3
import createAxiosError from 'axios/lib/core/createError';
4
5
6
export function resolveUrl(base, relativeUrl) {
7
    const baseUrl = base ? new URL(base) : undefined;
0 ignored issues
show
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
8
    const absoluteUrl = new URL(relativeUrl, baseUrl);
9
10
    if (absoluteUrl.href === relativeUrl) {
11
        return new URL(absoluteUrl,  baseUrl);
12
    }
13
14
    const apiPrefix = last(baseUrl.pathname) === '/'
15
        ? baseUrl.pathname.slice(0, -1)
16
        : baseUrl.pathname;
17
18
    const relPath = apiPrefix
19
        ? apiPrefix + absoluteUrl.pathname
20
        : relativeUrl;
21
22
    return new URL(relPath,  baseUrl);
23
}
24
25
export function _axiosError(
26
    opts,
27
    { message, code },
28
    data
29
) {
30
    return createAxiosError(
31
        message,
32
        opts,
33
        code,
34
        {},
35
        { data }
36
    );
37
}
38