CodeSampleX

Sample

ansi-styles 6.2.3: backgroundColorNames

Verified sample for npm ansi-styles 6.2.3: backgroundColorNames. The contract ran on node 22 · linux alpine/x64 · docker and passed.

sha256:f65d05a37f1ac5446d67fa36f163c16b6c408973634654fe59f3e3124475f066

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify ansi-styles.backgroundColorNames in pkg:npm/ansi-styles@6.2.3
Packages
Symbols
  • ansi-styles.backgroundColorNames
Environment
node 22.23.2
Created
2026-08-23T05:28:09Z

Contract

  1. backgroundColorNames is an array containing all standard and bright background color names
  2. every name in backgroundColorNames corresponds to a valid style in ansiStyles with matching open and close codes
  3. backgroundColorNames includes standard background colors and bright color aliases
  4. isValidBackgroundColor verifies whether a given name exists in backgroundColorNames
  5. applyBackgroundColor wraps text in the ANSI escape codes for the specified background color name

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js

Download the source artifact (tar.gz)

Source

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.backgroundColorNames 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.backgroundColorNames
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:183c5eddcb4520744144423e6ac194ffa1652f5d73ea637336284043776a9182","constraints":{"executionContext":"node"},"contract":["backgroundColorNames is an array containing all standard and bright background color names","every name in backgroundColorNames corresponds to a valid style in ansiStyles with matching open and close codes","backgroundColorNames includes standard background colors and bright color aliases","isValidBackgroundColor verifies whether a given name exists in backgroundColorNames","applyBackgroundColor wraps text in the ANSI escape codes for the specified background color name"],"goal":"verify ansi-styles.backgroundColorNames in pkg:npm/ansi-styles@6.2.3","kind":"HOW","packages":["pkg:npm/ansi-styles@6.2.3"],"schemaVersion":1,"symbols":["ansi-styles.backgroundColorNames"]},"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.backgroundColorNames"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-ansi-styles-bg-names",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ansi-styles-bg-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"
      }
    }
  }
}
package.json
{
  "name": "sample-ansi-styles-bg-names",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for ansi-styles backgroundColorNames",
  "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.backgroundColorNames in pkg:npm/ansi-styles@6.2.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ansi-styles@6.2.3"
  ],
  "symbols": [
    "ansi-styles.backgroundColorNames"
  ],
  "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 { backgroundColorNames } = ansiStylesModule;

/**
 * Returns the list of all supported background color names.
 * @returns {string[]}
 */
function getBackgroundColorNames() {
  return backgroundColorNames;
}

/**
 * Checks if a given string is a valid background color name in ansi-styles.
 * @param {string} name
 * @returns {boolean}
 */
function isValidBackgroundColor(name) {
  return backgroundColorNames.includes(name);
}

/**
 * Retrieves the open and close ANSI escape sequences for a background color name.
 * @param {string} name
 * @returns {{ open: string, close: string }}
 */
function getBackgroundColorCodes(name) {
  if (!isValidBackgroundColor(name)) {
    throw new Error(`Invalid background color name: ${name}`);
  }
  const style = (ansiStyles.bgColor && ansiStyles.bgColor[name]) || ansiStyles[name];
  if (!style) {
    throw new Error(`Style not found for background color: ${name}`);
  }
  return {
    open: style.open,
    close: style.close,
  };
}

/**
 * Wraps text in the specified background color's ANSI escape codes.
 * @param {string} text
 * @param {string} name
 * @returns {string}
 */
function applyBackgroundColor(text, name) {
  const { open, close } = getBackgroundColorCodes(name);
  return `${open}${text}${close}`;
}

module.exports = {
  ansiStyles,
  backgroundColorNames,
  getBackgroundColorNames,
  isValidBackgroundColor,
  getBackgroundColorCodes,
  applyBackgroundColor,
};
test/contract.js
const assert = require('node:assert');
const {
  ansiStyles,
  backgroundColorNames,
  getBackgroundColorNames,
  isValidBackgroundColor,
  getBackgroundColorCodes,
  applyBackgroundColor,
} = require('../src/index.js');

