https://github.com/dawsbot/arrford
Array to human readable list converter
https://github.com/dawsbot/arrford
Last synced: about 1 year ago
JSON representation
Array to human readable list converter
- Host: GitHub
- URL: https://github.com/dawsbot/arrford
- Owner: dawsbot
- License: mit
- Created: 2016-02-19T09:41:13.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-16T00:12:56.000Z (about 9 years ago)
- Last Synced: 2024-11-11T05:56:01.818Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 14
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# arrford
[](https://www.npmjs.com/package/arrford)
[](https://travis-ci.org/dawsbot/arrford)
[](http://npmjs.org/arrford)
> Array to human readable list converter
## Install
#### Node
```
npm install --save arrford
```
#### Web
arrford is exported for web and usable with the variable `arrford`
```html
```
## Usage
```js
// remove require statement if using the web bundle
const arrford = require('arrford');
arrford(['run', 'climb', 'jump!']);
//=> 'run, climb, and jump!'
```
#### Fewer than 3 elements in array
```js
arrford(['run', 'climb!']);
//=> 'run and climb!'
arrford(['run!']);
//=> 'run!'
```
#### Abort the Oxford comma
```js
arrford(['run', 'climb', 'jump!'], false);
//=> 'run, climb and jump!'
```
#### Replace the word 'and'
```js
arrford(['spring', 'klättra', 'hoppa!'], true, 'och');
//=> 'spring, klättra, och hoppa!'
```
#### Replace the word 'and' and abort the Oxford comma
```js
arrford(['spring', 'klättra', 'hoppa!'], false, 'och');
//=> 'spring, klättra och hoppa!'
```
## API
### arrford(target [, oxford, join])
#### target
**Type**: `Array` of `string`s
#### oxford
*optional*
**Type**: `boolean`
**Default**: true
**Description**: whether to use the Oxford comma or not
#### join
*optional*
**Type**: `string`
**Default**: 'and'
**Description**: word used to join the list with the last element
#### returns
**Type**: `string`
**Description**: Take an array of strings and return a string of these items as a list. Insert "," and "and" in a grammatically correct way. Follow the Oxford comma trend unless `false` is passed in for the second argument. Use the word 'and' to join the list unless some other "join" word is specified for the third argument.
## License
MIT © [Dawson Botsford](http://dawsonbotsford.com)