MCPcopy
hub / github.com/npm/node-semver / replaceCaret

Function replaceCaret

classes/range.js:348–399  ·  view source on GitHub ↗
(comp, options)

Source from the content-addressed store, hash-verified

346}
347
348const replaceCaret = (comp, options) => {
349 debug('caret', comp, options)
350 const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET]
351 const z = options.includePrerelease ? '-0' : ''
352 return comp.replace(r, (_, M, m, p, pr) => {
353 debug('caret', comp, _, M, m, p, pr)
354 let ret
355
356 if (isX(M)) {
357 ret = ''
358 } else if (isX(m)) {
359 ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`
360 } else if (isX(p)) {
361 if (M === '0') {
362 ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`
363 } else {
364 ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`
365 }
366 } else if (pr) {
367 debug('replaceCaret pr', pr)
368 if (M === '0') {
369 if (m === '0') {
370 ret = `>=${M}.${m}.${p}-${pr
371 } <${M}.${m}.${+p + 1}-0`
372 } else {
373 ret = `>=${M}.${m}.${p}-${pr
374 } <${M}.${+m + 1}.0-0`
375 }
376 } else {
377 ret = `>=${M}.${m}.${p}-${pr
378 } <${+M + 1}.0.0-0`
379 }
380 } else {
381 debug('no pr')
382 if (M === '0') {
383 if (m === '0') {
384 ret = `>=${M}.${m}.${p
385 } <${M}.${m}.${+p + 1}-0`
386 } else {
387 ret = `>=${M}.${m}.${p
388 } <${M}.${+m + 1}.0-0`
389 }
390 } else {
391 ret = `>=${M}.${m}.${p
392 } <${+M + 1}.0.0-0`
393 }
394 }
395
396 debug('caret return', ret)
397 return ret
398 })
399}
400
401const replaceXRanges = (comp, options) => {
402 debug('replaceXRanges', comp, options)

Callers 1

replaceCaretsFunction · 0.85

Calls 1

isXFunction · 0.85

Tested by

no test coverage detected