CodeSampleX

Ejemplo

semver 7.8.5: Check version satisfaction against ranges, coerce strings into versions, determine range minimum versions, test boundary relations with gtr, ltr, and outside, and extract prerelease components with semver

Muestra verificada para npm semver 7.8.5: Check version satisfaction against ranges, coerce strings into versions, determine range minimum versions, test…

sha256:b7cfd82b032190b07bc561320642a4e4d9ad350b26cdc8f208b45aac52ee2b99

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
2
Claves de firma que lo compilaron
2
Entorno declarado node 22.22 linux 24 · ubuntu · glibc 2.39 x64 node 22.22 javascript npm 11 wsl

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-07

Caso

HOW
Objetivo
Check version satisfaction against ranges, coerce strings into versions, determine range minimum versions, test boundary relations with gtr, ltr, and outside, and extract prerelease components with semver
Paquetes
Símbolos
  • coerce
  • gtr
  • ltr
  • minVersion
  • outside
  • prerelease
  • satisfies
Entorno
node 22.22.2
Creado
2026-08-19T08:23:36Z

Contrato

  1. assert semver.satisfies verifies whether a version satisfies a range expression, including prerelease options
  2. assert semver.coerce parses loose or dirty strings into SemVer objects with standard and right-to-left scanning
  3. assert semver.minVersion determines the lowest version that can satisfy a given range comparator
  4. assert semver.gtr and semver.ltr test whether a version is strictly greater than or less than all versions in a range
  5. assert semver.outside determines whether a version lies above or below range bounds
  6. assert semver.prerelease extracts array components of prerelease identifiers or returns null for release versions

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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: Check version satisfaction against ranges, coerce strings into versions, determine range minimum versions, test boundary relations with gtr, ltr, and outside, and extract prerelease components with semver
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/semver@7.8.5
Demonstrate these symbols/APIs:
  - coerce
  - gtr
  - ltr
  - minVersion
  - outside
  - prerelease
  - satisfies
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@11.8.0
  - runtime: node@22.22.2

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:058e569ea1b7f6b145be5ca91a0e132d81bd231b90f3280d7fe03eb7ae82db8c","constraints":{"executionContext":"node"},"contract":["assert semver.satisfies verifies whether a version satisfies a range expression, including prerelease options","assert semver.coerce parses loose or dirty strings into SemVer objects with standard and right-to-left scanning","assert semver.minVersion determines the lowest version that can satisfy a given range comparator","assert semver.gtr and semver.ltr test whether a version is strictly greater than or less than all versions in a range","assert semver.outside determines whether a version lies above or below range bounds","assert semver.prerelease extracts array components of prerelease identifiers or returns null for release versions"],"goal":"Check version satisfaction against ranges, coerce strings into versions, determine range minimum versions, test boundary relations with gtr, ltr, and outside, and extract prerelease components with semver","kind":"HOW","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["coerce","gtr","ltr","minVersion","outside","prerelease","satisfies"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"11.8.0","runtime":"node","runtimeVersion":"22.22.2","schemaVersion":1,"virtualization":"wsl"},"license":"MIT-0","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["coerce","gtr","ltr","minVersion","outside","prerelease","satisfies"],"verifierAdapter":"node-typescript@1"}
index.mjs
import semver from 'semver';

/**
 * Check if a version satisfies a SemVer range.
 */
export function checkSatisfies(version, range, options = {}) {
  return semver.satisfies(version, range, options);
}

/**
 * Coerce an arbitrary string into a SemVer object.
 */
export function coerceVersion(input, options = {}) {
  return semver.coerce(input, options);
}

/**
 * Find the minimum version that satisfies the given range.
 */
export function getMinVersion(range, options = {}) {
  return semver.minVersion(range, options);
}

/**
 * Check if a version is greater than every version in the range.
 */
export function isGreaterThanRange(version, range, options = {}) {
  return semver.gtr(version, range, options);
}

/**
 * Check if a version is less than every version in the range.
 */
export function isLessThanRange(version, range, options = {}) {
  return semver.ltr(version, range, options);
}

/**
 * Check if a version is outside a range on the given side ('>' or '<').
 */
export function isOutsideRange(version, range, hilo, options = {}) {
  return semver.outside(version, range, hilo, options);
}

/**
 * Extract prerelease components as an array or null.
 */
