word-join
v1.1.0
Published
Join an array of strings into a human-readable list with a customizable conjunction, separator, and optional Oxford comma
Maintainers
Readme
word-join

- Easily use the Oxford comma in any locale or language
- Customize the list separator (e.g.,
";") and the conjunction (e.g.,"or") - ES6-compatible for use in all modern environments
- TypeScript-first, with built-in type definitions
- Zero dependencies, for a minimal bundle footprint
Installation
npm install word-joinUsage
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 wineOptions
conjunction
Type: string. Default: "and".
The conjunction used to join the last item in the list.
wordJoin(["pasta", "sauce", "cheese", "wine"], { conjunction: "or" });
// pasta, sauce, cheese or wineoxford
Type: boolean. Default: false.
Whether to use an Oxford comma — i.e., a final comma before the conjunction.
wordJoin(["pasta", "sauce", "cheese", "wine"], { oxford: true });
// pasta, sauce, cheese, and wineseparator
Type: string. Default: ",".
The string used to separate the list items.
wordJoin(["pasta", "sauce", "cheese", "wine"], { separator: ";" });
// pasta; sauce; cheese and wineLicense
Copyright (C) 2022-present stldo
