Sample
mime 1.6.0
Verified sample for npm mime 1.6.0. The contract ran on node 22 · linux alpine/x64 · docker and passed: mime.lookup returns the correct MIME content type for…
sha256:6447e33fae448da0ff6bdb7e3e3ea43498f8d75516ce67a5e704c04ae0241524
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
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
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-20 |
Case
HOW- Goal
- verify pkg:npm/mime@1.6.0
- Packages
- Environment
- node 22.23.2
- Created
- 2026-08-20T01:44:38Z
Contract
- mime.lookup returns the correct MIME content type for standard file paths and extensions
- mime.lookup handles case-insensitive file extensions and nested paths
- mime.lookup returns application/octet-stream fallback for unrecognized file extensions
- mime.extension returns the canonical file extension for a given MIME type
- mime.charsets.lookup returns default character sets such as UTF-8 for text MIME types
- mime.define allows registering custom MIME types and extension mappings
Files
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
Source
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@1.6.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/mime@1.6.0
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:6ac01e7e6fcf438f669d29af0403001e5112220b5a5ce0b5825fd073c8159342","constraints":{"executionContext":"node"},"contract":["mime.lookup returns the correct MIME content type for standard file paths and extensions","mime.lookup handles case-insensitive file extensions and nested paths","mime.lookup returns application/octet-stream fallback for unrecognized file extensions","mime.extension returns the canonical file extension for a given MIME type","mime.charsets.lookup returns default character sets such as UTF-8 for text MIME types","mime.define allows registering custom MIME types and extension mappings"],"goal":"verify pkg:npm/mime@1.6.0","kind":"HOW","packages":["pkg:npm/mime@1.6.0"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/mime@1.6.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
{
"name": "mime-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "mime-sample",
"version": "1.0.0",
"dependencies": {
"mime": "1.6.0"
}
},
"node_modules/mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
"license": "MIT",
"bin": {
"mime": "cli.js"
},
"engines": {
"node": ">=4"
}
}
}
}
{
"name": "mime-sample",
"version": "1.0.0",
"dependencies": {
"mime": "1.6.0"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/mime@1.6.0",
"kind": "HOW",
"packages": [
"pkg:npm/mime@1.6.0"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const mime = require('mime');
/**
* Looks up the MIME content type for a given file path or extension.
*
* @param {string} path - File path or extension (e.g., 'document.pdf', 'file.txt', 'image.png').
* @param {string} [fallback] - Optional fallback MIME type if unknown.
* @returns {string} The MIME type string.
*/
function getMimeType(path, fallback) {
const type = mime.lookup(path);
if (type === mime.default_type && fallback !== undefined) {
return fallback;
}
return type;
}
/**
* Gets the default file extension for a given MIME content type.
*
* @param {string} type - MIME content type (e.g., 'text/plain', 'image/png').
* @returns {string|undefined} The default extension, or undefined if unknown.
*/
function getExtension(type) {
return mime.extension(type);
}
/**
* Looks up the default charset for a given MIME content type.
*
* @param {string} type - MIME content type (e.g., 'text/plain', 'text/html').
* @param {string} [defaultCharset] - Fallback charset if none defined.
* @returns {string|undefined} The charset string (e.g., 'UTF-8').
*/
function getCharset(type, defaultCharset) {
return mime.charsets.lookup(type, defaultCharset);
}
/**
* Registers custom MIME type to extension mappings.
*
* @param {Record<string, string[]>} typeMap - Mapping of MIME types to array of extensions.
*/
function defineCustomTypes(typeMap) {
mime.define(typeMap);
}
module.exports = {
mime,
getMimeType,
getExtension,
getCharset,
defineCustomTypes,
};
const assert = require('node:assert/strict');
const {
mime,
getMimeType,
getExtension,
getCharset,
defineCustomTypes,
} = require('../src/index.js');
function testLookupStandardTypes() {
// Common text formats
assert.strictEqual(mime.lookup('document.txt'), 'text/plain');
assert.strictEqual(mime.lookup('index.html'), 'text/html');
assert.strictEqual(mime.lookup('style.css'), 'text/css');
assert.strictEqual(mime.lookup('app.js'), 'application/javascript');
assert.strictEqual(getMimeType('data.json'), 'application/json');
assert.strictEqual(getMimeType('doc.xml'), 'application/xml');
// Binary and media formats
assert.strictEqual(mime.lookup('photo.png'), 'image/png');
assert.strictEqual(mime.lookup('photo.jpg'), 'image/jpeg');
assert.strictEqual(mime.lookup('photo.jpeg'), 'image/jpeg');
assert.strictEqual(mime.lookup('photo.gif'), 'image/gif');
assert.strictEqual(mime.lookup('photo.svg'), 'image/svg+xml');
assert.strictEqual(mime.lookup('document.pdf'), 'application/pdf');
assert.strictEqual(mime.lookup('archive.zip'), 'application/zip');
assert.strictEqual(mime.lookup('audio.mp3'), 'audio/mpeg');
assert.strictEqual(mime.lookup('video.mp4'), 'video/mp4');
}
function testLookupPathAndCaseHandling() {
// Nested paths
assert.strictEqual(mime.lookup('/path/to/nested/file.txt'), 'text/plain');
assert.strictEqual(mime.lookup('relative/dir/image.png'), 'image/png');
// Case insensitivity
assert.strictEqual(mime.lookup('PHOTO.PNG'), 'image/png');
assert.strictEqual(mime.lookup('DOCUMENT.PDF'), 'application/pdf');
assert.strictEqual(mime.lookup('DATA.JSON'), 'application/json');
// Extension-only or dotted strings
assert.strictEqual(mime.lookup('txt'), 'text/plain');
assert.strictEqual(mime.lookup('.txt'), 'text/plain');
}
function testLookupFallbacks() {
// Unknown extensions return default_type (application/octet-stream)
assert.strictEqual(mime.lookup('unknown.unrecognized_xyz_ext'), 'application/octet-stream');
assert.strictEqual(mime.lookup('noextensionfile'), 'application/octet-stream');
// getMimeType helper allows custom fallback
assert.strictEqual(
getMimeType('unknown.custom_ext_123', 'text/plain'),
'text/plain'
);
assert.strictEqual(
getMimeType('photo.png', 'text/plain'),
'image/png'
);
}
function testExtensionLookup() {
// Standard MIME types to extensions
assert.strictEqual(mime.extension('text/plain'), 'txt');
assert.strictEqual(mime.extension('text/html'), 'html');
assert.strictEqual(mime.extension('text/css'), 'css');
assert.strictEqual(mime.extension('application/json'), 'json');
assert.strictEqual(mime.extension('application/pdf'), 'pdf');
assert.strictEqual(mime.extension('image/png'), 'png');
assert.strictEqual(mime.extension('image/jpeg'), 'jpeg');
// Helper function
assert.strictEqual(getExtension('application/zip'), 'zip');
// Unknown MIME type returns undefined
assert.strictEqual(mime.extension('application/x-nonexistent-type'), undefined);
assert.strictEqual(getExtension('application/x-nonexistent-type'), undefined);
}
function testCharsetLookup() {
// Text types default to UTF-8
assert.strictEqual(mime.charsets.lookup('text/plain'), 'UTF-8');
assert.strictEqual(mime.charsets.lookup('text/html'), 'UTF-8');
assert.strictEqual(mime.charsets.lookup('application/json'), 'UTF-8');
// Non-text types return undefined or fallback
assert.strictEqual(mime.charsets.lookup('image/png'), undefined);
assert.strictEqual(mime.charsets.lookup('image/png', 'ISO-8859-1'), 'ISO-8859-1');
// Helper function
assert.strictEqual(getCharset('text/plain'), 'UTF-8');
assert.strictEqual(getCharset('image/jpeg', 'US-ASCII'), 'US-ASCII');
}
function testCustomTypeDefinition() {
// Define custom MIME types
defineCustomTypes({
'text/x-custom-sample': ['cstm', 'customsample'],
'application/x-csx-data': ['csxdat'],
});
// Verify custom lookup
assert.strictEqual(mime.lookup('file.cstm'), 'text/x-custom-sample');
assert.strictEqual(mime.lookup('data.customsample'), 'text/x-custom-sample');
assert.strictEqual(mime.lookup('record.csxdat'), 'application/x-csx-data');
// Verify custom extension
assert.strictEqual(mime.extension('text/x-custom-sample'), 'cstm');
assert.strictEqual(mime.extension('application/x-csx-data'), 'csxdat');
}
function main() {
testLookupStandardTypes();
testLookupPathAndCaseHandling();
testLookupFallbacks();
testExtensionLookup();
testCharsetLookup();
testCustomTypeDefinition();
console.log('All pkg:npm/mime@1.6.0 contracts passed successfully.');
}
main();
Origin Seeder
anonymous