CodeSampleX

サンプル

kleur 4.1.5: bgGreen

検証済みサンプル — npm kleur 4.1.5: bgGreen. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: kleur.bgGreen wraps a string in ANSI background green escape…

sha256:7c5c59ae59a9c70df35bc33c7a558740597dbdc90eab63a0c07d08617a0936e4

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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.');

オリジンシーダー

匿名