Skip to content

CharlesStover/delimiter

Repository files navigation

Delimiter Tweet

Places delimiters between items in an array. Defaults to a comma-separated list with an Oxford comma.

version minified size minzipped size downloads build

Install

  • npm install delimiter --save or
  • yarn 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 /> ]

Sponsor 💗

If you are a fan of this project, you may become a sponsor via GitHub's Sponsors Program.