# array-to-sentence

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

Latest version **2.0.0** (published 2018-03-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install array-to-sentence
pnpm add array-to-sentence
yarn add array-to-sentence
bun add array-to-sentence
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2018-03-02 |
| First published | 2014-11-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/array-to-sentence) |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Maintainers | shinnn |
| Keywords | to-sentence, sentence, array, join, human, readable, string, separator, comma, and, browser, client-side |

## Links

- npm: https://www.npmjs.com/package/array-to-sentence
- Repository: https://github.com/shinnn/array-to-sentence
- Homepage: https://github.com/shinnn/array-to-sentence#readme
- Issues: https://github.com/shinnn/array-to-sentence/issues
- npm.io page: https://npm.io/package/array-to-sentence

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2018-03-02
- 2.0.0-2 — 2018-03-01
- 2.0.0-1 — 2018-02-27
- 2.0.0-0 — 2018-02-27
- 1.1.0 — 2016-06-15
- 1.0.4 — 2015-12-04
- 1.0.3 — 2015-10-24
- 1.0.2 — 2015-10-16
- 1.0.1 — 2014-11-18
- 1.0.0 — 2014-11-17

## README

# array-to-sentence

[![npm version](https://img.shields.io/npm/v/array-to-sentence.svg)](https://www.npmjs.com/package/array-to-sentence)
[![Build Status](https://travis-ci.org/shinnn/array-to-sentence.svg?branch=master)](https://travis-ci.org/shinnn/array-to-sentence)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/array-to-sentence.svg)](https://coveralls.io/github/shinnn/array-to-sentence)

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

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

## Installation

#### [npm](https://www.npmjs.com/)

```
npm install array-to-sentence
```

## API

```js
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`.

```javascript
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.

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

arrayToSentence(['Earth', 'Wind', 'Fire'], {
  lastSeparator: ' & '
}); //=> 'Earth, Wind & Fire'
```

## Acknowledgement

I used [`.toSentence()` method](https://epeli.github.io/underscore.string/#tosentence-array-delimiter-lastdelimiter-gt-string) of [underscore.string](https://github.com/epeli/underscore.string) as API design reference. Thanks, [Esa-Matti Suuronen](https://github.com/epeli) and [the contributors](https://github.com/epeli/underscore.string/graphs/contributors).

## License

[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe

---
_Source: https://npm.io/package/array-to-sentence · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
