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.
- Host: GitHub
- URL: https://github.com/alexstevovich/commadus-node
- Owner: alexstevovich
- License: apache-2.0
- Created: 2025-03-15T00:38:26.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-15T00:39:14.000Z (about 1 year ago)
- Last Synced: 2025-09-24T20:00:06.696Z (9 months ago)
- Topics: atomic, formatting, list, nodejs, prose
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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).