| 298 | } |
| 299 | |
| 300 | const replaceTilde = (comp, options) => { |
| 301 | const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE] |
| 302 | // if we're including prereleases in the match, then the lower bound is |
| 303 | // -0, the lowest possible prerelease value, just like x-ranges and carets. |
| 304 | // this keeps `~1.2` equivalent to the `1.2.x` x-range it's documented as. |
| 305 | const z = options.includePrerelease ? '-0' : '' |
| 306 | return comp.replace(r, (_, M, m, p, pr) => { |
| 307 | debug('tilde', comp, _, M, m, p, pr) |
| 308 | let ret |
| 309 | |
| 310 | if (isX(M)) { |
| 311 | ret = '' |
| 312 | } else if (isX(m)) { |
| 313 | ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0` |
| 314 | } else if (isX(p)) { |
| 315 | // ~1.2 == >=1.2.0 <1.3.0-0 |
| 316 | ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0` |
| 317 | } else if (pr) { |
| 318 | debug('replaceTilde pr', pr) |
| 319 | ret = `>=${M}.${m}.${p}-${pr |
| 320 | } <${M}.${+m + 1}.0-0` |
| 321 | } else { |
| 322 | // ~1.2.3 == >=1.2.3 <1.3.0-0 |
| 323 | ret = `>=${M}.${m}.${p |
| 324 | } <${M}.${+m + 1}.0-0` |
| 325 | } |
| 326 | |
| 327 | debug('tilde return', ret) |
| 328 | return ret |
| 329 | }) |
| 330 | } |
| 331 | |
| 332 | // ^ --> * (any, kinda silly) |
| 333 | // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0 |