mirror of
https://github.com/flarum/framework.git
synced 2025-05-21 14:22:33 +08:00
Massive JavaScript cleanup
- Use JSX for templates - Docblock/comment everything - Mostly passes ESLint (still some work to do) - Lots of renaming, refactoring, etc. CSS hasn't been updated yet.
This commit is contained in:
@ -1,13 +1,28 @@
|
||||
/**
|
||||
* The `punctuate` helper formats a list of strings (e.g. names) to read
|
||||
* fluently in the application's locale.
|
||||
*
|
||||
* @example
|
||||
* punctuate(['Toby', 'Franz', 'Dominion'])
|
||||
* // Toby, Franz, and Dominion
|
||||
*
|
||||
* @param {Array} items
|
||||
* @return {Array}
|
||||
*/
|
||||
export default function punctuate(items) {
|
||||
var newItems = [];
|
||||
const punctuated = [];
|
||||
|
||||
// FIXME: update to use translation
|
||||
items.forEach((item, i) => {
|
||||
newItems.push(item);
|
||||
punctuated.push(item);
|
||||
|
||||
if (i <= items.length - 2) {
|
||||
newItems.push((items.length > 2 ? ', ' : '')+(i === items.length - 2 ? ' and ' : ''));
|
||||
// If this item is not the last one, then we will follow it with some
|
||||
// punctuation. If the list is more than 2 items long, we'll add a comma.
|
||||
// And if this is the second-to-last item, we'll add 'and'.
|
||||
if (i < items.length - 1) {
|
||||
punctuated.push((items.length > 2 ? ', ' : '') + (i === items.length - 2 ? ' and ' : ''));
|
||||
}
|
||||
});
|
||||
|
||||
return newItems;
|
||||
return punctuated;
|
||||
};
|
||||
|
Reference in New Issue
Block a user