示例
mime-types 3.0.2: lookup mime type and extension using mime-types
已验证示例 — npm mime-types 3.0.2: lookup mime type and extension using mime-types. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过.
sha256:b9b33577bfaae52cf9ea720442bf66b3ba3461d167f8f6c8179279246bb5f206
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
node 22 linux x64 node 22 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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- 目标
- lookup mime type and extension using mime-types
- 符号
-
- mime.contentType
- mime.extension
- mime.lookup
- 环境
- node 22
- 创建时间
- 2026-08-18T18:12:11Z
契约
- mime.lookup returns the MIME type for file paths or extensions and returns false for unknown extensions
- mime.contentType returns the full Content-Type header with default charset for valid types or extensions and returns false when unknown extension is given
- mime.extension returns the default file extension for a MIME type and returns false for unknown types
文件
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
源代码
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: lookup mime type and extension using mime-types
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/mime-types@3.0.2
Demonstrate these symbols/APIs:
- mime.contentType
- mime.extension
- mime.lookup
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.
{"case":{"caseId":"case:sha256:9aba615aa91272d2c135b562e0c0fdd8b5dfed1bc4bd428b0fdd2d2babe40e11","constraints":{"executionContext":"node"},"contract":["mime.lookup returns the MIME type for file paths or extensions and returns false for unknown extensions","mime.contentType returns the full Content-Type header with default charset for valid types or extensions and returns false when unknown extension is given","mime.extension returns the default file extension for a MIME type and returns false for unknown types"],"goal":"lookup mime type and extension using mime-types","kind":"HOW","packages":["pkg:npm/mime-types@3.0.2"],"schemaVersion":1,"symbols":["mime.contentType","mime.extension","mime.lookup"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"javascript","moduleSystem":"cjs","os":"linux","packageManager":"npm","packageManagerVersion":"10","runtime":"node","runtimeVersion":"22","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/mime-types@3.0.2"],"schemaVersion":1,"symbols":["mime.contentType","mime.extension","mime.lookup"],"verifierAdapter":"node-typescript@1"}
'use strict';
var mime = require('mime-types');
/**
* Look up the MIME type for a file path or extension.
* @param {string} pathOrExtension
* @returns {string|false}
*/
function lookup(pathOrExtension) {
return mime.lookup(pathOrExtension);
}
/**
* Create a full Content-Type header given a type or extension.
* @param {string} typeOrExtension
* @returns {string|false}
*/
function contentType(typeOrExtension) {
return mime.contentType(typeOrExtension);
}
/**
* Get the default extension for a MIME type.
* @param {string} mimeType
* @returns {string|false}
*/
function extension(mimeType) {
return mime.extension(mimeType);
}
/**
* Get the default charset for a MIME type.
* @param {string} mimeType
* @returns {string|false}
*/
function charset(mimeType) {
return mime.charset(mimeType);
}
module.exports = {
mime: mime,
lookup: lookup,
contentType: contentType,
extension: extension,
charset: charset
};
{
"name": "sample-mime-types",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-mime-types",
"version": "1.0.0",
"dependencies": {
"mime-types": "3.0.2"
}
},
"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"
}
},
"node_modules/mime-types": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
"integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
"license": "MIT",
"dependencies": {
"mime-db": "^1.54.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
}
}
}
{
"name": "sample-mime-types",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of mime-types package",
"main": "index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"mime-types": "3.0.2"
}
}
{
"schemaVersion": 1,
"goal": "lookup mime type and extension using mime-types",
"kind": "HOW",
"packages": [
"pkg:npm/mime-types@3.0.2"
],
"symbols": [
"mime.contentType",
"mime.extension",
"mime.lookup"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@11.8.0",
"runtime": "node@24.13.1"
}
}
'use strict';
var assert = require('assert');
var sample = require('../index.js');
var mime = sample.mime;
// 1. mime.lookup tests
// Lookup by extension with and without leading dot
assert.strictEqual(mime.lookup('json'), 'application/json');
assert.strictEqual(mime.lookup('.json'), 'application/json');
assert.strictEqual(mime.lookup('html'), 'text/html');
assert.strictEqual(mime.lookup('.html'), 'text/html');
assert.strictEqual(mime.lookup('md'), 'text/markdown');
assert.strictEqual(mime.lookup('png'), 'image/png');
assert.strictEqual(mime.lookup('svg'), 'image/svg+xml');
// Lookup by filename and file path
assert.strictEqual(mime.lookup('index.html'), 'text/html');
assert.strictEqual(mime.lookup('path/to/script.js'), 'text/javascript');
assert.strictEqual(mime.lookup('/etc/config.json'), 'application/json');
assert.strictEqual(mime.lookup('archive.tar.gz'), 'application/gzip');
// Unknown extensions or non-string inputs return false
assert.strictEqual(mime.lookup('nonexistent_extension_xyz'), false);
assert.strictEqual(mime.lookup('.unknown'), false);
assert.strictEqual(mime.lookup('noextensionfile'), false);
assert.strictEqual(mime.lookup(null), false);
assert.strictEqual(mime.lookup(123), false);
// 2. mime.contentType tests
// Full header construction with charset for extensions
assert.strictEqual(mime.contentType('json'), 'application/json; charset=utf-8');
assert.strictEqual(mime.contentType('markdown'), 'text/markdown; charset=utf-8');
// Full header construction with charset for MIME types
assert.strictEqual(mime.contentType('application/json'), 'application/json; charset=utf-8');
assert.strictEqual(mime.contentType('text/html'), 'text/html; charset=utf-8');
assert.strictEqual(mime.contentType('text/plain'), 'text/plain; charset=utf-8');
// MIME types without default charset return the MIME type directly
assert.strictEqual(mime.contentType('image/png'), 'image/png');
assert.strictEqual(mime.contentType('application/octet-stream'), 'application/octet-stream');
// Passing a content-type that already includes parameters preserves them
assert.strictEqual(mime.contentType('text/html; charset=iso-8859-1'), 'text/html; charset=iso-8859-1');
// Type strings containing slash return as-is even if custom/unknown
assert.strictEqual(mime.contentType('unknown/fake-type'), 'unknown/fake-type');
// Unknown extensions without slash return false
assert.strictEqual(mime.contentType('invalid'), false);
assert.strictEqual(mime.contentType('unknownext123'), false);
assert.strictEqual(mime.contentType(null), false);
assert.strictEqual(mime.contentType(123), false);
// 3. mime.extension tests
// Return default extension for standard MIME types
assert.strictEqual(mime.extension('application/json'), 'json');
assert.strictEqual(mime.extension('text/html'), 'html');
assert.strictEqual(mime.extension('image/jpeg'), 'jpg');
assert.strictEqual(mime.extension('image/png'), 'png');
assert.strictEqual(mime.extension('application/octet-stream'), 'bin');
// With charset parameter in content-type
assert.strictEqual(mime.extension('text/html; charset=utf-8'), 'html');
assert.strictEqual(mime.extension('application/json; charset=utf-8'), 'json');
// Unknown content-type or non-string inputs return false
assert.strictEqual(mime.extension('application/x-fake-unknown'), false);
assert.strictEqual(mime.extension('invalid'), false);
assert.strictEqual(mime.extension(null), false);
assert.strictEqual(mime.extension(123), false);
// 4. mime.charset tests
assert.strictEqual(mime.charset('text/markdown'), 'UTF-8');
assert.strictEqual(mime.charset('text/html'), 'UTF-8');
assert.strictEqual(mime.charset('image/png'), false);
assert.strictEqual(mime.charset('unknown/type'), false);
// 5. Helper function wrappers exported from sample
assert.strictEqual(sample.lookup('file.json'), 'application/json');
assert.strictEqual(sample.lookup('bad.unknown'), false);
assert.strictEqual(sample.contentType('json'), 'application/json; charset=utf-8');
assert.strictEqual(sample.contentType('invalid'), false);
assert.strictEqual(sample.extension('application/json'), 'json');
assert.strictEqual(sample.extension('invalid'), false);
assert.strictEqual(sample.charset('text/markdown'), 'UTF-8');
assert.strictEqual(sample.charset('image/png'), false);
// 6. Raw dictionary objects
assert.strictEqual(typeof mime.types, 'object');
assert.strictEqual(mime.types['json'], 'application/json');
assert.strictEqual(typeof mime.extensions, 'object');
assert.ok(Array.isArray(mime.extensions['application/json']));
assert.ok(mime.extensions['application/json'].indexOf('json') !== -1);
console.log('PASS: mime-types contract verified');
原始种子者
匿名