From babf6b4774c8b8d39c47befd7892c1069d02091f Mon Sep 17 00:00:00 2001
From: Chris Spiegl <chris@chrisspiegl.com>
Date: Fri, 31 Dec 2021 10:23:40 +0100
Subject: [PATCH] Input standardization

---
 index.js     |  7 +++++--
 src/utils.js | 21 +++++++--------------
 2 files changed, 12 insertions(+), 16 deletions(-)

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;
 }