response.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 30
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ➔ Response 0 16 3
A ➔ isJson 0 8 2
1
function trim(str) {
2
    return str.replace(/^\s+|\s+$/g, '');
3
}
4
5
6
function isJson(str) {
7
    try {
8
        JSON.parse(str);
9
    } catch (e) {
10
        return false;
11
    }
12
    return true;
13
}
14
15
function Response(xhr, error, success) {
16
    if (!isJson(xhr.responseText)) {
17
        console.error('Response give not JSON Data');
18
        // alert('Response give not JSON Data');
19
        console.log(xhr.responseText);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
20
        return false;
21
    }
22
    var data = JSON.parse(xhr.responseText);
23
    if (xhr.readyState == 4 && xhr.status == "200") {
24
        // console.table(data);
25
        success(data, xhr);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
26
    } else {
27
        // console.error(data);
28
        error(data, xhr);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
29
    }
30
};
31