13 lines
411 B
JavaScript
13 lines
411 B
JavaScript
![]() |
var rtrim = require('./rtrim');
|
||
|
|
||
|
module.exports = function toSentence(array, separator, lastSeparator, serial) {
|
||
|
separator = separator || ', ';
|
||
|
lastSeparator = lastSeparator || ' and ';
|
||
|
var a = array.slice(),
|
||
|
lastMember = a.pop();
|
||
|
|
||
|
if (array.length > 2 && serial) lastSeparator = rtrim(separator) + lastSeparator;
|
||
|
|
||
|
return a.length ? a.join(separator) + lastSeparator + lastMember : lastMember;
|
||
|
};
|