From d06259383cddb24b85e9b9501eee27ca6c117361 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 1 Jul 2019 11:51:31 -0700 Subject: [PATCH] coerce(number) will coerce to a string --- semver.js | 4 ++++ test/coerce.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/semver.js b/semver.js index b3ec9c4f..07529962 100644 --- a/semver.js +++ b/semver.js @@ -1541,6 +1541,10 @@ function coerce (version, options) { return version } + if (typeof version === 'number') { + version = String(version) + } + if (typeof version !== 'string') { return null } diff --git a/test/coerce.js b/test/coerce.js index 7673289d..996eee3b 100644 --- a/test/coerce.js +++ b/test/coerce.js @@ -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]