CodeSampleX

示例

tinyrainbow 2.0.0

已验证示例 — npm tinyrainbow 2.0.0. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: createColors returns color formatting functions that wrap text in ANSI…

sha256:0bbd7f63d5b3759acbcbe585485a5861df32ef0a1eeecb06deb1e554df9dfe25

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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@1
2026-08-21

案例

HOW
目标
verify pkg:npm/tinyrainbow@2.0.0
包
创建时间
2026-08-21T12:10:00Z

契约

  1. createColors returns color formatting functions that wrap text in ANSI escape codes when colors are enabled
  2. createColors returns no-op formatting functions that return plain text when colors are disabled
  3. getDefaultColors returns unformatted plain text functions with isColorSupported false
  4. nested color formatting restores the outer ANSI color code on close

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 pkg:npm/tinyrainbow@2.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/tinyrainbow@2.0.0

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:33c149464e21b9081f63f49a2397bb7858863f9602aaa049e3cd6b61b9dd81cd","contract":["createColors returns color formatting functions that wrap text in ANSI escape codes when colors are enabled","createColors returns no-op formatting functions that return plain text when colors are disabled","getDefaultColors returns unformatted plain text functions with isColorSupported false","nested color formatting restores the outer ANSI color code on close"],"goal":"verify pkg:npm/tinyrainbow@2.0.0","kind":"HOW","packages":["pkg:npm/tinyrainbow@2.0.0"],"schemaVersion":1},"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/tinyrainbow@2.0.0"],"schemaVersion":1,"subject":"pkg:npm/tinyrainbow@2.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-tinyrainbow",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-tinyrainbow",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "tinyrainbow": "2.0.0"
      }
    },
    "node_modules/tinyrainbow": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-2.0.0.tgz",
      "integrity": "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-tinyrainbow",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "description": "Clean-room verification sample for tinyrainbow",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "tinyrainbow": "2.0.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/tinyrainbow@2.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/tinyrainbow@2.0.0"
  ]
}
src/index.js
import c, { createColors, getDefaultColors, isSupported } from 'tinyrainbow';

export function formatMessage(text, colorName, forced = true) {
  const colors = createColors(forced);
  if (typeof colors[colorName] === 'function') {
    return colors[colorName](text);
  }
  return text;
}

export { c as defaultColors, createColors, getDefaultColors, isSupported };
test/contract.mjs
import assert from 'node:assert/strict';
import { createColors, getDefaultColors, isSupported } from 'tinyrainbow';
import { formatMessage } from '../src/index.js';

// 1. Basic properties and exports
assert.strictEqual(typeof createColors, 'function', 'createColors should be a function');
assert.strictEqual(typeof getDefaultColors, 'function', 'getDefaultColors should be a function');
assert.strictEqual(typeof isSupported, 'function', 'isSupported should be a function');

// 2. Default uncolored instance from getDefaultColors()
const defaultInstance = getDefaultColors();
assert.strictEqual(defaultInstance.isColorSupported, false, 'defaultInstance should have isColorSupported false');
assert.strictEqual(defaultInstance.red('test'), 'test', 'getDefaultColors red should return plain text');
assert.strictEqual(defaultInstance.bold('test'), 'test', 'getDefaultColors bold should return plain text');
assert.strictEqual(defaultInstance.red.open, '', 'getDefaultColors red.open should be empty');
assert.strictEqual(defaultInstance.red.close, '', 'getDefaultColors red.close should be empty');

// 3. Forced colors enabled with createColors(true) and FORCE_COLOR=1
process.env.FORCE_COLOR = '1';
delete process.env.NO_COLOR;
const enabled = createColors(true);
assert.strictEqual(enabled.isColorSupported, true, 'createColors(true) with FORCE_COLOR=1 should have isColorSupported true');

// Modifiers
assert.strictEqual(enabled.bold('bold'), '\x1b[1mbold\x1b[22m', 'bold should wrap with correct ANSI codes');
assert.strictEqual(enabled.dim('dim'), '\x1b[2mdim\x1b[22m', 'dim should wrap with correct ANSI codes');
assert.strictEqual(enabled.italic('italic'), '\x1b[3mitalic\x1b[23m', 'italic should wrap with correct ANSI codes');
assert.strictEqual(enabled.underline('under'), '\x1b[4munder\x1b[24m', 'underline should wrap with correct ANSI codes');
assert.strictEqual(enabled.inverse('inv'), '\x1b[7minv\x1b[27m', 'inverse should wrap with correct ANSI codes');
assert.strictEqual(enabled.hidden('hid'), '\x1b[8mhid\x1b[28m', 'hidden should wrap with correct ANSI codes');
assert.strictEqual(enabled.strikethrough('strike'), '\x1b[9mstrike\x1b[29m', 'strikethrough should wrap with correct ANSI codes');

