CodeSampleX

Beispiel

postcss-value-parser 4.2.0: ValueParser.unit

Verifiziertes Beispiel für npm postcss-value-parser 4.2.0: ValueParser.unit. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand…

sha256:d8af8cc6535175f520f6c60bb231ea0181c9ee616da75b41cd26d9ace8939636

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify ValueParser.unit in pkg:npm/postcss-value-parser@4.2.0
Pakete
Symbole
  • ValueParser.unit
Umgebung
node 22.23.2
Erstellt
2026-09-01T19:59:48Z

Contract

  1. ValueParser.unit(value) parses CSS dimension strings into numeric value and unit suffix objects
  2. ValueParser.unit(value) parses numbers with leading decimal point and fractional parts
  3. ValueParser.unit(value) parses positive and negative signed CSS dimensions
  4. ValueParser.unit(value) parses scientific notation numbers with exponent indicators
  5. ValueParser.unit(value) returns empty string unit for unitless numeric inputs
  6. ValueParser.unit(value) returns false for non-numeric, keyword or unparseable input strings
  7. ValueParser.unit(value) returns false for empty strings

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.cjs

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  ]
}
src/index.js
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
};
test/contract.cjs
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.');

Ursprungs-Seeder

anonym