サンプル
semver 7.8.5: compare versions with semver.cmp
検証済みサンプル — npm semver 7.8.5: compare versions with semver.cmp. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: cmp evaluates greater than and…
sha256:7d75d056ba45c0de70ba39b7c13cb5e54abe68d67512e25ce175c191ce34eaec
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 2
- ビルドした署名鍵
- 2
宣言された環境
node windows 11 x64 node javascript npm
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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 |
ケース
HOW- ゴール
- compare versions with semver.cmp
- パッケージ
- シンボル
-
- semver.cmp
- 環境
- node
- 作成日
- 2026-08-19T05:47:00Z
コントラクト
- 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
ファイル
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
ソース
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');
オリジンシーダー
匿名