Ejemplo
ansi-regex 6.4.0
Muestra verificada para npm ansi-regex 6.4.0. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: ansiRegex returns a RegExp instance for…
sha256:9c48b1325e2b5338906927f287d6f8fba83b5587d558127ec0d4d8640666f999
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-10-17 |
Caso
HOW- Objetivo
- verify pkg:npm/ansi-regex@6.4.0
- Paquetes
- Entorno
- node 22.23.2
- Creado
- 2026-10-17T19:33:01Z
Contrato
- ansiRegex returns a RegExp instance for matching ANSI escape sequences
- ansiRegex with default options returns a global regular expression
- ansiRegex with onlyFirst set to true returns a non-global regular expression
- ansiRegex matches standard SGR styling and color escape codes
- ansiRegex matches 256-color, truecolor, and OSC hyperlink escape sequences
- removeAnsi strips all ANSI escape sequences and leaves plain text intact
- containsAnsi detects presence of ANSI escape sequences
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Código fuente
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/ansi-regex@6.4.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ansi-regex@6.4.0
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:0a4739865e32b7de01da47223b84e4aede7a988a912150b3324e16ab68752768","contract":["ansiRegex returns a RegExp instance for matching ANSI escape sequences","ansiRegex with default options returns a global regular expression","ansiRegex with onlyFirst set to true returns a non-global regular expression","ansiRegex matches standard SGR styling and color escape codes","ansiRegex matches 256-color, truecolor, and OSC hyperlink escape sequences","removeAnsi strips all ANSI escape sequences and leaves plain text intact","containsAnsi detects presence of ANSI escape sequences"],"goal":"verify pkg:npm/ansi-regex@6.4.0","kind":"HOW","packages":["pkg:npm/ansi-regex@6.4.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":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/ansi-regex@6.4.0"],"schemaVersion":1,"subject":"pkg:npm/ansi-regex@6.4.0","verifierAdapter":"node-typescript@1"}
{
"name": "sample-ansi-regex",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ansi-regex",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"ansi-regex": "6.4.0"
}
},
"node_modules/ansi-regex": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.4.0.tgz",
"integrity": "sha512-KzTVk2tCWAHtYrvvvaP8bJKJq2pVinhLcGEQdtLIYPbmNGNyYe8QwNaTUYQp2J7/vIsUKt5QCqAfUkYyG9DkOw==",
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/ansi-regex?sponsor=1"
}
}
}
}
{
"name": "sample-ansi-regex",
"version": "1.0.0",
"private": true,
"type": "module",
"description": "Clean-room verification sample for ansi-regex",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"ansi-regex": "6.4.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/ansi-regex@6.4.0",
"kind": "HOW",
"packages": [
"pkg:npm/ansi-regex@6.4.0"
]
}
import ansiRegex from 'ansi-regex';
/**
* Returns a regular expression matching ANSI escape codes.
* @param {Object} [options]
* @param {boolean} [options.onlyFirst=false] - Match only the first occurrence.
* @returns {RegExp}
*/
export function createAnsiPattern(options) {
return ansiRegex(options);
}
/**
* Checks whether a string contains any ANSI escape sequences.
* @param {string} input
* @returns {boolean}
*/
export function containsAnsi(input) {
if (typeof input !== 'string') {
return false;
}
return ansiRegex({ onlyFirst: true }).test(input);
}
/**
* Removes all ANSI escape sequences from a string.
* @param {string} input
* @returns {string}
*/
export function removeAnsi(input) {
if (typeof input !== 'string') {
return '';
}
return input.replace(ansiRegex(), '');
}
/**
* Collects all ANSI escape sequences present in a string.
* @param {string} input
* @returns {string[]}
*/
export function findAllAnsi(input) {
if (typeof input !== 'string') {
return [];
}
const matches = input.match(ansiRegex());
return matches ? Array.from(matches) : [];
}
export { ansiRegex };
export default ansiRegex;
import assert from 'node:assert/strict';
import ansiRegex, { createAnsiPattern, containsAnsi, removeAnsi, findAllAnsi } from '../src/index.js';
// 1. ansiRegex returns a RegExp instance for matching ANSI escape sequences
const defaultPattern = ansiRegex();
assert.ok(defaultPattern instanceof RegExp, 'ansiRegex() should return a RegExp instance');
assert.equal(typeof ansiRegex, 'function', 'ansiRegex export should be a function');
// 2. ansiRegex with default options returns a global regular expression
assert.equal(defaultPattern.global, true, 'ansiRegex() with default options should set global flag to true');
assert.equal(createAnsiPattern().global, true, 'createAnsiPattern() should return a global RegExp');
// 3. ansiRegex with onlyFirst set to true returns a non-global regular expression
const singlePattern = ansiRegex({ onlyFirst: true });
assert.ok(singlePattern instanceof RegExp, 'ansiRegex({ onlyFirst: true }) should return a RegExp instance');
assert.equal(singlePattern.global, false, 'ansiRegex({ onlyFirst: true }) should set global flag to false');
assert.equal(createAnsiPattern({ onlyFirst: true }).global, false, 'createAnsiPattern({ onlyFirst: true }) should return non-global RegExp');
// 4. ansiRegex matches standard SGR styling and color escape codes
const styledText = '\u001B[31mError:\u001B[39m \u001B[1mFile not found\u001B[22m';
assert.equal(singlePattern.test(styledText), true, 'non-global pattern should match styled text');
const singleMatch = styledText.match(singlePattern);
assert.ok(singleMatch !== null, 'single match should succeed');
assert.equal(singleMatch[0], '\u001B[31m', 'onlyFirst pattern should match the first escape code');
const allStyleMatches = styledText.match(defaultPattern);
assert.deepEqual(
allStyleMatches ? Array.from(allStyleMatches) : [],
['\u001B[31m', '\u001B[39m', '\u001B[1m', '\u001B[22m'],
'global pattern should match all SGR escape sequences'
);
// 5. ansiRegex matches 256-color, truecolor, and OSC hyperlink escape sequences
const richAnsiText = '\u001B[38;5;208mOrange\u001B[39m \u001B[38;2;0;128;255mRGB\u001B[39m \u001B]8;;https://example.com\u0007Link\u001B]8;;\u0007';
const richMatches = findAllAnsi(richAnsiText);
assert.deepEqual(
richMatches,
[
'\u001B[38;5;208m',
'\u001B[39m',
'\u001B[38;2;0;128;255m',
'\u001B[39m',
'\u001B]8;;https://example.com\u0007',
'\u001B]8;;\u0007'
],
'should match 256-color, 24-bit RGB, and OSC 8 hyperlink sequences'
);
// 6. removeAnsi strips all ANSI escape sequences and leaves plain text intact
assert.equal(removeAnsi(styledText), 'Error: File not found', 'removeAnsi should strip all SGR codes');
assert.equal(removeAnsi(richAnsiText), 'Orange RGB Link', 'removeAnsi should strip extended color and hyperlink codes');
assert.equal(removeAnsi('Plain ASCII string'), 'Plain ASCII string', 'removeAnsi should preserve plain strings');
assert.equal(removeAnsi(null), '', 'removeAnsi should return empty string for non-string input');
// 7. containsAnsi detects presence of ANSI escape sequences
assert.equal(containsAnsi('\u001B[32mSuccess\u001B[39m'), true, 'containsAnsi should return true when ANSI sequence is present');
assert.equal(containsAnsi('Normal text without escapes'), false, 'containsAnsi should return false for plain text');
assert.equal(containsAnsi(''), false, 'containsAnsi should return false for empty string');
assert.equal(containsAnsi(undefined), false, 'containsAnsi should return false for non-string input');
console.log('All contract assertions passed.');
Seeder de origen
anónimo