Skip to content

Commit d062593

Browse files
committed
coerce(number) will coerce to a string
1 parent 3dc88f3 commit d062593

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

semver.js

+4
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,10 @@ function coerce (version, options) {
15411541
return version
15421542
}
15431543

1544+
if (typeof version === 'number') {
1545+
version = String(version)
1546+
}
1547+
15441548
if (typeof version !== 'string') {
15451549
return null
15461550
}

test/coerce.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ test('\ncoerce tests', function (t) {
103103
r('1')(16) + '.' + r('2')(16) + '.' + r('3')(16)],
104104
['1.2.3.' + r('4')(252) + '.5', '1.2.3'],
105105
['1.2.3.' + r('4')(1024), '1.2.3'],
106-
[r('1')(17) + '.4.7.4', '4.7.4']
106+
[r('1')(17) + '.4.7.4', '4.7.4'],
107+
[10, '10.0.0'],
107108
].forEach(function (tuple) {
108109
var input = tuple[0]
109110
var expected = tuple[1]

0 commit comments

Comments
 (0)