CodeSampleX

サンプル

yoctocolors-cjs 2.1.3

検証済みサンプル — npm yoctocolors-cjs 2.1.3. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: colors format text with standard ANSI color escape codes…

sha256:e6d94f3e3308fe32637c09cc5e3df75cc5aaace3a56c354c3e92c75e374e8088

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

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
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-16

ケース

HOW
ゴール
verify pkg:npm/yoctocolors-cjs@2.1.3
パッケージ
環境
node 22.23.2
作成日
2026-09-16T14:13:37Z

コントラクト

  1. colors format text with standard ANSI color escape codes when color is enabled
  2. colors format text with standard ANSI style modifier codes when color is enabled
  3. bright colors and background colors format text with corresponding ANSI escape codes
  4. nested color and style formatting properly preserves and reopens outer styling
  5. non-string input is coerced to string when formatting
  6. disabled color mode returns input unchanged without ANSI codes

ファイル

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

ソースアーティファクトをダウンロード (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 pkg:npm/yoctocolors-cjs@2.1.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/yoctocolors-cjs@2.1.3

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:dba3fb1d2c52b2b260a784478de753a495c9d39b810fc423ed4ee5870e2e6b6a","contract":["colors format text with standard ANSI color escape codes when color is enabled","colors format text with standard ANSI style modifier codes when color is enabled","bright colors and background colors format text with corresponding ANSI escape codes","nested color and style formatting properly preserves and reopens outer styling","non-string input is coerced to string when formatting","disabled color mode returns input unchanged without ANSI codes"],"goal":"verify pkg:npm/yoctocolors-cjs@2.1.3","kind":"HOW","packages":["pkg:npm/yoctocolors-cjs@2.1.3"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/yoctocolors-cjs@2.1.3"],"schemaVersion":1,"subject":"pkg:npm/yoctocolors-cjs@2.1.3","verifierAdapter":"node-typescript@1"}
index.cjs
'use strict';

const colors = require('yoctocolors-cjs');

function formatSuccess(message) {
  return colors.green(message);
}

function formatError(message) {
  return colors.red(message);
}

function formatHighlight(message) {
  return colors.bold(colors.cyan(message));
}

module.exports = {
  colors,
  formatSuccess,
  formatError,
  formatHighlight
};
package-lock.json
{
  "name": "sample-yoctocolors-cjs",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-yoctocolors-cjs",
      "version": "1.0.0",
      "dependencies": {
        "yoctocolors-cjs": "2.1.3"
      }
    },
    "node_modules/yoctocolors-cjs": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/yoctocolors-cjs/-/yoctocolors-cjs-2.1.3.tgz",
      "integrity": "sha512-U/PBtDf35ff0D8X8D0jfdzHYEPFxAI7jJlxZXwCSez5M3190m+QobIfh+sWDWSHMCWWJN2AWamkegn6vr6YBTw==",
      "license": "MIT",
      "engines": {
        "node": ">=18"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    }
  }
}
package.json
{
  "name": "sample-yoctocolors-cjs",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of yoctocolors-cjs",
  "dependencies": {
    "yoctocolors-cjs": "2.1.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/yoctocolors-cjs@2.1.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/yoctocolors-cjs@2.1.3"
  ]
}
test/contract.cjs
'use strict';

// Ensure color formatting is active for offline test execution
process.env.FORCE_COLOR = '1';

const assert = require('node:assert/strict');
const colors = require('yoctocolors-cjs');
const { formatSuccess, formatError, formatHighlight } = require('../index.cjs');

// 1. Basic text colors format with standard ANSI escape codes
assert.equal(colors.red('hello'), '\u001B[31mhello\u001B[39m');
assert.equal(colors.green('hello'), '\u001B[32mhello\u001B[39m');
assert.equal(colors.yellow('hello'), '\u001B[33mhello\u001B[39m');
assert.equal(colors.blue('hello'), '\u001B[34mhello\u001B[39m');
assert.equal(colors.magenta('hello'), '\u001B[35mhello\u001B[39m');
assert.equal(colors.cyan('hello'), '\u001B[36mhello\u001B[39m');
assert.equal(colors.white('hello'), '\u001B[37mhello\u001B[39m');
assert.equal(colors.gray('hello'), '\u001B[90mhello\u001B[39m');
assert.equal(colors.black('hello'), '\u001B[30mhello\u001B[39m');

// 2. Modifiers format with corresponding ANSI style codes
assert.equal(colors.bold('text'), '\u001B[1mtext\u001B[22m');
assert.equal(colors.dim('text'), '\u001B[2mtext\u001B[22m');
assert.equal(colors.italic('text'), '\u001B[3mtext\u001B[23m');
assert.equal(colors.underline('text'), '\u001B[4mtext\u001B[24m');
assert.equal(colors.overline('text'), '\u001B[53mtext\u001B[55m');
assert.equal(colors.inverse('text'), '\u001B[7mtext\u001B[27m');
assert.equal(colors.hidden('text'), '\u001B[8mtext\u001B[28m');
assert.equal(colors.strikethrough('text'), '\u001B[9mtext\u001B[29m');
assert.equal(colors.reset('text'), '\u001B[0mtext\u001B[0m');

// 3. Bright colors and background colors format properly
assert.equal(colors.redBright('bright'), '\u001B[91mbright\u001B[39m');
assert.equal(colors.greenBright('bright'), '\u001B[92mbright\u001B[39m');
assert.equal(colors.yellowBright('bright'), '\u001B[93mbright\u001B[39m');
assert.equal(colors.bgRed('bg'), '\u001B[41mbg\u001B[49m');
assert.equal(colors.bgGreen('bg'), '\u001B[42mbg\u001B[49m');
assert.equal(colors.bgBlue('bg'), '\u001B[44mbg\u001B[49m');
assert.equal(colors.bgCyanBright('bg'), '\u001B[106mbg\u001B[49m');

// 4. Nested styling and helper functions
assert.equal(colors.bold(colors.red('alert')), '\u001B[1m\u001B[31malert\u001B[39m\u001B[22m');
assert.equal(colors.dim('a ' + colors.bold('b') + ' c'), '\u001B[2ma \u001B[1mb\u001B[22m\u001B[2m c\u001B[22m');
assert.equal(formatSuccess('ok'), '\u001B[32mok\u001B[39m');
assert.equal(formatError('fail'), '\u001B[31mfail\u001B[39m');
assert.equal(formatHighlight('info'), '\u001B[1m\u001B[36minfo\u001B[39m\u001B[22m');

// 5. Non-string input is coerced to string
assert.equal(colors.blue(42), '\u001B[34m42\u001B[39m');
assert.equal(colors.green(true), '\u001B[32mtrue\u001B[39m');

// 6. Disabled color mode returns input unchanged
delete require.cache[require.resolve('yoctocolors-cjs')];
delete process.env.FORCE_COLOR;
process.env.NO_COLOR = '1';
const disabledColors = require('yoctocolors-cjs');
assert.equal(disabledColors.red('plain'), 'plain');
assert.equal(disabledColors.bold('plain'), 'plain');
assert.equal(disabledColors.bgBlue('plain'), 'plain');

console.log('Contract passed');

オリジンシーダー

匿名