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

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

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict'
2
3const parse = require('./parse.js')
4
5const diff = (version1, version2) => {
6 const v1 = parse(version1, null, true)
7 const v2 = parse(version2, null, true)
8 const comparison = v1.compare(v2)
9
10 if (comparison === 0) {
11 return null
12 }
13
14 const v1Higher = comparison > 0
15 const highVersion = v1Higher ? v1 : v2
16 const lowVersion = v1Higher ? v2 : v1
17 const highHasPre = !!highVersion.prerelease.length
18 const lowHasPre = !!lowVersion.prerelease.length
19
20 if (lowHasPre && !highHasPre) {
21 // Going from prerelease -> no prerelease requires some special casing
22
23 // If the low version has only a major, then it will always be a major
24 // Some examples:
25 // 1.0.0-1 -> 1.0.0
26 // 1.0.0-1 -> 1.1.1
27 // 1.0.0-1 -> 2.0.0
28 if (!lowVersion.patch && !lowVersion.minor) {
29 return 'major'
30 }
31
32 // If the main part has no difference
33 if (lowVersion.compareMain(highVersion) === 0) {
34 if (lowVersion.minor && !lowVersion.patch) {
35 return 'minor'
36 }
37 return 'patch'
38 }
39 }
40
41 // add the `pre` prefix if we are going to a prerelease version
42 const prefix = highHasPre ? 'pre' : ''
43
44 if (v1.major !== v2.major) {
45 return prefix + 'major'
46 }
47
48 if (v1.minor !== v2.minor) {
49 return prefix + 'minor'
50 }
51
52 if (v1.patch !== v2.patch) {
53 return prefix + 'patch'
54 }
55
56 // high and low are prereleases
57 return 'prerelease'
58}
59
60module.exports = diff
Note: See TracBrowser for help on using the repository browser.