Ejemplo
flatted 3.4.3: parse
Muestra verificada para npm flatted 3.4.3: parse. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: parse restores primitive values from…
sha256:2510f10e8a238e184972655cc9998e2c976ad77511638bff0b42784146b1c8d4
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
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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-29 |
Caso
HOW- Objetivo
- verify flatted.parse in pkg:npm/flatted@3.4.3
- Paquetes
- Símbolos
-
- flatted.parse
- Entorno
- node 22.23.2
- Creado
- 2026-08-29T14:39:38Z
Contrato
- parse restores primitive values from a flatted JSON string
- parse reconstructs plain nested objects and arrays without circular references
- parse reconstructs self-referencing circular objects and arrays
- parse reconstructs mutually recursive cyclic object graphs
- parse preserves reference identity across multiple occurrences of shared objects
- parse transforms values using a custom reviver function
- parse throws SyntaxError when input is malformed or invalid JSON
- flatted namespace parse and named parse export provide identical functionality
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
Código fuente
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 flatted.parse in pkg:npm/flatted@3.4.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/flatted@3.4.3
Demonstrate these symbols/APIs:
- flatted.parse
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.
{"case":{"caseId":"case:sha256:3ec069fb92b1f3bace6eef3b0a393c174204f9d342ce6da63d172d696d6f43de","contract":["parse restores primitive values from a flatted JSON string","parse reconstructs plain nested objects and arrays without circular references","parse reconstructs self-referencing circular objects and arrays","parse reconstructs mutually recursive cyclic object graphs","parse preserves reference identity across multiple occurrences of shared objects","parse transforms values using a custom reviver function","parse throws SyntaxError when input is malformed or invalid JSON","flatted namespace parse and named parse export provide identical functionality"],"goal":"verify flatted.parse in pkg:npm/flatted@3.4.3","kind":"HOW","packages":["pkg:npm/flatted@3.4.3"],"schemaVersion":1,"symbols":["flatted.parse"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/flatted@3.4.3"],"schemaVersion":1,"subject":"pkg:npm/flatted@3.4.3","symbols":["flatted.parse"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-flatted-parse",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-flatted-parse",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"flatted": "3.4.3"
}
},
"node_modules/flatted": {
"version": "3.4.3",
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.3.tgz",
"integrity": "sha512-/zipXxyO6rGvuNGDiULY9MvEGSkb2gaG4GGH4ygMi0ZZzyMHdUZBmntJmx5x1G2VuPytCwGN4xsJP6cw+sK+vQ==",
"license": "ISC"
}
}
}
{
"name": "sample-flatted-parse",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"flatted": "3.4.3"
}
}
{
"schemaVersion": 1,
"goal": "verify flatted.parse in pkg:npm/flatted@3.4.3",
"kind": "HOW",
"packages": [
"pkg:npm/flatted@3.4.3"
],
"symbols": [
"flatted.parse"
]
}
import * as flatted from 'flatted';
const { parse, stringify, fromJSON, toJSON } = flatted;
/**
* Parses a flatted JSON string, resolving circular and recursive references.
*
* @param {string} text - The flatted JSON string to parse.
* @param {Function} [reviver] - Optional reviver function to transform parsed values.
* @returns {*} The parsed value or reconstituted object hierarchy.
*/
export function parseFlatted(text, reviver) {
return parse(text, reviver);
}
/**
* Serializes a value to a flatted JSON string capable of preserving circular references.
*
* @param {*} value - The value to serialize.
* @param {Function|Array} [replacer] - Optional replacer function or property whitelist.
* @param {string|number} [space] - Formatting whitespace.
* @returns {string} The serialized flatted JSON string.
*/
export function stringifyFlatted(value, replacer, space) {
return stringify(value, replacer, space);
}
export { parse, stringify, fromJSON, toJSON, flatted };
export default { parse, stringify, fromJSON, toJSON };
import assert from 'node:assert/strict';
import * as flatted from 'flatted';
import { parse, stringify } from 'flatted';
import { parseFlatted, stringifyFlatted } from '../src/index.mjs';
// 1. parse restores primitive values from a flatted JSON string
{
assert.equal(parse(stringify('hello')), 'hello');
assert.equal(parse(stringify(42)), 42);
assert.equal(parse(stringify(true)), true);
assert.equal(parse(stringify(false)), false);
assert.equal(parse(stringify(null)), null);
assert.equal(parseFlatted(stringifyFlatted('world')), 'world');
}
// 2. parse reconstructs plain nested objects and arrays without circular references
{
const obj = { name: 'Alice', age: 30, items: [1, 2, 3], nested: { valid: true } };
const parsed = parse(stringify(obj));
assert.deepEqual(parsed, obj);
assert.deepEqual(parseFlatted(stringifyFlatted(obj)), obj);
}
// 3. parse reconstructs self-referencing circular objects and arrays
{
const circularObj = { name: 'node' };
circularObj.self = circularObj;
const parsedObj = parse(stringify(circularObj));
assert.equal(parsedObj.name, 'node');
assert.equal(parsedObj.self, parsedObj);
assert.equal(parsedObj.self.self, parsedObj);
const circularArr = ['first'];
circularArr.push(circularArr);
const parsedArr = parse(stringify(circularArr));
assert.equal(parsedArr[0], 'first');
assert.equal(parsedArr[1], parsedArr);
assert.equal(parsedArr[1][1], parsedArr);
}
// 4. parse reconstructs mutually recursive cyclic object graphs
{
const parent = { name: 'parent' };
const child = { name: 'child', parent };
parent.child = child;
const parsed = parse(stringify(parent));
assert.equal(parsed.name, 'parent');
assert.equal(parsed.child.name, 'child');
assert.equal(parsed.child.parent, parsed);
assert.equal(parsed.child.parent.child, parsed.child);
}
// 5. parse preserves reference identity across multiple occurrences of shared objects
{
const shared = { id: 100, label: 'shared-data' };
const container = { a: shared, b: shared, list: [shared] };
const parsed = parse(stringify(container));
assert.equal(parsed.a, parsed.b);
assert.equal(parsed.a, parsed.list[0]);
parsed.a.label = 'modified';
assert.equal(parsed.b.label, 'modified');
assert.equal(parsed.list[0].label, 'modified');
}
// 6. parse transforms values using a custom reviver function
{
const data = { timestamp: '2026-01-01T00:00:00.000Z', count: '10' };
const serialized = stringify(data);
const parsed = parse(serialized, (key, value) => {
if (key === 'timestamp') return new Date(value);
if (key === 'count') return Number(value);
return value;
});
assert.ok(parsed.timestamp instanceof Date);
assert.equal(parsed.timestamp.toISOString(), '2026-01-01T00:00:00.000Z');
assert.equal(parsed.count, 10);
}
// 7. parse throws SyntaxError when input is malformed or invalid JSON
{
assert.throws(() => parse('invalid json'), SyntaxError);
assert.throws(() => parse('{unquoted: 123}'), SyntaxError);
}
// 8. flatted namespace parse and named parse export provide identical functionality
{
assert.equal(flatted.parse, parse);
const data = { x: 1 };
data.loop = data;
const result1 = flatted.parse(flatted.stringify(data));
const result2 = parse(stringify(data));
assert.deepEqual(result1.x, result2.x);
assert.equal(result1.loop, result1);
assert.equal(result2.loop, result2);
}
console.log('Contract tests passed successfully.');
Seeder de origen
anónimo