CodeSampleX

Beispiel

json5 2.2.3: stringify

Verifiziertes Beispiel für npm json5 2.2.3: stringify. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: JSON5.stringify serializes…

sha256:d2a66a5d96c44ee11caea29dd63eb18824e7271be4e10e713301a1a345d77e4a

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

Fall

HOW
Ziel
verify json5.stringify in pkg:npm/json5@2.2.3
Pakete
Symbole
  • json5.stringify
Umgebung
node 22.23.2
Erstellt
2026-08-26T10:38:45Z

Contract

  1. JSON5.stringify serializes objects with unquoted identifier keys
  2. JSON5.stringify preserves Infinity, -Infinity, and NaN as literal identifiers
  3. JSON5.stringify formats output with custom indentation and trailing commas in objects and arrays
  4. JSON5.stringify filters and transforms properties using a replacer function or replacer array
  5. JSON5.stringify serializes objects implementing a custom toJSON method
  6. JSON5.stringify formats objects using options object specifying space and quote
  7. JSON5.stringify returns undefined for unsupported top-level types

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • 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 json5.stringify 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.stringify
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:24e37aaafff7ef177083329d9742a7d4ac114e275cc2468caffd552a74233507","constraints":{"executionContext":"node"},"contract":["JSON5.stringify serializes objects with unquoted identifier keys","JSON5.stringify preserves Infinity, -Infinity, and NaN as literal identifiers","JSON5.stringify formats output with custom indentation and trailing commas in objects and arrays","JSON5.stringify filters and transforms properties using a replacer function or replacer array","JSON5.stringify serializes objects implementing a custom toJSON method","JSON5.stringify formats objects using options object specifying space and quote","JSON5.stringify returns undefined for unsupported top-level types"],"goal":"verify json5.stringify in pkg:npm/json5@2.2.3","kind":"HOW","packages":["pkg:npm/json5@2.2.3"],"schemaVersion":1,"symbols":["json5.stringify"]},"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/json5@2.2.3"],"schemaVersion":1,"subject":"pkg:npm/json5@2.2.3","symbols":["json5.stringify"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-json5-stringify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-json5-stringify",
      "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-stringify",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "json5": "2.2.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify json5.stringify in pkg:npm/json5@2.2.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/json5@2.2.3"
  ],
  "symbols": [
    "json5.stringify"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require('node:assert/strict');
const JSON5 = require('json5');

// 1. JSON5.stringify serializes objects with unquoted identifier keys
{
  const input = {
    standardKey: 'hello',
    'special-key': 'world',
    _underscoreKey: 123,
    $dollarKey: true,
  };
  const result = JSON5.stringify(input);
  assert.ok(result.includes('standardKey:'));
  assert.ok(result.includes('_underscoreKey:'));
  assert.ok(result.includes('$dollarKey:'));
  assert.ok(result.includes('"special-key":') || result.includes("'special-key':"));
  assert.deepEqual(JSON5.parse(result), input);
}

// 2. JSON5.stringify preserves Infinity, -Infinity, and NaN as literal identifiers
{
  const numbers = {
    posInf: Infinity,
    negInf: -Infinity,
    notANumber: NaN,
  };
  const result = JSON5.stringify(numbers);
  assert.ok(result.includes('posInf:Infinity'));
  assert.ok(result.includes('negInf:-Infinity'));
  assert.ok(result.includes('notANumber:NaN'));

  const parsed = JSON5.parse(result);
  assert.equal(parsed.posInf, Infinity);
  assert.equal(parsed.negInf, -Infinity);
  assert.ok(Number.isNaN(parsed.notANumber));
}

// 3. JSON5.stringify formats output with custom indentation and trailing commas in objects and arrays
{
  const data = {
    items: [1, 2],
    nested: { active: true },
  };
  const formatted = JSON5.stringify(data, null, 2);
  assert.ok(formatted.includes('{\n  items: [\n    1,\n    2,\n  ],\n  nested: {\n    active: true,\n  },\n}'));
  assert.deepEqual(JSON5.parse(formatted), data);
}

// 4. JSON5.stringify filters and transforms properties using a replacer function or replacer array
{
  const obj = { id: 1, name: 'alpha', secret: 'hide', count: 5 };

  // Array replacer whitelist
  const arrayReplacerResult = JSON5.stringify(obj, ['id', 'name']);
  assert.deepEqual(JSON5.parse(arrayReplacerResult), { id: 1, name: 'alpha' });

  // Function replacer transform
  const funcReplacerResult = JSON5.stringify(obj, (key, value) => {
    if (key === 'secret') return undefined;
    if (typeof value === 'number') return value * 10;
    return value;
  });
  assert.deepEqual(JSON5.parse(funcReplacerResult), { id: 10, name: 'alpha', count: 50 });
}

// 5. JSON5.stringify serializes objects implementing a custom toJSON method
{
  const customObj = {
    data: 'raw',
    toJSON() {
      return { serialized: 'custom_output' };
    },
  };
  const result = JSON5.stringify(customObj);
  assert.deepEqual(JSON5.parse(result), { serialized: 'custom_output' });
}

// 6. JSON5.stringify formats objects using options object specifying space and quote
{
  const obj = { message: 'hello "world"' };
  const singleQuoted = JSON5.stringify(obj, { quote: "'" });
  assert.ok(singleQuoted.includes("message:'hello \"world\"'"));
  assert.deepEqual(JSON5.parse(singleQuoted), obj);

  const doubleQuoted = JSON5.stringify(obj, { quote: '"' });
  assert.ok(doubleQuoted.includes('message:"hello \\"world\\""'));
  assert.deepEqual(JSON5.parse(doubleQuoted), obj);
}

// 7. JSON5.stringify returns undefined for unsupported top-level types
{
  assert.equal(JSON5.stringify(undefined), undefined);
  assert.equal(JSON5.stringify(() => {}), undefined);
  assert.equal(JSON5.stringify(Symbol('test')), undefined);
}

Ursprungs-Seeder

anonym