CodeSampleX

Exemple

json-parse-even-better-errors 2.3.1: json-parse-even-better-errors

Échantillon vérifié pour npm json-parse-even-better-errors 2.3.1: json-parse-even-better-errors. Le contrat s'est exécuté sur node 22 · linux alpine/x64 …

sha256:321bab7a077194d29e97b67c21b593a9a5ac6ad814791d866a1550b083fd765d

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify json-parse-even-better-errors in pkg:npm/json-parse-even-better-errors@2.3.1
Paquets
Symboles
  • json-parse-even-better-errors
Environnement
node 22.23.2
Créé
2026-08-26T01:01:39Z

Contrat

  1. parseJson parses valid JSON text into JavaScript values
  2. parseJson transforms parsed values when given a custom reviver function
  3. parseJson strips leading UTF-8 byte-order mark before parsing
  4. parseJson attaches indentation and newline metadata symbols to objects and arrays
  5. parseJson throws JSONParseError subclassing SyntaxError on invalid JSON
  6. parseJson formats error message with context snippet when parsing truncated JSON
  7. parseJson.noExceptions returns undefined for invalid JSON and parsed value for valid JSON
  8. parseJson throws TypeError with code EJSONPARSE for non-string non-buffer input that cannot be parsed

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 json-parse-even-better-errors in pkg:npm/json-parse-even-better-errors@2.3.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/json-parse-even-better-errors@2.3.1
Demonstrate these symbols/APIs:
  - json-parse-even-better-errors
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:9e45757a47232634b37b236cc7b2207596a229f58b572edb3a5fcd3cf843b5c9","constraints":{"executionContext":"node"},"contract":["parseJson parses valid JSON text into JavaScript values","parseJson transforms parsed values when given a custom reviver function","parseJson strips leading UTF-8 byte-order mark before parsing","parseJson attaches indentation and newline metadata symbols to objects and arrays","parseJson throws JSONParseError subclassing SyntaxError on invalid JSON","parseJson formats error message with context snippet when parsing truncated JSON","parseJson.noExceptions returns undefined for invalid JSON and parsed value for valid JSON","parseJson throws TypeError with code EJSONPARSE for non-string non-buffer input that cannot be parsed"],"goal":"verify json-parse-even-better-errors in pkg:npm/json-parse-even-better-errors@2.3.1","kind":"HOW","packages":["pkg:npm/json-parse-even-better-errors@2.3.1"],"schemaVersion":1,"symbols":["json-parse-even-better-errors"]},"contractCommand":["node","test/contract.mjs"],"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/json-parse-even-better-errors@2.3.1"],"schemaVersion":1,"subject":"pkg:npm/json-parse-even-better-errors@2.3.1","symbols":["json-parse-even-better-errors"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-json-parse-even-better-errors",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-json-parse-even-better-errors",
      "version": "1.0.0",
      "dependencies": {
        "json-parse-even-better-errors": "2.3.1"
      }
    },
    "node_modules/json-parse-even-better-errors": {
      "version": "2.3.1",
      "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",
      "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-json-parse-even-better-errors",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "json-parse-even-better-errors": "2.3.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify json-parse-even-better-errors in pkg:npm/json-parse-even-better-errors@2.3.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/json-parse-even-better-errors@2.3.1"
  ],
  "symbols": [
    "json-parse-even-better-errors"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import parseJson from 'json-parse-even-better-errors';
import assert from 'node:assert/strict';

// 1. parseJson parses valid JSON text into JavaScript values
{
  const obj = parseJson('{"name": "csx", "count": 42}');
  assert.equal(obj.name, 'csx');
  assert.equal(obj.count, 42);

  const num = parseJson('12345');
  assert.equal(num, 12345);

  const arr = parseJson('["a", "b", "c"]');
  assert.equal(arr[0], 'a');
  assert.equal(arr[1], 'b');
  assert.equal(arr[2], 'c');
  assert.equal(arr.length, 3);
}

// 2. parseJson transforms parsed values when given a custom reviver function
{
  const revived = parseJson('{"count": 21, "name": "csx"}', (key, value) => {
    if (typeof value === 'number') {
      return value * 2;
    }
    return value;
  });
  assert.equal(revived.count, 42);
  assert.equal(revived.name, 'csx');
}

// 3. parseJson strips leading UTF-8 byte-order mark before parsing
{
  const withBOM = '\uFEFF{"status": "ok"}';
  const parsed = parseJson(withBOM);
  assert.equal(parsed.status, 'ok');
}

// 4. parseJson attaches indentation and newline metadata symbols to objects and arrays
{
  const jsonText = '{\r\n    "foo": "bar"\r\n}';
  const data = parseJson(jsonText);
  const kIndent = Symbol.for('indent');
  const kNewline = Symbol.for('newline');

  assert.equal(data[kIndent], '    ');
  assert.equal(data[kNewline], '\r\n');

  const defaultArray = parseJson('[]');
  assert.equal(defaultArray[kIndent], '  ');
  assert.equal(defaultArray[kNewline], '\n');
}

// 5. parseJson throws JSONParseError subclassing SyntaxError on invalid JSON
{
  const invalidJson = '{\n  "name": "csx",\n}';
  assert.throws(
    () => {
      parseJson(invalidJson);
    },
    (err) => {
      assert.ok(err instanceof parseJson.JSONParseError);
      assert.ok(err instanceof SyntaxError);
      assert.equal(err.name, 'JSONParseError');
      assert.equal(err.code, 'EJSONPARSE');
      assert.equal(typeof err.position, 'number');
      assert.ok(err.systemError instanceof SyntaxError);
      assert.match(err.message, /while parsing/);
      return true;
    }
  );
}

// 6. parseJson formats error message with context snippet when parsing truncated JSON
{
  assert.throws(
    () => {
      parseJson('{"foo": "bar", "incomplete": ' , null, 5);
    },
    (err) => {
      assert.ok(err instanceof parseJson.JSONParseError);
      assert.equal(err.position, 28);
      assert.match(err.message, /while parsing near/);
      return true;
    }
  );
}

// 7. parseJson.noExceptions returns undefined for invalid JSON and parsed value for valid JSON
{
  const valid = parseJson.noExceptions('{"valid": true}');
  assert.equal(valid.valid, true);

  const invalid = parseJson.noExceptions('{ invalid json }');
  assert.equal(invalid, undefined);
}

// 8. parseJson throws TypeError with code EJSONPARSE for non-string non-buffer input that cannot be parsed
{
  assert.throws(
    () => {
      parseJson({});
    },
    (err) => {
      assert.ok(err instanceof TypeError);
      assert.equal(err.code, 'EJSONPARSE');
      assert.match(err.message, /Cannot parse/);
      return true;
    }
  );

  assert.throws(
    () => {
      parseJson(undefined);
    },
    (err) => {
      assert.ok(err instanceof TypeError);
      assert.equal(err.code, 'EJSONPARSE');
      assert.match(err.message, /Cannot parse undefined/);
      return true;
    }
  );
}

Seeder d'origine

anonyme