diff --git a/index.js b/index.js index 37110c5..c8f2810 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,10 @@ import alfy from 'alfy'; import {filterOutput, findFilter, isFileAction} from './src/utils.js'; const {inputWithoutFilter, foundFilter: filter} = findFilter(alfy.input); -const input = inputWithoutFilter.replaceAll('\t', '\n').split('\n'); +const input = inputWithoutFilter + .replaceAll("\t", "\n") + .split("\n") + .map((element) => element.trim()); const options = [ { @@ -77,7 +80,7 @@ function run(input) { } return options.map(options => { - const files = input.map(filepath => options.action(filepath.trim())).filter(element => Boolean(element)); + const files = input.map(filepath => options.action(filepath)).filter(element => Boolean(element)); return { title: `${options.prefix}: ${files}`, subtitle: 'Copy to clipboard', diff --git a/src/utils.js b/src/utils.js index bc49471..7c964cc 100644 --- a/src/utils.js +++ b/src/utils.js @@ -22,19 +22,12 @@ export function filterOutput(filter, output) { } export function isFileAction(input) { - input = Array.isArray(input) ? input : [input]; - const filePaths = input.map(filepath => { - if (filepath.slice(0, 1) !== '/') { - return false; - } - - const stat = fs.lstatSync(filepath.trim()); - if (stat.isFile() || stat.isDirectory()) { - return true; - } - - return false; - }) - .filter(element => Boolean(element)); + const filePaths = input + .filter((element) => Boolean(element.trim())) + .filter(filepath => { + if (filepath.slice(0, 1) !== '/') return false; + const stat = fs.lstatSync(filepath.trim()); + return (stat.isFile() || stat.isDirectory()) + }) return filePaths.length > 0; }