Passed
Push — master ( 110e67...95fe0f )
by Sara
02:23
created

utils/index.js   A

Complexity

Total Complexity 8
Complexity/F 1.6

Size

Lines of Code 60
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 8
mnd 3
bc 3
fnc 5
bpm 0.6
cpm 1.6
noi 2

5 Functions

Rating   Name   Duplication   Size   Complexity  
A index.js ➔ prepareFrame 0 15 1
A index.js ➔ isJson 0 7 2
A index.js ➔ checkEmptyHtml 0 9 3
A index.js ➔ resetFrame 0 3 1
A index.js ➔ isEmpty 0 11 1
1
2
3
'use strict';
4
5
function isEmpty(x) {
6
    return (
7
        typeof x === 'undefined' ||
8
        x === null ||
9
        x === 'null' ||
10
        x === 'undefined' ||
11
        x === false ||
12
        x.length === 0 ||
13
        x === ''
14
    );
15
}
16
17
function isJson(str) {
18
    try {
19
      str=JSON.parse(str);
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...
20
    } catch (e) {
21
        return str;
22
    }
23
}
24
25
function checkEmptyHtml(id, checkChildNode = false) {
26
    const elem = document.querySelector(`${id}`);
27
    if (elem === null || elem === undefined) {
28
        return true;
29
    } else if (elem && elem.childNodes.length > 0 && checkChildNode) {
30
        return true;
31
    }
32
    return false;
33
}
34
35
function prepareFrame(id = "bSecurePaymentPluginContainer", checkout_url) {
36
    const ifrm = document.createElement("iframe");
37
    let url = new URL(checkout_url);
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...
38
39
    ifrm.setAttribute("src", url.href);
40
    ifrm.setAttribute("id", 'bSecurePaymentPluginEmbeddedIframe');
41
    ifrm.setAttribute("name", 'bSecurePaymentPluginEmbeddedIframe');
42
    ifrm.style.position = "absolute";
43
    ifrm.style.border = "none";
44
    ifrm.style.top = "0";
45
    ifrm.style.left = "0";
46
    ifrm.style.width = "100%";
47
    ifrm.style.height = "100%";
48
    document.getElementById(id).appendChild(ifrm);
49
}
50
51
52
function resetFrame(id = "bSecurePaymentPluginContainer") {
53
    document.getElementById(id).remove();
54
}
55
56
module.exports = {
57
    isEmpty: isEmpty,
58
    isJson: isJson,
59
    checkEmptyHtml: checkEmptyHtml,
60
    prepareFrame: prepareFrame,
61
    resetFrame: resetFrame,
62
};