Ejemplo
ansi-styles 6.2.3: default
Muestra verificada para npm ansi-styles 6.2.3: default. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: ansiStyles default export…
sha256:fb736d6551709723e3267fbe2ab168810ea82de61331baa6b9fa1d964e3dea6b
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
- 2
- Claves de firma que lo compilaron
- 1
Entorno declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify ansi-styles.default in pkg:npm/ansi-styles@6.2.3
- Paquetes
- Símbolos
-
- ansi-styles.default
- Entorno
- node 22.23.2
- Creado
- 2026-08-23T05:37:05Z
Contrato
- ansiStyles default export provides modifier, color, bgColor objects and codes Map
- ansiStyles.modifier defines standard text styling modifiers with matching open and close codes
- ansiStyles.color defines standard and bright foreground colors with close code
- ansiStyles.bgColor defines standard and bright background colors with close code
- ansiStyles.color.ansi256 and ansiStyles.bgColor.ansi256 generate 256-color palette escape sequences
- ansiStyles.color.ansi16m and ansiStyles.bgColor.ansi16m generate 24-bit truecolor escape sequences
- ansiStyles.codes maps opening ANSI codes to corresponding closing codes
- formatWithStyles combines foreground, background, and modifier styles on target text
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
Código fuente
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.default 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.default
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:8fbc2652fa8a93af07c9010169f981538cce83b7c21d53cd74dd0447f1923a88","contract":["ansiStyles default export provides modifier, color, bgColor objects and codes Map","ansiStyles.modifier defines standard text styling modifiers with matching open and close codes","ansiStyles.color defines standard and bright foreground colors with close code","ansiStyles.bgColor defines standard and bright background colors with close code","ansiStyles.color.ansi256 and ansiStyles.bgColor.ansi256 generate 256-color palette escape sequences","ansiStyles.color.ansi16m and ansiStyles.bgColor.ansi16m generate 24-bit truecolor escape sequences","ansiStyles.codes maps opening ANSI codes to corresponding closing codes","formatWithStyles combines foreground, background, and modifier styles on target text"],"goal":"verify ansi-styles.default in pkg:npm/ansi-styles@6.2.3","kind":"HOW","packages":["pkg:npm/ansi-styles@6.2.3"],"schemaVersion":1,"symbols":["ansi-styles.default"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","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.default"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-ansi-styles-default",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ansi-styles-default",
"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-default",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"ansi-styles": "6.2.3"
}
}
{
"schemaVersion": 1,
"goal": "verify ansi-styles.default in pkg:npm/ansi-styles@6.2.3",
"kind": "HOW",
"packages": [
"pkg:npm/ansi-styles@6.2.3"
],
"symbols": [
"ansi-styles.default"
]
}
import ansiStyles from 'ansi-styles';
/**
* Returns the default ansiStyles export.
* @returns {object}
*/
export function getDefaultStyles() {
return ansiStyles;
}
/**
* Applies a modifier style to text.
* @param {string} text
* @param {string} modifierName
* @returns {string}
*/
export function applyModifier(text, modifierName) {
const mod = ansiStyles.modifier[modifierName];
if (!mod) {
throw new Error(`Unknown modifier: ${modifierName}`);
}
return `${mod.open}${text}${mod.close}`;
}
/**
* Applies foreground and/or background styling and modifiers using default ansiStyles.
* @param {string} text
* @param {object} options
* @param {string} [options.color]
* @param {string} [options.bgColor]
* @param {string|string[]} [options.modifier]
* @returns {string}
*/
export function formatWithStyles(text, options = {}) {
let openSeq = '';
let closeSeq = '';
if (options.modifier) {
const modifiers = Array.isArray(options.modifier) ? options.modifier : [options.modifier];
for (const mod of modifiers) {
const style = ansiStyles.modifier[mod];
if (!style) {
throw new Error(`Unknown modifier: ${mod}`);
}
openSeq += style.open;
closeSeq = style.close + closeSeq;
}
}
if (options.color) {
const style = ansiStyles.color[options.color];
if (!style) {
throw new Error(`Unknown foreground color: ${options.color}`);
}
openSeq += style.open;
closeSeq = style.close + closeSeq;
}
if (options.bgColor) {
const style = ansiStyles.bgColor[options.bgColor];
if (!style) {
throw new Error(`Unknown background color: ${options.bgColor}`);
}
openSeq += style.open;
closeSeq = style.close + closeSeq;
}
return `${openSeq}${text}${closeSeq}`;
}
/**
* Formats text using a 256-color palette index.
* @param {string} text
* @param {number} code
* @param {boolean} isBackground
* @returns {string}
*/
export function formatAnsi256(text, code, isBackground = false) {
if (typeof code !== 'number' || code < 0 || code > 255) {
throw new RangeError(`Color code must be 0-255: ${code}`);
}
const target = isBackground ? ansiStyles.bgColor : ansiStyles.color;
return `${target.ansi256(code)}${text}${target.close}`;
}
/**
* Formats text using 24-bit RGB truecolor escape sequences.
* @param {string} text
* @param {number} red
* @param {number} green
* @param {number} blue
* @param {boolean} isBackground
* @returns {string}
*/
export function formatAnsi16m(text, red, green, blue, isBackground = false) {
const target = isBackground ? ansiStyles.bgColor : ansiStyles.color;
return `${target.ansi16m(red, green, blue)}${text}${target.close}`;
}
/**
* Looks up the corresponding closing ANSI code for a given opening code.
* @param {number} openCode
* @returns {number|undefined}
*/
export function getClosingCode(openCode) {
return ansiStyles.codes.get(openCode);
}
export default ansiStyles;
import assert from 'node:assert';
import ansiStyles, {
getDefaultStyles,
applyModifier,
formatWithStyles,
formatAnsi256,
formatAnsi16m,
getClosingCode,
} from '../src/index.mjs';
// 1. ansiStyles default export provides modifier, color, bgColor objects and codes Map
assert(ansiStyles && typeof ansiStyles === 'object', 'ansiStyles must be an object');
assert.strictEqual(getDefaultStyles(), ansiStyles, 'getDefaultStyles must return default ansiStyles export');
assert(typeof ansiStyles.modifier === 'object', 'ansiStyles.modifier must be an object');
assert(typeof ansiStyles.color === 'object', 'ansiStyles.color must be an object');
assert(typeof ansiStyles.bgColor === 'object', 'ansiStyles.bgColor must be an object');
assert(ansiStyles.codes instanceof Map, 'ansiStyles.codes must be a Map instance');
// 2. ansiStyles.modifier defines standard text styling modifiers with matching open and close codes
const expectedModifiers = {
reset: { open: '\u001B[0m', close: '\u001B[0m' },
bold: { open: '\u001B[1m', close: '\u001B[22m' },
dim: { open: '\u001B[2m', close: '\u001B[22m' },
italic: { open: '\u001B[3m', close: '\u001B[23m' },
underline: { open: '\u001B[4m', close: '\u001B[24m' },
overline: { open: '\u001B[53m', close: '\u001B[55m' },
inverse: { open: '\u001B[7m', close: '\u001B[27m' },
hidden: { open: '\u001B[8m', close: '\u001B[28m' },
strikethrough: { open: '\u001B[9m', close: '\u001B[29m' },
};
for (const [name, expected] of Object.entries(expectedModifiers)) {
const mod = ansiStyles.modifier[name];
assert(mod, `Missing modifier: ${name}`);
assert.strictEqual(mod.open, expected.open, `${name} open code mismatch`);
assert.strictEqual(mod.close, expected.close, `${name} close code mismatch`);
}
assert.strictEqual(applyModifier('bold text', 'bold'), '\u001B[1mbold text\u001B[22m');
assert.throws(() => applyModifier('text', 'invalidMod'), /Unknown modifier: invalidMod/);
// 3. ansiStyles.color defines standard and bright foreground colors with close code
assert.strictEqual(ansiStyles.color.close, '\u001B[39m');
const standardFg = {
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(standardFg)) {
const style = ansiStyles.color[name];
assert(style, `Missing foreground color: ${name}`);
assert.strictEqual(style.open, expectedOpen, `${name} open mismatch`);
assert.strictEqual(style.close, '\u001B[39m', `${name} close mismatch`);
}
const brightFg = {
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(brightFg)) {
const style = ansiStyles.color[name];
assert(style, `Missing bright foreground color: ${name}`);
assert.strictEqual(style.open, expectedOpen, `${name} open mismatch`);
assert.strictEqual(style.close, '\u001B[39m', `${name} close mismatch`);
}
assert.deepStrictEqual(ansiStyles.color.gray, ansiStyles.color.blackBright);
assert.deepStrictEqual(ansiStyles.color.grey, ansiStyles.color.blackBright);
// 4. ansiStyles.bgColor defines standard and bright background colors with close code
assert.strictEqual(ansiStyles.bgColor.close, '\u001B[49m');
const standardBg = {
bgBlack: '\u001B[40m',
bgRed: '\u001B[41m',
bgGreen: '\u001B[42m',
bgYellow: '\u001B[43m',
bgBlue: '\u001B[44m',
bgMagenta: '\u001B[45m',
bgCyan: '\u001B[46m',
bgWhite: '\u001B[47m',
};
for (const [name, expectedOpen] of Object.entries(standardBg)) {
const style = ansiStyles.bgColor[name];
assert(style, `Missing background color: ${name}`);
assert.strictEqual(style.open, expectedOpen, `${name} open mismatch`);
assert.strictEqual(style.close, '\u001B[49m', `${name} close mismatch`);
}
const brightBg = {
bgBlackBright: '\u001B[100m',
bgRedBright: '\u001B[101m',
bgGreenBright: '\u001B[102m',
bgYellowBright: '\u001B[103m',
bgBlueBright: '\u001B[104m',
bgMagentaBright: '\u001B[105m',
bgCyanBright: '\u001B[106m',
bgWhiteBright: '\u001B[107m',
};
for (const [name, expectedOpen] of Object.entries(brightBg)) {
const style = ansiStyles.bgColor[name];
assert(style, `Missing bright background color: ${name}`);
assert.strictEqual(style.open, expectedOpen, `${name} open mismatch`);
assert.strictEqual(style.close, '\u001B[49m', `${name} close mismatch`);
}
assert.deepStrictEqual(ansiStyles.bgColor.bgGray, ansiStyles.bgColor.bgBlackBright);
assert.deepStrictEqual(ansiStyles.bgColor.bgGrey, ansiStyles.bgColor.bgBlackBright);
// 5. ansiStyles.color.ansi256 and ansiStyles.bgColor.ansi256 generate 256-color palette escape sequences
assert.strictEqual(ansiStyles.color.ansi256(196), '\u001B[38;5;196m');
assert.strictEqual(ansiStyles.bgColor.ansi256(196), '\u001B[48;5;196m');
assert.strictEqual(formatAnsi256('palette', 201, false), '\u001B[38;5;201mpalette\u001B[39m');
assert.strictEqual(formatAnsi256('palette bg', 45, true), '\u001B[48;5;45mpalette bg\u001B[49m');
assert.throws(() => formatAnsi256('bad', -1), RangeError);
assert.throws(() => formatAnsi256('bad', 256), RangeError);
// 6. ansiStyles.color.ansi16m and ansiStyles.bgColor.ansi16m generate 24-bit truecolor escape sequences
assert.strictEqual(ansiStyles.color.ansi16m(255, 100, 50), '\u001B[38;2;255;100;50m');
assert.strictEqual(ansiStyles.bgColor.ansi16m(10, 20, 30), '\u001B[48;2;10;20;30m');
assert.strictEqual(formatAnsi16m('truecolor', 100, 150, 200, false), '\u001B[38;2;100;150;200mtruecolor\u001B[39m');
assert.strictEqual(formatAnsi16m('truecolor bg', 1, 2, 3, true), '\u001B[48;2;1;2;3mtruecolor bg\u001B[49m');
// 7. ansiStyles.codes maps opening ANSI codes to corresponding closing codes
assert.strictEqual(getClosingCode(1), 22);
assert.strictEqual(getClosingCode(2), 22);
assert.strictEqual(getClosingCode(3), 23);
assert.strictEqual(getClosingCode(4), 24);
assert.strictEqual(getClosingCode(7), 27);
assert.strictEqual(getClosingCode(8), 28);
assert.strictEqual(getClosingCode(9), 29);
assert.strictEqual(getClosingCode(31), 39);
assert.strictEqual(getClosingCode(41), 49);
assert.strictEqual(getClosingCode(53), 55);
// 8. formatWithStyles combines foreground, background, and modifier styles on target text
const styled = formatWithStyles('Hello World', {
color: 'green',
bgColor: 'bgBlack',
modifier: ['bold', 'underline'],
});
assert.strictEqual(styled, '\u001B[1m\u001B[4m\u001B[32m\u001B[40mHello World\u001B[49m\u001B[39m\u001B[24m\u001B[22m');
const singleMod = formatWithStyles('Sample', { color: 'blue', modifier: 'italic' });
assert.strictEqual(singleMod, '\u001B[3m\u001B[34mSample\u001B[39m\u001B[23m');
assert.throws(() => formatWithStyles('bad', { color: 'unknownColor' }), /Unknown foreground color: unknownColor/);
assert.throws(() => formatWithStyles('bad', { bgColor: 'unknownBg' }), /Unknown background color: unknownBg/);
assert.throws(() => formatWithStyles('bad', { modifier: 'unknownMod' }), /Unknown modifier: unknownMod/);
console.log('All contract assertions for ansi-styles.default passed successfully.');
Seeder de origen
anónimo