npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

join-words

v1.0.4

Published

a lightweight and easy-to-use JavaScript utility for formatting an array of words into a human-readable string.

Downloads

10

Readme

join-words

join-words is a lightweight and easy-to-use JavaScript utility for formatting an array of words into a human-readable string. It handles edge cases like empty arrays, single words, and proper punctuation for lists of two or more words.


Features

  • Empty Array Handling: Returns an empty string for an empty array.
  • Single Word Support: Returns the word itself when the array contains only one word.
  • Two Words: Joins two words with "and".
  • Three or More Words: Joins all but the last word with commas, and appends "and" before the last word.
  • Lightweight: No dependencies, simple and efficient.

Installation

Install the library via npm:

npm install join-words

Or using yarn:

yarn add join-words

Usage

Importing the Library

You can import the library into your project using CommonJS:

const joinWords = require('join-words');

Examples

const joinWords = require('join-words');

console.log(joinWords([])); // ""
console.log(joinWords(["apple"])); // "apple"
console.log(joinWords(["apple", "banana"])); // "apple and banana"
console.log(joinWords(["apple", "banana", "cherry"])); // "apple, banana, and cherry"
console.log(joinWords(["apple", "banana", "cherry", "date"])); // "apple, banana, cherry, and date"

Edge Cases

  • Empty Array: An empty array will return an empty string.
joinWords([]); // ""
  • Single Word: An array with one word will return the word itself.
joinWords(["apple"]); // "apple"
  • Two Words: Two words are joined with "and".
joinWords(["apple", "banana"]); // "apple and banana"
  • Three or More Words: Words are joined with commas, and "and" is appended before the last word.
joinWords(["apple", "banana", "cherry"]); // "apple, banana, and cherry"
joinWords(["apple", "banana", "cherry", "date"]); // "apple, banana, cherry, and date"

API

joinWords(words)

Parameters:

  • words (Array of Strings): The array of words to format.

Returns:

  • String: A formatted string of the words.

Behavior:

  • Returns an empty string if the array is empty.
  • Returns the single word if there is only one word in the array.
  • Joins two words with "and".
  • Joins three or more words with commas and appends "and" before the last word.

Why Use join-words?

  • Simplifies formatting of word lists in natural language.
  • Reduces boilerplate code for creating readable lists.
  • Handles edge cases seamlessly.
  • Lightweight and dependency-free.

Contributing

Contributions are welcome! If you'd like to improve or add features to this library, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Write clear and concise code with comments where necessary.
  4. Add tests for your changes (if applicable).
  5. Submit a pull request.

Development

  1. Clone the repository:

    git clone https://github.com/OroTeam/join-words.git
    cd join-words
  2. Install dependencies:

    npm install
  3. Run tests:

    npm test

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this library as long as you include the license in your project.


Support

If you encounter any issues or have questions, feel free to open an issue on the GitHub repository or contact the maintainer.


Acknowledgments

Special thanks to the open-source community for inspiring the creation of this library. Your feedback and contributions make this project better!


Enjoy using join-words! 🎉