left-split
v1.0.0
Published
Split string capture group retained on left
Downloads
7,506
Maintainers
Readme
left-split
Split string capture group is captured to the left hand array item.
Capturing parenthesis return the separator as a distinct array element.
left-split
puts it at the end of the left hand array item.
Install
npm install left-split
Usage
leftsplit = require('left-split')
'foo bar'.split(/(\s)/)
// => ['foo', ' ', 'bar']
leftsplit('foo bar', /(\s)/)
// => ['foo ', 'bar']
'foo\nbar\n'.split(/(\r?\n)/)
// => ['foo', '\n', 'bar', '\n', '']
leftsplit('foo\nbar\n', /(\r?\n)/)
// => ['foo\n', 'bar\n', '']