ccc-tnt-psd2ui/npm-packages/mac-v2.4.x/semver/functions/diff.js

24 lines
634 B
JavaScript
Raw Permalink Normal View History

2023-07-27 07:04:13 +00:00
const parse = require('./parse')
const eq = require('./eq')
2023-07-24 03:13:08 +00:00
const diff = (version1, version2) => {
2023-07-27 07:04:13 +00:00
if (eq(version1, version2)) {
2023-07-24 03:13:08 +00:00
return null
2023-07-27 07:04:13 +00:00
} else {
const v1 = parse(version1)
const v2 = parse(version2)
const hasPre = v1.prerelease.length || v2.prerelease.length
const prefix = hasPre ? 'pre' : ''
const defaultResult = hasPre ? 'prerelease' : ''
for (const key in v1) {
if (key === 'major' || key === 'minor' || key === 'patch') {
if (v1[key] !== v2[key]) {
return prefix + key
}
}
2023-07-24 03:13:08 +00:00
}
2023-07-27 07:04:13 +00:00
return defaultResult // may be undefined
2023-07-24 03:13:08 +00:00
}
}
module.exports = diff