CodeSampleX

Sample

tinyrainbow 1.2.0: createColors, getDefaultColors, isSupported

Verified sample for npm tinyrainbow 1.2.0: createColors, getDefaultColors, isSupported. The contract ran on node 22 · linux alpine/x64 · docker and passed.

sha256:13a35118b299dc3e1f056f9c14fbadd4c6e5552db6b4f4e06bd6563141f63134

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
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

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-27

Case

HOW
Goal
verify pkg:npm/tinyrainbow@1.2.0
Packages
Symbols
  • createColors
  • getDefaultColors
  • isSupported
Created
2026-08-27T19:02:22Z

Contract

  1. createColors returns formatting functions that apply ANSI escape sequences for basic and bright colors when color support is enabled
  2. createColors returns plain string passthrough functions with empty open and close delimiters when color support is disabled
  3. getDefaultColors returns an uncolored formatting instance with isColorSupported false
  4. isSupported returns boolean terminal color capability based on environment variables and TTY status
  5. nested colors restore parent foreground escape code and nested modifiers restore parent open escape code

Files

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

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 pkg:npm/tinyrainbow@1.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/tinyrainbow@1.2.0
Demonstrate these symbols/APIs:
  - createColors
  - getDefaultColors
  - isSupported

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:f972e55dc63199606e58aef7808ba6d1693daa6a53c1e3054498b80df219fdee","contract":["createColors returns formatting functions that apply ANSI escape sequences for basic and bright colors when color support is enabled","createColors returns plain string passthrough functions with empty open and close delimiters when color support is disabled","getDefaultColors returns an uncolored formatting instance with isColorSupported false","isSupported returns boolean terminal color capability based on environment variables and TTY status","nested colors restore parent foreground escape code and nested modifiers restore parent open escape code"],"goal":"verify pkg:npm/tinyrainbow@1.2.0","kind":"HOW","packages":["pkg:npm/tinyrainbow@1.2.0"],"schemaVersion":1,"symbols":["createColors","getDefaultColors","isSupported"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/tinyrainbow@1.2.0"],"schemaVersion":1,"subject":"pkg:npm/tinyrainbow@1.2.0","symbols":["createColors","getDefaultColors","isSupported"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-tinyrainbow",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-tinyrainbow",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "tinyrainbow": "1.2.0"
      }
    },
    "node_modules/tinyrainbow": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-1.2.0.tgz",
      "integrity": "sha512-weEDEq7Z5eTHPDh4xjX789+fHfF+P8boiFB+0vbWzpbnbsEr/GRaohi/uMKxg8RZMXnl1ItAi/IUHWMsjDV7kQ==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-tinyrainbow",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "description": "Clean-room verification sample for tinyrainbow ANSI color and style formatting",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "tinyrainbow": "1.2.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/tinyrainbow@1.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/tinyrainbow@1.2.0"
  ],
  "symbols": [
    "createColors",
    "getDefaultColors",
    "isSupported"
  ]
}
src/index.js
import colors, { createColors, getDefaultColors, isSupported } from 'tinyrainbow';

export function formatStatus(message, type = 'info') {
  const c = createColors();
  switch (type) {
    case 'error':
      return c.redBright(message);
    case 'success':
      return c.greenBright(message);
    case 'warn':
      return c.yellowBright(message);
    default:
      return c.cyanBright(message);
  }
}

export { colors as default, createColors, getDefaultColors, isSupported };
test/contract.mjs
import assert from 'node:assert/strict';
import colors, { createColors, getDefaultColors, isSupported } from 'tinyrainbow';
import { formatStatus } from '../src/index.js';

// 1. Module exports and functions
assert.strictEqual(typeof createColors, 'function', 'createColors should be exported as a function');
assert.strictEqual(typeof getDefaultColors, 'function', 'getDefaultColors should be exported as a function');
assert.strictEqual(typeof isSupported, 'function', 'isSupported should be exported as a function');

// 2. Color formatting enabled with FORCE_COLOR=1
process.env.FORCE_COLOR = '1';
delete process.env.NO_COLOR;

const c = createColors();
assert.strictEqual(isSupported(), true, 'isSupported should return true when FORCE_COLOR is set');
assert.strictEqual(c.isColorSupported, true, 'isColorSupported should be true');

// Basic foreground and background colors
assert.strictEqual(c.red('error'), '\x1b[31merror\x1b[39m', 'red should wrap text in ANSI escape code 31/39');
assert.strictEqual(c.green('success'), '\x1b[32msuccess\x1b[39m', 'green should wrap text in ANSI escape code 32/39');
assert.strictEqual(c.yellow('warn'), '\x1b[33mwarn\x1b[39m', 'yellow should wrap text in ANSI escape code 33/39');
assert.strictEqual(c.blue('info'), '\x1b[34minfo\x1b[39m', 'blue should wrap text in ANSI escape code 34/39');
assert.strictEqual(c.magenta('debug'), '\x1b[35mdebug\x1b[39m', 'magenta should wrap text in ANSI escape code 35/39');
assert.strictEqual(c.cyan('trace'), '\x1b[36mtrace\x1b[39m', 'cyan should wrap text in ANSI escape code 36/39');
assert.strictEqual(c.gray('muted'), '\x1b[90mmuted\x1b[39m', 'gray should wrap text in ANSI escape code 90/39');
assert.strictEqual(c.bgRed('bg-err'), '\x1b[41mbg-err\x1b[49m', 'bgRed should wrap text in ANSI escape code 41/49');
assert.strictEqual(c.bgGreen('bg-ok'), '\x1b[42mbg-ok\x1b[49m', 'bgGreen should wrap text in ANSI escape code 42/49');

