CodeSampleX

샘플

flatted 3.4.3: parse

검증된 샘플 — npm flatted 3.4.3: parse. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: parse restores primitive values from a flatted JSON string

sha256:2510f10e8a238e184972655cc9998e2c976ad77511638bff0b42784146b1c8d4

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify flatted.parse in pkg:npm/flatted@3.4.3
패키지
심벌
  • flatted.parse
환경
node 22.23.2
생성일
2026-08-29T14:39:38Z

컨트랙트

  1. parse restores primitive values from a flatted JSON string
  2. parse reconstructs plain nested objects and arrays without circular references
  3. parse reconstructs self-referencing circular objects and arrays
  4. parse reconstructs mutually recursive cyclic object graphs
  5. parse preserves reference identity across multiple occurrences of shared objects
  6. parse transforms values using a custom reviver function
  7. parse throws SyntaxError when input is malformed or invalid JSON
  8. flatted namespace parse and named parse export provide identical functionality

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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: 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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  ]
}
src/index.mjs
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 };
test/contract.mjs
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.');

오리진 시더

익명