Socket
Socket
Sign inDemoInstall

array-to-sentence

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

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
167K
decreased by-6.87%
Maintainers
1
Install size
6.36 kB
Created
Weekly downloads
 

Readme

Source

array-to-sentence

npm version Build Status Coverage Status

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

arrayToSentence(['foo', 'bar', 'baz', 'qux']); //=> 'foo, bar, baz and qux'

Installation

npm
npm install array-to-sentence

API

import arrayToSentence from 'array-to-sentence';

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.

arrayToSentence(['one', 'two', 3]); //=> 'one, two and 3'
arrayToSentence(['one', 'two']); //=> 'one and two'
arrayToSentence(['one']); //=> 'one'

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

I used .toSentence() method of underscore.string as API design reference. Thanks, Esa-Matti Suuronen and the contributors.

License

ISC License © 2018 Shinnosuke Watanabe

Keywords

FAQs

Last updated on 02 Mar 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc