Skip to content

Commit babf6b4

Browse files
committed
Input standardization
1 parent 6dcfd8f commit babf6b4

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import alfy from 'alfy';
44
import {filterOutput, findFilter, isFileAction} from './src/utils.js';
55

66
const {inputWithoutFilter, foundFilter: filter} = findFilter(alfy.input);
7-
const input = inputWithoutFilter.replaceAll('\t', '\n').split('\n');
7+
const input = inputWithoutFilter
8+
.replaceAll("\t", "\n")
9+
.split("\n")
10+
.map((element) => element.trim());
811

912
const options = [
1013
{
@@ -77,7 +80,7 @@ function run(input) {
7780
}
7881

7982
return options.map(options => {
80-
const files = input.map(filepath => options.action(filepath.trim())).filter(element => Boolean(element));
83+
const files = input.map(filepath => options.action(filepath)).filter(element => Boolean(element));
8184
return {
8285
title: `${options.prefix}: ${files}`,
8386
subtitle: 'Copy to clipboard',

src/utils.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,12 @@ export function filterOutput(filter, output) {
2222
}
2323

2424
export function isFileAction(input) {
25-
input = Array.isArray(input) ? input : [input];
26-
const filePaths = input.map(filepath => {
27-
if (filepath.slice(0, 1) !== '/') {
28-
return false;
29-
}
30-
31-
const stat = fs.lstatSync(filepath.trim());
32-
if (stat.isFile() || stat.isDirectory()) {
33-
return true;
34-
}
35-
36-
return false;
37-
})
38-
.filter(element => Boolean(element));
25+
const filePaths = input
26+
.filter((element) => Boolean(element.trim()))
27+
.filter(filepath => {
28+
if (filepath.slice(0, 1) !== '/') return false;
29+
const stat = fs.lstatSync(filepath.trim());
30+
return (stat.isFile() || stat.isDirectory())
31+
})
3932
return filePaths.length > 0;
4033
}

0 commit comments

Comments
 (0)