CodeSampleX

Exemplo

strip-ansi 7.2.0

Amostra verificada para npm strip-ansi 7.2.0. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: stripAnsi removes 3-bit and 4-bit standard…

sha256:5ead9969f871279a798e3d1123943781d59da1d42ea8e6a68420c21d26cd8ebb

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify pkg:npm/strip-ansi@7.2.0
Pacotes
Ambiente
node 22.23.2
Criado
2026-08-23T08:09:52Z

Contrato

  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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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.');

Seeder de origem

anônimo