CodeSampleX

Sample

strip-ansi 6.0.1

Verified sample for npm strip-ansi 6.0.1. The contract ran on node 22 · linux alpine/x64 · docker and passed: stripAnsi removes standard 3/4-bit color ANSI…

sha256:b00ce0901a02a79bdfd5cd7632e587ff3de529c4ae1a9204a82a0ef7c1970585

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

Case

HOW
Goal
verify pkg:npm/strip-ansi@6.0.1
Packages
Created
2026-08-23T07:37:39Z

Contract

  1. stripAnsi removes standard 3/4-bit color ANSI escape codes
  2. stripAnsi removes 256-color and RGB ANSI escape sequences
  3. stripAnsi removes text style formatting such as bold, dim, italic, and underline codes
  4. stripAnsi removes terminal cursor and line clear control sequences
  5. stripAnsi preserves plain text and passes non-string inputs unchanged
  6. cleanAnsi helper function correctly removes ANSI codes
  7. hasAnsi helper function accurately detects presence of ANSI escape codes
  8. cleanAnsiLines helper function strips ANSI codes from an array of strings

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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/strip-ansi@6.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/strip-ansi@6.0.1

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:18be7a99874adb16fadc136fc8a09848294551c324c380116f2725bcae7d7b3f","contract":["stripAnsi removes standard 3/4-bit color ANSI escape codes","stripAnsi removes 256-color and RGB ANSI escape sequences","stripAnsi removes text style formatting such as bold, dim, italic, and underline codes","stripAnsi removes terminal cursor and line clear control sequences","stripAnsi preserves plain text and passes non-string inputs unchanged","cleanAnsi helper function correctly removes ANSI codes","hasAnsi helper function accurately detects presence of ANSI escape codes","cleanAnsiLines helper function strips ANSI codes from an array of strings"],"goal":"verify pkg:npm/strip-ansi@6.0.1","kind":"HOW","packages":["pkg:npm/strip-ansi@6.0.1"],"schemaVersion":1},"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/strip-ansi@6.0.1"],"schemaVersion":1,"subject":"pkg:npm/strip-ansi@6.0.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-strip-ansi",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-strip-ansi",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "strip-ansi": "6.0.1"
      }
    },
    "node_modules/ansi-regex": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
      "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/strip-ansi": {
      "version": "6.0.1",
      "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
      "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
      "license": "MIT",
      "dependencies": {
        "ansi-regex": "^5.0.1"
      },
      "engines": {
        "node": ">=8"
      }
    }
  }
}
package.json
{
  "name": "sample-strip-ansi",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of strip-ansi@6.0.1",
  "main": "src/index.mjs",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "strip-ansi": "6.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/strip-ansi@6.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/strip-ansi@6.0.1"
  ]
}
src/index.mjs
import stripAnsi from "strip-ansi";

/**
 * Strips ANSI escape codes from the provided input string.
 * Non-string values are returned unchanged.
 *
 * @param {string} text - The input string containing ANSI escape sequences.
 * @returns {string} The cleaned string with ANSI escape codes removed.
 */
export function cleanAnsi(text) {
  return stripAnsi(text);
}

/**
 * Checks if a string contains any ANSI escape codes.
 *
 * @param {string} text - The input string to check.
 * @returns {boolean} True if ANSI escape codes are present, false otherwise.
 */
export function hasAnsi(text) {
  return typeof text === "string" && stripAnsi(text) !== text;
}

/**
 * Strips ANSI escape codes from an array of strings.
 *
 * @param {string[]} lines - Array of strings to clean.
 * @returns {string[]} Array of cleaned strings.
 */
export function cleanAnsiLines(lines) {
  return lines.map((line) => stripAnsi(line));
}

export { stripAnsi };
export default stripAnsi;
test/contract.mjs
import assert from "node:assert/strict";
import stripAnsi, {
  cleanAnsi,
  hasAnsi,
  cleanAnsiLines,
} from "../src/index.mjs";

