Skip to content

Commit

Permalink
🐛 Fix version badge label when contains _ or - (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
kefranabg committed Nov 27, 2019
1 parent 89cd82d commit 6c345b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/clean-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
* @param {Object} context
*/
module.exports = context => {
const cleanBadgeText = text => text.replace(/-/g, '--').replace(/_/g, '__')

// Why doing this?
// See https://github.com/kefranabg/readme-md-generator/pull/141
const licenseName = context.licenseName
.replace(/-/g, '--')
.replace(/_/g, '__')
const projectVersion = cleanBadgeText(context.projectVersion)

return {
...context,
licenseName
licenseName,
projectVersion
}
}
12 changes: 9 additions & 3 deletions src/clean-context.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const cleanContext = require('./clean-context')

describe('cleanContext', () => {
it('should replace licenseName - and _ characters by -- and __', () => {
const context = { licenseName: 'Apache-2_0' }
const cleanedContext = { licenseName: 'Apache--2__0' }
it('should replace licenseName and projectVersion - and _ characters by -- and __', () => {
const context = {
licenseName: 'Apache-2_0',
projectVersion: '1.0_0-alpha'
}
const cleanedContext = {
licenseName: 'Apache--2__0',
projectVersion: '1.0__0--alpha'
}

const result = cleanContext(context)

Expand Down

0 comments on commit 6c345b5

Please sign in to comment.