Socket
Socket
Sign inDemoInstall

array-to-sentence

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-to-sentence

Join all elements of an array and create a human-readable string


Version published
Weekly downloads
113K
decreased by-3.19%
Maintainers
1
Weekly downloads
 
Created
Source

array-to-sentence

NPM version Bower version Build Status Coverage Status devDependency Status

Join all elements of an array and create a human-readable string

arrayToSentence(['foo', 'bar', 'baz', 'qux']); //=> '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.

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([]); //=> ''

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.

arrayToSentence(['A', 'B', 'C'], {
  separator: '-',
  lastSeparator: '-'
}); //=> 'A-B-C'

arrayToSentence(['Earth', 'Wind', 'Fire'], {
  lastSeparator: ' & '
}); //=> '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.

Keywords

FAQs

Package last updated on 15 Jun 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc