Skip to content

Main content

SemVer Stable Sort

Stable SemVer precedence sort using the existing comparator, retaining all build-metadata ties and original spellings/indexes.

Loading tool…

Description

Stable SemVer precedence sort using the existing comparator, retaining all build-metadata ties and original spellings/indexes.

Semantic versions have a major.minor.patch core, optional prerelease identifiers after a hyphen, and build identifiers after a plus. Prereleases precede the corresponding release; build metadata does not affect precedence. A textual spelling, an equal-precedence group and a major.minor release lane therefore answer different questions.1

Stable SemVer precedence sort using the existing comparator, retaining all build-metadata ties and original spellings/indexes.

When to use this tool

Use this tool to sort versions by SemVer precedence while retaining input order for ties, including versions that differ only in build metadata.

How to use the tool and how it works

  1. Enter versions using the field definitions below.
  2. Run the operation. Correct input errors before interpreting an output.
  3. Read result.versions. Use the ordering, boundary rules and absence conditions described below.

Compare parsed versions by SemVer precedence, breaking ties with the original zero-based index. Return original spellings and indexes in ascending order.2

Input fieldMeaning and unitsAccepted input
versionsSemantic-version strings in the source order to inspect.Dense list of at most 128 strings, each at most 8,192 UTF-16 code units.
Output fieldInterpretation
resultObject containing the named fields below.
result.versionsSelected or sorted original version spellings with their original indexes.
json
{
  "input": {
    "versions": [
      "1.0.0+a",
      "1.0.0+b",
      "1.0.0-alpha"
    ]
  },
  "output": {
    "result": {
      "versions": [
        {
          "version": "1.0.0-alpha",
          "index": 2
        },
        {
          "version": "1.0.0+a",
          "index": 0
        },
        {
          "version": "1.0.0+b",
          "index": 1
        }
      ]
    }
  }
}

Limitations and assumptions

  • Build metadata does not break precedence ties; equal-precedence inputs retain source order.
  • Version text is limited to 1,024 UTF-16 code units with no whitespace. Parsed core and numeric prerelease components must be nonnegative safe integers. Range expressions and a leading v are not accepted.
  • Every declared top-level input field is required and unexpected fields are rejected. Ordinary strings are limited to 8,192 UTF-16 code units and lists to 128 entries, with tighter operation-specific bounds where stated. JSON text has bounded nesting and node counts.
  • Numeric outputs must be finite and no larger in absolute magnitude than the safe-integer limit; operations returning exact large integers use decimal text. Positions are zero-based and spans end exclusively unless the operation explicitly states a different convention.

Alternative or Complementary methods

Choose whether you need exact spelling, precedence or a release-lane grouping. Use a separate package manager or compatibility review for dependency resolution and release-policy decisions.

References

  1. Semantic Versioning 2.0.0 — Semantic Versioning

  2. Tool behavior and example: Semantic Version Stable Sort — tool.io

Similar or alternative tools