샘플
ansi-styles 6.2.3: bgColor
검증된 샘플 — npm ansi-styles 6.2.3: bgColor. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: ansiStyles.bgColor provides standard and bright…
sha256:caf615d8f931f328be77e354231aa3b58ac29b193e5f5a708e291cc4fbb69cf4
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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.bgColor in pkg:npm/ansi-styles@6.2.3
- 심벌
-
- ansi-styles.bgColor
- 환경
- node 22.23.2
- 생성일
- 2026-08-23T05:30:29Z
컨트랙트
- ansiStyles.bgColor provides standard and bright background colors with matching open and close ANSI escape sequences
- ansiStyles.bgColor.close defines the default background reset escape sequence
- ansiStyles.bgColor.ansi converts standard ANSI color codes to background escape sequences
- ansiStyles.bgColor.ansi256 generates 256-color palette background ANSI escape codes
- ansiStyles.bgColor.ansi16m converts RGB values into 24-bit truecolor background ANSI escape codes
- applyBackgroundColor applies background color styling including standard names, 256-color palette, and truecolor RGB to text
파일
- 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.bgColor 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.bgColor
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:22e5b45764d8255b36c5aacd51e0ca8d80c94171bb2e67e2c9b7a53356d25768","constraints":{"executionContext":"node"},"contract":["ansiStyles.bgColor provides standard and bright background colors with matching open and close ANSI escape sequences","ansiStyles.bgColor.close defines the default background reset escape sequence","ansiStyles.bgColor.ansi converts standard ANSI color codes to background escape sequences","ansiStyles.bgColor.ansi256 generates 256-color palette background ANSI escape codes","ansiStyles.bgColor.ansi16m converts RGB values into 24-bit truecolor background ANSI escape codes","applyBackgroundColor applies background color styling including standard names, 256-color palette, and truecolor RGB to text"],"goal":"verify ansi-styles.bgColor in pkg:npm/ansi-styles@6.2.3","kind":"HOW","packages":["pkg:npm/ansi-styles@6.2.3"],"schemaVersion":1,"symbols":["ansi-styles.bgColor"]},"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.bgColor"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-ansi-styles-bg-color",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ansi-styles-bg-color",
"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-bg-color",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification for ansi-styles bgColor",
"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.bgColor in pkg:npm/ansi-styles@6.2.3",
"kind": "HOW",
"packages": [
"pkg:npm/ansi-styles@6.2.3"
],
"symbols": [
"ansi-styles.bgColor"
],
"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 { bgColor } = ansiStyles;
/**
* Returns the bgColor object from ansi-styles.
* @returns {object}
*/
function getBgColor() {
return bgColor;
}
/**
* Retrieves standard or bright background color style pair.
* @param {string} name
* @returns {{ open: string, close: string }}
*/
function getNamedBgColor(name) {
const style = bgColor[name];
if (!style) {
throw new Error(`Unknown background color: ${name}`);
}
return {
open: style.open,
close: style.close,
};
}
/**
* Formats a background color escape sequence using a 256-color palette index.
* @param {number} code
* @returns {{ open: string, close: string }}
*/
function getAnsi256BgColor(code) {
if (typeof code !== 'number' || code < 0 || code > 255) {
throw new RangeError(`Color code must be between 0 and 255: ${code}`);
}
return {
open: bgColor.ansi256(code),
close: bgColor.close,
};
}
/**
* Formats a background color escape sequence using 24-bit truecolor RGB values.
* @param {number} red
* @param {number} green
* @param {number} blue
* @returns {{ open: string, close: string }}
*/
function getAnsi16mBgColor(red, green, blue) {
return {
open: bgColor.ansi16m(red, green, blue),
close: bgColor.close,
};
}
/**
* Applies background styling to the provided text.
* @param {string} text
* @param {{ name?: string, ansi256?: number, rgb?: [number, number, number] }} options
* @returns {string}
*/
function applyBackgroundColor(text, options = {}) {
let openSequence = '';
const closeSequence = bgColor.close;
if (options.name) {
openSequence = getNamedBgColor(options.name).open;
} else if (typeof options.ansi256 === 'number') {
openSequence = getAnsi256BgColor(options.ansi256).open;
} else if (Array.isArray(options.rgb) && options.rgb.length === 3) {
const [r, g, b] = options.rgb;
openSequence = getAnsi16mBgColor(r, g, b).open;
} else {
throw new Error('Must specify one of name, ansi256, or rgb options');
}
return `${openSequence}${text}${closeSequence}`;
}
module.exports = {
ansiStyles,
bgColor,
getBgColor,
getNamedBgColor,
getAnsi256BgColor,
getAnsi16mBgColor,
applyBackgroundColor,
};
const assert = require('node:assert');
const {
ansiStyles,
bgColor,
getBgColor,
getNamedBgColor,
getAnsi256BgColor,
getAnsi16mBgColor,
applyBackgroundColor,
} = require('../src/index.js');
// 1. ansiStyles.bgColor provides standard and bright background colors with matching open and close ANSI escape sequences
assert(bgColor && typeof bgColor === 'object', 'bgColor must be an object');
assert.strictEqual(getBgColor(), bgColor);
const standardBgColors = {
bgBlack: '\u001B[40m',
bgRed: '\u001B[41m',
bgGreen: '\u001B[42m',
bgYellow: '\u001B[43m',
bgBlue: '\u001B[44m',
bgMagenta: '\u001B[45m',
bgCyan: '\u001B[46m',
bgWhite: '\u001B[47m',
};
for (const [name, expectedOpen] of Object.entries(standardBgColors)) {
const style = bgColor[name];
assert(style, `Missing standard style ${name}`);
assert.strictEqual(style.open, expectedOpen, `${name} open code mismatch`);
assert.strictEqual(style.close, '\u001B[49m', `${name} close code mismatch`);
const named = getNamedBgColor(name);
assert.strictEqual(named.open, expectedOpen);
assert.strictEqual(named.close, '\u001B[49m');
}
const brightBgColors = {
bgBlackBright: '\u001B[100m',
bgRedBright: '\u001B[101m',
bgGreenBright: '\u001B[102m',
bgYellowBright: '\u001B[103m',
bgBlueBright: '\u001B[104m',
bgMagentaBright: '\u001B[105m',
bgCyanBright: '\u001B[106m',
bgWhiteBright: '\u001B[107m',
};
for (const [name, expectedOpen] of Object.entries(brightBgColors)) {
const style = bgColor[name];
assert(style, `Missing bright style ${name}`);
assert.strictEqual(style.open, expectedOpen, `${name} open code mismatch`);
assert.strictEqual(style.close, '\u001B[49m', `${name} close code mismatch`);
}
// Aliases
assert.deepStrictEqual(bgColor.bgGray, bgColor.bgBlackBright);
assert.deepStrictEqual(bgColor.bgGrey, bgColor.bgBlackBright);
// 2. ansiStyles.bgColor.close defines the default background reset escape sequence
assert.strictEqual(bgColor.close, '\u001B[49m');
// 3. ansiStyles.bgColor.ansi converts standard ANSI color codes to background escape sequences
assert(typeof bgColor.ansi === 'function', 'bgColor.ansi must be a function');
assert.strictEqual(bgColor.ansi(30), '\u001B[40m');
assert.strictEqual(bgColor.ansi(31), '\u001B[41m');
assert.strictEqual(bgColor.ansi(32), '\u001B[42m');
assert.strictEqual(bgColor.ansi(37), '\u001B[47m');
// 4. ansiStyles.bgColor.ansi256 generates 256-color palette background ANSI escape codes
assert(typeof bgColor.ansi256 === 'function', 'bgColor.ansi256 must be a function');
assert.strictEqual(bgColor.ansi256(0), '\u001B[48;5;0m');
assert.strictEqual(bgColor.ansi256(100), '\u001B[48;5;100m');
assert.strictEqual(bgColor.ansi256(255), '\u001B[48;5;255m');
const bg256 = getAnsi256BgColor(200);
assert.strictEqual(bg256.open, '\u001B[48;5;200m');
assert.strictEqual(bg256.close, '\u001B[49m');
assert.throws(() => getAnsi256BgColor(-1), RangeError);
assert.throws(() => getAnsi256BgColor(256), RangeError);
// 5. ansiStyles.bgColor.ansi16m converts RGB values into 24-bit truecolor background ANSI escape codes
assert(typeof bgColor.ansi16m === 'function', 'bgColor.ansi16m must be a function');
assert.strictEqual(bgColor.ansi16m(255, 128, 0), '\u001B[48;2;255;128;0m');
assert.strictEqual(bgColor.ansi16m(0, 0, 0), '\u001B[48;2;0;0;0m');
assert.strictEqual(bgColor.ansi16m(12, 34, 56), '\u001B[48;2;12;34;56m');
const bg16m = getAnsi16mBgColor(10, 20, 30);
assert.strictEqual(bg16m.open, '\u001B[48;2;10;20;30m');
assert.strictEqual(bg16m.close, '\u001B[49m');
// 6. applyBackgroundColor applies background color styling including standard names, 256-color palette, and truecolor RGB to text
const message = 'Sample Text';
assert.strictEqual(applyBackgroundColor(message, { name: 'bgCyan' }), `\u001B[46m${message}\u001B[49m`);
assert.strictEqual(applyBackgroundColor(message, { name: 'bgRedBright' }), `\u001B[101m${message}\u001B[49m`);
assert.strictEqual(applyBackgroundColor(message, { ansi256: 45 }), `\u001B[48;5;45m${message}\u001B[49m`);
assert.strictEqual(applyBackgroundColor(message, { rgb: [255, 100, 50] }), `\u001B[48;2;255;100;50m${message}\u001B[49m`);
assert.throws(() => applyBackgroundColor(message, { name: 'invalidBg' }), /Unknown background color: invalidBg/);
assert.throws(() => applyBackgroundColor(message, {}), /Must specify one of name, ansi256, or rgb options/);
console.log('All contract assertions passed successfully.');
오리진 시더
익명