CodeSampleX

示例

mime-db 1.54.0

已验证示例 — npm mime-db 1.54.0. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: mime-db contains standard MIME type entries with source, extensions…

sha256:09c1ef55abc26fb5d675288ee8ba2dc4fd875ded538d421dd0c3791a7f16cea5

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 windows 11 x64 npm

验证运行环境

环境 契约 阶段 运行日期
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

案例

HOW
目标
verify pkg:npm/mime-db@1.54.0
包
创建时间
2026-08-18T18:10:20Z

契约

  1. mime-db contains standard MIME type entries with source, extensions, charset, and compressible metadata
  2. db['application/json'] defines charset UTF-8, compressible true, and json extension
  3. db['text/html'] defines compressible true and html, htm extensions
  4. db['image/png'] defines non-compressible media type with png extension
  5. lookup retrieves MIME metadata for registered types and returns undefined for unknown types
  6. findTypeByExtension maps file extensions to corresponding media types
  7. isCompressible correctly identifies compressible text and data formats
  8. getExtensions retrieves all associated file extensions for a given MIME type

文件

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • 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/mime-db@1.54.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/mime-db@1.54.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:b3849d76cf31ccf2829ffb23ad948d8019d09175d758ce809ba865e0ef61a25f","contract":["mime-db contains standard MIME type entries with source, extensions, charset, and compressible metadata","db['application/json'] defines charset UTF-8, compressible true, and json extension","db['text/html'] defines compressible true and html, htm extensions","db['image/png'] defines non-compressible media type with png extension","lookup retrieves MIME metadata for registered types and returns undefined for unknown types","findTypeByExtension maps file extensions to corresponding media types","isCompressible correctly identifies compressible text and data formats","getExtensions retrieves all associated file extensions for a given MIME type"],"goal":"verify pkg:npm/mime-db@1.54.0","kind":"HOW","packages":["pkg:npm/mime-db@1.54.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/mime-db@1.54.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
index.mjs
import db from 'mime-db';

/**
 * Returns the MIME type entry for a given media type.
 * @param {string} type
 * @returns {object|undefined}
 */
export function lookup(type) {
  return db[type.toLowerCase()];
}

/**
 * Finds the first MIME type that has the given file extension.
 * @param {string} extension
 * @returns {string|undefined}
 */
export function findTypeByExtension(extension) {
  const ext = extension.toLowerCase().replace(/^\./, '');
  for (const [type, data] of Object.entries(db)) {
    if (data.extensions && data.extensions.includes(ext)) {
      return type;
    }
  }
  return undefined;
}

/**
 * Checks if a given MIME type is marked as compressible.
 * @param {string} type
 * @returns {boolean}
 */
export function isCompressible(type) {
  const entry = db[type.toLowerCase()];
  return Boolean(entry && entry.compressible);
}

/**
 * Returns the file extensions associated with a given MIME type.
 * @param {string} type
 * @returns {string[]}
 */
export function getExtensions(type) {
  const entry = db[type.toLowerCase()];
  return entry && entry.extensions ? [...entry.extensions] : [];
}

/**
 * Returns the default charset for a given MIME type.
 * @param {string} type
 * @returns {string|undefined}
 */
export function getCharset(type) {
  const entry = db[type.toLowerCase()];
  return entry ? entry.charset : undefined;
}

export { db };
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "mime-db": "1.54.0"
      }
    },
    "node_modules/mime-db": {
      "version": "1.54.0",
      "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz",
      "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "mime-db": "1.54.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/mime-db@1.54.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/mime-db@1.54.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import db from 'mime-db';
import {
  lookup,
  findTypeByExtension,
  isCompressible,
  getExtensions,
  getCharset,
  db as exportedDb
} from '../index.mjs';

// Case 1: database contains standard MIME entries
{
  assert.equal(typeof db, 'object', 'mime-db export must be an object');
  assert(Object.keys(db).length > 1000, 'mime-db should contain thousands of MIME type entries');
  assert.equal(exportedDb, db, 'exported db must match imported db');
}

// Case 2: application/json entry validation
{
  const jsonEntry = db['application/json'];
  assert.ok(jsonEntry, 'application/json entry must exist');
  assert.equal(jsonEntry.source, 'iana', 'application/json source must be iana');
  assert.equal(jsonEntry.charset, 'UTF-8', 'application/json charset must be UTF-8');
  assert.equal(jsonEntry.compressible, true, 'application/json must be compressible');
  assert.ok(Array.isArray(jsonEntry.extensions), 'application/json extensions must be an array');
  assert(jsonEntry.extensions.includes('json'), 'application/json must include "json" extension');
}

// Case 3: text/html entry validation
{
  const htmlEntry = db['text/html'];
  assert.ok(htmlEntry, 'text/html entry must exist');
  assert.equal(htmlEntry.source, 'iana', 'text/html source must be iana');
  assert.equal(htmlEntry.compressible, true, 'text/html must be compressible');
  assert.ok(htmlEntry.extensions.includes('html'), 'text/html extensions must include "html"');
  assert.ok(htmlEntry.extensions.includes('htm'), 'text/html extensions must include "htm"');
}

// Case 4: image/png entry validation
{
  const pngEntry = db['image/png'];
  assert.ok(pngEntry, 'image/png entry must exist');
  assert.equal(pngEntry.compressible, false, 'image/png compressible must be false');
  assert.deepEqual(pngEntry.extensions, ['png'], 'image/png extensions must be ["png"]');
}

// Case 5: lookup wrapper function
{
  assert.deepEqual(lookup('application/json'), db['application/json'], 'lookup should find application/json');
  assert.deepEqual(lookup('TEXT/HTML'), db['text/html'], 'lookup should be case-insensitive');
  assert.equal(lookup('non-existent/fake-type'), undefined, 'lookup should return undefined for unknown types');
}

// Case 6: findTypeByExtension wrapper function
{
  assert.equal(findTypeByExtension('json'), 'application/json', 'extension "json" should map to application/json');
  assert.equal(findTypeByExtension('.html'), 'text/html', 'extension ".html" with leading dot should map to text/html');
  assert.equal(findTypeByExtension('PNG'), 'image/png', 'case-insensitive extension lookup should work');
  assert.equal(findTypeByExtension('nonexistentext12345'), undefined, 'unknown extension should return undefined');
}

// Case 7: isCompressible wrapper function
{
  assert.equal(isCompressible('text/html'), true, 'text/html must be compressible');
  assert.equal(isCompressible('application/json'), true, 'application/json must be compressible');
  assert.equal(isCompressible('image/png'), false, 'image/png must not be compressible');
  assert.equal(isCompressible('unknown/type'), false, 'unknown type should not be compressible');
}

// Case 8: getExtensions and getCharset wrapper functions
{
  const htmlExts = getExtensions('text/html');
  assert.ok(htmlExts.includes('html') && htmlExts.includes('htm'), 'getExtensions should return html extensions');
  assert.deepEqual(getExtensions('unknown/type'), [], 'getExtensions should return empty array for unknown types');

  assert.equal(getCharset('application/json'), 'UTF-8', 'getCharset should return UTF-8 for application/json');
  assert.equal(getCharset('unknown/type'), undefined, 'getCharset should return undefined for unknown types');
}

console.log('PASS: all mime-db contract assertions passed');

原始种子者

匿名