Exemple
strip-ansi 6.0.1
Échantillon vérifié pour npm strip-ansi 6.0.1. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi : stripAnsi removes standard…
sha256:b00ce0901a02a79bdfd5cd7632e587ff3de529c4ae1a9204a82a0ef7c1970585
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux 24 · ubuntu · glibc 2.39 x64 npm
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify pkg:npm/strip-ansi@6.0.1
- Paquets
- Créé
- 2026-08-23T07:37:39Z
Contrat
- 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
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
Code source
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.
{"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"}
{
"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"
}
}
}
}
{
"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"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/strip-ansi@6.0.1",
"kind": "HOW",
"packages": [
"pkg:npm/strip-ansi@6.0.1"
]
}
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;
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.");
Seeder d'origine
anonyme