comma-split

1.0.0 • Public • Published

comma-split Build Status

Split comma delimited strings into an array. Optional handling for trailing and/or leading whitespace.

Installation

npm install --save comma-split

Usage

var commaSplit = require('comma-split');
 
commaSplit('some, string,\r\r\n\tdelimited\n,by, commas');
// => ['some','string','delimited','by','commas']
 
commaSplit('some, string,\r\r\n\tdelimited\n,by, commas', { ignoreWhitespace: true });
// => ['some',' string','\r\r\n\tdelimited\n','by',' commas']
 
commaSplit('some, string,\r\r\n\tdelimited\n,by, commas', { ignoreTrailingWhitespace: true });
// => ['some','string','delimited\n','by','commas']
 
commaSplit('some, string,\r\r\n\tdelimited\n,by, commas', { ignoreLeadingWhitespace: true });
// => ['some',' string','\r\r\n\tdelimited','by',' commas']
 
commaSplit(',,some, string,\r\r\n\tdelimited\n,by, commas,');
// => ['','','some','string','delimited','by','commas','']
 
commaSplit(',,some, string,\r\r\n\tdelimited\n,by, commas, ,,', { ignoreBlank: true });
// => [some','string','delimited','by','commas']
 
commaSplit('some, string, with,a, dupe, dupe', { ignoreDuplicate: true });
// => [some','string','with', 'a', 'dupe'']

Options

  • ignoreWhitespace:boolean - Ignore leading and trailing whitespace.
  • ignoreTrailingWhitespace:boolean - Ignore trailing whitespace.
  • ignoreLeadingWhitespace:boolean - Ignore leading whitespace.
  • ignoreDuplicate:boolean - Ignore duplicate elements.

License

MIT

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Crafted with <3 by John Otander (@4lpine).

This package was initially generated with yeoman and the p generator.

/comma-split/

    Package Sidebar

    Install

    npm i comma-split

    Weekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • johno