Completed
Push — master ( 06507b...6aec3d )
by Felipe
01:55
created

src/helpers.js   A

Complexity

Total Complexity 13
Complexity/F 2.6

Size

Lines of Code 66
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
eloc 47
nc 1
dl 0
loc 66
rs 10
c 1
b 0
f 0
wmc 13
mnd 2
bc 12
fnc 5
bpm 2.4
cpm 2.6
noi 1

4 Functions

Rating   Name   Duplication   Size   Complexity  
A helpers.js ➔ compact 0 14 4
A helpers.js ➔ parseHalf 0 3 1
A helpers.js ➔ rgbaString 0 16 2
A helpers.js ➔ omit 0 13 4
1
export function hslaString(hslcolor) {
2
	if (hslcolor.a) {
3
		return (
4
			"hsla(" +
5
			hslcolor.h +
6
			"," +
7
			hslcolor.s +
8
			"%," +
9
			hslcolor.l +
10
			"%," +
11
			hslcolor.a +
12
			")"
13
		);
14
	}
15
	return "hsl(" + hslcolor.h + "," + hslcolor.s + "%," + hslcolor.l + "%)";
16
}
17
18
export function rgbaString(hexcolor) {
19
	if (hexcolor.a) {
20
		return (
21
			"rgba(" +
22
			hexcolor.r +
23
			"," +
24
			hexcolor.g +
25
			"," +
26
			hexcolor.b +
27
			"," +
28
			hexcolor.a +
29
			")"
30
		);
31
	}
32
	return "rgb(" + hexcolor.r + "," + hexcolor.g + "," + hexcolor.b + ")";
33
}
34
35
export function parseHalf(foo) {
36
	return parseInt(foo / 2, 10);
37
}
38
39
export function compact(array) {
40
	let index = -1,
41
		length = array ? array.length : 0,
42
		resIndex = 0,
43
		result = [];
44
45
	while (++index < length) {
46
		let value = array[index];
47
		if (value) {
48
			result[resIndex++] = value;
49
		}
50
	}
51
	return result;
52
}
53
54
export function omit(obj, fn) {
55
	var target = {};
56
	for (var i in obj) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
57
		if (fn(i)) {
58
			continue;
59
		}
60
		if (!Object.prototype.hasOwnProperty.call(obj, i)) {
61
			continue;
62
		}
63
		target[i] = obj[i];
64
	}
65
	return target;
66
}
67