Shapeshift

Shapeshift Ports

PythonTypeScript

python-semver in TypeScript

The module-level functions of python-semver 3, in TypeScript, giving the answers Python gives. It ports python-semver 3 (commit 72734e6).

100%

24,876 of 24,876 calls recorded from the Python original answer the same in the port. Replayed again on .

What it ports

compare, match, parse, max_ver, min_ver, format_version, bump_major, bump_minor, bump_patch, bump_prerelease, bump_build, finalize_version, replace, Version.is_valid.

Install

The package is @pushkal-gupta/semver-py, version 0.1.0. It is not on npm yet; until it is, install it from the GitHub release. Needs Node 22 or later, or any runtime with ES2022 and BigInt.

npm install https://github.com/Pushkal-Gupta/shapeshift-semver-ts/releases/download/v0.1.0/pushkal-gupta-semver-py-0.1.0.tgz

Once it is on npm: npm install @pushkal-gupta/semver-py

Use it

import { compare, match, parse, bumpMinor, finalizeVersion, isValid } from "@pushkal-gupta/semver-py";

compare("1.0.0", "2.0.0");        // -1
match("2.3.7", ">=2.3.6");        // true
parse("1.2.3");                   // { major: 1n, minor: 2n, patch: 3n, prerelease: null, build: null }
bumpMinor("1.2.3");               // "1.3.0"
finalizeVersion("1.2.3-rc.5");    // "1.2.3"
isValid("1.2.3");                 // true

Checked by the documentation-example unit test in semver-ts/src/test/semver.test.ts.

Why use the port

Speed, as measured in the repository

100,000 compare() calls on the same 162 pairs of valid versions, best of five runs, run three times on one arm64 machine under macOS (bench/bench.py and bench/bench.mjs). Times for 100,000 calls; lower is faster. Other machines will differ.

RunTime
Python 3.12.3, semver.compare627 to 638 ms
Python 3.12.3, Version.parse(a).compare(b)525 to 534 ms
Node 24.21.0, the port's compare134 to 141 ms

The tapes

A tape is a file of calls recorded from the original while it ran: the arguments, and the result or the exception type. A call matches when the port gives the same result or raises the same exception type. The counted tapes make up the headline figure.

TapeWhere the calls came fromCallsMatchCounted
shadow/suite.jsonlpython-semver's own test suite and documentation examples159159yes
shadow/random.jsonlrandom versions from fuzz/gen_tape.py, valid and invalid numbers, prerelease and build parts4,2294,229yes
shadow/holdout.jsonlthe same generator with another seed, recorded after the port matched and never used to change it20,11220,112yes
shadow/edge.jsonlhand-picked edge cases: Unicode-digit prerelease identifiers, integers at the 10^255 limit, floats as parts376376yes

Replay it yourself

With pgremlin installed:

git clone https://github.com/Pushkal-Gupta/shapeshift-semver-ts
cd shapeshift-semver-ts
(cd semver-ts && npm ci && npm run build)
goblin shapeshift replay shadow/suite.jsonl -- node semver-ts/dist/adapter.js
goblin shapeshift replay shadow/random.jsonl -- node semver-ts/dist/adapter.js
goblin shapeshift replay shadow/holdout.jsonl -- node semver-ts/dist/adapter.js
goblin shapeshift replay shadow/edge.jsonl -- node semver-ts/dist/adapter.js

Or with the public checker, Shapeshifter, from the repository root:

shapeshifter replay shadow/suite.jsonl -- node semver-ts/dist/adapter.js
shapeshifter replay shadow/random.jsonl -- node semver-ts/dist/adapter.js
shapeshifter replay shadow/holdout.jsonl -- node semver-ts/dist/adapter.js
shapeshifter replay shadow/edge.jsonl -- node semver-ts/dist/adapter.js

What the tapes do not cover