mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-15 12:43:38 +09:00
First list and integer questions, spaces to tabs
This commit is contained in:
+38
-21
@@ -2,31 +2,48 @@ 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;
|
||||
}
|
||||
if (typeof value === 'boolean') {
|
||||
return value;
|
||||
} else if (value === 'true') {
|
||||
return true;
|
||||
} else if (value === 'false') {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new Error('Must be true or false.');
|
||||
throw new Error('Must be true or false.');
|
||||
}
|
||||
|
||||
export function filePath(value) {
|
||||
const unwrapped = value.replace(/"(.*?)"/, '$1');
|
||||
const absolute = path.resolve(unwrapped);
|
||||
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;
|
||||
}
|
||||
let fileExists;
|
||||
try {
|
||||
fileExists = fs.existsSync(absolute) && fs.statSync(absolute).isFile();
|
||||
} catch (ex) {
|
||||
fileExists = false;
|
||||
}
|
||||
|
||||
if (fileExists) {
|
||||
return absolute;
|
||||
} else {
|
||||
throw new Error('File not found at ' + absolute + '.');
|
||||
}
|
||||
if (fileExists) {
|
||||
return absolute;
|
||||
}
|
||||
|
||||
throw new Error('File not found at ' + absolute + '.');
|
||||
}
|
||||
|
||||
export function list(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return value;
|
||||
} else {
|
||||
return value.trim().split(/\s*,\s*/);
|
||||
}
|
||||
}
|
||||
|
||||
export function integer(value) {
|
||||
const int = parseInt(value);
|
||||
if (!Number.isNaN(int) && int >= 0) {
|
||||
return int;
|
||||
}
|
||||
|
||||
throw new Error('Must be an integer >= 0.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user