mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 16:23:16 +08:00
Add helper function for punctuating a list
e.g. [1,2,3] ⇒ [1, ‘, ‘, 2, ‘, and’, 3]
This commit is contained in:
parent
28aa7ed62f
commit
bb04d91b08
13
js/lib/helpers/punctuate.js
Normal file
13
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