Beispiel
semver 7.8.5: compare versions with semver.cmp
Verifiziertes Beispiel für npm semver 7.8.5: compare versions with semver.cmp. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.
sha256:7d75d056ba45c0de70ba39b7c13cb5e54abe68d67512e25ce175c191ce34eaec
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 2
- Signaturschlüssel, die es gebaut haben
- 2
Deklarierte Umgebung
node windows 11 x64 node javascript npm
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-19 |
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-09-07 |
Fall
HOW- Ziel
- compare versions with semver.cmp
- Pakete
- Symbole
-
- semver.cmp
- Umgebung
- node
- Erstellt
- 2026-08-19T05:47:00Z
Contract
- cmp evaluates greater than and greater than or equal comparisons between semantic versions
- cmp evaluates less than and less than or equal comparisons between semantic versions
- cmp evaluates equality and inequality operators correctly
- cmp evaluates strict string identity with triple equals operator
- cmp evaluates prerelease version precedence correctly
- cmp throws TypeError when an invalid comparison operator is provided
Dateien
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
Quelltext
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: compare versions with semver.cmp
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/semver@7.8.5
Demonstrate these symbols/APIs:
- semver.cmp
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@11.8.0
- runtime: node@24.13.1
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:a5f3387091b5d72d82db09eaf78fa3662f488ce6e3670d0afdc2c5958ed8ec8f","constraints":{"executionContext":"node"},"contract":["cmp evaluates greater than and greater than or equal comparisons between semantic versions","cmp evaluates less than and less than or equal comparisons between semantic versions","cmp evaluates equality and inequality operators correctly","cmp evaluates strict string identity with triple equals operator","cmp evaluates prerelease version precedence correctly","cmp throws TypeError when an invalid comparison operator is provided"],"goal":"compare versions with semver.cmp","kind":"HOW","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["semver.cmp"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"javascript","moduleSystem":"cjs","os":"windows","osVersionBucket":"11","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["semver.cmp"],"verifierAdapter":"node-typescript@1"}
const semver = require('semver');
module.exports = {
cmp: semver.cmp
};
{
"name": "sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample",
"version": "1.0.0",
"dependencies": {
"semver": "7.8.5"
}
},
"node_modules/semver": {
"version": "7.8.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
"integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
}
}
}
{
"name": "sample",
"version": "1.0.0",
"private": true,
"main": "index.js",
"dependencies": {
"semver": "7.8.5"
}
}
{
"schemaVersion": 1,
"goal": "compare versions with semver.cmp",
"kind": "HOW",
"packages": [
"pkg:npm/semver@7.8.5"
],
"symbols": [
"semver.cmp"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@11.8.0",
"runtime": "node@24.13.1"
}
}
const assert = require('assert');
const { cmp } = require('../index.js');
// cmp evaluates greater than and greater than or equal comparisons between semantic versions
assert.strictEqual(cmp('1.5.0', '>', '1.2.0'), true);
assert.strictEqual(cmp('1.2.0', '>', '1.5.0'), false);
assert.strictEqual(cmp('1.5.0', '>=', '1.5.0'), true);
assert.strictEqual(cmp('1.5.0', '>=', '1.2.0'), true);
// cmp evaluates less than and less than or equal comparisons between semantic versions
assert.strictEqual(cmp('1.2.0', '<', '1.5.0'), true);
assert.strictEqual(cmp('1.5.0', '<', '1.2.0'), false);
assert.strictEqual(cmp('1.2.0', '<=', '1.2.0'), true);
assert.strictEqual(cmp('1.2.0', '<=', '1.5.0'), true);
// cmp evaluates equality and inequality operators correctly
assert.strictEqual(cmp('1.2.3', '==', 'v1.2.3'), true);
assert.strictEqual(cmp('1.2.3', '=', '1.2.3'), true);
assert.strictEqual(cmp('1.2.3', '!=', '1.2.4'), true);
assert.strictEqual(cmp('1.2.3', '!=', '1.2.3'), false);
assert.strictEqual(cmp('1.2.3', '==', '1.2.3+build123'), true);
// cmp evaluates strict string identity with triple equals operator
assert.strictEqual(cmp('1.2.3', '===', '1.2.3'), true);
assert.strictEqual(cmp('1.2.3', '===', 'v1.2.3'), false);
assert.strictEqual(cmp('1.2.3', '!==', 'v1.2.3'), true);
// cmp evaluates prerelease version precedence correctly
assert.strictEqual(cmp('1.0.0-alpha', '<', '1.0.0'), true);
assert.strictEqual(cmp('1.0.0-beta', '>', '1.0.0-alpha'), true);
assert.strictEqual(cmp('1.0.0-alpha.1', '<', '1.0.0-alpha.2'), true);
// cmp throws TypeError when an invalid comparison operator is provided
assert.throws(() => {
cmp('1.0.0', 'invalid', '1.0.0');
}, TypeError);
console.log('PASS: semver.cmp contract verified');
Ursprungs-Seeder
anonym