1.0.1 • Published 5 years ago
conjunct v1.0.1
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 + finfor the last pair, andgluefor all other gaps.- Set
serialto','to achieve a serial comma (also Oxford comma or Harvard comma).
- Set
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