1 // given a set of versions and a range, create a "simplified" range
2 // that includes the same versions that the original range does
3 // If the original range is shorter than the simplified one, return that.
4 const satisfies = require('../functions/satisfies.js')
5 const compare = require('../functions/compare.js')
6 module.exports = (versions, range, options) => {
10 const v = versions.sort((a, b) => compare(a, b, options))
11 for (const version of v) {
12 const included = satisfies(version, range, options)
29 for (const [min, max] of set) {
32 else if (!max && min === v[0])
35 ranges.push(`>=${min}`)
36 else if (min === v[0])
37 ranges.push(`<=${max}`)
39 ranges.push(`${min} - ${max}`)
41 const simplified = ranges.join(' || ')
42 const original = typeof range.raw === 'string' ? range.raw : String(range)
43 return simplified.length < original.length ? simplified : range