CodeSampleX

샘플

strip-ansi 6.0.1

검증된 샘플 — npm strip-ansi 6.0.1. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: stripAnsi removes standard 3/4-bit color ANSI escape codes

sha256:b00ce0901a02a79bdfd5cd7632e587ff3de529c4ae1a9204a82a0ef7c1970585

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:npm/strip-ansi@6.0.1
패키지
생성일
2026-08-23T07:37:39Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (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 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.");

오리진 시더

익명