CodeSampleX

Пример

strip-ansi 7.2.0

Проверенный пример — npm strip-ansi 7.2.0. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: stripAnsi removes 3-bit and 4-bit standard…

sha256:5ead9969f871279a798e3d1123943781d59da1d42ea8e6a68420c21d26cd8ebb

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
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

Кейс

HOW
Цель
verify pkg:npm/strip-ansi@7.2.0
Пакеты
Окружение
node 22.23.2
Создан
2026-08-23T08:09:52Z

Контракт

  1. stripAnsi removes 3-bit and 4-bit standard ANSI color codes
  2. stripAnsi removes 8-bit (256 color) ANSI color sequences
  3. stripAnsi removes 24-bit (RGB) ANSI color sequences
  4. stripAnsi removes text styling such as bold, italic, and underline
  5. stripAnsi removes terminal cursor and line clear control sequences
  6. stripAnsi preserves strings without ANSI escape codes
  7. stripAnsi throws TypeError when given non-string input
  8. stripAnsiCodes wrapper removes ANSI formatting correctly
  9. hasAnsiCodes detects whether a string contains ANSI escape codes
  10. stripAnsiFromLines cleans an array of formatted strings

Файлы

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • 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@7.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/strip-ansi@7.2.0
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:3a0bc29c7abad45384f394cd33b66df5561bfa67adfa127db8ae0a3f77c0f955","constraints":{"executionContext":"node"},"contract":["stripAnsi removes 3-bit and 4-bit standard ANSI color codes","stripAnsi removes 8-bit (256 color) ANSI color sequences","stripAnsi removes 24-bit (RGB) ANSI color sequences","stripAnsi removes text styling such as bold, italic, and underline","stripAnsi removes terminal cursor and line clear control sequences","stripAnsi preserves strings without ANSI escape codes","stripAnsi throws TypeError when given non-string input","stripAnsiCodes wrapper removes ANSI formatting correctly","hasAnsiCodes detects whether a string contains ANSI escape codes","stripAnsiFromLines cleans an array of formatted strings"],"goal":"verify pkg:npm/strip-ansi@7.2.0","kind":"HOW","packages":["pkg:npm/strip-ansi@7.2.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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/strip-ansi@7.2.0"],"schemaVersion":1,"subject":"pkg:npm/strip-ansi@7.2.0","verifierAdapter":"node-typescript@1"}
index.js
const stripAnsiModule = require('strip-ansi');
const stripAnsi = stripAnsiModule.default || stripAnsiModule;

function stripAnsiCodes(text) {
  return stripAnsi(text);
}

function hasAnsiCodes(text) {
  if (typeof text !== 'string') {
    throw new TypeError(`Expected a string, got ${typeof text}`);
  }
  return text !== stripAnsi(text);
}

function stripAnsiFromLines(lines) {
  if (!Array.isArray(lines)) {
    throw new TypeError('Expected an array of strings');
  }
  return lines.map((line) => stripAnsi(line));
}

module.exports = {
  stripAnsiCodes,
  hasAnsiCodes,
  stripAnsiFromLines,
};
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": "7.2.0"
      }
    },
    "node_modules/ansi-regex": {
      "version": "6.3.0",
      "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.3.0.tgz",
      "integrity": "sha512-WpDfL7NO6j7tH88IDBNVdUJxDh9nmCteAVW9dsep846XdwF4naCBK+/tGLX3KJgcpgMRXCFlTM2hKGoK9FsdrQ==",
      "license": "MIT",
      "engines": {
        "node": ">=12"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-regex?sponsor=1"
      }
    },
    "node_modules/strip-ansi": {
      "version": "7.2.0",
      "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.2.0.tgz",
      "integrity": "sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w==",
      "license": "MIT",
      "dependencies": {
        "ansi-regex": "^6.2.2"
      },
      "engines": {
        "node": ">=12"
      },
      "funding": {
        "url": "https://github.com/chalk/strip-ansi?sponsor=1"
      }
    }
  }
}
package.json
{
  "name": "sample-strip-ansi",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for strip-ansi 7.2.0",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "strip-ansi": "7.2.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/strip-ansi@7.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/strip-ansi@7.2.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import stripAnsi from 'strip-ansi';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { stripAnsiCodes, hasAnsiCodes, stripAnsiFromLines } = require('../index.js');

// 1. stripAnsi removes 3-bit and 4-bit standard ANSI color codes
assert.equal(stripAnsi('\u001B[31mRed Text\u001B[39m'), 'Red Text');
assert.equal(stripAnsi('\u001B[42mGreen Background\u001B[49m'), 'Green Background');
assert.equal(stripAnsi('\u001B[93mBright Yellow\u001B[39m'), 'Bright Yellow');

// 2. stripAnsi removes 8-bit (256 color) ANSI color sequences
assert.equal(stripAnsi('\u001B[38;5;196m256 Color Text\u001B[0m'), '256 Color Text');
assert.equal(stripAnsi('\u001B[48;5;27m256 Background\u001B[0m'), '256 Background');

// 3. stripAnsi removes 24-bit (RGB) ANSI color sequences
assert.equal(stripAnsi('\u001B[38;2;255;100;50mRGB Color\u001B[0m'), 'RGB Color');
assert.equal(stripAnsi('\u001B[48;2;0;128;255mRGB Background\u001B[0m'), 'RGB Background');

// 4. stripAnsi removes text styling such as bold, italic, and underline
assert.equal(stripAnsi('\u001B[1mBold\u001B[22m \u001B[3mItalic\u001B[23m \u001B[4mUnderline\u001B[24m'), 'Bold Italic Underline');
assert.equal(stripAnsi('\u001B[2mDim\u001B[22m \u001B[9mStrikethrough\u001B[29m'), 'Dim Strikethrough');

// 5. stripAnsi removes terminal cursor and line clear control sequences
assert.equal(stripAnsi('\u001B[2K\u001B[1GCleared Line\u001B[0J'), 'Cleared Line');

// 6. stripAnsi preserves strings without ANSI escape codes
assert.equal(stripAnsi('Plain text without ANSI escape codes'), 'Plain text without ANSI escape codes');
assert.equal(stripAnsi(''), '');

// 7. stripAnsi throws TypeError when given non-string input
assert.throws(() => stripAnsi(123), { name: 'TypeError' });
assert.throws(() => stripAnsi(null), { name: 'TypeError' });
assert.throws(() => stripAnsi(undefined), { name: 'TypeError' });
assert.throws(() => stripAnsi({}), { name: 'TypeError' });

// 8. stripAnsiCodes wrapper removes ANSI formatting correctly
assert.equal(stripAnsiCodes('\u001B[34mWrapped Hello\u001B[0m'), 'Wrapped Hello');

// 9. hasAnsiCodes detects whether a string contains ANSI escape codes
assert.equal(hasAnsiCodes('\u001B[31mError\u001B[0m'), true);
assert.equal(hasAnsiCodes('Normal text'), false);
assert.throws(() => hasAnsiCodes(123), { name: 'TypeError' });

// 10. stripAnsiFromLines cleans an array of formatted strings
const rawLines = ['\u001B[32mLine 1\u001B[0m', '\u001B[33mLine 2\u001B[0m', 'Plain Line 3'];
const expectedLines = ['Line 1', 'Line 2', 'Plain Line 3'];
assert.deepEqual(stripAnsiFromLines(rawLines), expectedLines);
assert.throws(() => stripAnsiFromLines('not an array'), { name: 'TypeError' });

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

Исходный сидер

аноним