array-to-sentence
Join all elements of an array and create a human-readable string
; //=> 'foo, bar, baz and qux'
Installation
Package managers
npm
npm install array-to-sentence
bower
bower install array-to-sentence
Standalone
Download the script file directly.
API
arrayToSentence(array [, options])
array: Array
of any values
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'
It returns an empty string if the array is empty.
; //=> ''
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
For designing API, I used .toSentence()
method of underscore.string as reference. Thanks, Esa-Matti Suuronen and the contributors.
License
Copyright (c) 2014 - 2015 Shinnosuke Watanabe
Licensed under the MIT License.