delimiter
v1.0.2
Published
Places delimiters between items in an array.
Downloads
7
Readme
Delimiter
Places delimiters between items in an array. Defaults to a comma-separated list with an Oxford comma.
Install
npm install delimiter --save
oryarn add delimiter
Parameters
delimiter(arr, serial, del)
arr
The array to which you want to add delimiters.
serial
The separator for the last item in the array. (default: and
)
delimiter([ 1, 2 ], 'or') === [ 1, ' or ', 2 ]);
delimiter([ 1, 2, 3 ], 'or') === [ 1, ', ', 2, ', or ', 3 ]
del
The delimiter you want to use. (default: ,
)
delimiter(
[ 'Stover, Charles', 'Quisido, Ace', 'Gates, Bill' ],
'and', ';'
) === [ 'Stover, Charles', '; ', 'Quisido, Ace', '; and ', 'Gates, Bill' ]
Examples
This package was designed to separate React links using an Oxford comma but is extensible to other use cases.
Arrays with Two Items
import delimiter from 'delimiter';
// JSX
const myLinks = [
<CharlesStover />,
<Quisido />
];
delimiter(myLinks); // [ <CharlesStover />, ' and ', <Quisido /> ]
Arrays with Three or More Items
import delimiter from 'delimiter';
// JSX
const myLinks = [
<CharlesStover />,
<Quisido />,
<Mtgenius />
];
delimiter(myLinks); // [ <CharlesStover />, ', ', <Quisido />, ', and ', <Mtgenius /> ]