Exemple
ansi-styles 6.2.3: color
Échantillon vérifié pour npm ansi-styles 6.2.3: color. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.
sha256:c05c54127e5e0f2b6635793265b6378702311eee3e8b55d7e41bda59aace4596
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 2
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-23 |
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-07 |
Cas
HOW- Objectif
- verify ansi-styles.color in pkg:npm/ansi-styles@6.2.3
- Paquets
- Symboles
-
- ansi-styles.color
- Environnement
- node 22.23.2
- Créé
- 2026-08-23T05:32:32Z
Contrat
- ansiStyles.color provides standard and bright foreground colors with matching open and close ANSI escape sequences
- ansiStyles.color.close defines the default foreground reset escape sequence
- ansiStyles.color.ansi converts standard ANSI color codes to foreground escape sequences
- ansiStyles.color.ansi256 generates 256-color palette foreground ANSI escape codes
- ansiStyles.color.ansi16m converts RGB values into 24-bit truecolor foreground ANSI escape codes
- applyForegroundColor applies foreground color styling including standard names, 256-color palette, and truecolor RGB to text
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
Code 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 ansi-styles.color in pkg:npm/ansi-styles@6.2.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ansi-styles@6.2.3
Demonstrate these symbols/APIs:
- ansi-styles.color
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:b86dcca21c13fd772c479cdfaf1130a766591ea711a4e582933b9985079b6a7b","constraints":{"executionContext":"node"},"contract":["ansiStyles.color provides standard and bright foreground colors with matching open and close ANSI escape sequences","ansiStyles.color.close defines the default foreground reset escape sequence","ansiStyles.color.ansi converts standard ANSI color codes to foreground escape sequences","ansiStyles.color.ansi256 generates 256-color palette foreground ANSI escape codes","ansiStyles.color.ansi16m converts RGB values into 24-bit truecolor foreground ANSI escape codes","applyForegroundColor applies foreground color styling including standard names, 256-color palette, and truecolor RGB to text"],"goal":"verify ansi-styles.color in pkg:npm/ansi-styles@6.2.3","kind":"HOW","packages":["pkg:npm/ansi-styles@6.2.3"],"schemaVersion":1,"symbols":["ansi-styles.color"]},"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/ansi-styles@6.2.3"],"schemaVersion":1,"subject":"pkg:npm/ansi-styles@6.2.3","symbols":["ansi-styles.color"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-ansi-styles-color",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ansi-styles-color",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"ansi-styles": "6.2.3"
}
},
"node_modules/ansi-styles": {
"version": "6.2.3",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz",
"integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==",
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
}
}
}
{
"name": "sample-ansi-styles-color",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification for ansi-styles color",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"ansi-styles": "6.2.3"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify ansi-styles.color in pkg:npm/ansi-styles@6.2.3",
"kind": "HOW",
"packages": [
"pkg:npm/ansi-styles@6.2.3"
],
"symbols": [
"ansi-styles.color"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const ansiStylesModule = require('ansi-styles');
const ansiStyles = ansiStylesModule.default || ansiStylesModule;
const { color } = ansiStyles;
/**
* Returns the color object from ansi-styles.
* @returns {object}
*/
function getColor() {
return color;
}
/**
* Retrieves standard or bright foreground color style pair.
* @param {string} name
* @returns {{ open: string, close: string }}
*/
function getNamedColor(name) {
const style = color[name];
if (!style) {
throw new Error(`Unknown foreground color: ${name}`);
}
return {
open: style.open,
close: style.close,
};
}
/**
* Formats a foreground color escape sequence using a 256-color palette index.
* @param {number} code
* @returns {{ open: string, close: string }}
*/
function getAnsi256Color(code) {
if (typeof code !== 'number' || code < 0 || code > 255) {
throw new RangeError(`Color code must be between 0 and 255: ${code}`);
}
return {
open: color.ansi256(code),
close: color.close,
};
}
/**
* Formats a foreground color escape sequence using 24-bit truecolor RGB values.
* @param {number} red
* @param {number} green
* @param {number} blue
* @returns {{ open: string, close: string }}
*/
function getAnsi16mColor(red, green, blue) {
return {
open: color.ansi16m(red, green, blue),
close: color.close,
};
}
/**
* Applies foreground styling to the provided text.
* @param {string} text
* @param {{ name?: string, ansi256?: number, rgb?: [number, number, number] }} options
* @returns {string}
*/
function applyForegroundColor(text, options = {}) {
let openSequence = '';
const closeSequence = color.close;
if (options.name) {
openSequence = getNamedColor(options.name).open;
} else if (typeof options.ansi256 === 'number') {
openSequence = getAnsi256Color(options.ansi256).open;
} else if (Array.isArray(options.rgb) && options.rgb.length === 3) {
const [r, g, b] = options.rgb;
openSequence = getAnsi16mColor(r, g, b).open;
} else {
throw new Error('Must specify one of name, ansi256, or rgb options');
}
return `${openSequence}${text}${closeSequence}`;
}
module.exports = {
ansiStyles,
color,
getColor,
getNamedColor,
getAnsi256Color,
getAnsi16mColor,
applyForegroundColor,
};
const assert = require('node:assert');
const {
ansiStyles,
color,
getColor,
getNamedColor,
getAnsi256Color,
getAnsi16mColor,
applyForegroundColor,
} = require('../src/index.js');
// 1. ansiStyles.color provides standard and bright foreground colors with matching open and close ANSI escape sequences
assert(color && typeof color === 'object', 'color must be an object');
assert.strictEqual(getColor(), color);
const standardColors = {
black: '\u001B[30m',
red: '\u001B[31m',
green: '\u001B[32m',
yellow: '\u001B[33m',
blue: '\u001B[34m',
magenta: '\u001B[35m',
cyan: '\u001B[36m',
white: '\u001B[37m',
};
for (const [name, expectedOpen] of Object.entries(standardColors)) {
const style = color[name];
assert(style, `Missing standard style ${name}`);
assert.strictEqual(style.open, expectedOpen, `${name} open code mismatch`);
assert.strictEqual(style.close, '\u001B[39m', `${name} close code mismatch`);
const named = getNamedColor(name);
assert.strictEqual(named.open, expectedOpen);
assert.strictEqual(named.close, '\u001B[39m');
}
const brightColors = {
blackBright: '\u001B[90m',
redBright: '\u001B[91m',
greenBright: '\u001B[92m',
yellowBright: '\u001B[93m',
blueBright: '\u001B[94m',
magentaBright: '\u001B[95m',
cyanBright: '\u001B[96m',
whiteBright: '\u001B[97m',
};
for (const [name, expectedOpen] of Object.entries(brightColors)) {
const style = color[name];
assert(style, `Missing bright style ${name}`);
assert.strictEqual(style.open, expectedOpen, `${name} open code mismatch`);
assert.strictEqual(style.close, '\u001B[39m', `${name} close code mismatch`);
}
// Aliases
assert.deepStrictEqual(color.gray, color.blackBright);
assert.deepStrictEqual(color.grey, color.blackBright);
// 2. ansiStyles.color.close defines the default foreground reset escape sequence
assert.strictEqual(color.close, '\u001B[39m');
// 3. ansiStyles.color.ansi converts standard ANSI color codes to foreground escape sequences
assert(typeof color.ansi === 'function', 'color.ansi must be a function');
assert.strictEqual(color.ansi(30), '\u001B[30m');
assert.strictEqual(color.ansi(31), '\u001B[31m');
assert.strictEqual(color.ansi(32), '\u001B[32m');
assert.strictEqual(color.ansi(37), '\u001B[37m');
// 4. ansiStyles.color.ansi256 generates 256-color palette foreground ANSI escape codes
assert(typeof color.ansi256 === 'function', 'color.ansi256 must be a function');
assert.strictEqual(color.ansi256(0), '\u001B[38;5;0m');
assert.strictEqual(color.ansi256(100), '\u001B[38;5;100m');
assert.strictEqual(color.ansi256(255), '\u001B[38;5;255m');
const fg256 = getAnsi256Color(200);
assert.strictEqual(fg256.open, '\u001B[38;5;200m');
assert.strictEqual(fg256.close, '\u001B[39m');
assert.throws(() => getAnsi256Color(-1), RangeError);
assert.throws(() => getAnsi256Color(256), RangeError);
// 5. ansiStyles.color.ansi16m converts RGB values into 24-bit truecolor foreground ANSI escape codes
assert(typeof color.ansi16m === 'function', 'color.ansi16m must be a function');
assert.strictEqual(color.ansi16m(255, 128, 0), '\u001B[38;2;255;128;0m');
assert.strictEqual(color.ansi16m(0, 0, 0), '\u001B[38;2;0;0;0m');
assert.strictEqual(color.ansi16m(12, 34, 56), '\u001B[38;2;12;34;56m');
const fg16m = getAnsi16mColor(10, 20, 30);
assert.strictEqual(fg16m.open, '\u001B[38;2;10;20;30m');
assert.strictEqual(fg16m.close, '\u001B[39m');
// 6. applyForegroundColor applies foreground color styling including standard names, 256-color palette, and truecolor RGB to text
const message = 'Sample Text';
assert.strictEqual(applyForegroundColor(message, { name: 'cyan' }), `\u001B[36m${message}\u001B[39m`);
assert.strictEqual(applyForegroundColor(message, { name: 'redBright' }), `\u001B[91m${message}\u001B[39m`);
assert.strictEqual(applyForegroundColor(message, { ansi256: 45 }), `\u001B[38;5;45m${message}\u001B[39m`);
assert.strictEqual(applyForegroundColor(message, { rgb: [255, 100, 50] }), `\u001B[38;2;255;100;50m${message}\u001B[39m`);
assert.throws(() => applyForegroundColor(message, { name: 'invalidColor' }), /Unknown foreground color: invalidColor/);
assert.throws(() => applyForegroundColor(message, {}), /Must specify one of name, ansi256, or rgb options/);
console.log('All contract assertions passed successfully.');
Seeder d'origine
anonyme