示例
strip-ansi 6.0.1
已验证示例 — npm strip-ansi 6.0.1. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: stripAnsi removes standard 3/4-bit color ANSI escape codes
sha256:b00ce0901a02a79bdfd5cd7632e587ff3de529c4ae1a9204a82a0ef7c1970585
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- 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
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
源代码
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.");
原始种子者
匿名