-
Notifications
You must be signed in to change notification settings - Fork 4
/
validate.js
39 lines (33 loc) · 920 Bytes
/
validate.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
'use strict';
var fs = require('fs');
var path = require('path');
//
// Helpers for validation.
//
module.exports = {
config: function (config, name) {
var value = config.get(name);
if (!value) {
throw new Error('Configuration option not set: ' + name);
}
return value;
},
directoryExists: function (path) {
if (!fs.existsSync(path)) {
throw new Error('Path not found: ' + path);
}
var stat = fs.lstatSync(path);
if (!stat.isDirectory()) {
throw new Error('Path is not a directory: ' + path);
}
},
fileExists: function (path) {
if (!fs.existsSync(path)) {
throw new Error('Path not found: ' + path);
}
var stat = fs.lstatSync(path);
if (stat.isDirectory()) {
throw new Error('Path is a directory: ' + path);
}
},
};