Initial commit
[yaffs-website] / node_modules / semver-truncate / index.js
1 'use strict';
2 var semver = require('semver');
3
4 module.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 };