Sample
type-is 2.1.0
Verified sample for npm type-is 2.1.0. The contract ran on node 22 · linux alpine/x64 · docker and passed: typeis(req, types) matches the Content-Type header…
sha256:35246535f43a0cd345cfceb28cb2707635cfbd432b4fe78d068c7c009a1c1183
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:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-20 |
Case
HOW- Goal
- verify pkg:npm/type-is@2.1.0
- Packages
- Environment
- node 22.23.2
- Created
- 2026-08-20T13:18:51Z
Contract
- typeis(req, types) matches the Content-Type header of a request against candidate types and returns the matching type
- typeis(req, types) returns null when the request has no body headers (neither content-length nor transfer-encoding)
- typeis(req, types) returns false when the request body content-type does not match candidate types
- typeis.hasBody(req) returns true when request has content-length or transfer-encoding headers
- typeis.is(mediaType, types) matches media type strings against extensions, types, or wildcards
- typeis.normalize(type) normalizes type extensions and shorthand names to full MIME types
Files
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.cjs
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/type-is@2.1.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/type-is@2.1.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:56ce3f4263ae0a5032f1658b2a432bb3bae2d02a63850a9044feff3830cf05a3","constraints":{"executionContext":"node"},"contract":["typeis(req, types) matches the Content-Type header of a request against candidate types and returns the matching type","typeis(req, types) returns null when the request has no body headers (neither content-length nor transfer-encoding)","typeis(req, types) returns false when the request body content-type does not match candidate types","typeis.hasBody(req) returns true when request has content-length or transfer-encoding headers","typeis.is(mediaType, types) matches media type strings against extensions, types, or wildcards","typeis.normalize(type) normalizes type extensions and shorthand names to full MIME types"],"goal":"verify pkg:npm/type-is@2.1.0","kind":"HOW","packages":["pkg:npm/type-is@2.1.0"],"schemaVersion":1},"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/type-is@2.1.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
{
"name": "type-is-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "type-is-sample",
"version": "1.0.0",
"dependencies": {
"type-is": "2.1.0"
}
},
"node_modules/content-type": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz",
"integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/media-typer": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.1.tgz",
"integrity": "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"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"
}
},
"node_modules/type-is": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz",
"integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==",
"license": "MIT",
"dependencies": {
"content-type": "^2.0.0",
"media-typer": "^1.1.0",
"mime-types": "^3.0.0"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
}
}
}
{
"name": "type-is-sample",
"version": "1.0.0",
"description": "Minimal sample verifying type-is",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"type-is": "2.1.0"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/type-is@2.1.0",
"kind": "HOW",
"packages": [
"pkg:npm/type-is@2.1.0"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const typeis = require('type-is');
/**
* Checks if the incoming request has a body and matches any of the candidate types.
*
* @param {object} req - HTTP request object with headers.
* @param {string|string[]} candidateTypes - Acceptable MIME types, shorthands, or wildcards.
* @returns {string|false|null} - Matching type string, false if mismatch, or null if no body.
*/
function checkRequestType(req, candidateTypes) {
const types = Array.isArray(candidateTypes) ? candidateTypes : [candidateTypes];
return typeis(req, types);
}
/**
* Checks whether an HTTP request contains a request body.
*
* @param {object} req - HTTP request object with headers.
* @returns {boolean} - True if body is present, false otherwise.
*/
function hasRequestBody(req) {
return typeis.hasBody(req);
}
/**
* Compares a media type string against candidate types.
*
* @param {string} mediaType - Media type string (e.g. 'application/json').
* @param {string|string[]} candidateTypes - Candidate types, shorthands, or wildcards.
* @returns {string|false} - Matching type string or false.
*/
function matchMediaType(mediaType, candidateTypes) {
const types = Array.isArray(candidateTypes) ? candidateTypes : [candidateTypes];
return typeis.is(mediaType, types);
}
/**
* Normalizes a type shorthand or extension into a full MIME type.
*
* @param {string} type - Extension or shorthand (e.g. 'json', '+json', 'html').
* @returns {string|false} - Normalized MIME pattern or false.
*/
function normalizeType(type) {
return typeis.normalize(type);
}
module.exports = {
typeis,
checkRequestType,
hasRequestBody,
matchMediaType,
normalizeType,
};
const assert = require('node:assert/strict');
const typeis = require('type-is');
const {
checkRequestType,
hasRequestBody,
matchMediaType,
normalizeType,
} = require('../src/index.js');
function createMockReq(headers = {}) {
return {
headers: { ...headers },
};
}
async function main() {
// Contract 1: typeis(req, types) matches the Content-Type header of a request against candidate types and returns the matching type
{
const reqJson = createMockReq({
'content-type': 'application/json; charset=utf-8',
'content-length': '42',
});
assert.strictEqual(typeis(reqJson, ['json', 'html']), 'json');
assert.strictEqual(typeis(reqJson, ['application/json']), 'application/json');
assert.strictEqual(checkRequestType(reqJson, ['json', 'html']), 'json');
const reqHtml = createMockReq({
'content-type': 'text/html; charset=utf-8',
'transfer-encoding': 'chunked',
});
assert.strictEqual(typeis(reqHtml, ['html', 'json']), 'html');
assert.strictEqual(checkRequestType(reqHtml, 'html'), 'html');
const reqCustom = createMockReq({
'content-type': 'application/vnd.api+json',
'content-length': '100',
});
assert.strictEqual(typeis(reqCustom, ['+json']), 'application/vnd.api+json');
assert.strictEqual(checkRequestType(reqCustom, ['+json']), 'application/vnd.api+json');
}
// Contract 2: typeis(req, types) returns null when the request has no body headers (neither content-length nor transfer-encoding)
{
const reqNoBody = createMockReq({
'content-type': 'application/json',
});
assert.strictEqual(typeis(reqNoBody, ['json']), null);
assert.strictEqual(checkRequestType(reqNoBody, ['json']), null);
const reqEmptyHeaders = createMockReq({});
assert.strictEqual(typeis(reqEmptyHeaders, ['json', 'html']), null);
assert.strictEqual(checkRequestType(reqEmptyHeaders, ['json', 'html']), null);
}
// Contract 3: typeis(req, types) returns false when the request body content-type does not match candidate types
{
const reqText = createMockReq({
'content-type': 'text/plain',
'content-length': '20',
});
assert.strictEqual(typeis(reqText, ['json', 'html']), false);
assert.strictEqual(checkRequestType(reqText, ['json', 'html']), false);
const reqPng = createMockReq({
'content-type': 'image/png',
'transfer-encoding': 'chunked',
});
assert.strictEqual(typeis(reqPng, ['application/json', 'text/*']), false);
assert.strictEqual(checkRequestType(reqPng, ['application/json', 'text/*']), false);
}
// Contract 4: typeis.hasBody(req) returns true when request has content-length or transfer-encoding headers
{
const reqLength = createMockReq({ 'content-length': '15' });
assert.strictEqual(typeis.hasBody(reqLength), true);
assert.strictEqual(hasRequestBody(reqLength), true);
const reqChunked = createMockReq({ 'transfer-encoding': 'chunked' });
assert.strictEqual(typeis.hasBody(reqChunked), true);
assert.strictEqual(hasRequestBody(reqChunked), true);
const reqEmpty = createMockReq({});
assert.strictEqual(typeis.hasBody(reqEmpty), false);
assert.strictEqual(hasRequestBody(reqEmpty), false);
}
// Contract 5: typeis.is(mediaType, types) matches media type strings against extensions, types, or wildcards
{
assert.strictEqual(typeis.is('application/json', ['json']), 'json');
assert.strictEqual(typeis.is('application/json', ['text/html', 'application/json']), 'application/json');
assert.strictEqual(typeis.is('image/png', ['image/*']), 'image/png');
assert.strictEqual(typeis.is('text/html', ['json', 'image/*']), false);
assert.strictEqual(matchMediaType('application/json', ['json']), 'json');
assert.strictEqual(matchMediaType('image/png', ['image/*']), 'image/png');
assert.strictEqual(matchMediaType('text/html', ['json']), false);
}
// Contract 6: typeis.normalize(type) normalizes type extensions and shorthand names to full MIME types
{
assert.strictEqual(typeis.normalize('json'), 'application/json');
assert.strictEqual(typeis.normalize('html'), 'text/html');
assert.strictEqual(typeis.normalize('+json'), '*/*+json');
assert.strictEqual(typeis.normalize('application/json'), 'application/json');
assert.strictEqual(normalizeType('json'), 'application/json');
assert.strictEqual(normalizeType('html'), 'text/html');
assert.strictEqual(normalizeType('+json'), '*/*+json');
}
console.log('All contracts verified successfully.');
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
Origin Seeder
anonymous