示例
postcss-value-parser 4.2.0: ValueParser
已验证示例 — npm postcss-value-parser 4.2.0: ValueParser. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: postcss-value-parser package.json declares export…
sha256:eb5ba6d579605ec7eb7fcc98cd4fb1f9577046eede927f794be06c08dd2f5d08
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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-01 |
案例
HOW- 目标
- verify ValueParser in pkg:npm/postcss-value-parser@4.2.0
- 符号
-
- ValueParser
- 环境
- node 22.23.2
- 创建时间
- 2026-09-01T19:57:52Z
契约
- postcss-value-parser package.json declares export mappings and version 4.2.0
- postcss-value-parser exports ValueParser constructor and factory function
- ValueParser parses CSS declaration values into word, space, and literal nodes with source index offsets
- ValueParser parses nested function invocations into function nodes with nested argument nodes
- ValueParser parses quoted string literals preserving quote delimiters and unescaped values
- ValueParser walk traverses the AST recursively and supports early branch termination
- ValueParser toString serializes the AST back into equivalent CSS string
- ValueParser.unit parses CSS numeric values and dimension units
- ValueParser.stringify serializes an array of AST nodes into CSS string
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- 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 ValueParser in pkg:npm/postcss-value-parser@4.2.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/postcss-value-parser@4.2.0
Demonstrate these symbols/APIs:
- ValueParser
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:f50a82768bae3087ee9ccdc884509e4c21095f09b0df9f8a63c85e1d311702cc","contract":["postcss-value-parser package.json declares export mappings and version 4.2.0","postcss-value-parser exports ValueParser constructor and factory function","ValueParser parses CSS declaration values into word, space, and literal nodes with source index offsets","ValueParser parses nested function invocations into function nodes with nested argument nodes","ValueParser parses quoted string literals preserving quote delimiters and unescaped values","ValueParser walk traverses the AST recursively and supports early branch termination","ValueParser toString serializes the AST back into equivalent CSS string","ValueParser.unit parses CSS numeric values and dimension units","ValueParser.stringify serializes an array of AST nodes into CSS string"],"goal":"verify ValueParser in pkg:npm/postcss-value-parser@4.2.0","kind":"HOW","packages":["pkg:npm/postcss-value-parser@4.2.0"],"schemaVersion":1,"symbols":["ValueParser"]},"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/postcss-value-parser@4.2.0"],"schemaVersion":1,"subject":"pkg:npm/postcss-value-parser@4.2.0","symbols":["ValueParser"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-postcss-value-parser-value-parser",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-postcss-value-parser-value-parser",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"postcss-value-parser": "4.2.0"
}
},
"node_modules/postcss-value-parser": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==",
"license": "MIT"
}
}
}
{
"name": "sample-postcss-value-parser-value-parser",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"dependencies": {
"postcss-value-parser": "4.2.0"
}
}
{
"schemaVersion": 1,
"goal": "verify ValueParser in pkg:npm/postcss-value-parser@4.2.0",
"kind": "HOW",
"packages": [
"pkg:npm/postcss-value-parser@4.2.0"
],
"symbols": [
"ValueParser"
]
}
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { createRequire } from 'node:module';
import ValueParser from 'postcss-value-parser';
const require = createRequire(import.meta.url);
// Contract 1: postcss-value-parser package.json declares export mappings and version 4.2.0
{
const pkgJsonPath = require.resolve('postcss-value-parser/package.json');
assert.ok(fs.existsSync(pkgJsonPath));
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
assert.strictEqual(pkgJson.name, 'postcss-value-parser');
assert.strictEqual(pkgJson.version, '4.2.0');
assert.ok(pkgJson.main);
}
// Contract 2: postcss-value-parser exports ValueParser constructor and factory function
{
assert.strictEqual(typeof ValueParser, 'function');
const instance = new ValueParser('10px');
assert.ok(instance instanceof ValueParser);
const called = ValueParser('10px');
assert.ok(called instanceof ValueParser);
}
// Contract 3: ValueParser parses CSS declaration values into word, space, and literal nodes with source index offsets
{
const parsed = ValueParser('10px solid #333');
assert.ok(Array.isArray(parsed.nodes));
assert.strictEqual(parsed.nodes.length, 5);
assert.deepStrictEqual(parsed.nodes[0], {
type: 'word',
sourceIndex: 0,
sourceEndIndex: 4,
value: '10px'
});
assert.deepStrictEqual(parsed.nodes[1], {
type: 'space',
sourceIndex: 4,
sourceEndIndex: 5,
value: ' '
});
assert.deepStrictEqual(parsed.nodes[2], {
type: 'word',
sourceIndex: 5,
sourceEndIndex: 10,
value: 'solid'
});
assert.deepStrictEqual(parsed.nodes[3], {
type: 'space',
sourceIndex: 10,
sourceEndIndex: 11,
value: ' '
});
assert.deepStrictEqual(parsed.nodes[4], {
type: 'word',
sourceIndex: 11,
sourceEndIndex: 15,
value: '#333'
});
}
// Contract 4: ValueParser parses nested function invocations into function nodes with nested argument nodes
{
const parsed = ValueParser('calc(100% - 20px)');
assert.strictEqual(parsed.nodes.length, 1);
const fnNode = parsed.nodes[0];
assert.strictEqual(fnNode.type, 'function');
assert.strictEqual(fnNode.value, 'calc');
assert.strictEqual(fnNode.sourceIndex, 0);
assert.strictEqual(fnNode.sourceEndIndex, 17);
assert.strictEqual(fnNode.before, '');
assert.strictEqual(fnNode.after, '');
assert.ok(Array.isArray(fnNode.nodes));
assert.strictEqual(fnNode.nodes.length, 5);
assert.strictEqual(fnNode.nodes[0].type, 'word');
assert.strictEqual(fnNode.nodes[0].value, '100%');
assert.strictEqual(fnNode.nodes[0].sourceIndex, 5);
assert.strictEqual(fnNode.nodes[0].sourceEndIndex, 9);
assert.strictEqual(fnNode.nodes[2].type, 'word');
assert.strictEqual(fnNode.nodes[2].value, '-');
assert.strictEqual(fnNode.nodes[4].type, 'word');
assert.strictEqual(fnNode.nodes[4].value, '20px');
}
// Contract 5: ValueParser parses quoted string literals preserving quote delimiters and unescaped values
{
const parsed = ValueParser('url("image.png") \'Helvetica Neue\'');
const urlFn = parsed.nodes[0];
assert.strictEqual(urlFn.type, 'function');
assert.strictEqual(urlFn.value, 'url');
assert.strictEqual(urlFn.nodes[0].type, 'string');
assert.strictEqual(urlFn.nodes[0].value, 'image.png');
assert.strictEqual(urlFn.nodes[0].quote, '"');
assert.strictEqual(urlFn.nodes[0].sourceIndex, 4);
assert.strictEqual(urlFn.nodes[0].sourceEndIndex, 15);
const quotedFont = parsed.nodes[2];
assert.strictEqual(quotedFont.type, 'string');
assert.strictEqual(quotedFont.value, 'Helvetica Neue');
assert.strictEqual(quotedFont.quote, "'");
assert.strictEqual(quotedFont.sourceIndex, 17);
assert.strictEqual(quotedFont.sourceEndIndex, 33);
}
// Contract 6: ValueParser walk traverses the AST recursively and supports early branch termination
{
const parsed = ValueParser('rgba(255, 0, 0, 0.5) 10px');
const visited = [];
parsed.walk((node) => {
visited.push(node.value);
});
assert.ok(visited.includes('rgba'));
assert.ok(visited.includes('255'));
assert.ok(visited.includes('10px'));
const stopped = [];
parsed.walk((node) => {
stopped.push(node.value);
if (node.type === 'function') {
return false; // Skip walking inside the function
}
});
assert.ok(stopped.includes('rgba'));
assert.ok(!stopped.includes('255'));
assert.ok(stopped.includes('10px'));
}
// Contract 7: ValueParser toString serializes the AST back into equivalent CSS string
{
const input = 'linear-gradient(to right, red, blue)';
const parsed = ValueParser(input);
assert.strictEqual(parsed.toString(), input);
parsed.nodes[0].nodes[2].value = 'bottom';
assert.strictEqual(parsed.toString(), 'linear-gradient(to bottom, red, blue)');
}
// Contract 8: ValueParser.unit parses CSS numeric values and dimension units
{
assert.strictEqual(typeof ValueParser.unit, 'function');
assert.deepStrictEqual(ValueParser.unit('12.5px'), {
number: '12.5',
unit: 'px'
});
assert.deepStrictEqual(ValueParser.unit('-4rem'), {
number: '-4',
unit: 'rem'
});
assert.deepStrictEqual(ValueParser.unit('100%'), {
number: '100',
unit: '%'
});
assert.deepStrictEqual(ValueParser.unit('42'), {
number: '42',
unit: ''
});
assert.strictEqual(ValueParser.unit('auto'), false);
assert.strictEqual(ValueParser.unit(''), false);
}
// Contract 9: ValueParser.stringify serializes an array of AST nodes into CSS string
{
assert.strictEqual(typeof ValueParser.stringify, 'function');
const nodes = [
{ type: 'word', value: '1px' },
{ type: 'space', value: ' ' },
{ type: 'word', value: 'solid' },
{ type: 'space', value: ' ' },
{ type: 'word', value: 'black' }
];
assert.strictEqual(ValueParser.stringify(nodes), '1px solid black');
}
console.log('All postcss-value-parser ValueParser contract tests passed.');
原始种子者
匿名