diff.js 634 B

1234567891011121314151617181920212223
  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