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

use os module for cross-platform end of line #4

Merged
merged 1 commit into from
Jun 7, 2015
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
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ var lineReader = require('line-reader')
var semver = /\[?v?([\w\d\.-]+\.[\w\d\.-]+[a-zA-Z0-9])\]?/
var log = { versions: [] }
var current
var endOfLine = require('os').EOL

module.exports = function parse (file, callback) {
lineReader.eachLine(file, handleLine).then(function () {
lineReader.eachLine(file, handleLine, endOfLine).then(function () {
// push last version into log
pushCurrent()

Expand Down Expand Up @@ -41,9 +42,9 @@ function handleLine (line) {

// deal with body or description content
if (current) {
current.body += line + '\n'
current.body += line + endOfLine
} else {
log.description = (log.description || '') + line + '\n'
log.description = (log.description || '') + line + endOfLine
}
}

Expand All @@ -63,10 +64,12 @@ function pushCurrent () {
function clean (str) {
if (!str) return ''

// trim
str = str.trim()
// remove leading newlines
str = str.replace(/^[\n]*/, '')
str = str.replace(new RegExp('[' + endOfLine + ']*'), '')
// remove trailing newlines
str = str.replace(/[\n]*$/, '')
str = str.replace(new RegExp('[' + endOfLine + ']*$'), '')

return str
}
6 changes: 4 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var parseChangelog = require('..')
var test = require('tape')
var endOfLine = require('os').EOL

var expected = {
title: 'changelog title',
description: 'A cool description (optional).',
Expand All @@ -12,13 +14,13 @@ var expected = {
body: '* bar' },
{ version: 'a.b.c',
title: '[a.b.c]',
body: '### Changes\n\n* Update API\n* Fix bug #1' },
body: '### Changes' + endOfLine + endOfLine + '* Update API' + endOfLine + '* Fix bug #1' },
{ version: '2.2.3-pre.1',
title: '2.2.3-pre.1 - 2013-02-14',
body: '* Update API' },
{ version: '2.0.0-x.7.z.92',
title: '2.0.0-x.7.z.92 - 2013-02-14',
body: '* bark bark\n* woof\n* arf' },
body: '* bark bark' + endOfLine + '* woof' + endOfLine + '* arf' },
{ version: '1.3.0',
title: 'v1.3.0',
body: '* make it so' },
Expand Down