Giter VIP home page Giter VIP logo

arrford's Introduction

arrford

npm version Build Status NPM downloads

Array to human readable list converter


Install

Node

npm install --save arrford

Web

arrford is exported for web and usable with the variable arrford

<script src="https://rawgit.com/dawsonbotsford/arrford/master/bundle.js"></script>

Usage

// 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

arrford(['run', 'climb!']);
//=> 'run and climb!'

arrford(['run!']);
//=> 'run!'

Abort the Oxford comma

arrford(['run', 'climb', 'jump!'], false);
//=> 'run, climb and jump!'

Replace the word 'and'

arrford(['spring', 'klättra', 'hoppa!'], true, 'och');
//=> 'spring, klättra, och hoppa!'

Replace the word 'and' and abort the Oxford comma

arrford(['spring', 'klättra', 'hoppa!'], false, 'och');
//=> 'spring, klättra och hoppa!'

API

arrford(target [, oxford, join])


target

Type: Array of strings


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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.