CodeSampleX

Exemplo

content-type 3.1.1: parse

Amostra verificada para npm content-type 3.1.1: parse. O contrato rodou em node 22 · linux debian/x64 · docker e passou: parse(header) lowercases the media…

sha256:c4e05f191a42b453469d94ef8b60efc81d5bc4b3b29f8ba98d07299289677750

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-11-03

Caso

HOW
Objetivo
verify content-type.parse in pkg:npm/content-type@3.1.1
Pacotes
Símbolos
  • content-type.parse
Criado
2026-11-03T13:20:56Z

Contrato

  1. parse(header) lowercases the media type and parameter names and returns { type, index, parameters }
  2. parse(header) unquotes and unescapes quoted parameter values and retains the first value when duplicate parameter names appear
  3. parse(header, { parameters: false }) stops at the first semicolon and returns an empty parameters object
  4. parse(header, { comma: true, start }) stops at a comma delimiter and returns the stop index for incremental list parsing

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 content-type.parse in pkg:npm/content-type@3.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/content-type@3.1.1
Demonstrate these symbols/APIs:
  - content-type.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:2c70b468e9815f6824360e09df86dd825b0666aab28b76ee5f5798a6d42e387b","contract":["parse(header) lowercases the media type and parameter names and returns { type, index, parameters }","parse(header) unquotes and unescapes quoted parameter values and retains the first value when duplicate parameter names appear","parse(header, { parameters: false }) stops at the first semicolon and returns an empty parameters object","parse(header, { comma: true, start }) stops at a comma delimiter and returns the stop index for incremental list parsing"],"goal":"verify content-type.parse in pkg:npm/content-type@3.1.1","kind":"HOW","packages":["pkg:npm/content-type@3.1.1"],"schemaVersion":1,"symbols":["content-type.parse"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/content-type@3.1.1"],"schemaVersion":1,"subject":"pkg:npm/content-type@3.1.1","symbols":["content-type.parse"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-content-type-parse",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-content-type-parse",
      "version": "1.0.0",
      "dependencies": {
        "content-type": "3.1.1"
      }
    },
    "node_modules/content-type": {
      "version": "3.1.1",
      "resolved": "https://registry.npmjs.org/content-type/-/content-type-3.1.1.tgz",
      "integrity": "sha512-GW4qUsfFo59d0HbUibDlWv5wPz+vAAcaTWbKIuKCf0JkC7wWkSyf8f13IpXn5JkeMlB2P8iTSSIjwXljorg2vA==",
      "license": "MIT",
      "engines": {
        "node": ">=22"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/express"
      }
    }
  }
}
package.json
{
  "name": "sample-content-type-parse",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "content-type": "3.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify content-type.parse in pkg:npm/content-type@3.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/content-type@3.1.1"
  ],
  "symbols": [
    "content-type.parse"
  ]
}
test/contract.mjs
import assert from "node:assert/strict";
import { parse } from "content-type";

// 1. Parse basic Content-Type with parameters and case normalization
const basic = parse("Text/HTML; Charset=utf-8; boundary=\"something\"");
assert.equal(basic.type, "text/html");
assert.equal(basic.parameters.charset, "utf-8");
assert.equal(basic.parameters.boundary, "something");

// 2. Parse quoted parameter with escaped characters and first-value precedence
const quoted = parse('application/json; param="a\\"b\\\\c"; param="ignored"');
assert.equal(quoted.type, "application/json");
assert.equal(quoted.parameters.param, 'a"b\\c');

// 3. Parse with options: parameters: false (stops at first semicolon without parsing parameters)
const noParams = parse("text/plain; charset=utf-8", { parameters: false });
assert.equal(noParams.type, "text/plain");
assert.deepEqual({ ...noParams.parameters }, {});
assert.equal(noParams.index, 10);

// 4. Parse with options: comma: true and start offset
const listHeader = "text/html; level=1, application/xhtml+xml; q=0.8";
const first = parse(listHeader, { comma: true });
assert.equal(first.type, "text/html");
assert.equal(first.parameters.level, "1");
assert.equal(first.index, 18);

const second = parse(listHeader, { comma: true, start: first.index + 1 });
assert.equal(second.type, "application/xhtml+xml");
assert.equal(second.parameters.q, "0.8");

Seeder de origem

anônimo