-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguard.js
More file actions
35 lines (29 loc) · 849 Bytes
/
Copy pathguard.js
File metadata and controls
35 lines (29 loc) · 849 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
const check = require('check-types');
/**
* Various guards.
*/
class Guard {
static assertNonEmptyStringParameter(name, value) {
if (!check.nonEmptyString(value)) {
throw new Error('Parameter "' + name + '" has to be an non-empty string.');
}
}
static assertValidMetadata(metadata) {
if (!check.nonEmptyObject(metadata)) {
throw new Error('Metadata on an node has to be an object.');
}
}
static assertValidMetadataOrNull(metadataOrNull) {
if (check.assigned(metadataOrNull)) {
Guard.assertValidMetadata(metadataOrNull);
}
}
static assertValidDirected(directed) {
if (!check.boolean(directed)) {
throw new Error('Directed flag on an edge has to be boolean.');
}
}
}
module.exports = {
Guard,
};