CodeSampleX

Exemplo

postcss-value-parser 4.2.0: ValueParser

Amostra verificada para npm postcss-value-parser 4.2.0: ValueParser. O contrato rodou em node 22 · linux debian/x64 · docker e passou: postcss-value-parser…

sha256:eb5ba6d579605ec7eb7fcc98cd4fb1f9577046eede927f794be06c08dd2f5d08

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify ValueParser in pkg:npm/postcss-value-parser@4.2.0
Pacotes
Símbolos
  • ValueParser
Ambiente
node 22.23.2
Criado
2026-09-01T19:57:52Z

Contrato

  1. postcss-value-parser package.json declares export mappings and version 4.2.0
  2. postcss-value-parser exports ValueParser constructor and factory function
  3. ValueParser parses CSS declaration values into word, space, and literal nodes with source index offsets
  4. ValueParser parses nested function invocations into function nodes with nested argument nodes
  5. ValueParser parses quoted string literals preserving quote delimiters and unescaped values
  6. ValueParser walk traverses the AST recursively and supports early branch termination
  7. ValueParser toString serializes the AST back into equivalent CSS string
  8. ValueParser.unit parses CSS numeric values and dimension units
  9. ValueParser.stringify serializes an array of AST nodes into CSS string

Arquivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  ]
}
test/contract.mjs
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.');

Seeder de origem

anônimo