Semantic Versioning 2.0.0 · MoonBit package §11 precedence 4 grammars 0 dependencies

moonsver

Every version,
in its place.

moonsver implements Semantic Versioning 2.0.0: it reads and prints versions, orders them by the precedence rules of the spec, and answers whether a version fits a range. Ranges come in four grammars. The numbers are arbitrary precision.

  • Runs in your browser
  • Zero dependencies
  • Apache-2.0
parse / live
1.2.3-alpha.1+build.5
core1.2.3
stableno
prereleasealpha1
buildbuild5

Loading the compiled library…

§11
precedence, followed to the letter
4
range grammars: npm, Cargo, Ruby, strict
3
prerelease policies
0
third-party dependencies

What it does

Six things, done once

A version is a small, strict format. The work is in the edges: leading zeroes, prerelease ordering, build metadata, and the many ways a range can be written.

Arbitrary precision

The three numbers are BigInt. 18446744073709551616.0.0 parses, prints and compares exactly.

One parser, four grammars

npm, Cargo, Ruby and the strict standard are a setting on Syntax, not four forks of the parser.

Ranges are structure

^1.2.3 expands to >=1.2.3, <2.0.0. Read the sets back, or ask which versions fit.

Precedence per §11

Numeric identifiers before alphanumeric, a shorter list below a longer one, build metadata left out.

Bumps that match

Major, minor, patch and the prerelease corners that are easy to miss, including 1.0.0-pre → 1.0.0.

JSON in and out

Version and Range serialise as strings, so they drop straight into config files and API responses.

One string, four grammars

The same range, read four ways

Ranges are not in the standard, so each ecosystem wrote its own. Type one and see how npm, Cargo, Ruby and the strict grammar each expand it — live, through the compiled library.

grammar lens Try 1.2.3, ~1.2, 1.2.* or ^1.2.3 || ^2
npm=1.2.3default
cargo>=1.2.3, <2.0.0caret default
ruby=1.2.3pessimistic
strict=1.2.3standard only

Playground

Sort a list, test a range

Paste versions, pick a range and a grammar, and watch the version axis light up. Every answer comes from the compiled package.

Open the playground