CodeSampleX

Пример

content-disposition 0.5.4: contentDisposition, contentDisposition.parse

Проверенный пример — npm content-disposition 0.5.4: contentDisposition, contentDisposition.parse. Контракт выполнен на node 22 · linux debian/x64 · docker и…

sha256:67731d5116dc147af2a04e858f068ac67442119a00c331f3df3860f846e35763

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-09-16

Кейс

HOW
Цель
verify pkg:npm/content-disposition@0.5.4
Пакеты
Символы
  • contentDisposition
  • contentDisposition.parse
Окружение
node 22.23.2
Создан
2026-09-16T22:27:18Z

Контракт

  1. contentDisposition() generates attachment disposition without parameters when called with no arguments
  2. contentDisposition(filename) formats attachment disposition header with quoted basename
  3. contentDisposition(filename, { type }) supports custom disposition types including inline
  4. contentDisposition(filename) generates ISO-8859-1 fallback filename and RFC 5987 UTF-8 encoded filename* parameter for Unicode filenames
  5. contentDisposition(filename, { fallback }) supports custom fallback filename string and boolean false to omit fallback
  6. contentDisposition.parse(header) parses disposition header string into type and parameters map
  7. contentDisposition.parse(header) decodes RFC 5987 extended UTF-8 parameters into standard parameter keys
  8. contentDisposition.parse(header) throws TypeError on invalid arguments or malformed header syntax

Файлы

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

Скачать артефакт с исходным кодом (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/content-disposition@0.5.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/content-disposition@0.5.4

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:340d22c23af8c86647360043db8ef100fac400776345276992b43537eb068ff9","constraints":{"executionContext":"node"},"contract":["contentDisposition() generates attachment disposition without parameters when called with no arguments","contentDisposition(filename) formats attachment disposition header with quoted basename","contentDisposition(filename, { type }) supports custom disposition types including inline","contentDisposition(filename) generates ISO-8859-1 fallback filename and RFC 5987 UTF-8 encoded filename* parameter for Unicode filenames","contentDisposition(filename, { fallback }) supports custom fallback filename string and boolean false to omit fallback","contentDisposition.parse(header) parses disposition header string into type and parameters map","contentDisposition.parse(header) decodes RFC 5987 extended UTF-8 parameters into standard parameter keys","contentDisposition.parse(header) throws TypeError on invalid arguments or malformed header syntax"],"goal":"verify pkg:npm/content-disposition@0.5.4","kind":"HOW","packages":["pkg:npm/content-disposition@0.5.4"],"schemaVersion":1,"symbols":["contentDisposition","contentDisposition.parse"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/content-disposition@0.5.4"],"schemaVersion":1,"subject":"pkg:npm/content-disposition@0.5.4","symbols":["contentDisposition","contentDisposition.parse"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-content-disposition",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-content-disposition",
      "version": "1.0.0",
      "dependencies": {
        "content-disposition": "0.5.4"
      }
    },
    "node_modules/content-disposition": {
      "version": "0.5.4",
      "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
      "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
      "license": "MIT",
      "dependencies": {
        "safe-buffer": "5.2.1"
      },
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/safe-buffer": {
      "version": "5.2.1",
      "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
      "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-content-disposition",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for content-disposition",
  "main": "src/index.js",
  "dependencies": {
    "content-disposition": "0.5.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/content-disposition@0.5.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/content-disposition@0.5.4"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const contentDisposition = require('content-disposition');

/**
 * Format a Content-Disposition header.
 * @param {string} [filename] - File name or path
 * @param {object} [options] - Options object
 * @returns {string} Content-Disposition header value
 */
function createDisposition(filename, options) {
  return contentDisposition(filename, options);
}

/**
 * Parse a Content-Disposition header string.
 * @param {string} header - Header string
 * @returns {{ type: string, parameters: Record<string, string> }} Parsed disposition
 */
function parseDisposition(header) {
  return contentDisposition.parse(header);
}

module.exports = {
  contentDisposition,
  createDisposition,
  parseDisposition
};
test/contract.cjs
const assert = require('node:assert');
const contentDisposition = require('content-disposition');
const { createDisposition, parseDisposition } = require('../src/index.js');

// 1. contentDisposition() generates attachment disposition without parameters when called with no arguments
assert.strictEqual(contentDisposition(), 'attachment');
assert.strictEqual(createDisposition(), 'attachment');

// 2. contentDisposition(filename) formats attachment disposition header with quoted basename
assert.strictEqual(
  contentDisposition('report.pdf'),
  'attachment; filename="report.pdf"'
);
assert.strictEqual(
  contentDisposition('nested/directory/archive.tar.gz'),
  'attachment; filename="archive.tar.gz"'
);

// 3. contentDisposition(filename, { type }) supports custom disposition types including inline
assert.strictEqual(
  contentDisposition('photo.jpg', { type: 'inline' }),
  'inline; filename="photo.jpg"'
);
assert.strictEqual(
  contentDisposition(undefined, { type: 'inline' }),
  'inline'
);

// 4. contentDisposition(filename) generates ISO-8859-1 fallback filename and RFC 5987 UTF-8 encoded filename* parameter for Unicode filenames
assert.strictEqual(
  contentDisposition('€ rates.txt'),
  'attachment; filename="? rates.txt"; filename*=UTF-8\'\'%E2%82%AC%20rates.txt'
);

// 5. contentDisposition(filename, { fallback }) supports custom fallback filename string and boolean false to omit fallback
assert.strictEqual(
  contentDisposition('€ rates.txt', { fallback: 'euro_rates.txt' }),
  'attachment; filename="euro_rates.txt"; filename*=UTF-8\'\'%E2%82%AC%20rates.txt'
);
assert.strictEqual(
  contentDisposition('€ rates.txt', { fallback: false }),
  'attachment; filename*=UTF-8\'\'%E2%82%AC%20rates.txt'
);

// 6. contentDisposition.parse(header) parses disposition header string into type and parameters map
const basicParsed = parseDisposition('attachment; filename="plans.pdf"');
assert.strictEqual(basicParsed.type, 'attachment');
assert.deepStrictEqual(basicParsed.parameters, { filename: 'plans.pdf' });

const inlineParsed = parseDisposition('inline');
assert.strictEqual(inlineParsed.type, 'inline');
assert.deepStrictEqual(inlineParsed.parameters, {});

// 7. contentDisposition.parse(header) decodes RFC 5987 extended UTF-8 parameters into standard parameter keys
const extendedParsed = parseDisposition(
  "attachment; filename=\"EURO rates.txt\"; filename*=UTF-8''%e2%82%ac%20rates.txt"
);
assert.strictEqual(extendedParsed.type, 'attachment');
assert.deepStrictEqual(extendedParsed.parameters, { filename: '€ rates.txt' });

// 8. contentDisposition.parse(header) throws TypeError on invalid arguments or malformed header syntax
assert.throws(() => {
  parseDisposition(null);
}, TypeError);
assert.throws(() => {
  parseDisposition('attachment; filename=');
}, TypeError);

console.log('Contract tests passed successfully.');

Исходный сидер

аноним