export function getPrerelease(version, options = {}) {
  return semver.prerelease(version, options);
}
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=="
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "semver": "7.8.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "Check version satisfaction against ranges, coerce strings into versions, determine range minimum versions, test boundary relations with gtr, ltr, and outside, and extract prerelease components with semver",
  "kind": "HOW",
  "packages": [
    "pkg:npm/semver@7.8.5"
  ],
  "symbols": [
    "coerce",
    "gtr",
    "ltr",
    "minVersion",
    "outside",
    "prerelease",
    "satisfies"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@22.22.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import semver from 'semver';
import {
  checkSatisfies,
  coerceVersion,
  getMinVersion,
  isGreaterThanRange,
  isLessThanRange,
  isOutsideRange,
  getPrerelease
} from '../index.mjs';

// 1. assert semver.satisfies verifies whether a version satisfies a range expression, including prerelease options
{
  assert.equal(checkSatisfies('1.2.3', '^1.2.0'), true);
  assert.equal(checkSatisfies('1.3.0', '~1.2.0'), false);
  assert.equal(checkSatisfies('2.0.0', '>=1.0.0 <3.0.0'), true);
  assert.equal(checkSatisfies('1.2.3-alpha.1', '^1.2.0'), false);
  assert.equal(checkSatisfies('1.2.3-alpha.1', '^1.2.0', { includePrerelease: true }), true);
  assert.equal(checkSatisfies('invalid', '^1.0.0'), false);
}

// 2. assert semver.coerce parses loose or dirty strings into SemVer objects with standard and right-to-left scanning
{
  const standard = coerceVersion('v2');
  assert.ok(standard instanceof semver.SemVer);
  assert.equal(standard.version, '2.0.0');

  const dirty = coerceVersion('package 42.6.7.9-rc.1');
  assert.equal(dirty.version, '42.6.7');

  const rtl = coerceVersion('release-1.0.0-final-2.4.6', { rtl: true });
  assert.equal(rtl.version, '2.4.6');

  assert.equal(coerceVersion('no-version-here'), null);
}

// 3. assert semver.minVersion determines the lowest version that can satisfy a given range comparator
{
  const minGte = getMinVersion('>=1.2.3 <2.0.0');
  assert.ok(minGte instanceof semver.SemVer);
  assert.equal(minGte.version, '1.2.3');

  const minGt = getMinVersion('>1.2.3');
  assert.equal(minGt.version, '1.2.4');

  const minCaret = getMinVersion('^2.1.0');
  assert.equal(minCaret.version, '2.1.0');

  const minLessThan = getMinVersion('<1.0.0');
  assert.equal(minLessThan.version, '0.0.0');

  assert.equal(getMinVersion('>1.0.0 <1.0.0'), null);
}

// 4. assert semver.gtr and semver.ltr test whether a version is strictly greater than or less than all versions in a range
{
  assert.equal(isGreaterThanRange('2.0.0', '^1.0.0'), true);
  assert.equal(isGreaterThanRange('1.5.0', '^1.0.0'), false);
  assert.equal(isGreaterThanRange('0.9.0', '^1.0.0'), false);

  assert.equal(isLessThanRange('0.9.0', '^1.0.0'), true);
  assert.equal(isLessThanRange('1.5.0', '^1.0.0'), false);
  assert.equal(isLessThanRange('2.0.0', '^1.0.0'), false);
}

// 5. assert semver.outside determines whether a version lies above or below range bounds
{
  assert.equal(isOutsideRange('2.0.0', '^1.0.0', '>'), true);
  assert.equal(isOutsideRange('2.0.0', '^1.0.0', '<'), false);
  assert.equal(isOutsideRange('0.5.0', '^1.0.0', '<'), true);
  assert.equal(isOutsideRange('0.5.0', '^1.0.0', '>'), false);
  assert.equal(isOutsideRange('1.5.0', '^1.0.0', '>'), false);
  assert.equal(isOutsideRange('1.5.0', '^1.0.0', '<'), false);
}

// 6. assert semver.prerelease extracts array components of prerelease identifiers or returns null for release versions
{
  assert.deepEqual(getPrerelease('1.2.3-alpha.1'), ['alpha', 1]);
  assert.deepEqual(getPrerelease('2.0.0-beta'), ['beta']);
  assert.deepEqual(getPrerelease('3.0.0-rc.2.exp.4'), ['rc', 2, 'exp', 4]);
  assert.equal(getPrerelease('1.2.3'), null);
  assert.equal(getPrerelease('1.2.3+build.123'), null);
  assert.equal(getPrerelease('invalid'), null);
}

console.log('PASS: all contract assertions satisfied');

Seeder de origen

anónimo