Miss any of our Open RFC calls?Watch the recordings here! »

conjunct

1.0.1 • Public • Published

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

Install

npm i conjunct

DownloadsWeekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

4.84 kB

Total Files

4

Last publish

Collaborators

  • avatar