// Foreground colors
assert.strictEqual(enabled.black('text'), '\x1b[30mtext\x1b[39m', 'black should wrap with correct ANSI codes');
assert.strictEqual(enabled.red('text'), '\x1b[31mtext\x1b[39m', 'red should wrap with correct ANSI codes');
assert.strictEqual(enabled.green('text'), '\x1b[32mtext\x1b[39m', 'green should wrap with correct ANSI codes');
assert.strictEqual(enabled.yellow('text'), '\x1b[33mtext\x1b[39m', 'yellow should wrap with correct ANSI codes');
assert.strictEqual(enabled.blue('text'), '\x1b[34mtext\x1b[39m', 'blue should wrap with correct ANSI codes');
assert.strictEqual(enabled.magenta('text'), '\x1b[35mtext\x1b[39m', 'magenta should wrap with correct ANSI codes');
assert.strictEqual(enabled.cyan('text'), '\x1b[36mtext\x1b[39m', 'cyan should wrap with correct ANSI codes');
assert.strictEqual(enabled.white('text'), '\x1b[37mtext\x1b[39m', 'white should wrap with correct ANSI codes');
assert.strictEqual(enabled.gray('text'), '\x1b[90mtext\x1b[39m', 'gray should wrap with correct ANSI codes');

// Background colors
assert.strictEqual(enabled.bgBlack('text'), '\x1b[40mtext\x1b[49m', 'bgBlack should wrap with correct ANSI codes');
assert.strictEqual(enabled.bgRed('text'), '\x1b[41mtext\x1b[49m', 'bgRed should wrap with correct ANSI codes');
assert.strictEqual(enabled.bgGreen('text'), '\x1b[42mtext\x1b[49m', 'bgGreen should wrap with correct ANSI codes');
assert.strictEqual(enabled.bgYellow('text'), '\x1b[43mtext\x1b[49m', 'bgYellow should wrap with correct ANSI codes');
assert.strictEqual(enabled.bgBlue('text'), '\x1b[44mtext\x1b[49m', 'bgBlue should wrap with correct ANSI codes');
assert.strictEqual(enabled.bgMagenta('text'), '\x1b[45mtext\x1b[49m', 'bgMagenta should wrap with correct ANSI codes');
assert.strictEqual(enabled.bgCyan('text'), '\x1b[46mtext\x1b[49m', 'bgCyan should wrap with correct ANSI codes');
assert.strictEqual(enabled.bgWhite('text'), '\x1b[47mtext\x1b[49m', 'bgWhite should wrap with correct ANSI codes');

// Open / close properties
assert.strictEqual(enabled.red.open, '\x1b[31m', 'red.open should be opening escape sequence');
assert.strictEqual(enabled.red.close, '\x1b[39m', 'red.close should be closing escape sequence');
assert.strictEqual(enabled.bold.open, '\x1b[1m', 'bold.open should be opening escape sequence');
assert.strictEqual(enabled.bold.close, '\x1b[22m', 'bold.close should be closing escape sequence');

// Nested formatting
const nested = enabled.red('hello ' + enabled.green('world') + ' again');
assert.strictEqual(nested, '\x1b[31mhello \x1b[32mworld\x1b[31m again\x1b[39m', 'nested colors should restore outer color on close');

// Wrapper function test
assert.strictEqual(formatMessage('status', 'green', true), '\x1b[32mstatus\x1b[39m', 'formatMessage helper should format text');

// 4. Forced colors disabled with NO_COLOR=1
process.env.NO_COLOR = '1';
delete process.env.FORCE_COLOR;
const disabled = createColors(false);
assert.strictEqual(disabled.isColorSupported, false, 'createColors(false) with NO_COLOR=1 should have isColorSupported false');
assert.strictEqual(disabled.red('plain'), 'plain', 'disabled red should return plain text');
assert.strictEqual(disabled.bold('plain'), 'plain', 'disabled bold should return plain text');
assert.strictEqual(disabled.bgBlue('plain'), 'plain', 'disabled bgBlue should return plain text');

console.log('Contract tests passed successfully.');

原始种子者

匿名