CodeSampleX

Ejemplo

json-stable-stringify-without-jsonify 1.0.1: stringify

Muestra verificada para npm json-stable-stringify-without-jsonify 1.0.1: stringify. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:69ffc299da3e9cb29a64c81af3890ac1dfe903b825797277e5d81e97363e2a8b

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-01

Caso

HOW
Objetivo
verify stringify in pkg:npm/json-stable-stringify-without-jsonify@1.0.1
Paquetes
Símbolos
  • stringify
Creado
2026-09-01T19:51:48Z

Contrato

  1. stringify deterministically sorts object keys in alphabetical order regardless of insertion order
  2. stringify supports custom indentation formatting using numeric and string space options
  3. stringify supports custom key comparator functions to define explicit sorting order
  4. stringify supports custom replacer functions to transform or filter object properties
  5. stringify safely handles circular references by returning a placeholder when cycles option is enabled
  6. stringify throws a TypeError on circular references when cycles option is disabled
  7. stringify respects custom toJSON serialization methods on objects
  8. stringify handles nested structures containing arrays, objects, and primitive values

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 stringify in pkg:npm/json-stable-stringify-without-jsonify@1.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/json-stable-stringify-without-jsonify@1.0.1
Demonstrate these symbols/APIs:
  - 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:a508428e5d204c21b9f1bb6bdbe463c8239eb056a6746c5434b02f4689d8fd9c","contract":["stringify deterministically sorts object keys in alphabetical order regardless of insertion order","stringify supports custom indentation formatting using numeric and string space options","stringify supports custom key comparator functions to define explicit sorting order","stringify supports custom replacer functions to transform or filter object properties","stringify safely handles circular references by returning a placeholder when cycles option is enabled","stringify throws a TypeError on circular references when cycles option is disabled","stringify respects custom toJSON serialization methods on objects","stringify handles nested structures containing arrays, objects, and primitive values"],"goal":"verify stringify in pkg:npm/json-stable-stringify-without-jsonify@1.0.1","kind":"HOW","packages":["pkg:npm/json-stable-stringify-without-jsonify@1.0.1"],"schemaVersion":1,"symbols":["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-stable-stringify-without-jsonify@1.0.1"],"schemaVersion":1,"subject":"pkg:npm/json-stable-stringify-without-jsonify@1.0.1","symbols":["stringify"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-json-stable-stringify-without-jsonify",
  "version": "1.0.1",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-json-stable-stringify-without-jsonify",
      "version": "1.0.1",
      "license": "MIT-0",
      "dependencies": {
        "json-stable-stringify-without-jsonify": "1.0.1"
      }
    },
    "node_modules/json-stable-stringify-without-jsonify": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz",
      "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-json-stable-stringify-without-jsonify",
  "version": "1.0.1",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "json-stable-stringify-without-jsonify": "1.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify stringify in pkg:npm/json-stable-stringify-without-jsonify@1.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/json-stable-stringify-without-jsonify@1.0.1"
  ],
  "symbols": [
    "stringify"
  ]
}
src/index.mjs
import stringify from 'json-stable-stringify-without-jsonify';

/**
 * Deterministically stringifies a JavaScript value into a stable JSON string.
 * @param {any} obj The value to serialize
 * @param {object|Function} [opts] Options object or comparison function
 * @returns {string|undefined} The serialized JSON string
 */
export function stableStringify(obj, opts) {
  return stringify(obj, opts);
}

export { stringify };
export default stringify;
test/contract.mjs
import assert from 'node:assert/strict';
import { stringify, stableStringify } from '../src/index.mjs';

// 1. stringify deterministically sorts object keys in alphabetical order regardless of insertion order
{
  const obj1 = { c: 3, a: 1, b: 2 };
  const obj2 = { b: 2, c: 3, a: 1 };
  const result1 = stringify(obj1);
  const result2 = stableStringify(obj2);

  assert.equal(result1, '{"a":1,"b":2,"c":3}');
  assert.equal(result2, '{"a":1,"b":2,"c":3}');
  assert.equal(result1, result2);
}

// 2. stringify supports custom indentation formatting using numeric and string space options
{
  const obj = { b: 2, a: 1 };
  const formattedWithNumber = stringify(obj, { space: 2 });
  assert.equal(formattedWithNumber, '{\n  "a": 1,\n  "b": 2\n}');

  const formattedWithString = stringify(obj, { space: '\t' });
  assert.equal(formattedWithString, '{\n\t"a": 1,\n\t"b": 2\n}');
}

// 3. stringify supports custom key comparator functions to define explicit sorting order
{
  const obj = { apple: 10, zebra: 20, banana: 30 };
  const customSorted = stringify(obj, {
    cmp: (a, b) => b.key.localeCompare(a.key)
  });
  assert.equal(customSorted, '{"zebra":20,"banana":30,"apple":10}');

  const cmpShorthand = stringify(obj, (a, b) => b.key.localeCompare(a.key));
  assert.equal(cmpShorthand, '{"zebra":20,"banana":30,"apple":10}');
}

// 4. stringify supports custom replacer functions to transform or filter object properties
{
  const obj = { id: 1, secret: 'password123', visible: true };
  const filtered = stringify(obj, {
    replacer: (key, value) => {
      if (key === 'secret') return undefined;
      if (typeof value === 'number') return value * 10;
      return value;
    }
  });
  assert.equal(filtered, '{"id":10,"visible":true}');
}

// 5. stringify safely handles circular references by returning a placeholder when cycles option is enabled
{
  const circularObj = { name: 'cycle-test' };
  circularObj.self = circularObj;

  const result = stringify(circularObj, { cycles: true });
  assert.equal(result, '{"name":"cycle-test","self":"__cycle__"}');
}

// 6. stringify throws a TypeError on circular references when cycles option is disabled
{
  const circularObj = { name: 'cycle-error' };
  circularObj.self = circularObj;

  assert.throws(
    () => stringify(circularObj),
    (err) => err instanceof TypeError && /Converting circular structure to JSON/.test(err.message)
  );
}

// 7. stringify respects custom toJSON serialization methods on objects
{
  const customObj = {
    x: 10,
    toJSON() {
      return { normalized: this.x * 2 };
    }
  };
  const result = stringify({ item: customObj });
  assert.equal(result, '{"item":{"normalized":20}}');
}

// 8. stringify handles nested structures containing arrays, objects, and primitive values
{
  const nested = {
    users: [
      { z: 'last', a: 'first' },
      { y: 2, b: 1 }
    ],
    count: 2,
    active: true,
    empty: null
  };
  const result = stringify(nested);
  assert.equal(
    result,
    '{"active":true,"count":2,"empty":null,"users":[{"a":"first","z":"last"},{"b":1,"y":2}]}'
  );
}

console.log('Contract assertions passed.');

Seeder de origen

anónimo