// 1. stripAnsi removes standard 3/4-bit color ANSI escape codes
{
  const redText = "\u001B[31mError message\u001B[39m";
  assert.strictEqual(stripAnsi(redText), "Error message");

  const greenBg = "\u001B[42mSuccess\u001B[49m";
  assert.strictEqual(stripAnsi(greenBg), "Success");

  const brightYellow = "\u001B[93mWarning\u001B[39m";
  assert.strictEqual(stripAnsi(brightYellow), "Warning");
}

// 2. stripAnsi removes 256-color (8-bit) and RGB / truecolor (24-bit) escape sequences
{
  const color256 = "\u001B[38;5;196m256-color-red\u001B[0m";
  assert.strictEqual(stripAnsi(color256), "256-color-red");

  const trueColor = "\u001B[38;2;255;100;50mtruecolor-text\u001B[0m";
  assert.strictEqual(stripAnsi(trueColor), "truecolor-text");

  const bg256 = "\u001B[48;5;46mgreen-bg-256\u001B[49m";
  assert.strictEqual(stripAnsi(bg256), "green-bg-256");
}

// 3. stripAnsi removes text style formatting such as bold, dim, italic, and underline codes
{
  const boldText = "\u001B[1mBold Text\u001B[22m";
  assert.strictEqual(stripAnsi(boldText), "Bold Text");

  const underlineText = "\u001B[4mUnderlined\u001B[24m";
  assert.strictEqual(stripAnsi(underlineText), "Underlined");

  const combinedStyles = "\u001B[1m\u001B[3m\u001B[4mStyled\u001B[24m\u001B[23m\u001B[22m";
  assert.strictEqual(stripAnsi(combinedStyles), "Styled");
}

// 4. stripAnsi removes terminal cursor and line clear control sequences
{
  const cursorMove = "\u001B[2A\u001B[10CProgress: 50%";
  assert.strictEqual(stripAnsi(cursorMove), "Progress: 50%");

  const clearLine = "\u001B[2K\u001B[0GCompleted task";
  assert.strictEqual(stripAnsi(clearLine), "Completed task");

  const resetAll = "\u001B[0mAll Reset";
  assert.strictEqual(stripAnsi(resetAll), "All Reset");
}

// 5. stripAnsi preserves plain text and passes non-string inputs unchanged
{
  const plain = "Hello, world! 123 @#$";
  assert.strictEqual(stripAnsi(plain), plain);

  const empty = "";
  assert.strictEqual(stripAnsi(empty), "");

  assert.strictEqual(stripAnsi(12345), 12345);
  assert.strictEqual(stripAnsi(null), null);
  assert.strictEqual(stripAnsi(undefined), undefined);

  const testObj = { key: "value" };
  assert.strictEqual(stripAnsi(testObj), testObj);
}

// 6. cleanAnsi helper function correctly removes ANSI codes
{
  assert.strictEqual(cleanAnsi("\u001B[32mPASS\u001B[39m"), "PASS");
  assert.strictEqual(cleanAnsi("clean text"), "clean text");
}

// 7. hasAnsi helper function accurately detects presence of ANSI escape codes
{
  assert.strictEqual(hasAnsi("\u001B[31mcolored\u001B[39m"), true);
  assert.strictEqual(hasAnsi("regular text"), false);
  assert.strictEqual(hasAnsi(""), false);
  assert.strictEqual(hasAnsi(null), false);
  assert.strictEqual(hasAnsi(42), false);
}

// 8. cleanAnsiLines helper function strips ANSI codes from an array of strings
{
  const input = [
    "\u001B[31mLine 1\u001B[39m",
    "Line 2 (plain)",
    "\u001B[1mLine 3 (bold)\u001B[22m",
  ];
  const expected = ["Line 1", "Line 2 (plain)", "Line 3 (bold)"];
  assert.deepStrictEqual(cleanAnsiLines(input), expected);
}

console.log("All strip-ansi contract assertions passed successfully.");

Origin Seeder

anonymous