-
Notifications
You must be signed in to change notification settings - Fork 140
/
Copy pathutils.js
67 lines (54 loc) · 1.14 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @author emmanuelolaojo
* @since 11/11/18
*/
/**
* Validates the configuration object.
*
* @param config - configuration object
*/
const checkParams = config => {
const DEFAULT_GUTTER = 25;
const booleanProps = ["useTransform", "center"];
if (!config) {
throw new Error("No config object has been provided.");
}
for(let prop of booleanProps){
if(typeof config[prop] !== "boolean"){
config[prop] = true;
}
}
if(typeof config.gutter !== "number"){
config.gutter = DEFAULT_GUTTER;
}
if (!config.container) error("container");
if (!config.items && !config.static) error("items or static");
};
/**
* Handles invalid configuration object
* errors.
*
* @param prop - a property with a missing value
*/
const error = prop => {
throw new Error(`Missing property '${prop}' in MagicGrid config`);
};
/**
* Finds the shortest column in
* a column list.
*
* @param cols - list of columns
*
* @return shortest column
*/
const getMin = cols => {
let min = cols[0];
for (let col of cols) {
if (col.height < min.height) min = col;
}
return min;
};
module.exports = {
checkParams,
getMin
};