CodeSampleX

Beispiel

content-type 1.0.5: parse and format HTTP Content-Type header with parameters

Verifiziertes Beispiel für npm content-type 1.0.5: parse and format HTTP Content-Type header with parameters. Der Vertrag lief auf node 22 · linux alpine/x64…

sha256:40a665399a0d0b1fe0a3e3bf85ac8168e9486eaa439d59b6640c90d3802fcda2

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
parse and format HTTP Content-Type header with parameters
Pakete
Symbole
  • contentType.format
  • contentType.parse
Erstellt
2026-08-18T17:50:37Z

Contract

  1. contentType.parse parses media type and parameters from Content-Type header string
  2. contentType.parse extracts Content-Type from HTTP request header object
  3. contentType.format formats type and parameters into Content-Type header string
  4. contentType.format formats media type without parameters

Dateien

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

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: parse and format HTTP Content-Type header with parameters
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/content-type@1.0.5
Demonstrate these symbols/APIs:
  - contentType.format
  - contentType.parse

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:791314ac9aa80f762d751646446590f89c777a695dc2da654559cb215d2124e2","contract":["contentType.parse parses media type and parameters from Content-Type header string","contentType.parse extracts Content-Type from HTTP request header object","contentType.format formats type and parameters into Content-Type header string","contentType.format formats media type without parameters"],"goal":"parse and format HTTP Content-Type header with parameters","kind":"HOW","packages":["pkg:npm/content-type@1.0.5"],"schemaVersion":1,"symbols":["contentType.format","contentType.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/content-type@1.0.5"],"schemaVersion":1,"symbols":["contentType.format","contentType.parse"],"verifierAdapter":"node-typescript@1"}
index.mjs
import contentType from 'content-type';

/**
 * Parse an HTTP Content-Type header string or request/response object.
 * @param {string|object} header
 * @returns {{ type: string, parameters: Record<string, string> }}
 */
export function parseContentType(header) {
  return contentType.parse(header);
}

/**
 * Format a media type and parameters into a Content-Type header string.
 * @param {string} type
 * @param {Record<string, string>} [parameters]
 * @returns {string}
 */
export function formatContentType(type, parameters) {
  const obj = { type };
  if (parameters) {
    obj.parameters = parameters;
  }
  return contentType.format(obj);
}
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "content-type": "1.0.5"
      }
    },
    "node_modules/content-type": {
      "version": "1.0.5",
      "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
      "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "content-type": "1.0.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "parse and format HTTP Content-Type header with parameters",
  "kind": "HOW",
  "packages": [
    "pkg:npm/content-type@1.0.5"
  ],
  "symbols": [
    "contentType.format",
    "contentType.parse"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import contentType from 'content-type';

// Contract 1: contentType.parse parses media type and parameters from Content-Type header string
{
  const parsed = contentType.parse('text/html; charset=utf-8; foo=bar');
  assert.equal(parsed.type, 'text/html');
  assert.equal(parsed.parameters.charset, 'utf-8');
  assert.equal(parsed.parameters.foo, 'bar');
}

// Contract 2: contentType.parse extracts Content-Type from HTTP request header object
{
  const req = {
    headers: {
      'content-type': 'application/json; charset=utf-8'
    }
  };
  const parsed = contentType.parse(req);
  assert.equal(parsed.type, 'application/json');
  assert.equal(parsed.parameters.charset, 'utf-8');
}

// Contract 3: contentType.format formats type and parameters into Content-Type header string
{
  const formatted = contentType.format({
    type: 'text/html',
    parameters: { charset: 'utf-8' }
  });
  assert.equal(formatted, 'text/html; charset=utf-8');
}

// Contract 4: contentType.format formats media type without parameters
{
  const formatted = contentType.format({
    type: 'application/json'
  });
  assert.equal(formatted, 'application/json');
}

console.log('All contract assertions passed successfully.');

Ursprungs-Seeder

anonym