CodeSampleX

Ejemplo

mime-db 1.52.0: lookup MIME type metadata and extensions in mime-db

Muestra verificada para npm mime-db 1.52.0: lookup MIME type metadata and extensions in mime-db. El contrato se ejecutó en node 22 · linux alpine/x64 …

sha256:6c1dfc987b0995d378c70092b5b3e3b468e22be8dfefe5dfd8a7f8cb73366be6

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22 linux x64 node 22 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
lookup MIME type metadata and extensions in mime-db
Paquetes
Símbolos
  • mime-db
Entorno
node 22
Creado
2026-08-18T18:07:59Z

Contrato

  1. db is an object mapping MIME type strings to metadata entries
  2. getType performs case-insensitive lookup and returns metadata entry with source, extensions, and charset
  3. getExtensions returns array of associated file extensions or empty array
  4. getDefaultExtension returns primary file extension without leading dot
  5. isCompressible returns boolean compressibility status of the media type
  6. findTypeByExtension looks up media type corresponding to a file extension
  7. getSource returns database origin source such as iana or apache
  8. getCharset returns defined charset encoding or undefined

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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: lookup MIME type metadata and extensions in mime-db
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/mime-db@1.52.0
Demonstrate these symbols/APIs:
  - mime-db
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:12d74e8c2f394fabd1db4b5c503120475dd8d1c7c9d7602d55ed428b9dea38a5","constraints":{"executionContext":"node"},"contract":["db is an object mapping MIME type strings to metadata entries","getType performs case-insensitive lookup and returns metadata entry with source, extensions, and charset","getExtensions returns array of associated file extensions or empty array","getDefaultExtension returns primary file extension without leading dot","isCompressible returns boolean compressibility status of the media type","findTypeByExtension looks up media type corresponding to a file extension","getSource returns database origin source such as iana or apache","getCharset returns defined charset encoding or undefined"],"goal":"lookup MIME type metadata and extensions in mime-db","kind":"HOW","packages":["pkg:npm/mime-db@1.52.0"],"schemaVersion":1,"symbols":["mime-db"]},"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-db@1.52.0"],"schemaVersion":1,"symbols":["mime-db"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

var db = require('mime-db');

/**
 * Get the metadata entry for a MIME type (case-insensitive).
 * @param {string} type - MIME type string (e.g., 'application/json')
 * @returns {object|undefined}
 */
function getType(type) {
  if (typeof type !== 'string') {
    return undefined;
  }
  return db[type.toLowerCase().trim()];
}

/**
 * Get all extensions associated with a MIME type.
 * @param {string} type - MIME type string
 * @returns {string[]}
 */
function getExtensions(type) {
  var entry = getType(type);
  return (entry && Array.isArray(entry.extensions)) ? entry.extensions.slice() : [];
}

/**
 * Get the primary default extension for a MIME type.
 * @param {string} type - MIME type string
 * @returns {string|undefined}
 */
function getDefaultExtension(type) {
  var extensions = getExtensions(type);
  return extensions.length > 0 ? extensions[0] : undefined;
}

/**
 * Check whether a MIME type is marked as compressible.
 * @param {string} type - MIME type string
 * @returns {boolean}
 */
function isCompressible(type) {
  var entry = getType(type);
  return Boolean(entry && entry.compressible === true);
}

/**
 * Find a MIME type by file extension (without leading dot).
 * @param {string} ext - File extension (e.g., 'json', 'png')
 * @returns {string|undefined}
 */
function findTypeByExtension(ext) {
  if (typeof ext !== 'string') {
    return undefined;
  }
  var cleanExt = ext.replace(/^\./, '').toLowerCase().trim();
  for (var mimeType in db) {
    if (Object.prototype.hasOwnProperty.call(db, mimeType)) {
      var entry = db[mimeType];
      if (entry && Array.isArray(entry.extensions) && entry.extensions.indexOf(cleanExt) !== -1) {
        return mimeType;
      }
    }
  }
  return undefined;
}

/**
 * Get the source of a MIME type definition (e.g., 'iana', 'apache', 'nginx').
 * @param {string} type - MIME type string
 * @returns {string|undefined}
 */
function getSource(type) {
  var entry = getType(type);
  return entry ? entry.source : undefined;
}

/**
 * Get the charset of a MIME type if specified.
 * @param {string} type - MIME type string
 * @returns {string|undefined}
 */
function getCharset(type) {
  var entry = getType(type);
  return entry ? entry.charset : undefined;
}

