Skip to content

mk-pmb/conjunct-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

conjunct

Glue array items together, with a different glue for the last pair.

API

This module exports one function that also holds some convenience functions:

conj(list[, fin=' and/or '[, glue=', '[, serial='']]])

The list must support Array-like .slice() and .join().

  • For a single item list, returns the first item verbatim.
  • For an empty list, returns the empty string.
  • For a list with two items, returns them joined by fin.
  • For a list with three or more items, returns them concatenated by serial + fin for the last pair, and glue for all other gaps.
    • Set serial to ',' to achieve a serial comma (also Oxford comma or Harvard comma).

No spaces are added except those contained in fin/glue/serial.

conj.a(list)

Convenience function for fin = ' and ' and defaults for everything else.

conj.o(list)

Convenience function for fin = ' or ' and defaults for everything else.

conj.s(finWord, list)

Convenience function for easy serial comma. Uses fin = ' ' + finWord + ' ', i.e. one space character is added to each side of your finWord.

conj.sa(list)

Convenience function for fin = ' and ' and `serial = ','.

conj.so(list)

Convenience function for fin = ' or ' and `serial = ','.

Usage

see test.usage.js.

Known issues

  • Needs more/better tests and docs.

 

License

ISC

About

Glue array items together, with a different glue for the last pair.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published