array-to-sentence
Join all elements of an array and create a human-readable string
; //=> 'foo, bar, baz and qux'
Installation
npm
npm install array-to-sentence
API
;
arrayToSentence(array [, options])
array: Array<any>
options: Object
Return: string
It joins all elements of an array, and returns a string in the form A, B, ... and X
.
; //=> 'one, two and 3'; //=> 'one and two'; //=> 'one' ; //=> ''
options.separator
Type: string
Default: ', '
Set the separator string of each word.
options.lastSeparator
Type: string
Default: ' and '
Set the separator string before the last word.
; //=> 'A-B-C' ; //=> 'Earth, Wind & Fire'
Acknowledgement
I used .toSentence()
method of underscore.string as API design reference. Thanks, Esa-Matti Suuronen and the contributors.
License
ISC License © 2018 Shinnosuke Watanabe