Exemple
media-typer 1.1.1: mediaTyper.format, mediaTyper.parse, mediaTyper.test
Échantillon vérifié pour npm media-typer 1.1.1: mediaTyper.format, mediaTyper.parse, mediaTyper.test. Le contrat s'est exécuté sur node 22 · linux alpine/x64…
sha256:d77583129a34992bd73a7f234e7e203c37b6d5ff53a8f19877dac9291cdf1e26
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
windows 11 x64 npm
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify pkg:npm/media-typer@1.1.1
- Paquets
- Symboles
-
- mediaTyper.format
- mediaTyper.parse
- mediaTyper.test
- Créé
- 2026-08-18T18:22:25Z
Contrat
- mediaTyper.parse parses valid media type strings into type, subtype, and optional suffix
- mediaTyper.format formats media type descriptor objects into RFC 6838 media type strings
- mediaTyper.test validates whether a string conforms to RFC 6838 media type syntax
- mediaTyper.parse and mediaTyper.format throw TypeError on invalid input values
Fichiers
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
Code source
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: verify pkg:npm/media-typer@1.1.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/media-typer@1.1.1
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:c24b3ef76622798d08ef84061e83f995ba80101e09b7f9654eb5bb45b9ea7411","constraints":{"executionContext":"node"},"contract":["mediaTyper.parse parses valid media type strings into type, subtype, and optional suffix","mediaTyper.format formats media type descriptor objects into RFC 6838 media type strings","mediaTyper.test validates whether a string conforms to RFC 6838 media type syntax","mediaTyper.parse and mediaTyper.format throw TypeError on invalid input values"],"goal":"verify pkg:npm/media-typer@1.1.1","kind":"HOW","packages":["pkg:npm/media-typer@1.1.1"],"schemaVersion":1,"symbols":["mediaTyper.format","mediaTyper.parse","mediaTyper.test"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/media-typer@1.1.1"],"schemaVersion":1,"symbols":["mediaTyper.format","mediaTyper.parse","mediaTyper.test"],"verifierAdapter":"node-typescript@1"}
const mediaTyper = require('media-typer');
/**
* Parse media type string into an object containing type, subtype, and suffix.
* @param {string} string
* @returns {{ type: string, subtype: string, suffix?: string }}
*/
function parseMediaType(string) {
return mediaTyper.parse(string);
}
/**
* Format media type object into a media type string.
* @param {{ type: string, subtype: string, suffix?: string }} obj
* @returns {string}
*/
function formatMediaType(obj) {
return mediaTyper.format(obj);
}
/**
* Test if a string is a valid media type.
* @param {string} string
* @returns {boolean}
*/
function testMediaType(string) {
return mediaTyper.test(string);
}
module.exports = {
parseMediaType,
formatMediaType,
testMediaType
};
{
"name": "sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample",
"version": "1.0.0",
"dependencies": {
"media-typer": "1.1.1"
}
},
"node_modules/media-typer": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.1.tgz",
"integrity": "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
}
}
}
{
"name": "sample",
"version": "1.0.0",
"dependencies": {
"media-typer": "1.1.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/media-typer@1.1.1",
"kind": "HOW",
"packages": [
"pkg:npm/media-typer@1.1.1"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@11.8.0",
"runtime": "node@24.13.1"
}
}
const assert = require('node:assert/strict');
const mediaTyper = require('media-typer');
const { parseMediaType, formatMediaType, testMediaType } = require('../index.js');
// Contract 1: mediaTyper.parse parses valid media type strings into type, subtype, and optional suffix
{
const parsed1 = parseMediaType('application/json');
assert.equal(parsed1.type, 'application');
assert.equal(parsed1.subtype, 'json');
assert.equal(parsed1.suffix, undefined);
const parsed2 = parseMediaType('application/vnd.api+json');
assert.equal(parsed2.type, 'application');
assert.equal(parsed2.subtype, 'vnd.api');
assert.equal(parsed2.suffix, 'json');
const parsed3 = parseMediaType('image/svg+xml');
assert.equal(parsed3.type, 'image');
assert.equal(parsed3.subtype, 'svg');
assert.equal(parsed3.suffix, 'xml');
const parsedDirect = mediaTyper.parse('text/html');
assert.equal(parsedDirect.type, 'text');
assert.equal(parsedDirect.subtype, 'html');
assert.equal(parsedDirect.suffix, undefined);
}
// Contract 2: mediaTyper.format formats media type descriptor objects into RFC 6838 media type strings
{
const formatted1 = formatMediaType({ type: 'application', subtype: 'json' });
assert.equal(formatted1, 'application/json');
const formatted2 = formatMediaType({ type: 'application', subtype: 'vnd.api', suffix: 'json' });
assert.equal(formatted2, 'application/vnd.api+json');
const formatted3 = formatMediaType({ type: 'image', subtype: 'svg', suffix: 'xml' });
assert.equal(formatted3, 'image/svg+xml');
const formattedDirect = mediaTyper.format({ type: 'text', subtype: 'plain' });
assert.equal(formattedDirect, 'text/plain');
}
// Contract 3: mediaTyper.test validates whether a string conforms to RFC 6838 media type syntax
{
assert.equal(testMediaType('application/json'), true);
assert.equal(testMediaType('application/vnd.api+json'), true);
assert.equal(testMediaType('text/html'), true);
assert.equal(testMediaType('invalid media type'), false);
assert.equal(testMediaType('application/'), false);
assert.equal(testMediaType('/json'), false);
assert.equal(mediaTyper.test('image/png'), true);
assert.equal(mediaTyper.test('not-a-media-type'), false);
}
// Contract 4: mediaTyper.parse and mediaTyper.format throw TypeError on invalid input values
{
assert.throws(() => parseMediaType('invalid-media-type'), TypeError);
assert.throws(() => parseMediaType(null), TypeError);
assert.throws(() => parseMediaType(123), TypeError);
assert.throws(() => formatMediaType(null), TypeError);
assert.throws(() => formatMediaType({ type: 'invalid type', subtype: 'json' }), TypeError);
assert.throws(() => formatMediaType({ type: 'application', subtype: 'invalid/subtype' }), TypeError);
assert.throws(() => formatMediaType({ type: 'application', subtype: 'json', suffix: 'invalid+suffix' }), TypeError);
}
console.log('All media-typer contract assertions passed successfully.');
Seeder d'origine
anonyme