module.exports = {
  db: db,
  getType: getType,
  getExtensions: getExtensions,
  getDefaultExtension: getDefaultExtension,
  isCompressible: isCompressible,
  findTypeByExtension: findTypeByExtension,
  getSource: getSource,
  getCharset: getCharset
};
package-lock.json
{
  "name": "sample-mime-db",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-mime-db",
      "version": "1.0.0",
      "dependencies": {
        "mime-db": "1.52.0"
      }
    },
    "node_modules/mime-db": {
      "version": "1.52.0",
      "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
      "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    }
  }
}
package.json
{
  "name": "sample-mime-db",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of mime-db MIME type lookup and metadata query",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "mime-db": "1.52.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "lookup MIME type metadata and extensions in mime-db",
  "kind": "HOW",
  "packages": [
    "pkg:npm/mime-db@1.52.0"
  ],
  "symbols": [
    "mime-db"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/contract.js
'use strict';

var assert = require('assert');
var sample = require('../index.js');

// 1. Raw database sanity check
assert.strictEqual(typeof sample.db, 'object');
assert.ok(sample.db !== null);
assert.ok(Object.keys(sample.db).length > 1000);

// 2. application/json entry check
var jsonEntry = sample.getType('application/json');
assert.ok(jsonEntry, 'application/json should exist in mime-db');
assert.strictEqual(jsonEntry.source, 'iana');
assert.strictEqual(jsonEntry.charset, 'UTF-8');
assert.strictEqual(jsonEntry.compressible, true);
assert.deepStrictEqual(jsonEntry.extensions, ['json', 'map']);

// 3. text/html entry check
var htmlEntry = sample.getType('text/html');
assert.ok(htmlEntry, 'text/html should exist in mime-db');
assert.strictEqual(htmlEntry.source, 'iana');
assert.strictEqual(htmlEntry.compressible, true);
assert.ok(Array.isArray(htmlEntry.extensions));
assert.ok(htmlEntry.extensions.indexOf('html') !== -1);
assert.ok(htmlEntry.extensions.indexOf('htm') !== -1);

// 4. image/png entry check
var pngEntry = sample.getType('image/png');
assert.ok(pngEntry, 'image/png should exist in mime-db');
assert.strictEqual(pngEntry.source, 'iana');
assert.strictEqual(pngEntry.compressible, false);
assert.deepStrictEqual(pngEntry.extensions, ['png']);

// 5. Non-existent MIME type
assert.strictEqual(sample.getType('application/x-non-existent-fake-type'), undefined);
assert.strictEqual(sample.getType(null), undefined);
assert.strictEqual(sample.getType(123), undefined);

// 6. Case-insensitivity in getType
assert.deepStrictEqual(sample.getType('Application/JSON'), jsonEntry);
assert.deepStrictEqual(sample.getType('TEXT/HTML '), htmlEntry);

// 7. getExtensions
assert.deepStrictEqual(sample.getExtensions('application/json'), ['json', 'map']);
assert.deepStrictEqual(sample.getExtensions('image/png'), ['png']);
assert.deepStrictEqual(sample.getExtensions('non/existent'), []);

// 8. getDefaultExtension
assert.strictEqual(sample.getDefaultExtension('application/json'), 'json');
assert.strictEqual(sample.getDefaultExtension('image/png'), 'png');
assert.strictEqual(sample.getDefaultExtension('text/html'), 'html');
assert.strictEqual(sample.getDefaultExtension('non/existent'), undefined);

// 9. isCompressible
assert.strictEqual(sample.isCompressible('application/json'), true);
assert.strictEqual(sample.isCompressible('text/html'), true);
assert.strictEqual(sample.isCompressible('image/png'), false);
assert.strictEqual(sample.isCompressible('application/pdf'), false);
assert.strictEqual(sample.isCompressible('image/svg+xml'), true);
assert.strictEqual(sample.isCompressible('non/existent'), false);

// 10. findTypeByExtension
assert.strictEqual(sample.findTypeByExtension('json'), 'application/json');
assert.strictEqual(sample.findTypeByExtension('.json'), 'application/json');
assert.strictEqual(sample.findTypeByExtension('png'), 'image/png');
assert.strictEqual(sample.findTypeByExtension('svg'), 'image/svg+xml');
assert.strictEqual(sample.findTypeByExtension('unknownext123'), undefined);
assert.strictEqual(sample.findTypeByExtension(null), undefined);

// 11. getSource
assert.strictEqual(sample.getSource('application/json'), 'iana');
assert.strictEqual(sample.getSource('text/html'), 'iana');
assert.strictEqual(sample.getSource('non/existent'), undefined);

// 12. getCharset
assert.strictEqual(sample.getCharset('application/json'), 'UTF-8');
assert.strictEqual(sample.getCharset('image/png'), undefined);
assert.strictEqual(sample.getCharset('non/existent'), undefined);

console.log('PASS: mime-db contract verified');

Seeder de origen

anónimo