Skip to content

Commit

Permalink
Merge pull request #4 from ryanve/next
Browse files Browse the repository at this point in the history
0.4.0 release
  • Loading branch information
ryanve authored Oct 11, 2016
2 parents 562298e + 328d124 commit 66ffd48
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@ var eol = require('eol')
- Normalize line endings in <var>text</var> to <b>CR</b> (Mac OS)
- <b>@return</b> string with line endings normalized to `\r`

### `eol.before(text)`
- Add linebreak before <var>text</var>
- <b>@return</b> string with linebreak added before text

### `eol.after(text)`
- Add linebreak after <var>text</var>
- <b>@return</b> string with linebreak added after text

## License
MIT
14 changes: 12 additions & 2 deletions eol.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@

var api = {}
var isWindows = typeof process != 'undefined' && 'win32' === process.platform
var linebreak = isWindows ? '\r\n' : '\n'
var newline = /\r\n|\r|\n/g

function before(text) {
return linebreak + text
}

function after(text) {
return text + linebreak
}

function converts(to) {
return function(text) {
return text.replace(newline, to)
Expand All @@ -16,7 +25,8 @@
api['lf'] = converts('\n')
api['cr'] = converts('\r')
api['crlf'] = converts('\r\n')
api['auto'] = converts(isWindows ? '\r\n' : '\n')

api['auto'] = converts(linebreak)
api['before'] = before
api['after'] = after
return api
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eol",
"description": "Newline character converter",
"version": "0.3.0",
"version": "0.4.0",
"homepage": "https://github.com/ryanve/eol",
"license": "MIT",
"author": "Ryan Van Etten",
Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@
return eol.auto(sample) === eol[method](sample);
}) === 2)

aok('before', eol.lf(eol.before('text')) === '\ntext')
aok('before2', eol.lf(eol.before('\ntext\n')) === '\n\ntext\n')
aok('after', eol.lf(eol.after('text')) === 'text\n')
aok('after2', eol.lf(eol.after('\ntext\n')) === '\ntext\n\n')

aok.log('All tests passed =)')
}(this);

0 comments on commit 66ffd48

Please sign in to comment.