CodeSampleX

샘플

media-typer 0.3.0

검증된 샘플 — npm media-typer 0.3.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: mediaTyper.parse parses a media type string into type, subtype…

sha256:7f27940dbda0abff5d5ff727693c058106c5f65e678dbd7bc8db58090d9d8946

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 windows 10 x64 npm vm

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

케이스

HOW
목표
verify pkg:npm/media-typer@0.3.0
패키지
생성일
2026-08-20T00:36:54Z

컨트랙트

  1. mediaTyper.parse parses a media type string into type, subtype, suffix, and parameters
  2. mediaTyper.format formats a media type object into a media type string
  3. mediaTyper.parse and format throw TypeError for invalid media types

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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@0.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/media-typer@0.3.0

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:87bab51dfd8371addd9f30cadb64b562db97d1efa4ac3039bb1b5361a24624af","contract":["mediaTyper.parse parses a media type string into type, subtype, suffix, and parameters","mediaTyper.format formats a media type object into a media type string","mediaTyper.parse and format throw TypeError for invalid media types"],"goal":"verify pkg:npm/media-typer@0.3.0","kind":"HOW","packages":["pkg:npm/media-typer@0.3.0"],"schemaVersion":1,"symbols":["media-typer.parse","media-typer.format"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"10","packageManager":"npm","schemaVersion":1,"virtualization":"vm"},"license":"MIT-0","packages":["pkg:npm/media-typer@0.3.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "media-typer": "0.3.0"
      }
    },
    "node_modules/media-typer": {
      "version": "0.3.0",
      "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
      "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
      "engines": {
        "node": ">= 0.6"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "media-typer": "0.3.0"
  }
}
sample.mjs
import typer from 'media-typer';

/**
 * Parses a media type string into an object describing its components.
 * @param {string} mediaType - Media type string (e.g., 'application/json; charset=utf-8')
 * @returns {{ type: string, subtype: string, suffix?: string, parameters: Record<string, string> }}
 */
export function parseMediaType(mediaType) {
  return typer.parse(mediaType);
}

/**
 * Formats a media type object into a media type string.
 * @param {{ type: string, subtype: string, suffix?: string, parameters?: Record<string, string> }} obj
 * @returns {string}
 */
export function formatMediaType(obj) {
  return typer.format(obj);
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/media-typer@0.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/media-typer@0.3.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import typer from 'media-typer';
import { parseMediaType, formatMediaType } from '../sample.mjs';

function testParseMediaType() {
  const parsed1 = parseMediaType('application/json');
  assert.equal(parsed1.type, 'application');
  assert.equal(parsed1.subtype, 'json');
  assert.equal(parsed1.suffix, undefined);
  assert.deepEqual(parsed1.parameters, {});

  const parsed2 = parseMediaType('application/vnd.api+json; charset=utf-8');
  assert.equal(parsed2.type, 'application');
  assert.equal(parsed2.subtype, 'vnd.api');
  assert.equal(parsed2.suffix, 'json');
  assert.deepEqual(parsed2.parameters, { charset: 'utf-8' });

  const parsed3 = typer.parse('image/svg+xml; q=0.8');
  assert.equal(parsed3.type, 'image');
  assert.equal(parsed3.subtype, 'svg');
  assert.equal(parsed3.suffix, 'xml');
  assert.deepEqual(parsed3.parameters, { q: '0.8' });

  console.log('Contract 1 passed: parseMediaType parses media types correctly');
}

function testFormatMediaType() {
  const formatted1 = formatMediaType({ type: 'text', subtype: 'html' });
  assert.equal(formatted1, 'text/html');

  const formatted2 = formatMediaType({ type: 'image', subtype: 'svg', suffix: 'xml' });
  assert.equal(formatted2, 'image/svg+xml');

  const formatted3 = typer.format({
    type: 'application',
    subtype: 'json',
    parameters: { charset: 'utf-8', q: '1' }
  });
  assert.equal(formatted3, 'application/json; charset=utf-8; q=1');

  console.log('Contract 2 passed: formatMediaType formats objects into media type strings');
}

function testInvalidInputs() {
  assert.throws(() => {
    parseMediaType('invalid type');
  }, TypeError);

  assert.throws(() => {
    parseMediaType('');
  }, TypeError);

  assert.throws(() => {
    formatMediaType({ type: 'invalid type', subtype: 'json' });
  }, TypeError);

  assert.throws(() => {
    formatMediaType(null);
  }, TypeError);

  console.log('Contract 3 passed: validation errors thrown for invalid inputs');
}

function main() {
  testParseMediaType();
  testFormatMediaType();
  testInvalidInputs();
  console.log('All contracts passed successfully.');
}

main();

오리진 시더

익명