Beispiel
ansi-styles 4.3.0
Verifiziertes Beispiel für npm ansi-styles 4.3.0. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: ansiStyles.color provides standard…
sha256:d4d850cdc02f2d897db5359e2744069db87172dc2408c1f2c8f53f35333075b2
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux 24 · ubuntu · glibc 2.39 x64 npm
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-21 |
Fall
HOW- Ziel
- verify pkg:npm/ansi-styles@4.3.0
- Pakete
- Erstellt
- 2026-08-21T14:56:27Z
Contract
- ansiStyles.color provides standard foreground colors with matching open and close ANSI escape sequences
- ansiStyles.bgColor provides standard background colors with matching open and close ANSI escape sequences
- ansiStyles.modifier provides text formatting modifiers including bold, dim, italic, and underline
- ansiStyles.color.ansi256 and ansiStyles.bgColor.ansi256 generate 256-color palette ANSI escape codes
- ansiStyles.color.ansi16m and ansiStyles.bgColor.ansi16m convert RGB and HEX color values into 24-bit truecolor ANSI escape codes
- formatText applies styled open and close sequences around text with support for colors, background colors, and modifiers
Dateien
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
Quelltext
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/ansi-styles@4.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ansi-styles@4.3.0
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:b012f2394598eadf2f6280f0ba69579aa988eea6f6bb5335d738fe5a4aeabaed","contract":["ansiStyles.color provides standard foreground colors with matching open and close ANSI escape sequences","ansiStyles.bgColor provides standard background colors with matching open and close ANSI escape sequences","ansiStyles.modifier provides text formatting modifiers including bold, dim, italic, and underline","ansiStyles.color.ansi256 and ansiStyles.bgColor.ansi256 generate 256-color palette ANSI escape codes","ansiStyles.color.ansi16m and ansiStyles.bgColor.ansi16m convert RGB and HEX color values into 24-bit truecolor ANSI escape codes","formatText applies styled open and close sequences around text with support for colors, background colors, and modifiers"],"goal":"verify pkg:npm/ansi-styles@4.3.0","kind":"HOW","packages":["pkg:npm/ansi-styles@4.3.0"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/ansi-styles@4.3.0"],"schemaVersion":1,"subject":"pkg:npm/ansi-styles@4.3.0","verifierAdapter":"node-typescript@1"}
{
"name": "sample-ansi-styles",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ansi-styles",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"ansi-styles": "4.3.0"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"license": "MIT",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"license": "MIT",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"license": "MIT"
}
}
}
{
"name": "sample-ansi-styles",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification sample for ansi-styles",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"ansi-styles": "4.3.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/ansi-styles@4.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/ansi-styles@4.3.0"
]
}
'use strict';
const ansiStyles = require('ansi-styles');
/**
* Applies a specific open and close ANSI escape style to text.
* @param {string} text - The input text to style.
* @param {{ open: string, close: string }} styleObj - Object containing open and close escape codes.
* @returns {string} Styled text wrapped with open and close sequences.
*/
function wrapStyle(text, styleObj) {
if (!styleObj || typeof styleObj.open !== 'string' || typeof styleObj.close !== 'string') {
return text;
}
return `${styleObj.open}${text}${styleObj.close}`;
}
/**
* Formats text with 24-bit TrueColor foreground and background.
* @param {string} text - The input text.
* @param {string} [fgHex] - Hex code for foreground (e.g. "#FF0000").
* @param {string} [bgHex] - Hex code for background (e.g. "#00FF00").
* @returns {string} Text formatted with TrueColor ANSI escapes.
*/
function styleWithHex(text, fgHex, bgHex) {
let result = text;
if (fgHex) {
const open = ansiStyles.color.ansi16m.hex(fgHex);
const close = ansiStyles.color.close;
result = `${open}${result}${close}`;
}
if (bgHex) {
const open = ansiStyles.bgColor.ansi16m.hex(bgHex);
const close = ansiStyles.bgColor.close;
result = `${open}${result}${close}`;
}
return result;
}
/**
* Formats text with 256-color palette foreground and background.
* @param {string} text - The input text.
* @param {number} [fgCode] - ANSI 256 color index for foreground (0-255).
* @param {number} [bgCode] - ANSI 256 color index for background (0-255).
* @returns {string} Text formatted with 256-color ANSI escapes.
*/
function styleWithAnsi256(text, fgCode, bgCode) {
let result = text;
if (typeof fgCode === 'number') {
const open = ansiStyles.color.ansi256.ansi256(fgCode);
const close = ansiStyles.color.close;
result = `${open}${result}${close}`;
}
if (typeof bgCode === 'number') {
const open = ansiStyles.bgColor.ansi256.ansi256(bgCode);
const close = ansiStyles.bgColor.close;
result = `${open}${result}${close}`;
}
return result;
}
/**
* Formats text with color, background color, and modifiers.
* @param {string} text - The text to style.
* @param {object} options - Styling options.
* @param {string} [options.color] - Named foreground color (e.g. 'red', 'green').
* @param {string} [options.bgColor] - Named background color (e.g. 'bgBlue', 'bgYellow').
* @param {string[]} [options.modifiers] - Array of modifier names (e.g. ['bold', 'underline']).
* @returns {string} Formatted text.
*/
function formatText(text, options = {}) {
let result = text;
if (options.modifiers && Array.isArray(options.modifiers)) {
for (const mod of options.modifiers) {
if (ansiStyles.modifier[mod]) {
result = wrapStyle(result, ansiStyles.modifier[mod]);
}
}
}
if (options.bgColor && ansiStyles.bgColor[options.bgColor]) {
result = wrapStyle(result, ansiStyles.bgColor[options.bgColor]);
}
if (options.color && ansiStyles.color[options.color]) {
result = wrapStyle(result, ansiStyles.color[options.color]);
}
return result;
}
module.exports = {
ansiStyles,
wrapStyle,
styleWithHex,
styleWithAnsi256,
formatText
};
'use strict';
const assert = require('node:assert');
const ansiStyles = require('ansi-styles');
const {
wrapStyle,
styleWithHex,
styleWithAnsi256,
formatText
} = require('../src/index.js');
// 1. ansiStyles.color provides standard foreground colors with matching open and close ANSI escape sequences
assert.ok(ansiStyles.color, 'ansiStyles.color must be defined');
assert.strictEqual(typeof ansiStyles.color.red, 'object', 'ansiStyles.color.red must be an object');
assert.strictEqual(ansiStyles.color.red.open, '\x1b[31m', 'ansiStyles.color.red.open must be \\x1b[31m');
assert.strictEqual(ansiStyles.color.red.close, '\x1b[39m', 'ansiStyles.color.red.close must be \\x1b[39m');
assert.strictEqual(ansiStyles.color.green.open, '\x1b[32m', 'ansiStyles.color.green.open must be \\x1b[32m');
assert.strictEqual(ansiStyles.color.green.close, '\x1b[39m', 'ansiStyles.color.green.close must be \\x1b[39m');
assert.strictEqual(ansiStyles.color.blue.open, '\x1b[34m', 'ansiStyles.color.blue.open must be \\x1b[34m');
assert.strictEqual(ansiStyles.color.yellow.open, '\x1b[33m', 'ansiStyles.color.yellow.open must be \\x1b[33m');
assert.strictEqual(ansiStyles.color.magenta.open, '\x1b[35m', 'ansiStyles.color.magenta.open must be \\x1b[35m');
assert.strictEqual(ansiStyles.color.cyan.open, '\x1b[36m', 'ansiStyles.color.cyan.open must be \\x1b[36m');
assert.strictEqual(ansiStyles.color.white.open, '\x1b[37m', 'ansiStyles.color.white.open must be \\x1b[37m');
assert.strictEqual(ansiStyles.color.black.open, '\x1b[30m', 'ansiStyles.color.black.open must be \\x1b[30m');
assert.strictEqual(ansiStyles.color.close, '\x1b[39m', 'ansiStyles.color.close must be \\x1b[39m');
// Bright foreground colors
assert.strictEqual(ansiStyles.color.redBright.open, '\x1b[91m', 'ansiStyles.color.redBright.open must be \\x1b[91m');
assert.strictEqual(ansiStyles.color.greenBright.open, '\x1b[92m', 'ansiStyles.color.greenBright.open must be \\x1b[92m');
assert.strictEqual(ansiStyles.color.blackBright.open, '\x1b[90m', 'ansiStyles.color.blackBright.open must be \\x1b[90m');
// 2. ansiStyles.bgColor provides standard background colors with matching open and close ANSI escape sequences
assert.ok(ansiStyles.bgColor, 'ansiStyles.bgColor must be defined');
assert.strictEqual(typeof ansiStyles.bgColor.bgRed, 'object', 'ansiStyles.bgColor.bgRed must be an object');
assert.strictEqual(ansiStyles.bgColor.bgRed.open, '\x1b[41m', 'ansiStyles.bgColor.bgRed.open must be \\x1b[41m');
assert.strictEqual(ansiStyles.bgColor.bgRed.close, '\x1b[49m', 'ansiStyles.bgColor.bgRed.close must be \\x1b[49m');
assert.strictEqual(ansiStyles.bgColor.bgGreen.open, '\x1b[42m', 'ansiStyles.bgColor.bgGreen.open must be \\x1b[42m');
assert.strictEqual(ansiStyles.bgColor.bgGreen.close, '\x1b[49m', 'ansiStyles.bgColor.bgGreen.close must be \\x1b[49m');
assert.strictEqual(ansiStyles.bgColor.bgBlue.open, '\x1b[44m', 'ansiStyles.bgColor.bgBlue.open must be \\x1b[44m');
assert.strictEqual(ansiStyles.bgColor.bgYellow.open, '\x1b[43m', 'ansiStyles.bgColor.bgYellow.open must be \\x1b[43m');
assert.strictEqual(ansiStyles.bgColor.bgMagenta.open, '\x1b[45m', 'ansiStyles.bgColor.bgMagenta.open must be \\x1b[45m');
assert.strictEqual(ansiStyles.bgColor.bgCyan.open, '\x1b[46m', 'ansiStyles.bgColor.bgCyan.open must be \\x1b[46m');
assert.strictEqual(ansiStyles.bgColor.bgWhite.open, '\x1b[47m', 'ansiStyles.bgColor.bgWhite.open must be \\x1b[47m');
assert.strictEqual(ansiStyles.bgColor.bgBlack.open, '\x1b[40m', 'ansiStyles.bgColor.bgBlack.open must be \\x1b[40m');
assert.strictEqual(ansiStyles.bgColor.close, '\x1b[49m', 'ansiStyles.bgColor.close must be \\x1b[49m');
// Bright background colors
assert.strictEqual(ansiStyles.bgColor.bgRedBright.open, '\x1b[101m', 'ansiStyles.bgColor.bgRedBright.open must be \\x1b[101m');
assert.strictEqual(ansiStyles.bgColor.bgGreenBright.open, '\x1b[102m', 'ansiStyles.bgColor.bgGreenBright.open must be \\x1b[102m');
// 3. ansiStyles.modifier provides text formatting modifiers including bold, dim, italic, and underline
assert.ok(ansiStyles.modifier, 'ansiStyles.modifier must be defined');
assert.strictEqual(ansiStyles.modifier.bold.open, '\x1b[1m', 'ansiStyles.modifier.bold.open must be \\x1b[1m');
assert.strictEqual(ansiStyles.modifier.bold.close, '\x1b[22m', 'ansiStyles.modifier.bold.close must be \\x1b[22m');
assert.strictEqual(ansiStyles.modifier.dim.open, '\x1b[2m', 'ansiStyles.modifier.dim.open must be \\x1b[2m');
assert.strictEqual(ansiStyles.modifier.dim.close, '\x1b[22m', 'ansiStyles.modifier.dim.close must be \\x1b[22m');
assert.strictEqual(ansiStyles.modifier.italic.open, '\x1b[3m', 'ansiStyles.modifier.italic.open must be \\x1b[3m');
assert.strictEqual(ansiStyles.modifier.italic.close, '\x1b[23m', 'ansiStyles.modifier.italic.close must be \\x1b[23m');
assert.strictEqual(ansiStyles.modifier.underline.open, '\x1b[4m', 'ansiStyles.modifier.underline.open must be \\x1b[4m');
assert.strictEqual(ansiStyles.modifier.underline.close, '\x1b[24m', 'ansiStyles.modifier.underline.close must be \\x1b[24m');
assert.strictEqual(ansiStyles.modifier.inverse.open, '\x1b[7m', 'ansiStyles.modifier.inverse.open must be \\x1b[7m');
assert.strictEqual(ansiStyles.modifier.inverse.close, '\x1b[27m', 'ansiStyles.modifier.inverse.close must be \\x1b[27m');
assert.strictEqual(ansiStyles.modifier.hidden.open, '\x1b[8m', 'ansiStyles.modifier.hidden.open must be \\x1b[8m');
assert.strictEqual(ansiStyles.modifier.hidden.close, '\x1b[28m', 'ansiStyles.modifier.hidden.close must be \\x1b[28m');
assert.strictEqual(ansiStyles.modifier.strikethrough.open, '\x1b[9m', 'ansiStyles.modifier.strikethrough.open must be \\x1b[9m');
assert.strictEqual(ansiStyles.modifier.strikethrough.close, '\x1b[29m', 'ansiStyles.modifier.strikethrough.close must be \\x1b[29m');
assert.strictEqual(ansiStyles.modifier.reset.open, '\x1b[0m', 'ansiStyles.modifier.reset.open must be \\x1b[0m');
assert.strictEqual(ansiStyles.modifier.reset.close, '\x1b[0m', 'ansiStyles.modifier.reset.close must be \\x1b[0m');
// 4. ansiStyles.color.ansi256 and ansiStyles.bgColor.ansi256 generate 256-color palette ANSI escape codes
const fg256 = ansiStyles.color.ansi256.ansi256(196);
assert.strictEqual(fg256, '\x1b[38;5;196m', 'ansi256 foreground 196 escape code');
const bg256 = ansiStyles.bgColor.ansi256.ansi256(46);
assert.strictEqual(bg256, '\x1b[48;5;46m', 'ansi256 background 46 escape code');
const styled256 = styleWithAnsi256('256-color text', 196, 46);
assert.strictEqual(
styled256,
'\x1b[48;5;46m\x1b[38;5;196m256-color text\x1b[39m\x1b[49m',
'styleWithAnsi256 must correctly wrap with 256-color foreground and background'
);
// 5. ansiStyles.color.ansi16m and ansiStyles.bgColor.ansi16m convert RGB and HEX color values into 24-bit truecolor ANSI escape codes
const rgbFg = ansiStyles.color.ansi16m.rgb(255, 100, 50);
assert.strictEqual(rgbFg, '\x1b[38;2;255;100;50m', '24-bit truecolor RGB foreground escape code');
const hexFg = ansiStyles.color.ansi16m.hex('#FF6432');
assert.strictEqual(hexFg, '\x1b[38;2;255;100;50m', '24-bit truecolor HEX foreground escape code');
const rgbBg = ansiStyles.bgColor.ansi16m.rgb(20, 30, 40);
assert.strictEqual(rgbBg, '\x1b[48;2;20;30;40m', '24-bit truecolor RGB background escape code');
const hexBg = ansiStyles.bgColor.ansi16m.hex('#141E28');
assert.strictEqual(hexBg, '\x1b[48;2;20;30;40m', '24-bit truecolor HEX background escape code');
const styledHex = styleWithHex('Truecolor text', '#FF6432', '#141E28');
assert.strictEqual(
styledHex,
'\x1b[48;2;20;30;40m\x1b[38;2;255;100;50mTruecolor text\x1b[39m\x1b[49m',
'styleWithHex must correctly wrap with 24-bit truecolor sequences'
);
// 6. formatText applies styled open and close sequences around text with support for colors, background colors, and modifiers
const wrappedRed = wrapStyle('Hello', ansiStyles.color.red);
assert.strictEqual(wrappedRed, '\x1b[31mHello\x1b[39m', 'wrapStyle must surround text with open and close escape codes');
const complexFormatted = formatText('Error occurred', {
color: 'red',
bgColor: 'bgYellow',
modifiers: ['bold', 'underline']
});
assert.strictEqual(
complexFormatted,
'\x1b[31m\x1b[43m\x1b[4m\x1b[1mError occurred\x1b[22m\x1b[24m\x1b[49m\x1b[39m',
'formatText must nest modifiers, background, and foreground styles'
);
console.log('Contract tests passed successfully.');
Ursprungs-Seeder
anonym