-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve error message for multiple accepted extensions
- Loading branch information
1 parent
d2dc8a8
commit c54bea0
Showing
2 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Converts an array of strings to a list, ending with "or" | ||
* | ||
* @example | ||
* // returns the string "a, b or c" | ||
* orList(["a", "b", "c"]); | ||
* @param items array of strings to join | ||
* @returns human readable comma + or separated list | ||
*/ | ||
export function orList(items: string[]): string { | ||
if (items.length === 0) { | ||
return ""; | ||
} else if (items.length === 1) { | ||
return items[0] as string; | ||
} | ||
|
||
return items | ||
.reverse() | ||
.flatMap((item, index) => { | ||
if (index === 0) { | ||
return [item, " or "]; | ||
} else if (index !== 1) { | ||
return [", ", item]; | ||
} else { | ||
return [item]; | ||
} | ||
}) | ||
.reverse() | ||
.join(""); | ||
} |