word-join
Version:
Tiny module to join arrays with commas, "and", and Oxford comma support
1 lines • 304 B
JavaScript
function e(e=[],t={}){let n=e.length;if(n===0)return``;if(n===1)return`${e[0]}`;let r=t.conjunction||`and`;if(n===2)return`${e[0]} ${r} ${e[1]}`;let i=n-1,a=t.separator||`,`,o=e[0];for(let t=1;t<i;t++)o+=`${a} ${e[t]}`;let s=` ${r} ${e[i]}`;return t.oxford?`${o}${a}${s}`:`${o}${s}`}export{e as default};