CodeSampleX

示例

yoctocolors-cjs 2.1.3

已验证示例 — npm yoctocolors-cjs 2.1.3. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: colors format text with standard ANSI color escape codes when color…

sha256:e6d94f3e3308fe32637c09cc5e3df75cc5aaace3a56c354c3e92c75e374e8088

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

原始种子者

匿名