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.

25 lines
579 B

4 years ago
  1. const SemVer = require('../classes/semver')
  2. const Range = require('../classes/range')
  3. const maxSatisfying = (versions, range, options) => {
  4. let max = null
  5. let maxSV = null
  6. let rangeObj = null
  7. try {
  8. rangeObj = new Range(range, options)
  9. } catch (er) {
  10. return null
  11. }
  12. versions.forEach((v) => {
  13. if (rangeObj.test(v)) {
  14. // satisfies(v, range, options)
  15. if (!max || maxSV.compare(v) === -1) {
  16. // compare(max, v, true)
  17. max = v
  18. maxSV = new SemVer(max, options)
  19. }
  20. }
  21. })
  22. return max
  23. }
  24. module.exports = maxSatisfying