Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eol.split method #6

Merged
merged 2 commits into from
Feb 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@ var eol = require('eol')
- Add linebreak after <var>text</var>
- <b>@return</b> string with linebreak added after text

### `eol.split(text)`
- Split <var>text</var> by newline
- <b>@return</b> array of lines

## License
MIT
6 changes: 6 additions & 0 deletions eol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ declare module eol {
* @return string with linebreak added after text
*/
export function after(text: string): string;

/**
* Split text by newline
* @return array of lines
*/
export function split(text: string): Array<string>;
}

declare module "eol" {
Expand Down
5 changes: 5 additions & 0 deletions eol.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
}
}

function split(text) {
return text.split(newline)
}

api['lf'] = converts('\n')
api['cr'] = converts('\r')
api['crlf'] = converts('\r\n')
api['auto'] = converts(linebreak)
api['before'] = before
api['after'] = after
api['split'] = split
return api
});
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
aok('lf repeat newlines intact', eol.lf('\n\n\r\r') === '\n\n\n\n')
aok('cr repeat newlines intact', eol.cr('\n\n\r\r') === '\r\r\r\r')
aok('crlf repeat newlines intact', eol.crlf('\r\n\r\n') === '\r\n\r\n')
aok('split return type', eol.split('0\n1\n2') instanceof Array)
aok('split lf', eol.split('0\n1\n2').join('') === '012')
aok('split cr', eol.split('0\r1\r2').join('') === '012')
aok('split crlf', eol.split('0\r\n1\r\n2').join('') === '012')
aok('split mixed', eol.split('0\r\n1\n2\r3\r\n4').join('') === '01234')

aok.pass(meths, function(method, i) {
var normalized = eol[method](sample)
Expand Down