Skip to content

Commit

Permalink
Add eol.split method (#6)
Browse files Browse the repository at this point in the history
* Add eol.split method

* document eol.split
  • Loading branch information
ryanve authored Feb 18, 2017
1 parent f444a74 commit 5dbc293
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
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

0 comments on commit 5dbc293

Please sign in to comment.