Code guides

Check prerelease order and npm range matches

·

A release list can contain valid version strings in the wrong order. A dependency range is a separate kind of expression. Validate each list in the appropriate mode and check how prereleases affect the result.

Semver Validator

Find the out-of-order prerelease

Choose SemVer 2.0.0 versions and load the example. With Oldest to newest selected, line 2 displays Out of order. The release candidate 1.2.0-rc.2 sorts before 1.2.0 even though the stable version came first in the input.

Check that the sorted list starts with 1.2.0-rc.2 and excludes line 5, 01.2.3. Its major version has a leading zero. Download sorted versions returns valid lines in the selected order. Repeated entries remain visible for review.

Semantic Versioning 2.0.0 specification

Separate duplicates from precedence ties

Line 4 duplicates line 3 because both contain 1.2.0+build.1. Change line 4 to 1.2.0+build.2 and validate again. The duplicate disappears and both versions still have equal precedence.

Use the report to check which line was repeated. If you need to sort by build metadata within each tie, use a documented project-specific rule in addition to SemVer precedence.

Semantic Versioning 2.0.0 specification

Compare a prerelease with npm ranges

Switch Validation mode to npm ranges and load the example. The comparison version is 1.5.0-beta.2. The range ^1.2.0 does not match under npm's default prerelease rule. The range >=1.5.0-beta.1 <2.0.0 does match because it explicitly admits a prerelease with that major, minor and patch tuple.

Enable Include prereleases in range matching and validate again. The caret range now matches. The tag latest reports an error because this mode accepts range expressions. Download the JSON report to keep the normalized ranges and matching outcomes.

npm node-semver documentation, ranges and prerelease rules

Common questions

Why is 1.2.3-01 invalid while 1.2.3+01 is valid?

A numeric prerelease identifier follows the leading-zero restriction. Build identifiers use separate rules and can contain 01.

What happens if I leave the npm comparison version empty?

The tool validates and normalizes each range. A match result appears after you enter a comparison version.

Sources

Put it into practice.

Related guides