Skip to content

Navigation Menu

Sign in
Appearance settings
Sign up
Appearance settings
Open more actions menu

Repository files navigation

word-join License Build status npm minzipped size

  • 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-join

Usage

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

Options

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 wine

oxford

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 wine

separator

Type: string. Default: ",".

The string used to separate the list items.

wordJoin(["pasta", "sauce", "cheese", "wine"], { separator: ";" });
// pasta; sauce; cheese and wine

License

The MIT License

Copyright (C) 2022-present stldo

About

Join an array of strings into a human-readable list with a customizable conjunction, separator, and optional Oxford comma

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.