mirror of
https://github.com/flarum/framework.git
synced 2024-12-04 08:13:39 +08:00
Add helper function for punctuating a list
e.g. [1,2,3] ⇒ [1, ‘, ‘, 2, ‘, and’, 3]
This commit is contained in:
parent
a8ad5a1ac8
commit
8156f23968
13
framework/core/js/lib/helpers/punctuate.js
Normal file
13
framework/core/js/lib/helpers/punctuate.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
export default function punctuate(items) {
|
||||
var newItems = [];
|
||||
|
||||
items.forEach((item, i) => {
|
||||
newItems.push(item);
|
||||
|
||||
if (i <= items.length - 2) {
|
||||
newItems.push((items.length > 2 ? ', ' : '')+(i === items.length - 2 ? ' and ' : ''));
|
||||
}
|
||||
});
|
||||
|
||||
return newItems;
|
||||
};
|
Loading…
Reference in New Issue
Block a user