CodeSampleX

Sample

semver 7.8.5: clean version strings with semver.clean

Verified sample for npm semver 7.8.5: clean version strings with semver.clean. The contract ran on node 22 · linux alpine/x64 · docker and passed.

sha256:595d0c9524d162f907cefd50bb50779536cdbbb70f5f96467377a547e98b5e56

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
2
Declared environment node windows 11 x64 node javascript npm

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
clean version strings with semver.clean
Packages
Symbols
  • semver.clean
Environment
node
Created
2026-08-18T22:56:57Z

Contract

  1. clean strips leading equals signs and v prefixes from version strings
  2. clean trims surrounding whitespace from version strings
  3. clean preserves valid prerelease identifiers
  4. clean returns null for invalid version strings and range operators
  5. clean supports loose option for non-standard version strings
  6. clean returns null for empty string

Files

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.js

Download the source artifact (tar.gz)

Source

PROMPT.md
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: clean version strings with semver.clean
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/semver@7.8.5
Demonstrate these symbols/APIs:
  - semver.clean
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.
csx.json
{"case":{"caseId":"case:sha256:daac483ef5c725da851ceae52112b30b467ea109d2c0b33966c118767479a77a","constraints":{"executionContext":"node"},"contract":["clean strips leading equals signs and v prefixes from version strings","clean trims surrounding whitespace from version strings","clean preserves valid prerelease identifiers","clean returns null for invalid version strings and range operators","clean supports loose option for non-standard version strings","clean returns null for empty string"],"goal":"clean version strings with semver.clean","kind":"HOW","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["semver.clean"]},"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.clean"],"verifierAdapter":"node-typescript@1"}
index.js
const semver = require('semver');

function cleanVersion(version, options) {
  return semver.clean(version, options);
}

module.exports = {
  clean: semver.clean,
  cleanVersion
};
package-lock.json
{
  "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"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "private": true,
  "main": "index.js",
  "dependencies": {
    "semver": "7.8.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "clean version strings with semver.clean",
  "kind": "HOW",
  "packages": [
    "pkg:npm/semver@7.8.5"
  ],
  "symbols": [
    "semver.clean"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/contract.js
const assert = require('assert');
const { clean, cleanVersion } = require('../index.js');

// Assertion 1: clean strips leading equals signs and v prefixes from version strings
assert.strictEqual(clean('=v1.2.3'), '1.2.3');
assert.strictEqual(clean('v1.2.3'), '1.2.3');
assert.strictEqual(clean('=1.2.3'), '1.2.3');
assert.strictEqual(cleanVersion('===v2.0.0'), '2.0.0');

// Assertion 2: clean trims surrounding whitespace from version strings
assert.strictEqual(clean('  1.2.3  '), '1.2.3');
assert.strictEqual(clean('   =v1.2.3   '), '1.2.3');
assert.strictEqual(cleanVersion('\t=v3.4.5\n'), '3.4.5');

// Assertion 3: clean preserves valid prerelease identifiers
assert.strictEqual(clean('1.2.3-beta.1'), '1.2.3-beta.1');
assert.strictEqual(clean('v2.0.0-alpha.5'), '2.0.0-alpha.5');
assert.strictEqual(cleanVersion('  =v1.0.0-rc.1  '), '1.0.0-rc.1');

// Assertion 4: clean returns null for invalid version strings and range operators
assert.strictEqual(clean('~1.2.3'), null);
assert.strictEqual(clean('^1.2.3'), null);
assert.strictEqual(clean('>=1.2.3'), null);
assert.strictEqual(clean('invalid'), null);
assert.strictEqual(cleanVersion('1.2.x'), null);

// Assertion 5: clean supports loose option for non-standard version strings
assert.strictEqual(clean('  =v1.2.3-4  ', { loose: true }), '1.2.3-4');
assert.strictEqual(cleanVersion(' =v2.0.0-01 ', { loose: true }), '2.0.0-1');

// Assertion 6: clean returns null for empty string
assert.strictEqual(clean(''), null);
assert.strictEqual(clean('   '), null);
assert.strictEqual(cleanVersion(''), null);

console.log('PASS: all contract assertions passed for semver.clean');

Origin Seeder

anonymous