And
Join arrays with commas and »and« before the last item
Installation
npm install and
Usage
const and = require('and');
console.log(and(['John', 'Frank', 'Jimmy']));
console.log(and(['John', 'Frank']));
console.log(and(['Frank']));
console.log(and(['John', 'Frank', 'Jimmy'], 'and'));
console.log(and(['John', 'Frank', 'Jimmy'], 'or'));
console.log(and(['John', 'Frank', 'Jimmy'], 'and', true));
API
and
accepts the following three parameters.
data
Input data.
Example: ['John', 'Frank', 'Jimmy']
separator
The separator to be used for the last item.
Example: and
Default: &
(= language-independent)
oxfordComma
Use oxford comma in front of the last separator?
Example: true
(= 'John, Frank, and Jimmy'
)
Default: false
(= 'John, Frank and Jimmy'
)
Changelog
- 0.0.3
- Fix oxford comma for <3 items
- 0.0.2
- 0.0.1
License
Copyright (c) 2018 Thomas Rasshofer
Licensed under the MIT license.
See LICENSE for more info.