bin/utils/index.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 2.25

Size

Lines of Code 28
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 17
mnd 5
bc 5
fnc 4
dl 0
loc 28
rs 10
bpm 1.25
cpm 2.25
noi 1
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B index.js ➔ buildDocoptParams 0 16 6
1
function docoptKey(key) {
2
    const patterns = [ /--(.+)/, /<(.+)>/ ];
3
4
    for (const pattern of patterns) {
5
        const match = key.match(pattern);
6
7
        if (match && match.index === 0) {
8
            return match[1];
9
        }
10
    }
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...
11
}
12
13
export function buildDocoptParams(opts, { include, exclude } = {}) {
14
    const clean = {};
15
    const filtered = Object.keys(opts)
16
        .map(raw => ({ raw, key: docoptKey(raw) }))
17
        .filter(
18
            ({ key }) =>
19
                (include ? include.includes(key) : true)
20
                && (exclude ? !exclude.includes(key) : true)
21
        );
22
23
    for (const { raw, key } of filtered) {
24
        clean[key] = opts[raw];
25
    }
26
27
    return clean;
28
}
29