// 1. backgroundColorNames is an array containing all standard and bright background color names
assert(Array.isArray(backgroundColorNames), 'backgroundColorNames must be an Array');
assert.strictEqual(backgroundColorNames.length, 18, 'backgroundColorNames must have 18 color names');
assert.deepStrictEqual(getBackgroundColorNames(), backgroundColorNames);

// 2. every name in backgroundColorNames corresponds to a valid style in ansiStyles with matching open and close codes
for (const name of backgroundColorNames) {
  const codes = getBackgroundColorCodes(name);
  assert(typeof codes.open === 'string' && codes.open.startsWith('\u001B['), `${name} open code must start with ANSI escape`);
  assert(codes.open.endsWith('m'), `${name} open code must end with 'm'`);
  assert.strictEqual(codes.close, '\u001B[49m', `${name} close code must be default background close`);

  // Direct access on ansiStyles.bgColor and ansiStyles root
  const directStyle = ansiStyles.bgColor ? ansiStyles.bgColor[name] : ansiStyles[name];
  assert.strictEqual(directStyle.open, codes.open);
  assert.strictEqual(directStyle.close, codes.close);
}

// 3. backgroundColorNames includes standard background colors and bright color aliases
const expectedStandard = ['bgBlack', 'bgRed', 'bgGreen', 'bgYellow', 'bgBlue', 'bgMagenta', 'bgCyan', 'bgWhite'];
const expectedBright = [
  'bgBlackBright', 'bgGray', 'bgGrey',
  'bgRedBright', 'bgGreenBright', 'bgYellowBright',
  'bgBlueBright', 'bgMagentaBright', 'bgCyanBright', 'bgWhiteBright'
];

for (const name of expectedStandard) {
  assert(backgroundColorNames.includes(name), `Missing standard color ${name}`);
}
for (const name of expectedBright) {
  assert(backgroundColorNames.includes(name), `Missing bright color ${name}`);
}

// Test specific open code mappings
assert.strictEqual(ansiStyles.bgColor.bgRed.open, '\u001B[41m');
assert.strictEqual(ansiStyles.bgColor.bgGreen.open, '\u001B[42m');
assert.strictEqual(ansiStyles.bgColor.bgBlue.open, '\u001B[44m');
assert.strictEqual(ansiStyles.bgColor.bgRedBright.open, '\u001B[101m');
assert.strictEqual(ansiStyles.bgColor.bgGreenBright.open, '\u001B[102m');
assert.strictEqual(ansiStyles.bgColor.bgBlueBright.open, '\u001B[104m');
assert.deepStrictEqual(ansiStyles.bgColor.bgGray, ansiStyles.bgColor.bgBlackBright);
assert.deepStrictEqual(ansiStyles.bgColor.bgGrey, ansiStyles.bgColor.bgBlackBright);

// 4. isValidBackgroundColor verifies whether a given name exists in backgroundColorNames
assert.strictEqual(isValidBackgroundColor('bgBlue'), true);
assert.strictEqual(isValidBackgroundColor('bgMagentaBright'), true);
assert.strictEqual(isValidBackgroundColor('red'), false);
assert.strictEqual(isValidBackgroundColor('nonExistentColor'), false);
assert.strictEqual(isValidBackgroundColor(''), false);

// 5. applyBackgroundColor wraps text in the ANSI escape codes for the specified background color name
const text = 'Hello CodeSampleX';
assert.strictEqual(applyBackgroundColor(text, 'bgBlue'), `\u001B[44m${text}\u001B[49m`);
assert.strictEqual(applyBackgroundColor(text, 'bgRedBright'), `\u001B[101m${text}\u001B[49m`);
assert.strictEqual(applyBackgroundColor(text, 'bgGreen'), `\u001B[42m${text}\u001B[49m`);

assert.throws(() => {
  applyBackgroundColor(text, 'invalidColor');
}, /Invalid background color name: invalidColor/);

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

Origin Seeder

anonymous