-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.js
More file actions
38 lines (35 loc) · 943 Bytes
/
utils.js
File metadata and controls
38 lines (35 loc) · 943 Bytes
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
export function isUUID(uuid) {
let s = "" + uuid;
s = s.match(
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
);
if (s === null) {
return false;
}
return true;
}
export function compareArrayoOfObjectsByOrder(a, b) {
if (a.order < b.order) {
return -1;
} else {
return 1;
}
}
export function replaceNullWithEmptyStrings(param) {
if (param === null) {
// Note: null is also object, but explicitly comared before testing for object below
return "";
} else if (typeof param === "string") {
return param;
} else if (Array.isArray(param)) {
return param.map((element) => replaceNullWithEmptyStrings(element));
} else if (typeof param === "object") {
Object.entries(param).map(function ([key, val]) {
return (param[key] = replaceNullWithEmptyStrings(val));
});
return param;
} else {
// e.g. number, boolean
return param;
}
}