示例
ansi-styles 6.2.3: colorNames
已验证示例 — npm ansi-styles 6.2.3: colorNames. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: colorNames is an array containing all 36 standard and…
sha256:070f1cad7fa0eb5a5882135a0b053bdf797e3149bfdec643bd61ee1d94d07b75
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 2
- 构建过它的签名密钥
- 1
声明的环境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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-23 |
| 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-07 |
案例
HOW- 目标
- verify ansi-styles.colorNames in pkg:npm/ansi-styles@6.2.3
- 符号
-
- ansi-styles.colorNames
- 环境
- node 22.23.2
- 创建时间
- 2026-08-23T05:34:58Z
契约
- colorNames is an array containing all 36 standard and bright foreground and background color names
- every name in colorNames corresponds to a valid style in ansiStyles with matching open and close codes
- colorNames includes standard foreground, bright foreground, standard background, and bright background colors
- isValidColorName verifies whether a given name exists in colorNames
- applyColorStyle wraps text in the ANSI escape codes for the specified color name
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
源代码
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 ansi-styles.colorNames in pkg:npm/ansi-styles@6.2.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ansi-styles@6.2.3
Demonstrate these symbols/APIs:
- ansi-styles.colorNames
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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.
{"case":{"caseId":"case:sha256:d5fcddc6a4cfddb16ec1519297db3f27704ca29a8fadfe69d9e951a57e005722","constraints":{"executionContext":"node"},"contract":["colorNames is an array containing all 36 standard and bright foreground and background color names","every name in colorNames corresponds to a valid style in ansiStyles with matching open and close codes","colorNames includes standard foreground, bright foreground, standard background, and bright background colors","isValidColorName verifies whether a given name exists in colorNames","applyColorStyle wraps text in the ANSI escape codes for the specified color name"],"goal":"verify ansi-styles.colorNames in pkg:npm/ansi-styles@6.2.3","kind":"HOW","packages":["pkg:npm/ansi-styles@6.2.3"],"schemaVersion":1,"symbols":["ansi-styles.colorNames"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","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/ansi-styles@6.2.3"],"schemaVersion":1,"subject":"pkg:npm/ansi-styles@6.2.3","symbols":["ansi-styles.colorNames"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-ansi-styles-color-names",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ansi-styles-color-names",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"ansi-styles": "6.2.3"
}
},
"node_modules/ansi-styles": {
"version": "6.2.3",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz",
"integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==",
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
}
}
}
{
"name": "sample-ansi-styles-color-names",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification for ansi-styles colorNames",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"ansi-styles": "6.2.3"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify ansi-styles.colorNames in pkg:npm/ansi-styles@6.2.3",
"kind": "HOW",
"packages": [
"pkg:npm/ansi-styles@6.2.3"
],
"symbols": [
"ansi-styles.colorNames"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const ansiStylesModule = require('ansi-styles');
const ansiStyles = ansiStylesModule.default || ansiStylesModule;
const { colorNames } = ansiStylesModule;
/**
* Returns the array of all supported ANSI color names (foreground and background).
* @returns {string[]}
*/
function getColorNames() {
return colorNames;
}
/**
* Checks if the provided color name is a valid ANSI color name.
* @param {string} name
* @returns {boolean}
*/
function isValidColorName(name) {
return colorNames.includes(name);
}
/**
* Retrieves the style object containing open and close ANSI escape sequences for a given color name.
* @param {string} name
* @returns {{ open: string, close: string }}
*/
function getColorStyle(name) {
if (!isValidColorName(name)) {
throw new Error(`Invalid color name: ${name}`);
}
const style = ansiStyles[name];
if (!style) {
throw new Error(`Style definition not found for color: ${name}`);
}
return {
open: style.open,
close: style.close,
};
}
/**
* Applies the ANSI escape styling for the specified color name to text.
* @param {string} text
* @param {string} name
* @returns {string}
*/
function applyColorStyle(text, name) {
const { open, close } = getColorStyle(name);
return `${open}${text}${close}`;
}
module.exports = {
ansiStyles,
colorNames,
getColorNames,
isValidColorName,
getColorStyle,
applyColorStyle,
};
const assert = require('node:assert');
const {
ansiStyles,
colorNames,
getColorNames,
isValidColorName,
getColorStyle,
applyColorStyle,
} = require('../src/index.js');
// 1. colorNames is an array containing all 36 standard and bright foreground and background color names
assert(Array.isArray(colorNames), 'colorNames must be an Array');
assert.strictEqual(colorNames.length, 36, 'colorNames must contain exactly 36 color names');
assert.deepStrictEqual(getColorNames(), colorNames);
// 2. every name in colorNames corresponds to a valid style in ansiStyles with matching open and close codes
for (const name of colorNames) {
const codes = getColorStyle(name);
assert(typeof codes.open === 'string' && codes.open.startsWith('\u001B['), `${name} open code must start with ANSI escape sequence`);
assert(codes.open.endsWith('m'), `${name} open code must end with 'm'`);
assert(typeof codes.close === 'string' && codes.close.startsWith('\u001B['), `${name} close code must start with ANSI escape sequence`);
assert(codes.close.endsWith('m'), `${name} close code must end with 'm'`);
// Direct access on ansiStyles
const directStyle = ansiStyles[name];
assert.strictEqual(directStyle.open, codes.open);
assert.strictEqual(directStyle.close, codes.close);
}
// 3. colorNames includes standard foreground, bright foreground, standard background, and bright background colors
const expectedForegroundStandard = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'];
const expectedForegroundBright = [
'blackBright', 'gray', 'grey',
'redBright', 'greenBright', 'yellowBright',
'blueBright', 'magentaBright', 'cyanBright', 'whiteBright'
];
const expectedBackgroundStandard = ['bgBlack', 'bgRed', 'bgGreen', 'bgYellow', 'bgBlue', 'bgMagenta', 'bgCyan', 'bgWhite'];
const expectedBackgroundBright = [
'bgBlackBright', 'bgGray', 'bgGrey',
'bgRedBright', 'bgGreenBright', 'bgYellowBright',
'bgBlueBright', 'bgMagentaBright', 'bgCyanBright', 'bgWhiteBright'
];
for (const name of expectedForegroundStandard) {
assert(colorNames.includes(name), `Missing standard foreground color ${name}`);
assert.strictEqual(ansiStyles[name].close, '\u001B[39m');
}
for (const name of expectedForegroundBright) {
assert(colorNames.includes(name), `Missing bright foreground color ${name}`);
assert.strictEqual(ansiStyles[name].close, '\u001B[39m');
}
for (const name of expectedBackgroundStandard) {
assert(colorNames.includes(name), `Missing standard background color ${name}`);
assert.strictEqual(ansiStyles[name].close, '\u001B[49m');
}
for (const name of expectedBackgroundBright) {
assert(colorNames.includes(name), `Missing bright background color ${name}`);
assert.strictEqual(ansiStyles[name].close, '\u001B[49m');
}
// Specific open escape code checks
assert.strictEqual(ansiStyles.red.open, '\u001B[31m');
assert.strictEqual(ansiStyles.green.open, '\u001B[32m');
assert.strictEqual(ansiStyles.blue.open, '\u001B[34m');
assert.strictEqual(ansiStyles.bgRed.open, '\u001B[41m');
assert.strictEqual(ansiStyles.bgGreen.open, '\u001B[42m');
assert.strictEqual(ansiStyles.bgBlue.open, '\u001B[44m');
assert.deepStrictEqual(ansiStyles.gray, ansiStyles.blackBright);
assert.deepStrictEqual(ansiStyles.grey, ansiStyles.blackBright);
assert.deepStrictEqual(ansiStyles.bgGray, ansiStyles.bgBlackBright);
assert.deepStrictEqual(ansiStyles.bgGrey, ansiStyles.bgBlackBright);
// 4. isValidColorName verifies whether a given name exists in colorNames
assert.strictEqual(isValidColorName('red'), true);
assert.strictEqual(isValidColorName('blueBright'), true);
assert.strictEqual(isValidColorName('bgYellow'), true);
assert.strictEqual(isValidColorName('bgMagentaBright'), true);
assert.strictEqual(isValidColorName('bold'), false);
assert.strictEqual(isValidColorName('unknownColor'), false);
assert.strictEqual(isValidColorName(''), false);
// 5. applyColorStyle wraps text in the ANSI escape codes for the specified color name
const text = 'CodeSampleX';
assert.strictEqual(applyColorStyle(text, 'red'), `\u001B[31m${text}\u001B[39m`);
assert.strictEqual(applyColorStyle(text, 'greenBright'), `\u001B[92m${text}\u001B[39m`);
assert.strictEqual(applyColorStyle(text, 'bgBlue'), `\u001B[44m${text}\u001B[49m`);
assert.strictEqual(applyColorStyle(text, 'bgRedBright'), `\u001B[101m${text}\u001B[49m`);
assert.throws(() => {
applyColorStyle(text, 'invalidColorName');
}, /Invalid color name: invalidColorName/);
console.log('All ansi-styles.colorNames contract assertions passed successfully.');
原始种子者
匿名