An open API service indexing awesome lists of open source software.

https://github.com/alexstevovich/commadus-node

[Node.js] Elegantly formats lists with proper punctuation, including support for the Oxford comma.
https://github.com/alexstevovich/commadus-node

atomic formatting list nodejs prose

Last synced: 4 months ago
JSON representation

[Node.js] Elegantly formats lists with proper punctuation, including support for the Oxford comma.

Awesome Lists containing this project

README

          

# commadus

Master the art of the comma.

> **Archetype:** Node.js package
> **Purpose:** Formats lists with elegant punctuation, including optional Oxford commas.

**Commadus** elegantly formats lists with proper punctuation, including support for the **Oxford comma**.

## Details

- **Proper List Formatting** – Outputs grammatically correct lists in prose.
- **Oxford Comma Support** – Toggle the famous **oxford comma** on or off.
- **Handles Edge Cases** – Works with lists of any length, from empty arrays to long item lists.
- **Lightweight & Fast** – A single function, no dependencies.

## Install

```sh
npm install commadus
```

## ⚙️ API

### `list(items, options?)`

Formats an array of items into a **human-readable list** with optional Oxford comma.

#### Parameters

| Name | Type | Default | Description |
| ---------------- | ---------- | ------------------ | ----------------------------------------------------- |
| `items` | `string[]` | **Required** | The list of items to format. |
| `options` | `Object` | `{ oxford: true }` | Formatting options. |
| `options.oxford` | `boolean` | `true` | Whether to include the **Oxford comma** before "and". |

#### Returns

- **`string`** – The **formatted** list.

## Usage

```js
import list from 'commadus';

console.log(list(['apple', 'banana', 'cherry']));
// "apple, banana, and cherry"

console.log(list(['apple', 'banana', 'cherry'], { oxford: false }));
// "apple, banana and cherry"

console.log(list(['moon', 'stars']));
// "moon and stars"

console.log(list(['sun']));
// "sun"

console.log(list([]));
// ""
```

### Development Homepage

[https://github.com/alexstevovich/commadus-node](https://github.com/alexstevovich/commadus-node)

_This link might be suffixed with "-node" in the future if conflicts arise._

## License

Licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).