array-to-sentence
Join all elements of an array and create a human-readable string
Last updated 7 years ago by shinnn .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install array-to-sentence 
SYNC missed versions from official npm registry.

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

Current Tags

  • 2.0.0                                ...           latest (7 years ago)

10 Versions

  • 2.0.0                                ...           7 years ago
  • 2.0.0-2                                ...           7 years ago
  • 2.0.0-1                                ...           7 years ago
  • 2.0.0-0                                ...           7 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.4                                ...           9 years ago
  • 1.0.3                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (6)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE