示例
esutils 2.0.3
已验证示例 — npm esutils 2.0.3. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: keyword module identifies JavaScript keywords, reserved words, and valid…
sha256:478d8047a030f6c5ff1a8907ec3ba1058b22c2be0ee02c52bf4b2cf1e00b9ea0
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 2
- 构建过它的签名密钥
- 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 |
| 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 |
案例
HOW- 目标
- verify pkg:npm/esutils@2.0.3
- 创建时间
- 2026-08-23T14:12:26Z
契约
- keyword module identifies JavaScript keywords, reserved words, and valid identifier names
- code module determines character categories including digits, whitespace, and identifier boundaries
- ast module identifies AST node classifications including expressions, statements, and iteration statements
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
源代码
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/esutils@2.0.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/esutils@2.0.3
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:3ce354a7046e3a386367dc5edf9c709f94acd159833dd3124672cfd56b80a363","contract":["keyword module identifies JavaScript keywords, reserved words, and valid identifier names","code module determines character categories including digits, whitespace, and identifier boundaries","ast module identifies AST node classifications including expressions, statements, and iteration statements"],"goal":"verify pkg:npm/esutils@2.0.3","kind":"HOW","packages":["pkg:npm/esutils@2.0.3"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/esutils@2.0.3"],"schemaVersion":1,"subject":"pkg:npm/esutils@2.0.3","verifierAdapter":"node-typescript@1"}
{
"name": "sample-esutils",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-esutils",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"esutils": "2.0.3"
}
},
"node_modules/esutils": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=0.10.0"
}
}
}
}
{
"name": "sample-esutils",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification sample for esutils",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"esutils": "2.0.3"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/esutils@2.0.3",
"kind": "HOW",
"packages": [
"pkg:npm/esutils@2.0.3"
]
}
const esutils = require('esutils');
/**
* Checks if a string is a valid JavaScript identifier name in ES6.
* @param {string} name
* @returns {boolean}
*/
function isValidIdentifier(name) {
return esutils.keyword.isIdentifierES6(name);
}
/**
* Checks if a string is a reserved keyword in ES6.
* @param {string} word
* @param {boolean} [strict=true]
* @returns {boolean}
*/
function isKeyword(word, strict = true) {
return esutils.keyword.isKeywordES6(word, strict);
}
/**
* Checks if a character code represents a whitespace character.
* @param {number} code
* @returns {boolean}
*/
function isWhitespaceChar(code) {
return esutils.code.isWhiteSpace(code);
}
/**
* Checks if an AST node is a statement.
* @param {object} node
* @returns {boolean}
*/
function isStatementNode(node) {
return esutils.ast.isStatement(node);
}
module.exports = {
esutils,
isValidIdentifier,
isKeyword,
isWhitespaceChar,
isStatementNode,
};
const assert = require('node:assert');
const esutils = require('esutils');
const {
isValidIdentifier,
isKeyword,
isWhitespaceChar,
isStatementNode,
} = require('../src/index.js');
// 1. keyword module identifies JavaScript keywords, reserved words, and valid identifier names
{
// Keywords in ES6
assert.strictEqual(esutils.keyword.isKeywordES6('class', true), true, 'class is ES6 keyword');
assert.strictEqual(esutils.keyword.isKeywordES6('const', true), true, 'const is ES6 keyword');
assert.strictEqual(esutils.keyword.isKeywordES6('let', true), true, 'let is ES6 keyword');
assert.strictEqual(esutils.keyword.isKeywordES6('import', true), true, 'import is ES6 keyword');
assert.strictEqual(esutils.keyword.isKeywordES6('export', true), true, 'export is ES6 keyword');
assert.strictEqual(esutils.keyword.isKeywordES6('myVariable', true), false, 'myVariable is not a keyword');
assert.strictEqual(isKeyword('function'), true, 'helper isKeyword confirms function');
assert.strictEqual(isKeyword('nonKeyword'), false, 'helper isKeyword rejects nonKeyword');
// Reserved words & restricted words
assert.strictEqual(esutils.keyword.isRestrictedWord('eval'), true, 'eval is restricted word');
assert.strictEqual(esutils.keyword.isRestrictedWord('arguments'), true, 'arguments is restricted word');
assert.strictEqual(esutils.keyword.isRestrictedWord('regularName'), false, 'regularName is not restricted');
// Valid / invalid identifiers
assert.strictEqual(esutils.keyword.isIdentifierES6('validIdent'), true, 'validIdent is valid identifier');
assert.strictEqual(esutils.keyword.isIdentifierES6('$dollar'), true, '$dollar is valid identifier');
assert.strictEqual(esutils.keyword.isIdentifierES6('_underscore'), true, '_underscore is valid identifier');
assert.strictEqual(esutils.keyword.isIdentifierES6('123number'), false, '123number is invalid identifier');
assert.strictEqual(esutils.keyword.isIdentifierES6('class'), false, 'keyword is not valid identifier');
assert.strictEqual(esutils.keyword.isIdentifierNameES6('class'), true, 'class is valid identifier name');
assert.strictEqual(isValidIdentifier('myVar'), true, 'helper isValidIdentifier confirms valid name');
assert.strictEqual(isValidIdentifier('for'), false, 'helper isValidIdentifier rejects keyword');
}
// 2. code module determines character categories including digits, whitespace, and identifier boundaries
{
// Digits
assert.strictEqual(esutils.code.isDecimalDigit('0'.charCodeAt(0)), true, '0 is decimal digit');
assert.strictEqual(esutils.code.isDecimalDigit('9'.charCodeAt(0)), true, '9 is decimal digit');
assert.strictEqual(esutils.code.isDecimalDigit('a'.charCodeAt(0)), false, 'a is not decimal digit');
assert.strictEqual(esutils.code.isHexDigit('a'.charCodeAt(0)), true, 'a is hex digit');
assert.strictEqual(esutils.code.isHexDigit('F'.charCodeAt(0)), true, 'F is hex digit');
assert.strictEqual(esutils.code.isHexDigit('g'.charCodeAt(0)), false, 'g is not hex digit');
assert.strictEqual(esutils.code.isOctalDigit('7'.charCodeAt(0)), true, '7 is octal digit');
assert.strictEqual(esutils.code.isOctalDigit('8'.charCodeAt(0)), false, '8 is not octal digit');
// Whitespace and Line Terminators
assert.strictEqual(esutils.code.isWhiteSpace(' '.charCodeAt(0)), true, 'space is whitespace');
assert.strictEqual(esutils.code.isWhiteSpace('\t'.charCodeAt(0)), true, 'tab is whitespace');
assert.strictEqual(isWhitespaceChar(' '.charCodeAt(0)), true, 'helper isWhitespaceChar confirms space');
assert.strictEqual(esutils.code.isLineTerminator('\n'.charCodeAt(0)), true, 'newline is line terminator');
assert.strictEqual(esutils.code.isLineTerminator('\r'.charCodeAt(0)), true, 'carriage return is line terminator');
// Identifier start and part
assert.strictEqual(esutils.code.isIdentifierStartES6('a'.charCodeAt(0)), true, 'a can start identifier');
assert.strictEqual(esutils.code.isIdentifierStartES6('$'.charCodeAt(0)), true, '$ can start identifier');
assert.strictEqual(esutils.code.isIdentifierStartES6('_'.charCodeAt(0)), true, '_ can start identifier');
assert.strictEqual(esutils.code.isIdentifierStartES6('1'.charCodeAt(0)), false, '1 cannot start identifier');
assert.strictEqual(esutils.code.isIdentifierPartES6('1'.charCodeAt(0)), true, '1 can be identifier part');
}
// 3. ast module identifies AST node classifications including expressions, statements, and iteration statements
{
// Expressions
assert.strictEqual(esutils.ast.isExpression({ type: 'Identifier' }), true, 'Identifier is expression');
assert.strictEqual(esutils.ast.isExpression({ type: 'BinaryExpression' }), true, 'BinaryExpression is expression');
assert.strictEqual(esutils.ast.isExpression({ type: 'FunctionDeclaration' }), false, 'FunctionDeclaration is not expression');
// Statements
assert.strictEqual(esutils.ast.isStatement({ type: 'IfStatement' }), true, 'IfStatement is statement');
assert.strictEqual(esutils.ast.isStatement({ type: 'BlockStatement' }), true, 'BlockStatement is statement');
assert.strictEqual(isStatementNode({ type: 'WhileStatement' }), true, 'helper isStatementNode confirms WhileStatement');
assert.strictEqual(isStatementNode({ type: 'Literal' }), false, 'helper isStatementNode rejects Literal');
// Iteration statements
assert.strictEqual(esutils.ast.isIterationStatement({ type: 'ForStatement' }), true, 'ForStatement is iteration');
assert.strictEqual(esutils.ast.isIterationStatement({ type: 'WhileStatement' }), true, 'WhileStatement is iteration');
assert.strictEqual(esutils.ast.isIterationStatement({ type: 'DoWhileStatement' }), true, 'DoWhileStatement is iteration');
assert.strictEqual(esutils.ast.isIterationStatement({ type: 'IfStatement' }), false, 'IfStatement is not iteration');
// Source element
assert.strictEqual(esutils.ast.isSourceElement({ type: 'FunctionDeclaration' }), true, 'FunctionDeclaration is source element');
assert.strictEqual(esutils.ast.isSourceElement({ type: 'VariableDeclaration' }), true, 'VariableDeclaration is source element');
}
console.log('Contract tests passed successfully.');
原始种子者
匿名