word-join
Version:
Tiny module to join arrays with commas, "and", and Oxford comma support
81 lines (56 loc) • 1.53 kB
Markdown
```sh
npm install word-join
```
```js
import wordJoin from "word-join";
wordJoin(["pasta", "sauce", "cheese", "wine"]);
// pasta, sauce, cheese and wine
wordJoin(["pasta", "sauce", "cheese", "wine"], {
conjunction: "or",
});
// pasta, sauce, cheese or wine
wordJoin(["pasta", "sauce", "cheese", "wine"], {
conjunction: "or",
oxford: true,
});
// pasta, sauce, cheese, or wine
wordJoin(["pasta", "sauce", "cheese", "wine"], {
conjunction: "or",
oxford: true,
separator: ";",
});
// pasta; sauce; cheese; or wine
```
Type: `string`. Default: `"and"`.
The conjunction to join the last word of the sentence.
```js
wordJoin(["pasta", "sauce", "cheese", "wine"], { conjunction: "or" });
// pasta, sauce, cheese or wine
```
Type: `boolean`. Default: `false`.
Whether to use an Oxford comma or not — i.e. a last comma before the
conjunction.
```js
wordJoin(["pasta", "sauce", "cheese", "wine"], { oxford: true });
// pasta, sauce, cheese, and wine
```
Type: `string`. Default: `","`.
String to separate the list items.
```js
wordJoin(["pasta", "sauce", "cheese", "wine"], { separator: ";" });
// pasta; sauce; cheese and wine
```
[][license]
[]: https://img.shields.io/npm/v/word-join
[]: https://www.npmjs.com/package/word-join
[]: https://img.shields.io/bundlejs/size/word-join
[]: https://bundlejs.com/?q=word-join
[]: ./LICENSE