blob: c43c1e75a6cd17d5fcf04945bbd2c2607089a322 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2var semver = require('semver');
3
4module.exports = function (version, type) {
5 if (['major', 'minor', 'patch'].indexOf(type) === -1) {
6 throw new TypeError('Invalid version type');
7 }
8
9 version = semver.parse(version, {loose: true});
10
11 if (!version) {
12 throw new Error('Version ' + version + ' is not valid semver');
13 }
14
15 version.build = '';
16 version.prerelease = '';
17
18 if (type === 'minor') {
19 version.patch = 0;
20 }
21
22 if (type === 'major') {
23 version.patch = 0;
24 version.minor = 0;
25 }
26
27 return version.format();
28};