source: frontend/node_modules/semver/functions/truncate.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1021 bytes
Line 
1'use strict'
2
3const parse = require('./parse')
4const constants = require('../internal/constants')
5const SemVer = require('../classes/semver')
6
7const truncate = (version, truncation, options) => {
8 if (!constants.RELEASE_TYPES.includes(truncation)) {
9 return null
10 }
11
12 const clonedVersion = cloneInputVersion(version, options)
13 return clonedVersion && doTruncation(clonedVersion, truncation)
14}
15
16const cloneInputVersion = (version, options) => {
17 const versionStringToParse = (
18 version instanceof SemVer ? version.version : version
19 )
20
21 return parse(versionStringToParse, options)
22}
23
24const doTruncation = (version, truncation) => {
25 if (isPrerelease(truncation)) {
26 return version.version
27 }
28
29 version.prerelease = []
30
31 switch (truncation) {
32 case 'major':
33 version.minor = 0
34 version.patch = 0
35 break
36 case 'minor':
37 version.patch = 0
38 break
39 }
40
41 return version.format()
42}
43
44const isPrerelease = (type) => {
45 return type.startsWith('pre')
46}
47
48module.exports = truncate
Note: See TracBrowser for help on using the repository browser.