Array To Sentence Save

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

Project README

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

Use 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'

License

ISC License © 2018 Shinnosuke Watanabe

Open Source Agenda is not affiliated with "Array To Sentence" Project. README Source: shinnn/array-to-sentence
Stars
33
Open Issues
2
Last Commit
5 years ago
License
ISC

Open Source Agenda Badge

Open Source Agenda Rating