샘플
semver 7.8.5: coerce loose version strings into valid semver with semver.coerce
검증된 샘플 — npm semver 7.8.5: coerce loose version strings into valid semver with semver.coerce. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:e12c401ab9754a0e13f9dd7e06ce765eb0ec770294e2d37692c7bde116e07b8f
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 2
선언된 환경
windows 11 x64 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- 목표
- coerce loose version strings into valid semver with semver.coerce
- 패키지
- 심벌
-
- semver.coerce
- 생성일
- 2026-08-18T22:37:09Z
컨트랙트
- semver.coerce parses short or partial version strings into valid SemVer objects with zero-filled minor and patch
- semver.coerce extracts valid SemVer versions from strings containing surrounding text and multiple version segments
- semver.coerce supports right-to-left parsing with the rtl option
- semver.coerce preserves prerelease tags when includePrerelease option is true
- semver.coerce returns null for non-version strings that contain no valid numeric version pattern
파일
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
소스
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: coerce loose version strings into valid semver with semver.coerce
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/semver@7.8.5
Demonstrate these symbols/APIs:
- semver.coerce
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:afbf314f3cac02c3147715d2bcc1090bf6b613ff44f03b15fe035384f2b70e06","constraints":{"executionContext":"node"},"contract":["semver.coerce parses short or partial version strings into valid SemVer objects with zero-filled minor and patch","semver.coerce extracts valid SemVer versions from strings containing surrounding text and multiple version segments","semver.coerce supports right-to-left parsing with the rtl option","semver.coerce preserves prerelease tags when includePrerelease option is true","semver.coerce returns null for non-version strings that contain no valid numeric version pattern"],"goal":"coerce loose version strings into valid semver with semver.coerce","kind":"HOW","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["semver.coerce"]},"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.coerce"],"verifierAdapter":"node-typescript@1"}
import semver from 'semver';
/**
* Coerces a string or number into a SemVer object if possible.
* @param {string | number} input
* @param {semver.CoerceOptions} [options]
* @returns {semver.SemVer | null}
*/
export function coerceVersion(input, options) {
return semver.coerce(input, options);
}
export default {
coerceVersion
};
{
"name": "sample-semver-coerce",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-semver-coerce",
"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-coerce",
"version": "1.0.0",
"type": "module",
"dependencies": {
"semver": "7.8.5"
}
}
{
"schemaVersion": 1,
"goal": "coerce loose version strings into valid semver with semver.coerce",
"kind": "HOW",
"packages": [
"pkg:npm/semver@7.8.5"
],
"symbols": [
"semver.coerce"
],
"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 from 'semver';
import { coerceVersion } from '../index.mjs';
// Verify semver.coerce function contract
assert.equal(typeof semver.coerce, 'function', 'semver.coerce must be a function');
assert.equal(typeof coerceVersion, 'function', 'coerceVersion must be a function');
// Contract 1: semver.coerce parses short or partial version strings into valid SemVer objects with zero-filled minor and patch
{
const coercedV2 = semver.coerce('v2');
assert.notEqual(coercedV2, null);
assert.equal(coercedV2.version, '2.0.0');
assert.equal(coercedV2.major, 2);
assert.equal(coercedV2.minor, 0);
assert.equal(coercedV2.patch, 0);
const coercedMinor = semver.coerce('1.2');
assert.notEqual(coercedMinor, null);
assert.equal(coercedMinor.version, '1.2.0');
const coercedNum = semver.coerce(42);
assert.notEqual(coercedNum, null);
assert.equal(coercedNum.version, '42.0.0');
const helperResult = coerceVersion('v3.5');
assert.notEqual(helperResult, null);
assert.equal(helperResult.version, '3.5.0');
}
// Contract 2: semver.coerce extracts valid SemVer versions from strings containing surrounding text and multiple version segments
{
const coercedPrefix = semver.coerce('release-2.4.1.8');
assert.notEqual(coercedPrefix, null);
assert.equal(coercedPrefix.version, '2.4.1');
const coercedText = semver.coerce('app version 3.14.15 build 99');
assert.notEqual(coercedText, null);
assert.equal(coercedText.version, '3.14.15');
const helperText = coerceVersion('build-v1.0.4-rc1');
assert.notEqual(helperText, null);
assert.equal(helperText.version, '1.0.4');
}
// Contract 3: semver.coerce supports right-to-left parsing with the rtl option
{
const standardLtr = semver.coerce('1.2.3.4');
assert.notEqual(standardLtr, null);
assert.equal(standardLtr.version, '1.2.3');
const parsedRtl = semver.coerce('1.2.3.4', { rtl: true });
assert.notEqual(parsedRtl, null);
assert.equal(parsedRtl.version, '2.3.4');
const helperRtl = coerceVersion('release-1.0.0-final-2.0.0', { rtl: true });
assert.notEqual(helperRtl, null);
assert.equal(helperRtl.version, '2.0.0');
}
// Contract 4: semver.coerce preserves prerelease tags when includePrerelease option is true
{
const strippedPrerelease = semver.coerce('1.2.3-alpha.1');
assert.notEqual(strippedPrerelease, null);
assert.equal(strippedPrerelease.version, '1.2.3');
assert.deepEqual(strippedPrerelease.prerelease, []);
const preservedPrerelease = semver.coerce('1.2.3-alpha.1', { includePrerelease: true });
assert.notEqual(preservedPrerelease, null);
assert.equal(preservedPrerelease.raw, '1.2.3-alpha.1');
assert.deepEqual(preservedPrerelease.prerelease, ['alpha', 1]);
const helperPrerelease = coerceVersion('2.0.0-beta.2', { includePrerelease: true });
assert.notEqual(helperPrerelease, null);
assert.equal(helperPrerelease.raw, '2.0.0-beta.2');
}
// Contract 5: semver.coerce returns null for non-version strings that contain no valid numeric version pattern
{
assert.equal(semver.coerce('invalid-string'), null);
assert.equal(semver.coerce(''), null);
assert.equal(semver.coerce('no-digits-here'), null);
assert.equal(coerceVersion('xyz'), null);
}
console.log('semver.coerce contract verified successfully.');
오리진 시더
익명