// Bright colors
assert.strictEqual(c.redBright('bright-red'), '\x1b[91mbright-red\x1b[39m', 'redBright should wrap text in ANSI escape code 91/39');
assert.strictEqual(c.greenBright('bright-green'), '\x1b[92mbright-green\x1b[39m', 'greenBright should wrap text in ANSI escape code 92/39');
assert.strictEqual(c.yellowBright('bright-yellow'), '\x1b[93mbright-yellow\x1b[39m', 'yellowBright should wrap text in ANSI escape code 93/39');
assert.strictEqual(c.blueBright('bright-blue'), '\x1b[94mbright-blue\x1b[39m', 'blueBright should wrap text in ANSI escape code 94/39');
assert.strictEqual(c.bgRedBright('bg-bright-red'), '\x1b[101mbg-bright-red\x1b[49m', 'bgRedBright should wrap text in ANSI escape code 101/49');
assert.strictEqual(c.bgGreenBright('bg-bright-green'), '\x1b[102mbg-bright-green\x1b[49m', 'bgGreenBright should wrap text in ANSI escape code 102/49');

// Modifiers and reset
assert.strictEqual(c.bold('bold-txt'), '\x1b[1mbold-txt\x1b[22m', 'bold should wrap text in ANSI escape code 1/22');
assert.strictEqual(c.dim('dim-txt'), '\x1b[2mdim-txt\x1b[22m', 'dim should wrap text in ANSI escape code 2/22');
assert.strictEqual(c.italic('italic-txt'), '\x1b[3mitalic-txt\x1b[23m', 'italic should wrap text in ANSI escape code 3/23');
assert.strictEqual(c.underline('underline-txt'), '\x1b[4munderline-txt\x1b[24m', 'underline should wrap text in ANSI escape code 4/24');
assert.strictEqual(c.inverse('inverse-txt'), '\x1b[7minverse-txt\x1b[27m', 'inverse should wrap text in ANSI escape code 7/27');
assert.strictEqual(c.strikethrough('strikethrough-txt'), '\x1b[9mstrikethrough-txt\x1b[29m', 'strikethrough should wrap text in ANSI escape code 9/29');
assert.strictEqual(c.reset('reset-txt'), '\x1b[0mreset-txt\x1b[0m', 'reset should wrap text in ANSI escape code 0/0');

// Open and close delimiter properties
assert.strictEqual(c.bold.open, '\x1b[1m', 'bold.open should return opening escape sequence');
assert.strictEqual(c.bold.close, '\x1b[22m', 'bold.close should return closing escape sequence');
assert.strictEqual(c.red.open, '\x1b[31m', 'red.open should return opening escape sequence');
assert.strictEqual(c.red.close, '\x1b[39m', 'red.close should return closing escape sequence');
assert.strictEqual(c.redBright.open, '\x1b[91m', 'redBright.open should return opening escape sequence');
assert.strictEqual(c.redBright.close, '\x1b[39m', 'redBright.close should return closing escape sequence');

// Nested color formatting
const nestedColor = c.red('outer ' + c.yellow('nested') + ' text');
assert.strictEqual(nestedColor, '\x1b[31mouter \x1b[33mnested\x1b[31m text\x1b[39m', 'nested foreground colors should restore outer color code upon close');

// Nested modifier formatting
const nestedBold = c.bold('bold ' + c.bold('nested') + ' end');
assert.strictEqual(nestedBold, '\x1b[1mbold \x1b[1mnested\x1b[22m\x1b[1m end\x1b[22m', 'nested bold styling should re-apply outer bold upon nested close');

// Helper function
assert.strictEqual(formatStatus('failed', 'error'), '\x1b[91mfailed\x1b[39m', 'formatStatus error should return redBright formatted text');
assert.strictEqual(formatStatus('done', 'success'), '\x1b[92mdone\x1b[39m', 'formatStatus success should return greenBright formatted text');

// 3. Default uncolored instance from getDefaultColors()
const uncolored = getDefaultColors();
assert.strictEqual(uncolored.isColorSupported, false, 'uncolored instance should have isColorSupported false');
assert.strictEqual(uncolored.red('plain'), 'plain', 'uncolored red should return plain text');
assert.strictEqual(uncolored.bold('plain'), 'plain', 'uncolored bold should return plain text');
assert.strictEqual(uncolored.redBright('plain'), 'plain', 'uncolored redBright should return plain text');
assert.strictEqual(uncolored.red.open, '', 'uncolored red.open should be empty string');
assert.strictEqual(uncolored.red.close, '', 'uncolored red.close should be empty string');

// 4. Color formatting disabled with NO_COLOR=1
process.env.NO_COLOR = '1';
delete process.env.FORCE_COLOR;
const disabled = createColors();
assert.strictEqual(disabled.isColorSupported, false, 'disabled instance should have isColorSupported false');
assert.strictEqual(disabled.green('plain-text'), 'plain-text', 'disabled green should return plain text');
assert.strictEqual(disabled.bgBlue('plain-text'), 'plain-text', 'disabled bgBlue should return plain text');
assert.strictEqual(disabled.redBright('plain-text'), 'plain-text', 'disabled redBright should return plain text');
assert.strictEqual(isSupported(), false, 'isSupported should return false when NO_COLOR is set');

console.log('Contract tests passed successfully.');

Origin Seeder

anonymous