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
|
13 | npm install and
|
14 | ```
|
15 |
|
16 | ## Usage
|
17 |
|
18 | ```js
|
19 | const and = require('and');
|
20 |
|
21 | console.log(and(['John', 'Frank', 'Jimmy'])); // = 'John, Frank & Jimmy'
|
22 |
|
23 | console.log(and(['John', 'Frank'])); // = 'John & Frank'
|
24 |
|
25 | console.log(and(['Frank'])); // = 'Frank'
|
26 |
|
27 | console.log(and(['John', 'Frank', 'Jimmy'], 'and')); // = 'John, Frank and Jimmy'
|
28 |
|
29 | console.log(and(['John', 'Frank', 'Jimmy'], 'or')); // = 'John, Frank or Jimmy'
|
30 |
|
31 | console.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 |
|
40 | Input data.
|
41 |
|
42 | Example: `['John', 'Frank', 'Jimmy']`
|
43 |
|
44 | ### `separator`
|
45 |
|
46 | The separator to be used for the last item.
|
47 |
|
48 | Example: `and`
|
49 |
|
50 | Default: `&` (= language-independent)
|
51 |
|
52 | ### `oxfordComma`
|
53 |
|
54 | Use oxford comma in front of the last separator?
|
55 |
|
56 | Example: `true` (= `'John, Frank, and Jimmy'`)
|
57 |
|
58 | Default: `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 |
|
69 | Copyright (c) 2018 [Thomas Rasshofer](http://thomasrasshofer.com/)
|
70 | Licensed under the MIT license.
|
71 |
|
72 | See LICENSE for more info.
|