CodeSampleX

샘플

ansi-styles 6.2.3: color

검증된 샘플 — npm ansi-styles 6.2.3: color. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: ansiStyles.color provides standard and bright foreground…

sha256:c05c54127e5e0f2b6635793265b6378702311eee3e8b55d7e41bda59aace4596

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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.color in pkg:npm/ansi-styles@6.2.3
패키지
심벌
  • ansi-styles.color
환경
node 22.23.2
생성일
2026-08-23T05:32:32Z

컨트랙트

  1. ansiStyles.color provides standard and bright foreground colors with matching open and close ANSI escape sequences
  2. ansiStyles.color.close defines the default foreground reset escape sequence
  3. ansiStyles.color.ansi converts standard ANSI color codes to foreground escape sequences
  4. ansiStyles.color.ansi256 generates 256-color palette foreground ANSI escape codes
  5. ansiStyles.color.ansi16m converts RGB values into 24-bit truecolor foreground ANSI escape codes
  6. applyForegroundColor applies foreground 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

소스 아티팩트 내려받기 (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 ansi-styles.color 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.color
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.
csx.json
{"case":{"caseId":"case:sha256:b86dcca21c13fd772c479cdfaf1130a766591ea711a4e582933b9985079b6a7b","constraints":{"executionContext":"node"},"contract":["ansiStyles.color provides standard and bright foreground colors with matching open and close ANSI escape sequences","ansiStyles.color.close defines the default foreground reset escape sequence","ansiStyles.color.ansi converts standard ANSI color codes to foreground escape sequences","ansiStyles.color.ansi256 generates 256-color palette foreground ANSI escape codes","ansiStyles.color.ansi16m converts RGB values into 24-bit truecolor foreground ANSI escape codes","applyForegroundColor applies foreground color styling including standard names, 256-color palette, and truecolor RGB to text"],"goal":"verify ansi-styles.color in pkg:npm/ansi-styles@6.2.3","kind":"HOW","packages":["pkg:npm/ansi-styles@6.2.3"],"schemaVersion":1,"symbols":["ansi-styles.color"]},"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.color"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-ansi-styles-color",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ansi-styles-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"
      }
    }
  }
}
package.json
{
  "name": "sample-ansi-styles-color",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for ansi-styles color",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "ansi-styles": "6.2.3"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify ansi-styles.color in pkg:npm/ansi-styles@6.2.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ansi-styles@6.2.3"
  ],
  "symbols": [
    "ansi-styles.color"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const ansiStylesModule = require('ansi-styles');

const ansiStyles = ansiStylesModule.default || ansiStylesModule;
const { color } = ansiStyles;

/**
 * Returns the color object from ansi-styles.
 * @returns {object}
 */
function getColor() {
  return color;
}

/**
 * Retrieves standard or bright foreground color style pair.
 * @param {string} name
 * @returns {{ open: string, close: string }}
 */
function getNamedColor(name) {
  const style = color[name];
  if (!style) {
    throw new Error(`Unknown foreground color: ${name}`);
  }
  return {
    open: style.open,
    close: style.close,
  };
}

/**
 * Formats a foreground color escape sequence using a 256-color palette index.
 * @param {number} code
 * @returns {{ open: string, close: string }}
 */
function getAnsi256Color(code) {
  if (typeof code !== 'number' || code < 0 || code > 255) {
    throw new RangeError(`Color code must be between 0 and 255: ${code}`);
  }
  return {
    open: color.ansi256(code),
    close: color.close,
  };
}

/**
 * Formats a foreground color escape sequence using 24-bit truecolor RGB values.
 * @param {number} red
 * @param {number} green
 * @param {number} blue
 * @returns {{ open: string, close: string }}
 */
function getAnsi16mColor(red, green, blue) {
  return {
    open: color.ansi16m(red, green, blue),
    close: color.close,
  };
}

/**
 * Applies foreground styling to the provided text.
 * @param {string} text
 * @param {{ name?: string, ansi256?: number, rgb?: [number, number, number] }} options
 * @returns {string}
 */
function applyForegroundColor(text, options = {}) {
  let openSequence = '';
  const closeSequence = color.close;

  if (options.name) {
    openSequence = getNamedColor(options.name).open;
  } else if (typeof options.ansi256 === 'number') {
    openSequence = getAnsi256Color(options.ansi256).open;
  } else if (Array.isArray(options.rgb) && options.rgb.length === 3) {
    const [r, g, b] = options.rgb;
    openSequence = getAnsi16mColor(r, g, b).open;
  } else {
    throw new Error('Must specify one of name, ansi256, or rgb options');
  }

  return `${openSequence}${text}${closeSequence}`;
}

module.exports = {
  ansiStyles,
  color,
  getColor,
  getNamedColor,
  getAnsi256Color,
  getAnsi16mColor,
  applyForegroundColor,
};
test/contract.js
const assert = require('node:assert');
const {
  ansiStyles,
  color,
  getColor,
  getNamedColor,
  getAnsi256Color,
  getAnsi16mColor,
  applyForegroundColor,
} = require('../src/index.js');

// 1. ansiStyles.color provides standard and bright foreground colors with matching open and close ANSI escape sequences
assert(color && typeof color === 'object', 'color must be an object');
assert.strictEqual(getColor(), color);

const standardColors = {
  black: '\u001B[30m',
  red: '\u001B[31m',
  green: '\u001B[32m',
  yellow: '\u001B[33m',
  blue: '\u001B[34m',
  magenta: '\u001B[35m',
  cyan: '\u001B[36m',
  white: '\u001B[37m',
};

for (const [name, expectedOpen] of Object.entries(standardColors)) {
  const style = color[name];
  assert(style, `Missing standard style ${name}`);
  assert.strictEqual(style.open, expectedOpen, `${name} open code mismatch`);
  assert.strictEqual(style.close, '\u001B[39m', `${name} close code mismatch`);

  const named = getNamedColor(name);
  assert.strictEqual(named.open, expectedOpen);
  assert.strictEqual(named.close, '\u001B[39m');
}

const brightColors = {
  blackBright: '\u001B[90m',
  redBright: '\u001B[91m',
  greenBright: '\u001B[92m',
  yellowBright: '\u001B[93m',
  blueBright: '\u001B[94m',
  magentaBright: '\u001B[95m',
  cyanBright: '\u001B[96m',
  whiteBright: '\u001B[97m',
};

for (const [name, expectedOpen] of Object.entries(brightColors)) {
  const style = color[name];
  assert(style, `Missing bright style ${name}`);
  assert.strictEqual(style.open, expectedOpen, `${name} open code mismatch`);
  assert.strictEqual(style.close, '\u001B[39m', `${name} close code mismatch`);
}

// Aliases
assert.deepStrictEqual(color.gray, color.blackBright);
assert.deepStrictEqual(color.grey, color.blackBright);

// 2. ansiStyles.color.close defines the default foreground reset escape sequence
assert.strictEqual(color.close, '\u001B[39m');

// 3. ansiStyles.color.ansi converts standard ANSI color codes to foreground escape sequences
assert(typeof color.ansi === 'function', 'color.ansi must be a function');
assert.strictEqual(color.ansi(30), '\u001B[30m');
assert.strictEqual(color.ansi(31), '\u001B[31m');
assert.strictEqual(color.ansi(32), '\u001B[32m');
assert.strictEqual(color.ansi(37), '\u001B[37m');

// 4. ansiStyles.color.ansi256 generates 256-color palette foreground ANSI escape codes
assert(typeof color.ansi256 === 'function', 'color.ansi256 must be a function');
assert.strictEqual(color.ansi256(0), '\u001B[38;5;0m');
assert.strictEqual(color.ansi256(100), '\u001B[38;5;100m');
assert.strictEqual(color.ansi256(255), '\u001B[38;5;255m');

const fg256 = getAnsi256Color(200);
assert.strictEqual(fg256.open, '\u001B[38;5;200m');
assert.strictEqual(fg256.close, '\u001B[39m');

assert.throws(() => getAnsi256Color(-1), RangeError);
assert.throws(() => getAnsi256Color(256), RangeError);

// 5. ansiStyles.color.ansi16m converts RGB values into 24-bit truecolor foreground ANSI escape codes
assert(typeof color.ansi16m === 'function', 'color.ansi16m must be a function');
assert.strictEqual(color.ansi16m(255, 128, 0), '\u001B[38;2;255;128;0m');
assert.strictEqual(color.ansi16m(0, 0, 0), '\u001B[38;2;0;0;0m');
assert.strictEqual(color.ansi16m(12, 34, 56), '\u001B[38;2;12;34;56m');

const fg16m = getAnsi16mColor(10, 20, 30);
assert.strictEqual(fg16m.open, '\u001B[38;2;10;20;30m');
assert.strictEqual(fg16m.close, '\u001B[39m');

// 6. applyForegroundColor applies foreground color styling including standard names, 256-color palette, and truecolor RGB to text
const message = 'Sample Text';
assert.strictEqual(applyForegroundColor(message, { name: 'cyan' }), `\u001B[36m${message}\u001B[39m`);
assert.strictEqual(applyForegroundColor(message, { name: 'redBright' }), `\u001B[91m${message}\u001B[39m`);
assert.strictEqual(applyForegroundColor(message, { ansi256: 45 }), `\u001B[38;5;45m${message}\u001B[39m`);
assert.strictEqual(applyForegroundColor(message, { rgb: [255, 100, 50] }), `\u001B[38;2;255;100;50m${message}\u001B[39m`);

assert.throws(() => applyForegroundColor(message, { name: 'invalidColor' }), /Unknown foreground color: invalidColor/);
assert.throws(() => applyForegroundColor(message, {}), /Must specify one of name, ansi256, or rgb options/);

console.log('All contract assertions passed successfully.');

오리진 시더

익명