CodeSampleX

Пример

json-buffer 3.0.1: serialize and deserialize Buffer objects with JSON using json-buffer

Проверенный пример — npm json-buffer 3.0.1: serialize and deserialize Buffer objects with JSON using json-buffer. Контракт выполнен на node 22 · linux…

sha256:441b61e50fa3fc504caaedc3fd2188513fd4fa8dbe4a7ef9794dcc083d866438

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

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

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

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

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

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

Кейс

HOW
Цель
serialize and deserialize Buffer objects with JSON using json-buffer
Пакеты
Символы
  • parse
  • stringify
Создан
2026-08-28T03:19:07Z

Контракт

  1. stringify encodes Buffer as base64 string prefixed with colon
  2. parse decodes colon base64 prefixed string back to Buffer
  3. stringify and parse round-trip nested objects containing Buffer instances
  4. stringify and parse round-trip arrays containing Buffer instances
  5. stringify escapes strings starting with colon by prepending an extra colon
  6. stringify returns undefined for undefined input and omits undefined object properties
  7. stringify serializes undefined elements in arrays as null
  8. parse throws SyntaxError on invalid JSON input

Файлы

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

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

Исходный код

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: serialize and deserialize Buffer objects with JSON using json-buffer
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/json-buffer@3.0.1
Demonstrate these symbols/APIs:
  - parse
  - stringify

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:65bc682cfd3a132b0f0bc5522f7a41c9492fbef768383b77dc5b3b077727c199","contract":["stringify encodes Buffer as base64 string prefixed with colon","parse decodes colon base64 prefixed string back to Buffer","stringify and parse round-trip nested objects containing Buffer instances","stringify and parse round-trip arrays containing Buffer instances","stringify escapes strings starting with colon by prepending an extra colon","stringify returns undefined for undefined input and omits undefined object properties","stringify serializes undefined elements in arrays as null","parse throws SyntaxError on invalid JSON input"],"goal":"serialize and deserialize Buffer objects with JSON using json-buffer","kind":"HOW","packages":["pkg:npm/json-buffer@3.0.1"],"schemaVersion":1,"symbols":["parse","stringify"]},"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/json-buffer@3.0.1"],"schemaVersion":1,"subject":"pkg:npm/json-buffer@3.0.1","symbols":["parse","stringify"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "json-buffer-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "json-buffer-verification",
      "version": "1.0.0",
      "dependencies": {
        "json-buffer": "3.0.1"
      }
    },
    "node_modules/json-buffer": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
      "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "json-buffer-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for json-buffer",
  "dependencies": {
    "json-buffer": "3.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "serialize and deserialize Buffer objects with JSON using json-buffer",
  "kind": "HOW",
  "packages": [
    "pkg:npm/json-buffer@3.0.1"
  ],
  "symbols": [
    "parse",
    "stringify"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import { parse, stringify } from 'json-buffer';

// 1. stringify encodes Buffer as base64 string prefixed with colon
const buf = Buffer.from('hello', 'utf8');
const json = stringify(buf);
assert.strictEqual(json, JSON.stringify(':base64:' + buf.toString('base64')));

// 2. parse decodes colon base64 prefixed string back to Buffer
const parsed = parse(json);
assert.ok(Buffer.isBuffer(parsed));
assert.strictEqual(parsed.toString('utf8'), 'hello');

// 3. stringify and parse round-trip nested objects containing Buffer instances
const obj = { id: 42, buf: Buffer.from([0xde, 0xad, 0xbe, 0xef]), text: 'sample' };
const encoded = stringify(obj);
const decoded = parse(encoded);
assert.strictEqual(decoded.id, 42);
assert.strictEqual(decoded.text, 'sample');
assert.ok(Buffer.isBuffer(decoded.buf));
assert.deepStrictEqual(Array.from(decoded.buf), [0xde, 0xad, 0xbe, 0xef]);

// 4. stringify and parse round-trip arrays containing Buffer instances
const arr = [Buffer.from('first'), 123, Buffer.from('second')];
const encodedArr = stringify(arr);
const decodedArr = parse(encodedArr);
assert.strictEqual(decodedArr.length, 3);
assert.ok(Buffer.isBuffer(decodedArr[0]));
assert.strictEqual(decodedArr[0].toString('utf8'), 'first');
assert.strictEqual(decodedArr[1], 123);
assert.ok(Buffer.isBuffer(decodedArr[2]));
assert.strictEqual(decodedArr[2].toString('utf8'), 'second');

// 5. stringify escapes strings starting with colon by prepending an extra colon
const colonStr = ':my-colon-string';
const encodedStr = stringify(colonStr);
assert.strictEqual(encodedStr, JSON.stringify('::my-colon-string'));
assert.strictEqual(parse(encodedStr), colonStr);

// 6. stringify returns undefined for undefined input and omits undefined object properties
assert.strictEqual(stringify(undefined), undefined);
const objWithUndef = { keep: 1, remove: undefined };
assert.strictEqual(stringify(objWithUndef), '{"keep":1}');

// 7. stringify serializes undefined elements in arrays as null
const arrWithUndef = [1, undefined, 3];
const encUndef = stringify(arrWithUndef);
assert.strictEqual(encUndef, '[1,null,3]');
assert.deepStrictEqual(parse(encUndef), [1, null, 3]);

// 8. parse throws SyntaxError on invalid JSON input
assert.throws(
  () => parse('{ malformed json }'),
  { name: 'SyntaxError' }
);

console.log('Contract passed');

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

аноним