Exemplo
semver 7.8.5: parse and inspect semantic versions with semver.parse and SemVer
Amostra verificada para npm semver 7.8.5: parse and inspect semantic versions with semver.parse and SemVer. O contrato rodou em node 22 · linux alpine/x64 …
sha256:f5c202e86faa222a55afd210da4eb53c1589e1be62d9f9362ad772f07b34893d
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 2
- Chaves de assinatura que o compilaram
- 2
Ambiente declarado
windows 11 x64 npm
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- parse and inspect semantic versions with semver.parse and SemVer
- Pacotes
- Símbolos
-
- SemVer
- semver.parse
- Criado
- 2026-08-18T23:43:41Z
Contrato
- semver.parse decomposes valid version strings into major, minor, patch, prerelease, and build metadata
- semver.parse handles loose formatting and leading characters when loose option is specified
- semver.parse returns null for invalid semver strings
- SemVer constructor creates instances and supports comparison and formatting methods
- SemVer instance inc method increments release version components in place
Arquivos
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código-fonte
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: parse and inspect semantic versions with semver.parse and SemVer
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/semver@7.8.5
Demonstrate these symbols/APIs:
- SemVer
- semver.parse
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:e91030501045b1edf39989edaa5fb3a490315819f89d165e9dd8f4a894bfefe7","contract":["semver.parse decomposes valid version strings into major, minor, patch, prerelease, and build metadata","semver.parse handles loose formatting and leading characters when loose option is specified","semver.parse returns null for invalid semver strings","SemVer constructor creates instances and supports comparison and formatting methods","SemVer instance inc method increments release version components in place"],"goal":"parse and inspect semantic versions with semver.parse and SemVer","kind":"HOW","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["SemVer","semver.parse"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["SemVer","semver.parse"],"verifierAdapter":"node-typescript@1"}
import semver, { SemVer } from 'semver';
/**
* Parses a version string into a SemVer object.
* @param {string} version
* @param {semver.Options} [options]
* @returns {semver.SemVer | null}
*/
export function parseVersion(version, options) {
return semver.parse(version, options);
}
/**
* Creates a new SemVer instance directly using the SemVer class.
* @param {string | semver.SemVer} version
* @param {semver.Options} [options]
* @returns {semver.SemVer}
*/
export function createSemVer(version, options) {
return new SemVer(version, options);
}
export default {
parseVersion,
createSemVer,
SemVer
};
{
"name": "sample-semver-parse",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-semver-parse",
"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-semver-parse",
"version": "1.0.0",
"type": "module",
"dependencies": {
"semver": "7.8.5"
}
}
{
"schemaVersion": 1,
"goal": "parse and inspect semantic versions with semver.parse and SemVer",
"kind": "HOW",
"packages": [
"pkg:npm/semver@7.8.5"
],
"symbols": [
"SemVer",
"semver.parse"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@11.8.0",
"runtime": "node@24.13.1"
}
}
import assert from 'node:assert/strict';
import semver, { SemVer } from 'semver';
import { parseVersion, createSemVer } from '../index.mjs';
// Verify symbols and exported helpers
assert.equal(typeof semver.parse, 'function', 'semver.parse must be a function');
assert.equal(typeof SemVer, 'function', 'SemVer must be a constructor function');
assert.equal(typeof parseVersion, 'function', 'parseVersion must be a function');
assert.equal(typeof createSemVer, 'function', 'createSemVer must be a function');
// Contract 1: semver.parse decomposes valid version strings into major, minor, patch, prerelease, and build metadata
{
const parsed = semver.parse('1.2.3-alpha.1+build.42');
assert.notEqual(parsed, null);
assert.equal(parsed.major, 1);
assert.equal(parsed.minor, 2);
assert.equal(parsed.patch, 3);
assert.deepEqual(parsed.prerelease, ['alpha', 1]);
assert.deepEqual(parsed.build, ['build', '42']);
assert.equal(parsed.version, '1.2.3-alpha.1');
assert.equal(parsed.raw, '1.2.3-alpha.1+build.42');
const helperParsed = parseVersion('2.0.1-rc.2');
assert.notEqual(helperParsed, null);
assert.equal(helperParsed.major, 2);
assert.equal(helperParsed.minor, 0);
assert.equal(helperParsed.patch, 1);
assert.deepEqual(helperParsed.prerelease, ['rc', 2]);
}
// Contract 2: semver.parse handles loose formatting and leading characters when loose option is specified
{
const looseParsed = semver.parse(' =v1.2.3 ', { loose: true });
assert.notEqual(looseParsed, null);
assert.equal(looseParsed.version, '1.2.3');
assert.equal(looseParsed.major, 1);
assert.equal(looseParsed.minor, 2);
assert.equal(looseParsed.patch, 3);
const helperLoose = parseVersion('v2.3.4', { loose: false });
assert.notEqual(helperLoose, null);
assert.equal(helperLoose.version, '2.3.4');
}
// Contract 3: semver.parse returns null for invalid semver strings
{
assert.equal(semver.parse('not-a-valid-version'), null);
assert.equal(semver.parse('1.2.3.4'), null);
assert.equal(semver.parse(''), null);
assert.equal(parseVersion(null), null);
assert.equal(parseVersion(undefined), null);
}
// Contract 4: SemVer constructor creates instances and supports comparison and formatting methods
{
const sv1 = new SemVer('1.2.3');
const sv2 = createSemVer('2.0.0');
assert.equal(sv1 instanceof SemVer, true);
assert.equal(sv2 instanceof SemVer, true);
assert.equal(sv1.format(), '1.2.3');
assert.equal(sv2.format(), '2.0.0');
assert.equal(sv1.compare(sv2), -1);
assert.equal(sv2.compare(sv1), 1);
assert.equal(sv1.compare('1.2.3'), 0);
}
// Contract 5: SemVer instance inc method increments release version components in place
{
const sv = new SemVer('1.0.0');
sv.inc('minor');
assert.equal(sv.version, '1.1.0');
assert.equal(sv.minor, 1);
sv.inc('patch');
assert.equal(sv.version, '1.1.1');
assert.equal(sv.patch, 1);
sv.inc('major');
assert.equal(sv.version, '2.0.0');
assert.equal(sv.major, 2);
}
console.log('semver.parse and SemVer contracts verified successfully.');
Seeder de origem
anônimo