Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
array-to-sentence
Advanced tools
Join all elements of an array and create a human-readable string
arrayToSentence(['foo', 'bar', 'baz', 'qux']); //=> 'foo, bar, baz and qux'
npm install array-to-sentence
bower install array-to-sentence
Download the script file directly.
array: Array
of any values
options: Object
Return: Array
It joins all elements of an array, and returns a string in the form A, B, ... and X
.
Note that it doesn't support serial comma.
arrayToSentence(['one', 'two', 3]); //=> 'one, two and 3'
arrayToSentence(['one', 'two']); //=> 'one and two'
arrayToSentence(['one']); //=> 'one'
It returns an empty string if the array is empty.
arrayToSentence([]); //=> ''
Type: String
Default: ', '
Set the separator string of each word.
Type: String
Default: ' and '
Set the separator string before the last word.
arrayToSentence(['A', 'B', 'C'], {
separator: '-',
lastSeparator: '-'
}); //=> 'A-B-C'
arrayToSentence(['Earth', 'Wind', 'Fire'], {
lastSeparator: ' & '
}); //=> 'Earth, Wind & Fire'
For designing API, I used .toSentence()
method of underscore.string as reference. Thanks, Esa-Matti Suuronen and the contributors.
Copyright (c) 2014 - 2015 Shinnosuke Watanabe
Licensed under the MIT License.
FAQs
Join all elements of an array and create a human-readable string
The npm package array-to-sentence receives a total of 96,821 weekly downloads. As such, array-to-sentence popularity was classified as popular.
We found that array-to-sentence demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.