(range)
| 98 | } |
| 99 | |
| 100 | parseRange (range) { |
| 101 | // strip build metadata so it can't bleed into the version |
| 102 | range = range.replace(BUILDSTRIPRE, '') |
| 103 | |
| 104 | // memoize range parsing for performance. |
| 105 | // this is a very hot path, and fully deterministic. |
| 106 | const memoOpts = |
| 107 | (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | |
| 108 | (this.options.loose && FLAG_LOOSE) |
| 109 | const memoKey = memoOpts + ':' + range |
| 110 | const cached = cache.get(memoKey) |
| 111 | if (cached) { |
| 112 | return cached |
| 113 | } |
| 114 | |
| 115 | const loose = this.options.loose |
| 116 | // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4` |
| 117 | const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE] |
| 118 | range = range.replace(hr, hyphenReplace(this.options.includePrerelease)) |
| 119 | debug('hyphen replace', range) |
| 120 | |
| 121 | // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5` |
| 122 | range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace) |
| 123 | debug('comparator trim', range) |
| 124 | |
| 125 | // `~ 1.2.3` => `~1.2.3` |
| 126 | range = range.replace(re[t.TILDETRIM], tildeTrimReplace) |
| 127 | debug('tilde trim', range) |
| 128 | |
| 129 | // `^ 1.2.3` => `^1.2.3` |
| 130 | range = range.replace(re[t.CARETTRIM], caretTrimReplace) |
| 131 | debug('caret trim', range) |
| 132 | |
| 133 | // At this point, the range is completely trimmed and |
| 134 | // ready to be split into comparators. |
| 135 | |
| 136 | let rangeList = range |
| 137 | .split(' ') |
| 138 | .map(comp => parseComparator(comp, this.options)) |
| 139 | .join(' ') |
| 140 | .split(/\s+/) |
| 141 | // >=0.0.0 is equivalent to * |
| 142 | .map(comp => replaceGTE0(comp, this.options)) |
| 143 | |
| 144 | if (loose) { |
| 145 | // in loose mode, throw out any that are not valid comparators |
| 146 | rangeList = rangeList.filter(comp => { |
| 147 | debug('loose invalid filter', comp, this.options) |
| 148 | return !!comp.match(re[t.COMPARATORLOOSE]) |
| 149 | }) |
| 150 | } |
| 151 | debug('range list', rangeList) |
| 152 | |
| 153 | // if any comparators are the null set, then replace with JUST null set |
| 154 | // if more than one comparator, remove any * comparators |
| 155 | // also, don't include the same comparator more than once |
| 156 | const rangeMap = new Map() |
| 157 | const comparators = rangeList.map(comp => new Comparator(comp, this.options)) |
no test coverage detected