-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathutils.js
63 lines (49 loc) · 1.44 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
export function normalize(attr) {
if (attr === null || typeof attr !== 'object' || Object.prototype.toString.call(attr) === '[object Array]') {
return attr;
}
let mutable = {};
Object.keys(attr).forEach(key => {
_setOnPath(mutable, key.split('.'), normalize(attr[key]));
});
return mutable;
}
function _setOnPath(obj, path, value) {
if (!path) {
return obj;
}
var currentPath = path[0];
if (path.length === 1) {
var oldVal = obj[currentPath];
if (oldVal === undefined) {
obj[currentPath] = value;
}
return oldVal;
}
if (obj[currentPath] === undefined) {
obj[currentPath] = {};
}
return _setOnPath(obj[currentPath], path.slice(1), value);
}
export function repeatableOptionCallback(val, result) {
result.push(val);
return result;
}
export function parseVersion(version) {
if (!version.includes("enterprise-edition")) {
// remove any postfix, i.e., 0.11.0-rc1 should be 0.11.0
return version.split("-")[0];
}
// Kong EE versioning is X.Y(-Z)-enterprise-edition
var vAry = version.split("-")
if (vAry.length == 4) {
version = vAry[0] + "." + vAry[1]
} else {
version = vAry[0];
}
// add .0 so that kong EE has a patch version, i.e, 0.29 should be 0.29.0
if (version.split(".").length == 2) {
version = version + ".0"
}
return version
}