Separate normalizers out, fix config flag checks

This commit is contained in:
Will Boyd
2025-01-25 16:23:45 -05:00
parent 6a6e5074f0
commit 8841c607e7
4 changed files with 46 additions and 47 deletions
+32
View File
@@ -0,0 +1,32 @@
import fs from 'fs';
import path from 'path';
export function boolean(value) {
if (typeof value === 'boolean') {
return value;
} else if (value === 'true') {
return true;
} else if (value === 'false') {
return false;
}
throw 'Must be true or false.';
}
export function filePath(value) {
const unwrapped = value.replace(/"(.*?)"/, '$1');
const absolute = path.resolve(unwrapped);
let fileExists;
try {
fileExists = fs.existsSync(absolute) && fs.statSync(absolute).isFile();
} catch (ex) {
fileExists = false;
}
if (fileExists) {
return absolute;
} else {
throw 'File not found at ' + absolute + '.';
}
}