Total Complexity | 13 |
Complexity/F | 2.6 |
Lines of Code | 66 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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) { |
||
|
|||
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 |
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: