CodeSampleX

Пример

pretty-format 27.5.1: format

Проверенный пример — npm pretty-format 27.5.1: format. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: format formats primitives and…

sha256:75915dd9e63ee3984613374bdd7fe31f1687941b94569c016ed07be3a7991b44

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-04

Кейс

HOW
Цель
verify pretty-format.format in pkg:npm/pretty-format@27.5.1
Пакеты
Символы
  • pretty-format.format
Создан
2026-09-04T09:21:37Z

Контракт

  1. format formats primitives and nested objects into readable strings
  2. format supports custom indentation width via indent option
  3. format detects and handles circular references with [Circular]
  4. format truncates nested structure traversal with maxDepth option
  5. format formats compactly without newlines when min option is true
  6. format supports custom serialization via plugins option

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

.npmrc
audit=false
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 pretty-format.format in pkg:npm/pretty-format@27.5.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/pretty-format@27.5.1
Demonstrate these symbols/APIs:
  - pretty-format.format

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:8f60413dceaa59e3075e27c6bd22f18c7c81fc8ba0acd2589905f3c3dfb64180","contract":["format formats primitives and nested objects into readable strings","format supports custom indentation width via indent option","format detects and handles circular references with [Circular]","format truncates nested structure traversal with maxDepth option","format formats compactly without newlines when min option is true","format supports custom serialization via plugins option"],"goal":"verify pretty-format.format in pkg:npm/pretty-format@27.5.1","kind":"HOW","packages":["pkg:npm/pretty-format@27.5.1"],"schemaVersion":1,"symbols":["pretty-format.format"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/pretty-format@27.5.1"],"schemaVersion":1,"subject":"pkg:npm/pretty-format@27.5.1","symbols":["pretty-format.format"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-pretty-format",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-pretty-format",
      "version": "1.0.0",
      "dependencies": {
        "pretty-format": "27.5.1"
      }
    },
    "node_modules/ansi-regex": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
      "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "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": "27.5.1",
      "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz",
      "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==",
      "license": "MIT",
      "dependencies": {
        "ansi-regex": "^5.0.1",
        "ansi-styles": "^5.0.0",
        "react-is": "^17.0.1"
      },
      "engines": {
        "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"
      }
    },
    "node_modules/react-is": {
      "version": "17.0.2",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
      "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-pretty-format",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of pretty-format.format",
  "main": "src/index.js",
  "dependencies": {
    "pretty-format": "27.5.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pretty-format.format in pkg:npm/pretty-format@27.5.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pretty-format@27.5.1"
  ],
  "symbols": [
    "pretty-format.format"
  ]
}
src/index.js
const { format } = require('pretty-format');

function formatData(value, options = {}) {
  return format(value, options);
}

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

function formatWithMaxDepth(value, maxDepth = 2) {
  return format(value, { maxDepth });
}

module.exports = {
  format,
  formatData,
  formatCompact,
  formatWithMaxDepth
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { format, formatData, formatCompact, formatWithMaxDepth } = require('../src/index.js');

// 1. Basic formatting for primitives and nested objects
const basicObj = { name: 'sample', count: 42, active: true, list: [1, 2] };
const basicFormatted = format(basicObj);
assert.strictEqual(typeof basicFormatted, 'string', 'format should return a string');
assert.match(basicFormatted, /"name": "sample"/, 'format should include key-value pairs');
assert.match(basicFormatted, /"count": 42/, 'format should format numbers');
assert.match(basicFormatted, /Array \[/, 'format should format arrays');

// 2. Custom indentation
const customIndentFormatted = format({ key: 'val' }, { indent: 4 });
assert.match(customIndentFormatted, /^ {4}"key": "val"/m, 'format should respect 4-space indentation');

// 3. Circular reference handling
const circularObj = { title: 'node' };
circularObj.self = circularObj;
const circularFormatted = format(circularObj);
assert.match(circularFormatted, /\[Circular\]/, 'format should handle circular references');

// 4. maxDepth option
const deeplyNested = { a: { b: { c: { d: 'deep' } } } };
const depthFormatted = formatWithMaxDepth(deeplyNested, 2);
assert.match(depthFormatted, /"b": \[Object\]/, 'format should truncate beyond maxDepth');

// 5. Min option (compact)
const compactFormatted = formatCompact({ a: 1, b: 2 });
assert.strictEqual(compactFormatted, '{"a": 1, "b": 2}', 'format should format compactly on single line');

// 6. Custom plugin
const customPlugin = {
  test: (val) => val && val.__customType === 'UserToken',
  serialize: (val) => `Token(${val.id})`
};
const pluginFormatted = format({ user: { __customType: 'UserToken', id: '12345' } }, { plugins: [customPlugin] });
assert.match(pluginFormatted, /Token\(12345\)/, 'format should apply custom plugins');

console.log('Contract tests passed successfully.');

Исходный сидер

аноним