UNPKG

1.64 kBMarkdownView Raw
1# And
2
3> Join arrays with commas and »and« before the last item
4
5[![Build Status](https://travis-ci.org/rasshofer/and.svg)](https://travis-ci.org/rasshofer/and)
6[![Coverage Status](https://coveralls.io/repos/github/rasshofer/and/badge.svg)](https://coveralls.io/github/rasshofer/and)
7[![Dependency Status](https://david-dm.org/rasshofer/and/status.svg)](https://david-dm.org/rasshofer/and)
8[![Dependency Status](https://david-dm.org/rasshofer/and/dev-status.svg)](https://david-dm.org/rasshofer/and)
9
10## Installation
11
12```shell
13npm install and
14```
15
16## Usage
17
18```js
19const and = require('and');
20
21console.log(and(['John', 'Frank', 'Jimmy'])); // = 'John, Frank & Jimmy'
22
23console.log(and(['John', 'Frank'])); // = 'John & Frank'
24
25console.log(and(['Frank'])); // = 'Frank'
26
27console.log(and(['John', 'Frank', 'Jimmy'], 'and')); // = 'John, Frank and Jimmy'
28
29console.log(and(['John', 'Frank', 'Jimmy'], 'or')); // = 'John, Frank or Jimmy'
30
31console.log(and(['John', 'Frank', 'Jimmy'], 'and', true)); // = 'John, Frank, and Jimmy'
32```
33
34## API
35
36`and` accepts the following three parameters.
37
38### `data`
39
40Input data.
41
42Example: `['John', 'Frank', 'Jimmy']`
43
44### `separator`
45
46The separator to be used for the last item.
47
48Example: `and`
49
50Default: `&` (= language-independent)
51
52### `oxfordComma`
53
54Use oxford comma in front of the last separator?
55
56Example: `true` (= `'John, Frank, and Jimmy'`)
57
58Default: `false` (= `'John, Frank and Jimmy'`)
59
60## Changelog
61
62* 0.0.2
63 * Fix README
64* 0.0.1
65 * Initial version
66
67## License
68
69Copyright (c) 2018 [Thomas Rasshofer](http://thomasrasshofer.com/)
70Licensed under the MIT license.
71
72See LICENSE for more info.