mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-15 20:53:46 +09:00
Separate normalizers out, fix config flag checks
This commit is contained in:
@@ -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 + '.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user