CodeSampleX

Exemple

pretty-format 29.7.0: format

Échantillon vérifié pour npm pretty-format 29.7.0: format. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:79c9aa153f2d26cf9319dff72ca12d9859d5ee4e394e31402087ccf7e7425fbf

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
1
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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-02

Cas

HOW
Objectif
verify format in pkg:npm/pretty-format@29.7.0
Paquets
Symboles
  • format
Environnement
node 22.23.2
Créé
2026-09-02T00:50:57Z

Contrat

  1. format serializes primitive values including strings, numbers, booleans, symbols, and BigInt
  2. format serializes plain objects and nested arrays with standard indentation
  3. format serializes Set and Map collections with entry representations
  4. format detects circular references and marks recursive pointers as Circular
  5. format respects maxDepth option by truncating objects beyond depth limit
  6. format min option outputs compact single-line representation
  7. format indent option controls spaces per indentation level
  8. format printFunctionName option controls whether function names are printed
  9. format supports custom plugins implementing test and serialize hooks
  10. format serializes Date, RegExp, and Error objects accurately

Fichiers

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

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 format in pkg:npm/pretty-format@29.7.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/pretty-format@29.7.0
Demonstrate these symbols/APIs:
  - format
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:b2a8c1f6094dd8b3e024160eb689057d1d3d9fcc9781a8646f368486e957b426","constraints":{"executionContext":"node"},"contract":["format serializes primitive values including strings, numbers, booleans, symbols, and BigInt","format serializes plain objects and nested arrays with standard indentation","format serializes Set and Map collections with entry representations","format detects circular references and marks recursive pointers as Circular","format respects maxDepth option by truncating objects beyond depth limit","format min option outputs compact single-line representation","format indent option controls spaces per indentation level","format printFunctionName option controls whether function names are printed","format supports custom plugins implementing test and serialize hooks","format serializes Date, RegExp, and Error objects accurately"],"goal":"verify format in pkg:npm/pretty-format@29.7.0","kind":"HOW","packages":["pkg:npm/pretty-format@29.7.0"],"schemaVersion":1,"symbols":["format"]},"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/pretty-format@29.7.0"],"schemaVersion":1,"subject":"pkg:npm/pretty-format@29.7.0","symbols":["format"],"verifierAdapter":"node-typescript@1"}
index.js
const { format, plugins, DEFAULT_OPTIONS } = require('pretty-format');

function formatWithCustomPlugin(value, plugin) {
  return format(value, { plugins: [plugin] });
}

function formatMinified(value) {
  return format(value, { min: true });
}

module.exports = {
  format,
  plugins,
  DEFAULT_OPTIONS,
  formatWithCustomPlugin,
  formatMinified,
};
package-lock.json
{
  "name": "sample-pretty-format",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-pretty-format",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "pretty-format": "29.7.0"
      }
    },
    "node_modules/@jest/schemas": {
      "version": "29.6.3",
      "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz",
      "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==",
      "license": "MIT",
      "dependencies": {
        "@sinclair/typebox": "^0.27.8"
      },
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    },
    "node_modules/@sinclair/typebox": {
      "version": "0.27.12",
      "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.12.tgz",
      "integrity": "sha512-hhyNJ+nbR6ZR7pToHvllEFun9TL0sbL+tk/ON75lo+Xas054uez98qRbsuNt7MBCyZKK4+8Yli/OAGZhmfBZ/g==",
      "license": "MIT"
    },
    "node_modules/ansi-styles": {
      "version": "5.2.0",
      "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
      "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
      "license": "MIT",
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-styles?sponsor=1"
      }
    },
    "node_modules/pretty-format": {
      "version": "29.7.0",
      "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz",
      "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==",
      "license": "MIT",
      "dependencies": {
        "@jest/schemas": "^29.6.3",
        "ansi-styles": "^5.0.0",
        "react-is": "^18.0.0"
      },
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    },
    "node_modules/react-is": {
      "version": "18.3.1",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz",
      "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-pretty-format",
  "version": "1.0.0",
  "description": "Clean-room verification sample for pretty-format",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "pretty-format": "29.7.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify format in pkg:npm/pretty-format@29.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pretty-format@29.7.0"
  ],
  "symbols": [
    "format"
  ],
  "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 { format, plugins, DEFAULT_OPTIONS } = require('pretty-format');
