示例
postcss-value-parser 4.2.0: ValueParser.unit
已验证示例 — npm postcss-value-parser 4.2.0: ValueParser.unit. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: ValueParser.unit(value) parses CSS dimension…
sha256:d8af8cc6535175f520f6c60bb231ea0181c9ee616da75b41cd26d9ace8939636
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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.unit in pkg:npm/postcss-value-parser@4.2.0
- 符号
-
- ValueParser.unit
- 环境
- node 22.23.2
- 创建时间
- 2026-09-01T19:59:48Z
契约
- ValueParser.unit(value) parses CSS dimension strings into numeric value and unit suffix objects
- ValueParser.unit(value) parses numbers with leading decimal point and fractional parts
- ValueParser.unit(value) parses positive and negative signed CSS dimensions
- ValueParser.unit(value) parses scientific notation numbers with exponent indicators
- ValueParser.unit(value) returns empty string unit for unitless numeric inputs
- ValueParser.unit(value) returns false for non-numeric, keyword or unparseable input strings
- ValueParser.unit(value) returns false for empty strings
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.cjs
源代码
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.unit 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.unit
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:14bde1713e1d2b382be9345b8ff7415cc1eee7a5a7690d7808eed7a72fbd64c5","contract":["ValueParser.unit(value) parses CSS dimension strings into numeric value and unit suffix objects","ValueParser.unit(value) parses numbers with leading decimal point and fractional parts","ValueParser.unit(value) parses positive and negative signed CSS dimensions","ValueParser.unit(value) parses scientific notation numbers with exponent indicators","ValueParser.unit(value) returns empty string unit for unitless numeric inputs","ValueParser.unit(value) returns false for non-numeric, keyword or unparseable input strings","ValueParser.unit(value) returns false for empty strings"],"goal":"verify ValueParser.unit in pkg:npm/postcss-value-parser@4.2.0","kind":"HOW","packages":["pkg:npm/postcss-value-parser@4.2.0"],"schemaVersion":1,"symbols":["ValueParser.unit"]},"contractCommand":["node","test/contract.cjs"],"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/postcss-value-parser@4.2.0"],"schemaVersion":1,"subject":"pkg:npm/postcss-value-parser@4.2.0","symbols":["ValueParser.unit"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-postcss-value-parser-unit",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-postcss-value-parser-unit",
"version": "1.0.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-unit",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification for ValueParser.unit in postcss-value-parser",
"main": "src/index.js",
"dependencies": {
"postcss-value-parser": "4.2.0"
}
}
{
"schemaVersion": 1,
"goal": "verify ValueParser.unit in pkg:npm/postcss-value-parser@4.2.0",
"kind": "HOW",
"packages": [
"pkg:npm/postcss-value-parser@4.2.0"
],
"symbols": [
"ValueParser.unit"
]
}
const valueParser = require('postcss-value-parser');
/**
* Parse a CSS dimension string into its numeric component and unit.
*
* @param {string} value - The CSS value string to parse (e.g. "12px", "-0.5em", "100%").
* @returns {{ number: string, unit: string } | false} An object with number and unit strings, or false if not a number.
*/
function parseUnit(value) {
return valueParser.unit(value);
}
/**
* Check if a given CSS value has a valid numeric unit.
*
* @param {string} value - The CSS value string to check.
* @returns {boolean} True if the value can be parsed as a numeric dimension.
*/
function hasValidUnit(value) {
const result = valueParser.unit(value);
return result !== false;
}
/**
* Extract only the unit name from a CSS dimension string.
*
* @param {string} value - The CSS value string (e.g. "15rem").
* @returns {string | null} The unit suffix (e.g. "rem"), or null if parsing failed.
*/
function getUnitName(value) {
const result = valueParser.unit(value);
return result ? result.unit : null;
}
/**
* Extract only the numeric value from a CSS dimension string.
*
* @param {string} value - The CSS value string (e.g. "15rem").
* @returns {string | null} The numeric string (e.g. "15"), or null if parsing failed.
*/
function getNumericValue(value) {
const result = valueParser.unit(value);
return result ? result.number : null;
}
module.exports = {
ValueParser: valueParser,
valueParser,
parseUnit,
hasValidUnit,
getUnitName,
getNumericValue
};
const assert = require('node:assert');
const valueParser = require('postcss-value-parser');
const {
ValueParser,
parseUnit,
hasValidUnit,
getUnitName,
getNumericValue
} = require('../src/index.js');
// Verify ValueParser.unit is the static unit parser method
assert.strictEqual(typeof ValueParser.unit, 'function');
assert.strictEqual(ValueParser.unit, valueParser.unit);
// 1. ValueParser.unit(value) parses CSS dimension strings into numeric value and unit suffix objects
const pxResult = ValueParser.unit('16px');
assert.deepStrictEqual(pxResult, { number: '16', unit: 'px' });
const remResult = parseUnit('2rem');
assert.deepStrictEqual(remResult, { number: '2', unit: 'rem' });
const degResult = ValueParser.unit('180deg');
assert.deepStrictEqual(degResult, { number: '180', unit: 'deg' });
// 2. ValueParser.unit(value) parses numbers with leading decimal point and fractional parts
const leadingDotResult = ValueParser.unit('.5em');
assert.deepStrictEqual(leadingDotResult, { number: '.5', unit: 'em' });
const floatResult = parseUnit('12.75vh');
assert.deepStrictEqual(floatResult, { number: '12.75', unit: 'vh' });
// 3. ValueParser.unit(value) parses positive and negative signed CSS dimensions
const negResult = ValueParser.unit('-25%');
assert.deepStrictEqual(negResult, { number: '-25', unit: '%' });
const posResult = parseUnit('+100ms');
assert.deepStrictEqual(posResult, { number: '+100', unit: 'ms' });
const signedFloat = ValueParser.unit('-0.5fr');
assert.deepStrictEqual(signedFloat, { number: '-0.5', unit: 'fr' });
// 4. ValueParser.unit(value) parses scientific notation numbers with exponent indicators
const sciResult = ValueParser.unit('1e3s');
assert.deepStrictEqual(sciResult, { number: '1e3', unit: 's' });
const sciNegResult = ValueParser.unit('2.5e-4em');
assert.deepStrictEqual(sciNegResult, { number: '2.5e-4', unit: 'em' });
const sciPosResult = parseUnit('1.2E+2px');
assert.deepStrictEqual(sciPosResult, { number: '1.2E+2', unit: 'px' });
// 5. ValueParser.unit(value) returns empty string unit for unitless numeric inputs
const unitlessZero = ValueParser.unit('0');
assert.deepStrictEqual(unitlessZero, { number: '0', unit: '' });
const unitlessInt = parseUnit('42');
assert.deepStrictEqual(unitlessInt, { number: '42', unit: '' });
const unitlessFloat = ValueParser.unit('-3.14');
assert.deepStrictEqual(unitlessFloat, { number: '-3.14', unit: '' });
// 6. ValueParser.unit(value) returns false for non-numeric, keyword or unparseable input strings
assert.strictEqual(ValueParser.unit('auto'), false);
assert.strictEqual(ValueParser.unit('inherit'), false);
assert.strictEqual(ValueParser.unit('calc(100% - 20px)'), false);
assert.strictEqual(ValueParser.unit('var(--main-color)'), false);
assert.strictEqual(ValueParser.unit('solid'), false);
assert.strictEqual(parseUnit('none'), false);
// 7. ValueParser.unit(value) returns false for empty strings
assert.strictEqual(ValueParser.unit(''), false);
assert.strictEqual(parseUnit(''), false);
// Helper functions validation
assert.strictEqual(hasValidUnit('10px'), true);
assert.strictEqual(hasValidUnit('auto'), false);
assert.strictEqual(getUnitName('15rem'), 'rem');
assert.strictEqual(getUnitName('auto'), null);
assert.strictEqual(getNumericValue('15rem'), '15');
assert.strictEqual(getNumericValue('auto'), null);
console.log('All ValueParser.unit contract assertions passed.');
原始种子者
匿名