CodeSampleX

Ejemplo

ansi-styles 6.2.3: rgbToAnsi256

Muestra verificada para npm ansi-styles 6.2.3: rgbToAnsi256. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:130a482094456a8fcab5f4c21ca1ca52acc67467d977c2783ea469c66d9f87a8

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 linux 24 · ubuntu · glibc 2.39 x64 npm

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.rgbToAnsi256 in pkg:npm/ansi-styles@6.2.3
Paquetes
Símbolos
  • ansi-styles.rgbToAnsi256
Creado
2026-08-23T05:51:31Z

Contrato

  1. ansiStyles.rgbToAnsi256 converts RGB values to ANSI 256 color space number
  2. ansiStyles.rgbToAnsi256(255, 255, 255) returns 231
  3. ansiStyles.rgbToAnsi256(0, 0, 0) returns 16
  4. ansiStyles.rgbToAnsi256(255, 0, 0) returns 196

Archivos

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

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

Código fuente

PROMPT.md
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.rgbToAnsi256 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.rgbToAnsi256

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.
csx.json
{"case":{"caseId":"case:sha256:c8d31abdf43522afd0ea873a9bd21aa970919019cebabcdd2e571589898855cc","contract":["ansiStyles.rgbToAnsi256 converts RGB values to ANSI 256 color space number","ansiStyles.rgbToAnsi256(255, 255, 255) returns 231","ansiStyles.rgbToAnsi256(0, 0, 0) returns 16","ansiStyles.rgbToAnsi256(255, 0, 0) returns 196"],"goal":"verify ansi-styles.rgbToAnsi256 in pkg:npm/ansi-styles@6.2.3","kind":"HOW","packages":["pkg:npm/ansi-styles@6.2.3"],"schemaVersion":1,"symbols":["ansi-styles.rgbToAnsi256"]},"contractCommand":["node","test/contract.mjs"],"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@6.2.3"],"schemaVersion":1,"subject":"pkg:npm/ansi-styles@6.2.3","symbols":["ansi-styles.rgbToAnsi256"],"verifierAdapter":"node-typescript@1"}
index.mjs
import ansiStyles from 'ansi-styles';

export function rgbToAnsi256(red, green, blue) {
  return ansiStyles.rgbToAnsi256(red, green, blue);
}

export function formatRgb256Text(red, green, blue, text) {
  const code = ansiStyles.rgbToAnsi256(red, green, blue);
  return `${ansiStyles.color.ansi256(code)}${text}${ansiStyles.color.close}`;
}
package-lock.json
{
  "name": "sample-ansi-styles",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ansi-styles",
      "version": "1.0.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"
      }
    }
  }
}
package.json
{
  "name": "sample-ansi-styles",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "ansi-styles": "6.2.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify ansi-styles.rgbToAnsi256 in pkg:npm/ansi-styles@6.2.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ansi-styles@6.2.3"
  ],
  "symbols": [
    "ansi-styles.rgbToAnsi256"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import ansiStyles from 'ansi-styles';
import { rgbToAnsi256, formatRgb256Text } from '../index.mjs';

// Verify ansiStyles.rgbToAnsi256 directly
assert.equal(typeof ansiStyles.rgbToAnsi256, 'function');
assert.equal(ansiStyles.rgbToAnsi256(255, 255, 255), 231);
assert.equal(ansiStyles.rgbToAnsi256(0, 0, 0), 16);
assert.equal(ansiStyles.rgbToAnsi256(255, 0, 0), 196);
assert.equal(ansiStyles.rgbToAnsi256(0, 255, 0), 46);
assert.equal(ansiStyles.rgbToAnsi256(0, 0, 255), 21);

// Verify module wrapper
assert.equal(rgbToAnsi256(255, 255, 255), 231);
assert.equal(rgbToAnsi256(0, 0, 0), 16);
assert.equal(formatRgb256Text(255, 0, 0, 'hello'), '\x1b[38;5;196mhello\x1b[39m');

console.log('Contract verification passed for ansi-styles.rgbToAnsi256');

Seeder de origen

anónimo