const { formatWithCustomPlugin, formatMinified } = require('../index.js');

// 1. format serializes primitive values including strings, numbers, booleans, symbols, and BigInt
{
  assert.equal(format('hello world'), '"hello world"');
  assert.equal(format(42), '42');
  assert.equal(format(true), 'true');
  assert.equal(format(null), 'null');
  assert.equal(format(undefined), 'undefined');
  assert.equal(format(Symbol('testKey')), 'Symbol(testKey)');
  assert.equal(format(12345678901234567890n), '12345678901234567890n');
}

// 2. format serializes plain objects and nested arrays with standard indentation
{
  const obj = {
    str: 'value',
    num: 10,
    list: [1, 2],
  };
  const expected = [
    'Object {',
    '  "list": Array [',
    '    1,',
    '    2,',
    '  ],',
    '  "num": 10,',
    '  "str": "value",',
    '}',
  ].join('\n');
  assert.equal(format(obj), expected);
}

// 3. format serializes Set and Map collections with entry representations
{
  const set = new Set(['alpha', 'beta']);
  const setFormatted = format(set);
  assert.ok(setFormatted.includes('Set {'));
  assert.ok(setFormatted.includes('"alpha",'));
  assert.ok(setFormatted.includes('"beta",'));

  const map = new Map([['k1', 'v1'], ['k2', 'v2']]);
  const mapFormatted = format(map);
  assert.ok(mapFormatted.includes('Map {'));
  assert.ok(mapFormatted.includes('"k1" => "v1",'));
  assert.ok(mapFormatted.includes('"k2" => "v2",'));
}

// 4. format detects circular references and marks recursive pointers as Circular
{
  const circular = { name: 'root' };
  circular.self = circular;
  const result = format(circular);
  assert.ok(result.includes('"self": [Circular]'));
}

// 5. format respects maxDepth option by truncating objects beyond depth limit
{
  const deeplyNested = {
    level1: {
      level2: {
        level3: 'deep',
      },
    },
  };
  const shallow = format(deeplyNested, { maxDepth: 1 });
  assert.ok(shallow.includes('"level1": [Object]'));
  assert.ok(!shallow.includes('level3'));
}

// 6. format min option outputs compact single-line representation
{
  const data = { a: 1, b: 'two' };
  const minified = format(data, { min: true });
  assert.equal(minified, '{"a": 1, "b": "two"}');
  assert.equal(formatMinified(data), '{"a": 1, "b": "two"}');
}

// 7. format indent option controls spaces per indentation level
{
  const data = { x: 1 };
  const formatted4 = format(data, { indent: 4 });
  const expected4 = 'Object {\n    "x": 1,\n}';
  assert.equal(formatted4, expected4);
}

// 8. format printFunctionName option controls whether function names are printed
{
  function sampleFunction() {}
  assert.equal(format(sampleFunction, { printFunctionName: true }), '[Function sampleFunction]');
  assert.equal(format(sampleFunction, { printFunctionName: false }), '[Function]');
}

// 9. format supports custom plugins implementing test and serialize hooks
{
  const customPlugin = {
    test(val) {
      return val && typeof val === 'object' && val.__brand === 'Currency';
    },
    serialize(val, config, indentation, depth, refs, printer) {
      return `${val.currency} ${val.amount.toFixed(2)}`;
    },
  };

  const payload = {
    price: { __brand: 'Currency', currency: 'USD', amount: 49.99 },
  };
  const result = format(payload, { plugins: [customPlugin] });
  assert.ok(result.includes('"price": USD 49.99'));

  const resultHelper = formatWithCustomPlugin(payload, customPlugin);
  assert.ok(resultHelper.includes('"price": USD 49.99'));
}

// 10. format serializes Date, RegExp, and Error objects accurately
{
  const dt = new Date('2026-01-01T00:00:00.000Z');
  assert.equal(format(dt), '2026-01-01T00:00:00.000Z');

  const rgx = /test-pattern/gi;
  assert.equal(format(rgx), '/test-pattern/gi');

  const err = new Error('something went wrong');
  assert.ok(format(err).includes('[Error: something went wrong]'));
}

console.log('All pretty-format contract assertions passed.');

Seeder d'origine

anonyme