Ejemplo
js-tokens 9.0.1
Muestra verificada para npm js-tokens 9.0.1. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: jsTokens yields token objects with type…
sha256:284b15822e9206d3e555c82eb5a056c3e3e1587c4813b90b94c472ae01d244cf
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
- 2
- 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 alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-21 |
| 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-09-07 |
Caso
HOW- Objetivo
- verify pkg:npm/js-tokens@9.0.1
- Paquetes
- Entorno
- node 22.23.2
- Creado
- 2026-08-21T03:26:42Z
Contrato
- jsTokens yields token objects with type and value for JavaScript code constructs
- tokenize parses identifiers, keywords, punctuators, and numeric literals
- tokenize handles regular expression literals and string literals with closed flag
- tokenize supports JSX syntax when jsx option is enabled
- tokenize handles template literals and template substitutions
- extractSignificantTokens filters whitespace and comments
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/js-tokens@9.0.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/js-tokens@9.0.1
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.
{"case":{"caseId":"case:sha256:f39a58783c94076348c759449624c8ac8f6dd46517146b97e6cba7dd1de2b0b3","constraints":{"executionContext":"node"},"contract":["jsTokens yields token objects with type and value for JavaScript code constructs","tokenize parses identifiers, keywords, punctuators, and numeric literals","tokenize handles regular expression literals and string literals with closed flag","tokenize supports JSX syntax when jsx option is enabled","tokenize handles template literals and template substitutions","extractSignificantTokens filters whitespace and comments"],"goal":"verify pkg:npm/js-tokens@9.0.1","kind":"HOW","packages":["pkg:npm/js-tokens@9.0.1"],"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/js-tokens@9.0.1"],"schemaVersion":1,"subject":"pkg:npm/js-tokens@9.0.1","verifierAdapter":"node-typescript@1"}
{
"name": "sample-js-tokens",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-js-tokens",
"version": "1.0.0",
"dependencies": {
"js-tokens": "9.0.1"
}
},
"node_modules/js-tokens": {
"version": "9.0.1",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-9.0.1.tgz",
"integrity": "sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ==",
"license": "MIT"
}
}
}
{
"name": "sample-js-tokens",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of js-tokens",
"main": "src/index.js",
"dependencies": {
"js-tokens": "9.0.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/js-tokens@9.0.1",
"kind": "HOW",
"packages": [
"pkg:npm/js-tokens@9.0.1"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const jsTokens = require('js-tokens');
/**
* Tokenize JavaScript code into an array of token objects.
* @param {string} input - JavaScript code to tokenize.
* @param {object} [options] - Tokenizer options.
* @param {boolean} [options.jsx=false] - Whether to tokenize JSX syntax.
* @returns {Array<{type: string, value: string, closed?: boolean}>}
*/
function tokenize(input, options = {}) {
return Array.from(jsTokens(input, options));
}
/**
* Extract non-whitespace and non-comment token values.
* @param {string} input - JavaScript code.
* @param {object} [options] - Tokenizer options.
* @returns {string[]} Array of significant token string values.
*/
function extractSignificantTokens(input, options = {}) {
const tokens = tokenize(input, options);
return tokens
.filter(
(t) =>
t.type !== 'WhiteSpace' &&
t.type !== 'LineTerminatorSequence' &&
t.type !== 'SingleLineComment' &&
t.type !== 'MultiLineComment' &&
t.type !== 'HashbangComment'
)
.map((t) => t.value);
}
module.exports = {
jsTokens,
tokenize,
extractSignificantTokens
};
import assert from 'node:assert';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { jsTokens, tokenize, extractSignificantTokens } = require('../src/index.js');
// 1. Export verification
assert.strictEqual(typeof jsTokens, 'function', 'jsTokens should be exported as a function');
assert.strictEqual(typeof tokenize, 'function', 'tokenize should be exported as a function');
assert.strictEqual(typeof extractSignificantTokens, 'function', 'extractSignificantTokens should be exported as a function');
// 2. Tokenize basic JavaScript declarations and statements
const basicTokens = tokenize('const answer = 42;');
assert.strictEqual(basicTokens.length, 8);
assert.deepStrictEqual(
basicTokens.map((t) => t.type),
[
'IdentifierName',
'WhiteSpace',
'IdentifierName',
'WhiteSpace',
'Punctuator',
'WhiteSpace',
'NumericLiteral',
'Punctuator'
]
);
assert.strictEqual(basicTokens[0].value, 'const');
assert.strictEqual(basicTokens[2].value, 'answer');
assert.strictEqual(basicTokens[4].value, '=');
assert.strictEqual(basicTokens[6].value, '42');
assert.strictEqual(basicTokens[7].value, ';');
// 3. Tokenize regular expression literals and string literals with closed status
const regexTokens = tokenize('/^[a-z]+$/i;');
assert.strictEqual(regexTokens[0].type, 'RegularExpressionLiteral');
assert.strictEqual(regexTokens[0].value, '/^[a-z]+$/i');
assert.strictEqual(regexTokens[0].closed, true);
const closedString = tokenize('"clean room"');
assert.strictEqual(closedString[0].type, 'StringLiteral');
assert.strictEqual(closedString[0].value, '"clean room"');
assert.strictEqual(closedString[0].closed, true);
const unclosedString = tokenize('"unclosed');
assert.strictEqual(unclosedString[0].type, 'StringLiteral');
assert.strictEqual(unclosedString[0].closed, false);
// 4. Tokenize JSX elements when jsx option is true
const jsxCode = '<Button onClick={handleClick}>Click Me</Button>';
const jsxTokens = tokenize(jsxCode, { jsx: true });
const tokenTypes = jsxTokens.map((t) => t.type);
assert.ok(tokenTypes.includes('JSXIdentifier'), 'Should identify JSX tag names');
assert.ok(tokenTypes.includes('JSXPunctuator'), 'Should identify JSX punctuators');
assert.ok(tokenTypes.includes('JSXText'), 'Should identify JSX text content');
const jsxIdentifiers = jsxTokens.filter((t) => t.type === 'JSXIdentifier').map((t) => t.value);
assert.deepStrictEqual(jsxIdentifiers, ['Button', 'onClick', 'Button']);
// 5. Tokenize template literals and substitutions
const templateTokens = tokenize('`User ${name} logged in.`');
assert.strictEqual(templateTokens[0].type, 'TemplateHead');
assert.strictEqual(templateTokens[0].value, '`User ${');
assert.strictEqual(templateTokens[1].type, 'IdentifierName');
assert.strictEqual(templateTokens[1].value, 'name');
assert.strictEqual(templateTokens[2].type, 'TemplateTail');
assert.strictEqual(templateTokens[2].value, '} logged in.`');
assert.strictEqual(templateTokens[2].closed, true);
// 6. Extract significant tokens excluding whitespace and comments
const sourceWithComments = '/* preamble */ let total = 10 + 20; // end of line';
const significant = extractSignificantTokens(sourceWithComments);
assert.deepStrictEqual(significant, ['let', 'total', '=', '10', '+', '20', ';']);
console.log('Contract tests passed successfully.');
Seeder de origen
anónimo