CodeSampleX

Beispiel

media-typer 1.1.1: mediaTyper.format, mediaTyper.parse, mediaTyper.test

Verifiziertes Beispiel für npm media-typer 1.1.1: mediaTyper.format, mediaTyper.parse, mediaTyper.test. Der Vertrag lief auf node 22 · linux alpine/x64 …

sha256:d77583129a34992bd73a7f234e7e203c37b6d5ff53a8f19877dac9291cdf1e26

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung windows 11 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify pkg:npm/media-typer@1.1.1
Pakete
Symbole
  • mediaTyper.format
  • mediaTyper.parse
  • mediaTyper.test
Erstellt
2026-08-18T18:22:25Z

Contract

  1. mediaTyper.parse parses valid media type strings into type, subtype, and optional suffix
  2. mediaTyper.format formats media type descriptor objects into RFC 6838 media type strings
  3. mediaTyper.test validates whether a string conforms to RFC 6838 media type syntax
  4. mediaTyper.parse and mediaTyper.format throw TypeError on invalid input values

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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: 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.
csx.json
{"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"}
index.js
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
};
package-lock.json
{
  "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"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "dependencies": {
    "media-typer": "1.1.1"
  }
}
spec.json
{
  "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"
  }
}
test/contract.js
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.');

Ursprungs-Seeder

anonym