CodeSampleX

Ejemplo

chalk 6.0.0: Apply Chalk v6 extended underline styles and SGR 58 underline colors with level-dependent downsampling and separate color export catalogs.

Muestra verificada para npm chalk 6.0.0: Apply Chalk v6 extended underline styles and SGR 58 underline colors with level-dependent downsampling and separate…

sha256:b96150657e900e7afc7af76e5c63c74d2de2ef16bdfea180adc7d3b713d5cc28

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
2
Entorno declarado node linux x64 node node npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-17
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-18

Caso

HOW
Objetivo
Apply Chalk v6 extended underline styles and SGR 58 underline colors with level-dependent downsampling and separate color export catalogs.
Paquetes
Símbolos
  • chalk.underlineRgb
  • chalk.underlineHex
  • chalk.underlineCurly
  • chalk.underlineRed
  • underlineColorNames
Entorno
node
Creado
2026-08-17T18:28:06Z

Contrato

  1. Chalk v6 underline colors emit SGR 58 escape sequences with SGR 59 resets across all color levels, downsampling to palette-indexed SGR 58;5 codes at level 1 rather than 2-digit ANSI codes.
  2. Level 3 truecolor underlineHex and underlineRgb emit 24-bit SGR 58;2 sequences closed by \u001b[59m.
  3. Level 2 256-color underlineHex downsamples to 8-bit palette SGR 58;5 sequences closed by \u001b[59m.
  4. Extended underline styles underlineCurly, underlineDouble, underlineDotted, and underlineDashed emit SGR 4:x subparameter sequences closed by \u001b[24m.
  5. Chaining extended underline styles with underline colors combines open sequences and nests closing sequences in LIFO order.
  6. underlineColorNames is exported separately and omitted from the colorNames export.
  7. Level 0 completely strips underline style and color escape sequences, returning plain text.

Archivos

  • NOTES.md
  • csx.json
  • package-lock.json
  • package.json
  • src/index.mjs
  • test/contract.mjs

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

Código fuente

NOTES.md
# Chalk v6 Underline Styles and SGR 58 Color Architecture

## Search Results and Prior Work
Prior searches for `chalk` returned samples covering runtime level disabling (`sha256:525f14e9ff41964b2cf8700329f042389c75335c2b13dc4d12796c1cbb8e0f28`), `chalkStderr` stream separation (`sha256:2f6838edb7c63b1b528b3bfb3a2bea8805f50b06592b69b3f62ca5166f239c8b`), malformed `hex()` input handling (`sha256:8a0531ffe818e26b9036a49be7c8f41af3ee24f2802f62aa006deb0ac042b7dd`), and basic foreground RGB downsampling (`sha256:1d01640309b3b61194965429100ee64dc820854d9541aa68eaf18e0830575a8a`).

This sample proves behaviour in Chalk v6: extended underline styles (`underlineCurly`, `underlineDouble`, `underlineDotted`, `underlineDashed`, `overline`), SGR 58 underline color formatting (`underlineHex`, `underlineRgb`, `underlineAnsi256`, `underlineRed`), level-specific downsampling anomalies, and separate color export catalogs.

## Exact Release Pinned
- `chalk@6.0.0`

## Observed Behaviour

1. **SGR 58 Escape Sequences & SGR 59 Reset**:
   Unlike foreground colors (which use SGR 38 and reset with `\u001b[39m`) and background colors (which use SGR 48 and reset with `\u001b[49m`), Chalk v6 underline colors use SGR 58 and close with SGR 59 (`\u001b[59m`).

2. **Level 1 Downsampling Trap**:
   In level 1 (basic 16-color) mode, foreground colors downsample to 2-digit ANSI escapes (e.g. `\u001b[91m`), and background colors downsample to `\u001b[101m`. However, standard ANSI has no 2-digit direct escape code for underline colors. Consequently, Chalk v6 maps level 1 underline colors to palette indices within SGR 58;5 (e.g. `\u001b[58;5;9m` for `#FF0000`).

3. **Extended Underline Subparameters**:
   Chalk v6 introduces distinct underline geometry using ITU T.416 subparameters:
   - `underlineCurly`: `\u001b[4:3m` ... `\u001b[24m`
   - `underlineDouble`: `\u001b[4:2m` ... `\u001b[24m`
   - `underlineDotted`: `\u001b[4:4m` ... `\u001b[24m`
   - `underlineDashed`: `\u001b[4:5m` ... `\u001b[24m`
   - `overline`: `\u001b[53m` ... `\u001b[55m`

4. **Separate Color Export Catalogs**:
   `underlineColorNames` is exported as its own array of style keys. The legacy `colorNames` export contains only foreground and background color names (`[...foregroundColorNames, ...backgroundColorNames]`), excluding underline colors.

5. **Chaining and Nesting**:
   Chaining extended underline styles with underline colors concatenates opening escape codes and nests closing codes in LIFO order (`\u001b[59m\u001b[24m`).

## How the Wrong Expectation Fails
- **Loud assertion failures on ANSI codes**: Expecting `underlineHex('#FF0000')` to produce standard 2-digit escape codes (`\u001b[91m`) at level 1 fails because Chalk generates `\u001b[58;5;9m` with `\u001b[59m`.
- **Loud assertion failures on color catalogs**: Expecting `colorNames.includes('underlineRed')` fails as `colorNames` omits all underline color identifiers.
csx.json
{"case":{"believed":"Underline colors downsample to standard 2-digit 16-color ANSI codes at level 1 and are included in the default colorNames array like foreground and background styles.","caseId":"case:sha256:c490b7cb416690457ea4924570aa8ddcff96f11c833239efb64a000e287bd4d1","contract":["Chalk v6 underline colors emit SGR 58 escape sequences with SGR 59 resets across all color levels, downsampling to palette-indexed SGR 58;5 codes at level 1 rather than 2-digit ANSI codes.","Level 3 truecolor underlineHex and underlineRgb emit 24-bit SGR 58;2 sequences closed by \\u001b[59m.","Level 2 256-color underlineHex downsamples to 8-bit palette SGR 58;5 sequences closed by \\u001b[59m.","Extended underline styles underlineCurly, underlineDouble, underlineDotted, and underlineDashed emit SGR 4:x subparameter sequences closed by \\u001b[24m.","Chaining extended underline styles with underline colors combines open sequences and nests closing sequences in LIFO order.","underlineColorNames is exported separately and omitted from the colorNames export.","Level 0 completely strips underline style and color escape sequences, returning plain text."],"goal":"Apply Chalk v6 extended underline styles and SGR 58 underline colors with level-dependent downsampling and separate color export catalogs.","kind":"HOW","packages":["pkg:npm/chalk@6.0.0"],"schemaVersion":1,"symbols":["chalk.underlineRgb","chalk.underlineHex","chalk.underlineCurly","chalk.underlineRed","underlineColorNames"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/chalk@6.0.0"],"schemaVersion":1,"symbols":["chalk.underlineRgb","chalk.underlineHex","chalk.underlineCurly","chalk.underlineRed","underlineColorNames"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "npm-chalk-v6",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "npm-chalk-v6",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "chalk": "6.0.0"
      }
    },
    "node_modules/chalk": {
      "version": "6.0.0",
      "resolved": "https://registry.npmjs.org/chalk/-/chalk-6.0.0.tgz",
      "integrity": "sha512-2uNTXIuTTxk7ciZgAU1BQcgnchcG0xXnrs6jzkQfj9SsRa9M2s5zE8WT96hS6KmG4MzWHSrvH43DF1m4XRkrFg==",
      "license": "MIT",
      "engines": {
        "node": ">=22"
      },
      "funding": {
        "url": "https://github.com/chalk/chalk?sponsor=1"
      }
    }
  }
}
package.json
{
  "name": "npm-chalk-v6",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "chalk": "6.0.0"
  }
}
src/index.mjs
import { Chalk, underlineColorNames, colorNames } from 'chalk';

export function formatUnderlineCurly(text, level = 3) {
  const instance = new Chalk({ level });
  return instance.underlineCurly(text);
}

export function formatUnderlineDouble(text, level = 3) {
  const instance = new Chalk({ level });
  return instance.underlineDouble(text);
}

export function formatUnderlineDotted(text, level = 3) {
  const instance = new Chalk({ level });
  return instance.underlineDotted(text);
}

export function formatUnderlineDashed(text, level = 3) {
  const instance = new Chalk({ level });
  return instance.underlineDashed(text);
}

export function formatOverline(text, level = 3) {
  const instance = new Chalk({ level });
  return instance.overline(text);
}

export function formatUnderlineHex(hex, text, level = 3) {
  const instance = new Chalk({ level });
  return instance.underlineHex(hex)(text);
}

export function formatUnderlineRgb(r, g, b, text, level = 3) {
  const instance = new Chalk({ level });
  return instance.underlineRgb(r, g, b)(text);
}

export function formatUnderlineNamed(colorName, text, level = 3) {
  const instance = new Chalk({ level });
  return instance[colorName](text);
}

export function formatStyledUnderline(text, level = 3) {
  const instance = new Chalk({ level });
  return instance.underlineCurly.underlineRed(text);
}

export function getUnderlineColorNames() {
  return underlineColorNames;
}

export function getColorNames() {
  return colorNames;
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  formatUnderlineCurly,
  formatUnderlineDouble,
  formatUnderlineDotted,
  formatUnderlineDashed,
  formatOverline,
  formatUnderlineHex,
  formatUnderlineRgb,
  formatUnderlineNamed,
  formatStyledUnderline,
  getUnderlineColorNames,
  getColorNames,
} from '../src/index.mjs';

// 1. Primary Contract: Underline colors emit SGR 58 sequences with SGR 59 reset across all levels,
// downsampling to palette-indexed SGR 58;5 codes at level 1 rather than 2-digit basic ANSI codes.
const redLevel1 = formatUnderlineHex('#FF0000', 'sample', 1);
assert.equal(
  redLevel1,
  '\u001b[58;5;9msample\u001b[59m',
  'Level 1 underlineHex emits palette-indexed SGR 58;5;9m rather than 2-digit ANSI 91m'
);
const namedRedLevel1 = formatUnderlineNamed('underlineRed', 'sample', 1);
assert.equal(
  namedRedLevel1,
  '\u001b[58;5;1msample\u001b[59m',
  'Level 1 named underlineRed emits SGR 58;5;1m'
);

// 2. Level 3 truecolor underlineHex and underlineRgb emit 24-bit SGR 58;2 sequences closed by \u001b[59m.
const hexLevel3 = formatUnderlineHex('#FF0000', 'sample', 3);
assert.equal(
  hexLevel3,
  '\u001b[58;2;255;0;0msample\u001b[59m',
  'Level 3 underlineHex emits 24-bit SGR 58;2 sequence closed by 59m'
);
const rgbLevel3 = formatUnderlineRgb(255, 0, 0, 'sample', 3);
assert.equal(
  rgbLevel3,
  '\u001b[58;2;255;0;0msample\u001b[59m',
  'Level 3 underlineRgb emits 24-bit SGR 58;2 sequence closed by 59m'
);

// 3. Level 2 256-color underlineHex downsamples to 8-bit palette SGR 58;5 sequences closed by \u001b[59m.
const hexLevel2 = formatUnderlineHex('#FF0000', 'sample', 2);
assert.equal(
  hexLevel2,
  '\u001b[58;5;196msample\u001b[59m',
  'Level 2 underlineHex downsamples to 256-color palette index 196 in SGR 58;5 sequence'
);

// 4. Extended underline styles emit SGR 4:x subparameter sequences closed by \u001b[24m.
assert.equal(
  formatUnderlineCurly('curly', 3),
  '\u001b[4:3mcurly\u001b[24m',
  'underlineCurly emits SGR 4:3 subparameter closed by 24m'
);
assert.equal(
  formatUnderlineDouble('double', 3),
  '\u001b[4:2mdouble\u001b[24m',
  'underlineDouble emits SGR 4:2 subparameter closed by 24m'
);
assert.equal(
  formatUnderlineDotted('dotted', 3),
  '\u001b[4:4mdotted\u001b[24m',
  'underlineDotted emits SGR 4:4 subparameter closed by 24m'
);
assert.equal(
  formatUnderlineDashed('dashed', 3),
  '\u001b[4:5mdashed\u001b[24m',
  'underlineDashed emits SGR 4:5 subparameter closed by 24m'
);
assert.equal(
  formatOverline('over', 3),
  '\u001b[53mover\u001b[55m',
  'overline emits SGR 53 closed by 55m'
);

// 5. Chaining extended underline styles with underline colors combines open sequences and nests closing sequences in LIFO order.
const styled = formatStyledUnderline('styled text', 3);
assert.equal(
  styled,
  '\u001b[4:3m\u001b[58;5;1mstyled text\u001b[59m\u001b[24m',
  'Combined chain emits openAll (4:3 + 58;5;1) and closeAll (59 + 24) in LIFO order'
);

// 6. underlineColorNames is exported separately and omitted from the colorNames export.
const exportedUnderlineNames = getUnderlineColorNames();
const exportedColorNames = getColorNames();
assert.equal(Array.isArray(exportedUnderlineNames), true);
assert.equal(exportedUnderlineNames.includes('underlineRed'), true);
assert.equal(exportedUnderlineNames.includes('underlineCyanBright'), true);
assert.equal(
  exportedColorNames.includes('underlineRed'),
  false,
  'colorNames contains foreground and background color names only, excluding underline colors'
);

// 7. Level 0 completely strips underline style and color escape sequences, returning plain text.
assert.equal(
  formatUnderlineHex('#FF0000', 'plain', 0),
  'plain',
  'Level 0 underlineHex returns unstyled text'
);
assert.equal(
  formatUnderlineCurly('plain', 0),
  'plain',
  'Level 0 underlineCurly returns unstyled text'
);
assert.equal(
  formatStyledUnderline('plain', 0),
  'plain',
  'Level 0 combined underline styles return unstyled text'
);

Seeder de origen

csx-seed