Completed
Push — master ( dc50e4...8acfd5 )
by
unknown
51s
created

src/utils.js   A

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 19
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 0
wmc 4
c 1
b 0
f 1
nc 1
mnd 1
bc 3
fnc 3
dl 0
loc 19
rs 10
bpm 1
cpm 1.3333
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A utils.js ➔ formatURL 0 6 1
A utils.js ➔ getFullPath 0 4 1
A utils.js ➔ getAPIPrefix 0 4 2
1
import { uri } from 'unity-utils';
2
import { format } from 'url';
3
4
export function getAPIPrefix(APINamespace) {
5
    const reAbsolute = /^(\/|https?:\/\/)/ig;
6
    return reAbsolute.test(APINamespace) ? APINamespace : '/' + APINamespace;
7
}
8
9
export function getFullPath(APINamespace, namespace, path=[]) {
10
    path = [].concat(path);
11
    return uri.join(getAPIPrefix(APINamespace), namespace, ...path).replace(':/', '://');
12
}
13
14
export function formatURL(APINamespace = '', namespace = '', path=[], query={}) {
15
    return format({
16
        pathname: getFullPath(APINamespace, namespace, path),
17
        query: uri.query(query)
18
    });
19
}