From 98307b05697d6157eb8025ee6fd9a370f2f45fee Mon Sep 17 00:00:00 2001 From: Ryan Van Etten Date: Mon, 10 Oct 2016 17:16:10 -0700 Subject: [PATCH 1/2] add .before and .after methods --- README.md | 8 ++++++++ eol.js | 14 ++++++++++++-- test.js | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 200401a..58a7ede 100644 --- a/README.md +++ b/README.md @@ -27,5 +27,13 @@ var eol = require('eol') - Normalize line endings in text to CR (Mac OS) - @return string with line endings normalized to `\r` +### `eol.before(text)` +- Add linebreak before text +- @return string with linebreak added before text + +### `eol.after(text)` +- Add linebreak after text +- @return string with linebreak added after text + ## License MIT diff --git a/eol.js b/eol.js index 2113f95..958c45b 100644 --- a/eol.js +++ b/eol.js @@ -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) @@ -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 }); diff --git a/test.js b/test.js index 7f03a62..0a7e3a0 100644 --- a/test.js +++ b/test.js @@ -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); From 328d12499cb4500523e3a9560841f1cf454f33d9 Mon Sep 17 00:00:00 2001 From: Ryan Van Etten Date: Mon, 10 Oct 2016 17:17:00 -0700 Subject: [PATCH 2/2] 0.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ced52b5..3b08d44 100644 --- a/package.json +++ b/package.json @@ -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",