https://github.com/ljharb/listify
Turn an array into a list of comma-separated values, appropriate for use in an English sentence.
https://github.com/ljharb/listify
Last synced: 6 months ago
JSON representation
Turn an array into a list of comma-separated values, appropriate for use in an English sentence.
- Host: GitHub
- URL: https://github.com/ljharb/listify
- Owner: ljharb
- License: mit
- Created: 2013-09-07T21:10:45.000Z (about 12 years ago)
- Default Branch: main
- Last Pushed: 2022-10-27T05:25:21.000Z (almost 3 years ago)
- Last Synced: 2025-04-15T11:08:14.765Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 64.5 KB
- Stars: 26
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
#listify [![Version Badge][npm-version-svg]][npm-url]
[![Build Status][travis-svg]][travis-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]Turn an array into a list of comma-separated values, appropriate for use in an English sentence.
## Example
```js
var listify = require('listify');assert(listify([1, 2]) === '1 and 2');
assert(listify([1, 2, 3]) === '1, 2, and 3');
assert(listify([1, 2, 3, 4]) === '1, 2, 3, and 4');
assert(listify([1, 2, 3], { separator: '… ' }) === '1… 2… and 3');
assert(listify([1, 2, 3], { finalWord: false }) === '1, 2, 3');
assert(listify([1, 2, 3], { separator: '… ', finalWord: 'or' }) === '1… 2… or 3');
```## Tests
Simply clone the repo, `npm install`, and run `npm test`[npm-url]: https://npmjs.org/package/listify
[npm-version-svg]: http://versionbadg.es/ljharb/listify.svg
[travis-svg]: https://travis-ci.org/ljharb/listify.svg
[travis-url]: https://travis-ci.org/ljharb/listify
[deps-svg]: https://david-dm.org/ljharb/listify.svg
[deps-url]: https://david-dm.org/ljharb/listify
[dev-deps-svg]: https://david-dm.org/ljharb/listify/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/listify#info=devDependencies