CodeSampleX

Ejemplo

kleur 4.1.5: bgGreen

Muestra verificada para npm kleur 4.1.5: bgGreen. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: kleur.bgGreen wraps a string in ANSI…

sha256:7c5c59ae59a9c70df35bc33c7a558740597dbdc90eab63a0c07d08617a0936e4

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
1
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-27

Caso

HOW
Objetivo
verify kleur.bgGreen in pkg:npm/kleur@4.1.5
Paquetes
Símbolos
  • kleur.bgGreen
Creado
2026-08-27T12:03:21Z

Contrato

  1. kleur.bgGreen wraps a string in ANSI background green escape codes \u001b[42m and \u001b[49m
  2. kleur.bgGreen returns a chainable formatter when called with no arguments
  3. kleur.bgGreen coerces numeric and non-string inputs into styled strings
  4. kleur.bgGreen handles empty strings by wrapping them in open and close ANSI codes
  5. setting kleur.enabled to false disables styling and returns the input as plain text

Archivos

  • PROMPT.md
  • csx.json
  • index.js
  • 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 kleur.bgGreen in pkg:npm/kleur@4.1.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/kleur@4.1.5
Demonstrate these symbols/APIs:
  - kleur.bgGreen

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:c9978dd71308004585136282f83a9590ab1f45c81b1658457f2818d51683528b","contract":["kleur.bgGreen wraps a string in ANSI background green escape codes \\u001b[42m and \\u001b[49m","kleur.bgGreen returns a chainable formatter when called with no arguments","kleur.bgGreen coerces numeric and non-string inputs into styled strings","kleur.bgGreen handles empty strings by wrapping them in open and close ANSI codes","setting kleur.enabled to false disables styling and returns the input as plain text"],"goal":"verify kleur.bgGreen in pkg:npm/kleur@4.1.5","kind":"HOW","packages":["pkg:npm/kleur@4.1.5"],"schemaVersion":1,"symbols":["kleur.bgGreen"]},"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/kleur@4.1.5"],"schemaVersion":1,"subject":"pkg:npm/kleur@4.1.5","symbols":["kleur.bgGreen"],"verifierAdapter":"node-typescript@1"}
index.js
import kleur from 'kleur';

/**
 * Formats text with green background ANSI styling.
 * @param {string|number|boolean} text
 * @returns {string}
 */
export function formatSuccessBadge(text) {
  return kleur.bgGreen().white().bold(` ${text} `);
}

/**
 * Applies green background directly using kleur.bgGreen.
 * @param {string|number|boolean} text
 * @returns {string}
 */
export function applyBgGreen(text) {
  return kleur.bgGreen(text);
}

export { kleur };
package-lock.json
{
  "name": "verify-kleur-bggreen",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-kleur-bggreen",
      "version": "1.0.0",
      "dependencies": {
        "kleur": "4.1.5"
      }
    },
    "node_modules/kleur": {
      "version": "4.1.5",
      "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz",
      "integrity": "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    }
  }
}
package.json
{
  "name": "verify-kleur-bggreen",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for kleur.bgGreen in kleur@4.1.5",
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "kleur": "4.1.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify kleur.bgGreen in pkg:npm/kleur@4.1.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/kleur@4.1.5"
  ],
  "symbols": [
    "kleur.bgGreen"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { kleur, applyBgGreen, formatSuccessBadge } from '../index.js';

// Ensure predictable styling behavior in non-interactive / CI environments
kleur.enabled = true;

// Contract 1: kleur.bgGreen wraps a string in ANSI background green escape codes (\u001b[42m and \u001b[49m).
const basic = kleur.bgGreen('SUCCESS');
assert.equal(basic, '\u001b[42mSUCCESS\u001b[49m');
assert.equal(applyBgGreen('PASS'), '\u001b[42mPASS\u001b[49m');

// Contract 2: kleur.bgGreen returns a chainable formatter when called with no arguments.
const chained = kleur.bgGreen().bold('HIGHLIGHT');
assert.equal(chained, '\u001b[42m\u001b[1mHIGHLIGHT\u001b[49m\u001b[22m');

const badge = formatSuccessBadge('OK');
assert.equal(badge, '\u001b[42m\u001b[37m\u001b[1m OK \u001b[49m\u001b[39m\u001b[22m');

// Contract 3: kleur.bgGreen coerces numeric and non-string inputs into styled strings.
const num = kleur.bgGreen(200);
assert.equal(num, '\u001b[42m200\u001b[49m');

// Contract 4: kleur.bgGreen handles empty strings by wrapping them in open and close ANSI codes.
const empty = kleur.bgGreen('');
assert.equal(empty, '\u001b[42m\u001b[49m');

// Contract 5: setting kleur.enabled to false disables styling and returns the input as plain text.
kleur.enabled = false;
assert.equal(kleur.bgGreen('NO_COLOR'), 'NO_COLOR');
assert.equal(applyBgGreen('PLAIN'), 'PLAIN');
assert.equal(formatSuccessBadge('DISABLED'), ' DISABLED ');

// Restore enabled state
kleur.enabled = true;

console.log('All kleur.bgGreen contract tests passed.');

Seeder de origen

anónimo