MCPcopy Index your code
hub / github.com/nodejs/node / comparePrereleaseIdentifiers

Function comparePrereleaseIdentifiers

test/fixtures/snapshot/typescript.js:3371–3416  ·  view source on GitHub ↗
(left, right)

Source from the content-addressed store, hash-verified

3369 };
3370 }
3371 function comparePrereleaseIdentifiers(left, right) {
3372 // https://semver.org/#spec-item-11
3373 // > When major, minor, and patch are equal, a pre-release version has lower precedence
3374 // > than a normal version.
3375 if (left === right)
3376 return 0 /* Comparison.EqualTo */;
3377 if (left.length === 0)
3378 return right.length === 0 ? 0 /* Comparison.EqualTo */ : 1 /* Comparison.GreaterThan */;
3379 if (right.length === 0)
3380 return -1 /* Comparison.LessThan */;
3381 // https://semver.org/#spec-item-11
3382 // > Precedence for two pre-release versions with the same major, minor, and patch version
3383 // > MUST be determined by comparing each dot separated identifier from left to right until
3384 // > a difference is found [...]
3385 var length = Math.min(left.length, right.length);
3386 for (var i = 0; i < length; i++) {
3387 var leftIdentifier = left[i];
3388 var rightIdentifier = right[i];
3389 if (leftIdentifier === rightIdentifier)
3390 continue;
3391 var leftIsNumeric = numericIdentifierRegExp.test(leftIdentifier);
3392 var rightIsNumeric = numericIdentifierRegExp.test(rightIdentifier);
3393 if (leftIsNumeric || rightIsNumeric) {
3394 // https://semver.org/#spec-item-11
3395 // > Numeric identifiers always have lower precedence than non-numeric identifiers.
3396 if (leftIsNumeric !== rightIsNumeric)
3397 return leftIsNumeric ? -1 /* Comparison.LessThan */ : 1 /* Comparison.GreaterThan */;
3398 // https://semver.org/#spec-item-11
3399 // > identifiers consisting of only digits are compared numerically
3400 var result = ts.compareValues(+leftIdentifier, +rightIdentifier);
3401 if (result)
3402 return result;
3403 }
3404 else {
3405 // https://semver.org/#spec-item-11
3406 // > identifiers with letters or hyphens are compared lexically in ASCII sort order.
3407 var result = ts.compareStringsCaseSensitive(leftIdentifier, rightIdentifier);
3408 if (result)
3409 return result;
3410 }
3411 }
3412 // https://semver.org/#spec-item-11
3413 // > A larger set of pre-release fields has a higher precedence than a smaller set, if all
3414 // > of the preceding identifiers are equal.
3415 return ts.compareValues(left.length, right.length);
3416 }
3417 /**
3418 * Describes a semantic version range, per https://github.com/npm/node-semver#ranges
3419 */

Callers 1

typescript.jsFile · 0.85

Calls 2

minMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…