CodeSampleX

Exemplo

json5 2.2.3: parse

Amostra verificada para npm json5 2.2.3: parse. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: JSON5.parse parses objects with unquoted…

sha256:6039f4a7fc083f610e913572d6a99a5e502e7e3db27d20c84937d77aaed4cddc

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
2
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 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-26
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

Caso

HOW
Objetivo
verify json5.parse in pkg:npm/json5@2.2.3
Pacotes
Símbolos
  • json5.parse
Ambiente
node 22.23.2
Criado
2026-08-26T10:36:28Z

Contrato

  1. JSON5.parse parses objects with unquoted keys, single-quoted keys, and trailing commas
  2. JSON5.parse ignores single-line and multi-line comments
  3. JSON5.parse parses hexadecimal numbers, leading and trailing decimals, explicit plus signs, Infinity, and NaN
  4. JSON5.parse supports single-quoted strings with line continuations and escape sequences
  5. JSON5.parse transforms parsed key-value pairs using an optional reviver function
  6. JSON5.parse throws SyntaxError on invalid JSON5 input syntax

Arquivos

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

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 json5.parse in pkg:npm/json5@2.2.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/json5@2.2.3
Demonstrate these symbols/APIs:
  - json5.parse
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:756db42df75fcec1d54bb14c682a422346cfc4bdf3b80eabace4f8ce8c92d37b","constraints":{"executionContext":"node"},"contract":["JSON5.parse parses objects with unquoted keys, single-quoted keys, and trailing commas","JSON5.parse ignores single-line and multi-line comments","JSON5.parse parses hexadecimal numbers, leading and trailing decimals, explicit plus signs, Infinity, and NaN","JSON5.parse supports single-quoted strings with line continuations and escape sequences","JSON5.parse transforms parsed key-value pairs using an optional reviver function","JSON5.parse throws SyntaxError on invalid JSON5 input syntax"],"goal":"verify json5.parse in pkg:npm/json5@2.2.3","kind":"HOW","packages":["pkg:npm/json5@2.2.3"],"schemaVersion":1,"symbols":["json5.parse"]},"contractCommand":["node","test/contract.js"],"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/json5@2.2.3"],"schemaVersion":1,"subject":"pkg:npm/json5@2.2.3","symbols":["json5.parse"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-json5-parse",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-json5-parse",
      "version": "1.0.0",
      "dependencies": {
        "json5": "2.2.3"
      }
    },
    "node_modules/json5": {
      "version": "2.2.3",
      "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
      "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
      "license": "MIT",
      "bin": {
        "json5": "lib/cli.js"
      },
      "engines": {
        "node": ">=6"
      }
    }
  }
}
package.json
{
  "name": "sample-json5-parse",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "json5": "2.2.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify json5.parse in pkg:npm/json5@2.2.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/json5@2.2.3"
  ],
  "symbols": [
    "json5.parse"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
const assert = require('node:assert/strict');
const JSON5 = require('json5');

// 1. JSON5.parse parses objects with unquoted keys, single-quoted keys, and trailing commas
{
  const json5Text = `{
    unquotedKey: 'value1',
    'singleQuotedKey': "value2",
    list: [1, 2, 3,],
  }`;
  const parsed = JSON5.parse(json5Text);
  assert.deepEqual(parsed, {
    unquotedKey: 'value1',
    singleQuotedKey: 'value2',
    list: [1, 2, 3],
  });
}

// 2. JSON5.parse ignores single-line and multi-line comments
{
  const json5Text = `// Single line comment
  {
    /* Multi-line
       comment */
    title: "JSON5 Demo", // inline comment
    count: 42, /* another comment */
  }`;
  const parsed = JSON5.parse(json5Text);
  assert.deepEqual(parsed, {
    title: 'JSON5 Demo',
    count: 42,
  });
}

// 3. JSON5.parse parses hexadecimal numbers, leading and trailing decimals, explicit plus signs, Infinity, and NaN
{
  const json5Text = `{
    hex: 0xdecaf,
    hexUpper: 0XFF,
    leadingDecimal: .5,
    trailingDecimal: 7.,
    positive: +100,
    posInfinity: Infinity,
    negInfinity: -Infinity,
    notANumber: NaN,
  }`;
  const parsed = JSON5.parse(json5Text);
  assert.equal(parsed.hex, 0xdecaf);
  assert.equal(parsed.hexUpper, 255);
  assert.equal(parsed.leadingDecimal, 0.5);
  assert.equal(parsed.trailingDecimal, 7);
  assert.equal(parsed.positive, 100);
  assert.equal(parsed.posInfinity, Infinity);
  assert.equal(parsed.negInfinity, -Infinity);
  assert.ok(Number.isNaN(parsed.notANumber));
}

// 4. JSON5.parse supports single-quoted strings with line continuations and escape sequences
{
  const json5Text = `{
    single: 'hello world',
    multiLine: 'first line\\\nsecond line',
    escaped: 'line1\\nline2',
  }`;
  const parsed = JSON5.parse(json5Text);
  assert.equal(parsed.single, 'hello world');
  assert.equal(parsed.multiLine, 'first linesecond line');
  assert.equal(parsed.escaped, 'line1\nline2');
}

// 5. JSON5.parse transforms parsed key-value pairs using an optional reviver function
{
  const json5Text = `{ count: 10, multiplier: 2 }`;
  const parsed = JSON5.parse(json5Text, (key, value) => {
    if (typeof value === 'number') {
      return value * 10;
    }
    return value;
  });
  assert.deepEqual(parsed, {
    count: 100,
    multiplier: 20,
  });
}

// 6. JSON5.parse throws SyntaxError on invalid JSON5 input syntax
{
  assert.throws(
    () => {
      JSON5.parse('{ unclosed: "string }');
    },
    (err) => err instanceof SyntaxError
  );

  assert.throws(
    () => {
      JSON5.parse('{ duplicateColon:: 1 }');
    },
    (err) => err instanceof SyntaxError
  );
}

Seeder de origem

anônimo