CodeSampleX

Sample

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

Verified sample for npm media-typer 1.1.1: mediaTyper.format, mediaTyper.parse, mediaTyper.test. The contract ran on node 22 · linux alpine/x64 · docker and…

sha256:d77583129a34992bd73a7f234e7e203c37b6d5ff53a8f19877dac9291cdf1e26

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment windows 11 x64 npm

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify pkg:npm/media-typer@1.1.1
Packages
Symbols
  • mediaTyper.format
  • mediaTyper.parse
  • mediaTyper.test
Created
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

Files

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

Download the source artifact (tar.gz)

Source

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.');

Origin Seeder

anonymous