comma-split
v1.0.0
Published
Split comma delimited strings into an array.
Downloads
147
Maintainers
Readme
comma-split
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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Crafted with <3 by John Otander (@4lpine).
This package was initially generated with yeoman and the p generator.