|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | 'use strict'
|
|---|
| 2 |
|
|---|
| 3 | // given a set of versions and a range, create a "simplified" range
|
|---|
| 4 | // that includes the same versions that the original range does
|
|---|
| 5 | // If the original range is shorter than the simplified one, return that.
|
|---|
| 6 | const satisfies = require('../functions/satisfies.js')
|
|---|
| 7 | const compare = require('../functions/compare.js')
|
|---|
| 8 | module.exports = (versions, range, options) => {
|
|---|
| 9 | const set = []
|
|---|
| 10 | let first = null
|
|---|
| 11 | let prev = null
|
|---|
| 12 | const v = versions.sort((a, b) => compare(a, b, options))
|
|---|
| 13 | for (const version of v) {
|
|---|
| 14 | const included = satisfies(version, range, options)
|
|---|
| 15 | if (included) {
|
|---|
| 16 | prev = version
|
|---|
| 17 | if (!first) {
|
|---|
| 18 | first = version
|
|---|
| 19 | }
|
|---|
| 20 | } else {
|
|---|
| 21 | if (prev) {
|
|---|
| 22 | set.push([first, prev])
|
|---|
| 23 | }
|
|---|
| 24 | prev = null
|
|---|
| 25 | first = null
|
|---|
| 26 | }
|
|---|
| 27 | }
|
|---|
| 28 | if (first) {
|
|---|
| 29 | set.push([first, null])
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | const ranges = []
|
|---|
| 33 | for (const [min, max] of set) {
|
|---|
| 34 | if (min === max) {
|
|---|
| 35 | ranges.push(min)
|
|---|
| 36 | } else if (!max && min === v[0]) {
|
|---|
| 37 | ranges.push('*')
|
|---|
| 38 | } else if (!max) {
|
|---|
| 39 | ranges.push(`>=${min}`)
|
|---|
| 40 | } else if (min === v[0]) {
|
|---|
| 41 | ranges.push(`<=${max}`)
|
|---|
| 42 | } else {
|
|---|
| 43 | ranges.push(`${min} - ${max}`)
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 | const simplified = ranges.join(' || ')
|
|---|
| 47 | const original = typeof range.raw === 'string' ? range.raw : String(range)
|
|---|
| 48 | return simplified.length < original.length ? simplified : range
|
|---|
| 49 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.