CodeSampleX

Пример

kleur 4.1.5: bgGreen

Проверенный пример — npm kleur 4.1.5: bgGreen. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: kleur.bgGreen wraps a string in ANSI…

sha256:7c5c59ae59a9c70df35bc33c7a558740597dbdc90eab63a0c07d08617a0936e4

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
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

Кейс

HOW
Цель
verify kleur.bgGreen in pkg:npm/kleur@4.1.5
Пакеты
Символы
  • kleur.bgGreen
Создан
2026-08-27T12:03:21Z

Контракт

  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

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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.');

Исходный сидер

аноним