ci(lint): assert description, error on missing userstyle (#469)
This commit is contained in:
1 parent
7b459ceaf9
commit
3c9cd75ed0
2 files changed
+37
-2
No files matched your search
@@ -44,4 +44,27 @@ export const getUserstylesData = (): Promise<Userstyles> => {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility function that formats a list of items into the "x, y, ..., and z" format.
|
||||
* @example
|
||||
* formatListOfItems(['x']); // 'x'
|
||||
* @example
|
||||
* formatListOfItems(['x', 'y']); // 'x and y'
|
||||
* @example
|
||||
* formatListOfItems(['x', 'y', 'z']); // 'x, y, and z'
|
||||
*/
|
||||
export const formatListOfItems = (items: unknown[]): string => {
|
||||
// If there are two items, connect them with an "and".
|
||||
if (items.length === 2) return items.join(" and ");
|
||||
// Otherwise, there is either just one item or more than two items.
|
||||
return items.reduce((prev, curr, idx, arr) => {
|
||||
// If this is the first item of the items we are looping through, set our initial string to it.
|
||||
if (idx === 0) return curr;
|
||||
// If this is the last one, add a comma (Oxford commas are amazing) followed by "and" and the item to the string.
|
||||
if (curr === arr.at(-1)) return prev + `, and ${curr}`;
|
||||
// Otherwise, it is some item in the middle of the list and we can just add it as a comma followed by the item to the string.
|
||||
return prev + `, ${curr}`;
|
||||
}) as string;
|
||||
};
|
||||
|
||||
type Userstyles = SetRequired<UserstylesSchema, "userstyles" | "collaborators">;
|
||||
Reference in new issue
Block a user