You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
634 B

4 years ago
  1. const parse = require('./parse')
  2. const eq = require('./eq')
  3. const diff = (version1, version2) => {
  4. if (eq(version1, version2)) {
  5. return null
  6. } else {
  7. const v1 = parse(version1)
  8. const v2 = parse(version2)
  9. const hasPre = v1.prerelease.length || v2.prerelease.length
  10. const prefix = hasPre ? 'pre' : ''
  11. const defaultResult = hasPre ? 'prerelease' : ''
  12. for (const key in v1) {
  13. if (key === 'major' || key === 'minor' || key === 'patch') {
  14. if (v1[key] !== v2[key]) {
  15. return prefix + key
  16. }
  17. }
  18. }
  19. return defaultResult // may be undefined
  20. }
  21. }
  22. module.exports = diff