Skip to content

Commit

Permalink
coerce(number) will coerce to a string
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 1, 2019
1 parent 3dc88f3 commit d062593
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,10 @@ function coerce (version, options) {
return version
}

if (typeof version === 'number') {
version = String(version)
}

if (typeof version !== 'string') {
return null
}
Expand Down
3 changes: 2 additions & 1 deletion test/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ test('\ncoerce tests', function (t) {
r('1')(16) + '.' + r('2')(16) + '.' + r('3')(16)],
['1.2.3.' + r('4')(252) + '.5', '1.2.3'],
['1.2.3.' + r('4')(1024), '1.2.3'],
[r('1')(17) + '.4.7.4', '4.7.4']
[r('1')(17) + '.4.7.4', '4.7.4'],
[10, '10.0.0'],
].forEach(function (tuple) {
var input = tuple[0]
var expected = tuple[1]
Expand Down

0 comments on commit d062593

Please sign in to comment.